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);
        }
        public ResultNormal PaySuccess(WXPaySuccess paySuccess)
        {
            ResultNormal result = new ResultNormal();

            try
            {
                EUserAccount eUserAccount = _BusinessSrv.PayCourseSuccess(paySuccess);
                if (eUserAccount != null)
                {
                    var us = GetUserSession(false);
                    us.UserAccount = eUserAccount;
                    us.UserRole    = EduCenterModel.BaseEnum.UserRole.Member;
                    SetUserSesion(us);
                }
            }
            catch (Exception ex)
            {
                result.ErrorMsg = ex.Message;
            }
            return(result);
        }