Beispiel #1
0
        public EUserAccount PayCourseSuccess(WXPaySuccess wXPaySuccess)
        {
            EUserAccount eUserAccount = null;

            try
            {
                string orderId = wXPaySuccess.OrderId;
                //    NLogHelper.InfoTxt($"PayCourseSuccess OrderId:{orderId}");
                BeginTrans();
                //跟新订单状态
                var order = _dbContext.DBOrder.Where(a => a.OrderId == orderId && a.OrderStatus == OrderStatus.Created).FirstOrDefault();
                if (order == null)
                {
                    throw new Exception($"没有找到状态为[{ OrderStatus.Created}]的[{orderId}]订单,");
                }
                order.OrderStatus = OrderStatus.PaySuccess;

                //获取订单行,更新课时
                var line = _dbContext.DBOrderLine.Where(a => a.OrderId == orderId).FirstOrDefault();
                eUserAccount = UpdateUserAccountByOrderLine(order.CustOpenId, line);

                var ui = _dbContext.DBUserInfo.Where(a => a.OpenId == order.CustOpenId).FirstOrDefault();
                if (ui.UserRole == UserRole.Visitor)
                {
                    ui.UserRole = UserRole.Member;
                }
                //如果是JSPay
                if (wXPaySuccess.IsJSPay)
                {
                    ui.MemberType          = MemberType.VIP;
                    eUserAccount.VIPPrice1 = Math.Round(line.Price / line.Qty, 2);
                }
                //查看用户是否有邀请人

                SalesSrv salesSrv  = new SalesSrv(_dbContext);
                var      inviteLog = salesSrv.GetInviteLogByInvitedOpenId(ui.OpenId);
                if (inviteLog != null)
                {
                    salesSrv.CreateRewardTrans(inviteLog.Id, inviteLog.OwnOpenId, AmountTransType.Invited_Paied, out eUserAccount, false);
                }

                _dbContext.SaveChanges();
                CommitTrans();
            }
            catch (Exception ex)
            {
                RollBackTrans();
                NLogHelper.ErrorTxt($"[PayCourseSuccess] {ex.Message}");
                throw ex;
            }
            return(eUserAccount);
        }
Beispiel #2
0
        /// <summary>
        /// 被邀请用户首次进入公众号,绑定关系
        /// wxUser 因为获取方式不同
        /// </summary>
        /// <param name="wxMessage"></param>
        /// <param name="ownOpenId"></param>
        /// <returns></returns>
        public EUserInfo InvitedUserComing(string InvitedOpenId, string ownOpenId, WXUserInfo wxUser = null)
        {
            UserSrv   userSrv  = new UserSrv(_dbContext);
            SalesSrv  salesSrv = new SalesSrv(_dbContext);
            EUserInfo user     = null;

            try
            {
                if (wxUser == null)
                {
                    wxUser = WXApi.GetWXUserInfo(InvitedOpenId);
                }
            }
            catch (Exception ex)
            {
                NLogHelper.ErrorTxt($"businessSrv-[InvitedUserComing] -GetWXUserInfo Error:{ex.Message}");
                throw ex;
            }


            EUserInfo owner = null;

            try
            {
                //如果是老用户,不能绑定邀请
                if (!userSrv.IsExistUser(InvitedOpenId))
                {
                    owner = salesSrv.BindUser(ownOpenId, InvitedOpenId);
                }
            }
            catch (Exception ex)
            {
                NLogHelper.ErrorTxt($"businessSrv-[InvitedUserComing] -BindUser Error:{ex.Message}");
                throw ex;
            }

            try
            {
                user = userSrv.AddOrUpdateFromWXUser(wxUser, owner, false);
            }
            catch (Exception ex)
            {
                NLogHelper.ErrorTxt($"businessSrv-[InvitedUserComing] -AddOrUpdateFromWXUser Error:{ex.Message}");
                throw ex;
            }


            _dbContext.SaveChanges();
            return(user);
        }