示例#1
0
        public CustomJsonResult Apply(string pOperater, string pClientId, RopWithdrawApply rop)
        {
            CustomJsonResult result = new CustomJsonResult();

            lock (lock_Apply)
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    var fund = CurrentDb.Fund.Where(m => m.ClientId == pClientId).FirstOrDefault();

                    if (fund == null)
                    {
                        LogUtil.Error("用户Id:" + pClientId + ",在Fund表没有记录");
                        return(new CustomJsonResult(ResultType.Failure, "系统繁忙"));
                    }

                    if (rop.Amount <= 0)
                    {
                        return(new CustomJsonResult(ResultType.Failure, "提现金额必须大于0"));
                    }

                    if (fund.AvailableBalance < rop.Amount)
                    {
                        return(new CustomJsonResult(ResultType.Failure, "可提现余额不够"));
                    }

                    if (DateTime.Now > DateTime.Parse("2018-11-15 14:00:00"))
                    {
                        return(new CustomJsonResult(ResultType.Failure, "提现失败,已超过指定时间内提现,谢谢"));
                    }

                    var withdraw = new Withdraw();
                    withdraw.Id               = GuidUtil.New();
                    withdraw.Sn               = SnUtil.Build(Enumeration.BizSnType.Withraw, pClientId);
                    withdraw.ClientId         = pClientId;
                    withdraw.Amount           = rop.Amount;
                    withdraw.AcIdNumber       = rop.AcIdNumber;
                    withdraw.AcName           = rop.AcName;
                    withdraw.AcBank           = rop.AcBank;
                    withdraw.AcBankCardNumber = rop.AcBankCardNumber;
                    withdraw.ApplyTime        = this.DateTime;
                    withdraw.ApplyMethod      = "1";
                    withdraw.Status           = Enumeration.WithdrawStatus.Apply;
                    withdraw.Creator          = pOperater;
                    withdraw.CreateTime       = this.DateTime;
                    CurrentDb.Withdraw.Add(withdraw);

                    fund.AvailableBalance -= rop.Amount;
                    fund.LockBalance      += rop.Amount;
                    fund.Mender            = pOperater;
                    fund.MendTime          = this.DateTime;

                    var fundTrans = new FundTrans();
                    fundTrans.Id               = GuidUtil.New();
                    fundTrans.Sn               = SnUtil.Build(Enumeration.BizSnType.FundTrans, pClientId);
                    fundTrans.ClientId         = pClientId;
                    fundTrans.ChangeType       = Enumeration.FundTransChangeType.WtihdrawApply;
                    fundTrans.ChangeAmount     = -rop.Amount;
                    fundTrans.CurrentBalance   = fund.CurrentBalance;
                    fundTrans.AvailableBalance = fund.AvailableBalance;
                    fundTrans.LockBalance      = fund.LockBalance;
                    fundTrans.Creator          = pOperater;
                    fundTrans.CreateTime       = this.DateTime;
                    fundTrans.TipsIcon         = IconUtil.Withdraw;
                    fundTrans.Description      = string.Format("资金提现-到{0}({1})", withdraw.AcBank, CommonUtil.GetLastString(withdraw.AcBankCardNumber, 4));
                    CurrentDb.FundTrans.Add(fundTrans);
                    CurrentDb.SaveChanges();
                    ts.Complete();


                    var ret = new RetWithdrawApply();

                    ret.Id = withdraw.Id;

                    result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "提现申请成功", ret);
                }
            }

            return(result);
        }
示例#2
0
        public CustomJsonResult <RetOrderUnifiedOrder> UnifiedOrder(string operater, string clientId, RopOrderUnifiedOrder rop)
        {
            CustomJsonResult <RetOrderUnifiedOrder> result = new CustomJsonResult <RetOrderUnifiedOrder>();

            try
            {
                lock (lock_UnifiedOrder)
                {
                    var ret = new RetOrderUnifiedOrder();

                    using (TransactionScope ts = new TransactionScope())
                    {
                        LogUtil.Info("用户id:" + clientId);

                        var wxUserInfo = CurrentDb.WxUserInfo.Where(m => m.ClientId == clientId).FirstOrDefault();

                        if (wxUserInfo == null)
                        {
                            return(new CustomJsonResult <RetOrderUnifiedOrder>(ResultType.Failure, ResultCode.Failure, "找不到用户微信信息", null));
                        }

                        var orderByBuyed = CurrentDb.Order.Where(m => m.ClientId == clientId && m.PromoteId == rop.PromoteId && m.Status == Enumeration.OrderStatus.Payed).FirstOrDefault();
                        if (orderByBuyed != null)
                        {
                            return(new CustomJsonResult <RetOrderUnifiedOrder>(ResultType.Failure, ResultCode.Failure, "您已成功抢购,支付成功", null));
                        }

                        var promoteBlackList = CurrentDb.PromoteBlackList.Where(m => m.PromoteId == rop.PromoteId && m.ClientId == clientId).FirstOrDefault();
                        if (promoteBlackList != null)
                        {
                            return(new CustomJsonResult <RetOrderUnifiedOrder>(ResultType.Failure, ResultCode.Failure, "谢谢参与,已售罄", null));
                        }

                        var promote = CurrentDb.Promote.Where(m => m.Id == rop.PromoteId).FirstOrDefault();

                        if (promote != null)
                        {
                            if (promote.TargetType == Enumeration.PromoteTargetType.NotStudent)
                            {
                                var student = CurrentDb.Student.Where(m => m.Phone == rop.PromoteUser.CtPhone).FirstOrDefault();
                                if (student != null)
                                {
                                    return(new CustomJsonResult <RetOrderUnifiedOrder>(ResultType.Failure, ResultCode.Failure, "仅限于非学员参与报名,谢谢关注", null));
                                }
                            }


                            var promoteUser = CurrentDb.PromoteUser.Where(m => m.ClientId == clientId && m.PromoteId == rop.PromoteId).FirstOrDefault();

                            if (promoteUser == null)
                            {
                                promoteUser                    = new PromoteUser();
                                promoteUser.Id                 = GuidUtil.New();
                                promoteUser.PromoteId          = rop.PromoteId;
                                promoteUser.ClientId           = clientId;
                                promoteUser.BroadcastChannelId = rop.BcId;
                                promoteUser.RefereerId         = rop.RefereerId;
                                promoteUser.CtName             = rop.PromoteUser.CtName;
                                promoteUser.CtPhone            = rop.PromoteUser.CtPhone;
                                promoteUser.CtIsStudent        = rop.PromoteUser.CtIsStudent;
                                promoteUser.CtSchool           = rop.PromoteUser.CtSchool;
                                promoteUser.CreateTime         = DateTime.Now;
                                promoteUser.Creator            = operater;
                                CurrentDb.PromoteUser.Add(promoteUser);
                            }
                            else
                            {
                                promoteUser.BroadcastChannelId = rop.BcId;
                                promoteUser.RefereerId         = rop.RefereerId;
                                promoteUser.CtName             = rop.PromoteUser.CtName;
                                promoteUser.CtPhone            = rop.PromoteUser.CtPhone;
                                promoteUser.CtIsStudent        = rop.PromoteUser.CtIsStudent;
                                promoteUser.CtSchool           = rop.PromoteUser.CtSchool;
                            }



                            foreach (var sku in rop.Skus)
                            {
                                var productSku = CurrentDb.ProductSku.Where(m => m.Id == sku.SkuId).FirstOrDefault();

                                if (productSku == null)
                                {
                                    return(new CustomJsonResult <RetOrderUnifiedOrder>(ResultType.Failure, ResultCode.Failure, "找不到该商品", null));
                                }

                                var promoteSku = CurrentDb.PromoteSku.Where(m => m.PromoteId == rop.PromoteId && m.SkuId == sku.SkuId && m.BuyStartTime <= this.DateTime && m.BuyEndTime >= this.DateTime).FirstOrDefault();

                                if (promoteSku == null)
                                {
                                    return(new CustomJsonResult <RetOrderUnifiedOrder>(ResultType.Failure, ResultCode.Failure, "谢谢参与,活动已经结束", null));
                                }

                                if (!string.IsNullOrEmpty(promoteSku.RefereePromoteId))
                                {
                                    var clientCoupon = CurrentDb.ClientCoupon.Where(m => m.PromoteId == promoteSku.RefereePromoteId && m.ClientId == clientId && m.IsBuy == true).FirstOrDefault();
                                    if (clientCoupon == null)
                                    {
                                        return(new CustomJsonResult <RetOrderUnifiedOrder>(ResultType.Failure, ResultCode.Failure, "谢谢参与,您没有资格参与购买", null));
                                    }
                                }

                                if (promoteSku.StockQuantity > -1)
                                {
                                    if (promoteSku.SellQuantity <= 0)
                                    {
                                        return(new CustomJsonResult <RetOrderUnifiedOrder>(ResultType.Failure, ResultCode.Failure, "谢谢参与,商品已经售罄", null));
                                    }
                                }
                            }
                        }

                        var order = CurrentDb.Order.Where(m => m.PromoteId == rop.PromoteId && m.ClientId == clientId && m.Status == Entity.Enumeration.OrderStatus.WaitPay).FirstOrDefault();

                        if (order == null)
                        {
                            string orderId = GuidUtil.New();

                            var l_orderDetails = new List <OrderDetails>();

                            foreach (var sku in rop.Skus)
                            {
                                var productSku = CurrentDb.ProductSku.Where(m => m.Id == sku.SkuId).FirstOrDefault();

                                var productSkuOriginalPrice = productSku.SalePrice;
                                var productSkuSalePrice     = productSku.SalePrice;

                                var promoteSku = CurrentDb.PromoteSku.Where(m => m.PromoteId == rop.PromoteId && m.SkuId == sku.SkuId && m.BuyStartTime <= this.DateTime && m.BuyEndTime >= this.DateTime).FirstOrDefault();
                                if (promoteSku != null)
                                {
                                    productSkuSalePrice = promoteSku.SkuSalePrice;

                                    if (promoteSku.StockQuantity > -1)
                                    {
                                        promoteSku.SellQuantity -= 1;
                                        promoteSku.LockQuantity += 1;
                                    }
                                }

                                var orderDetails = new OrderDetails();
                                orderDetails.Id                 = GuidUtil.New();
                                orderDetails.ClientId           = clientId;
                                orderDetails.OrderId            = orderId;
                                orderDetails.BroadcastChannelId = rop.BcId;
                                orderDetails.PromoteId          = rop.PromoteId;
                                orderDetails.SkuId              = productSku.Id;
                                orderDetails.SkuName            = productSku.Name;
                                orderDetails.SkuImgUrl          = ImgSet.GetMain(productSku.DisplayImgUrls);
                                orderDetails.Quantity           = 1;
                                orderDetails.SalePrice          = productSkuSalePrice;
                                orderDetails.OriginalAmount     = productSkuOriginalPrice;
                                orderDetails.DiscountAmount     = productSkuOriginalPrice - productSkuSalePrice;
                                orderDetails.ChargeAmount       = orderDetails.OriginalAmount - orderDetails.DiscountAmount;
                                orderDetails.CreateTime         = this.DateTime;
                                orderDetails.Creator            = operater;
                                orderDetails.Status             = Enumeration.OrderDetailsStatus.WaitPay;
                                CurrentDb.OrderDetails.Add(orderDetails);
                                l_orderDetails.Add(orderDetails);
                            }


                            order                    = new Order();
                            order.Id                 = orderId;
                            order.ClientId           = clientId;
                            order.Sn                 = SnUtil.Build(Enumeration.BizSnType.Order, order.ClientId);
                            order.BroadcastChannelId = rop.BcId;
                            order.PromoteId          = rop.PromoteId;
                            order.RefereerId         = rop.RefereerId;
                            order.OriginalAmount     = l_orderDetails.Sum(m => m.OriginalAmount);
                            order.DiscountAmount     = l_orderDetails.Sum(m => m.DiscountAmount);
                            order.ChargeAmount       = order.OriginalAmount - order.DiscountAmount;
                            order.SubmitTime         = this.DateTime;
                            order.CreateTime         = this.DateTime;
                            order.Creator            = operater;
                            order.IsInVisiable       = true;
                            order.Status             = Enumeration.OrderStatus.WaitPay; //待支付状态

                            CurrentDb.Order.Add(order);
                            CurrentDb.SaveChanges();
                        }


                        bool    isNeedBuy    = true;
                        decimal chargeAmount = order.ChargeAmount;
                        if (chargeAmount <= 0)
                        {
                            isNeedBuy = false;
                        }

                        string[] testClientId = new string[2] {
                            "62c587c13c124f96b436de9522fb31f0", "4faecb3507aa48698405cf492dc26916"
                        };

                        if (isNeedBuy)
                        {
                            if (testClientId.Contains(order.ClientId))
                            {
                                chargeAmount = 0.01m;
                            }

                            string goods_tag = "";
                            string prepayId  = SdkFactory.Wx.Instance().GetPrepayId(operater, "JSAPI", wxUserInfo.OpenId, order.Sn, chargeAmount, goods_tag, Common.CommonUtil.GetIP(), "商品购买", order.PayExpireTime);
                            if (string.IsNullOrEmpty(prepayId))
                            {
                                LogUtil.Error("去结算,微信支付中生成预支付订单失败");
                                return(new CustomJsonResult <RetOrderUnifiedOrder>(ResultType.Failure, ResultCode.Failure, "抢购失败,刷新页面再试试", null));
                            }

                            order.WxPrepayId    = prepayId;
                            order.PayExpireTime = this.DateTime.AddMinutes(2);

                            Task4Factory.Tim2Global.Enter(TimerTaskType.CheckOrderPay, order.PayExpireTime.Value, order);

                            ret.IsBuy      = false;
                            ret.WxPrepayId = order.WxPrepayId;
                        }
                        else
                        {
                            ret.IsBuy = true;
                            BizFactory.Order.PayCompleted(operater, order.Sn, this.DateTime);
                        }

                        CurrentDb.SaveChanges();
                        ts.Complete();

                        ret.OrderId = order.Id;
                        ret.OrderSn = order.Sn;

                        result = new CustomJsonResult <RetOrderUnifiedOrder>(ResultType.Success, ResultCode.Success, "操作成功", ret);
                        LogUtil.Info("去结算结束");
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                LogUtil.Error("检查下单发生异常", ex);

                return(new CustomJsonResult <RetOrderUnifiedOrder>(ResultType.Exception, ResultCode.Exception, "下单发生异常", null));
            }
        }
        private void PromoteRefereerRewardByBuyerBuy()
        {
            LogUtil.Info(string.Format("正在处理消息类型为:{0},具体的参数未:{1}", this.Type.GetCnName(), Newtonsoft.Json.JsonConvert.SerializeObject(this.Pms)));

            using (LumosDbContext CurrentDb = new LumosDbContext())
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    #region 购买前奖励
                    var model = ((JObject)this.Pms).ToObject <RedisMqHandlePms4PromoteRefereerRewardByBuyerBuy>();

                    var promote = CurrentDb.Promote.Where(m => m.Id == model.PromoteId).FirstOrDefault();

                    if (promote == null)
                    {
                        LogUtil.Info("活动:" + model.PromoteId + ",为空");
                        return;
                    }

                    if (model.BuyerId == null)
                    {
                        LogUtil.Info("购买人,为空");
                        return;
                    }

                    if (model.RefereerId == null)
                    {
                        LogUtil.Info("推荐人,为空");
                        return;
                    }

                    if (model.BuyerId == model.RefereerId)
                    {
                        LogUtil.Info("购买人和推荐人是同一个人");
                        return;
                    }



                    var promoteRefereerRewardSets = CurrentDb.PromoteRefereerRewardSet.Where(m => m.PromoteId == model.PromoteId && m.Channel == Enumeration.PromoteRefereerRewardSetChannel.BuyerBuyProductSku).ToList();

                    if (promoteRefereerRewardSets.Count > 0)
                    {
                        foreach (var reward in promoteRefereerRewardSets)
                        {
                            var rewardModel = Newtonsoft.Json.JsonConvert.DeserializeObject <RewardModel>(reward.Reward);

                            var promoteRefereerRewardFactor = CurrentDb.PromoteRefereerRewardFactor.Where(m => m.RefereerId == model.RefereerId && m.PromoteId == reward.PromoteId && m.PromoteRefereerRewardSetId == reward.Id).FirstOrDefault();
                            if (promoteRefereerRewardFactor == null)
                            {
                                promoteRefereerRewardFactor    = new PromoteRefereerRewardFactor();
                                promoteRefereerRewardFactor.Id = GuidUtil.New();
                                promoteRefereerRewardFactor.PromoteRefereerRewardSetId = reward.Id;
                                promoteRefereerRewardFactor.RefereerId = model.RefereerId;
                                promoteRefereerRewardFactor.PromoteId  = model.PromoteId;
                                promoteRefereerRewardFactor.Factor     = reward.IncreaseFactor;
                                CurrentDb.PromoteRefereerRewardFactor.Add(promoteRefereerRewardFactor);
                                CurrentDb.SaveChanges();
                            }

                            if (model.RefereerRefereeCount == promoteRefereerRewardFactor.Factor)
                            {
                                promoteRefereerRewardFactor.Factor += reward.IncreaseFactor;

                                foreach (var gift in rewardModel.Gifts)
                                {
                                    var giftGive = CurrentDb.GiftGive.Where(m => m.ClientId == model.RefereerId && m.SkuId == gift.SkuId).FirstOrDefault();
                                    if (giftGive == null)
                                    {
                                        giftGive                   = new GiftGive();
                                        giftGive.Id                = GuidUtil.New();
                                        giftGive.ClientId          = model.RefereerId;
                                        giftGive.CurrentQuantity   = gift.Quantity;
                                        giftGive.AvailableQuantity = gift.Quantity;
                                        giftGive.LockQuantity      = 0;
                                        giftGive.SkuId             = gift.SkuId;
                                        giftGive.Creator           = GuidUtil.New();
                                        giftGive.CreateTime        = DateTime.Now;
                                        CurrentDb.GiftGive.Add(giftGive);
                                        CurrentDb.SaveChanges();
                                    }
                                    else
                                    {
                                        giftGive.CurrentQuantity   += gift.Quantity;
                                        giftGive.AvailableQuantity += gift.Quantity;
                                        giftGive.Mender             = GuidUtil.New();
                                        giftGive.MendTime           = DateTime.Now;
                                    }


                                    var giftGiveTrans = new GiftGiveTrans();
                                    giftGiveTrans.Id                = GuidUtil.New();
                                    giftGiveTrans.Sn                = SnUtil.Build(Enumeration.BizSnType.GiftGiveTrans, model.RefereerId);
                                    giftGiveTrans.ClientId          = model.RefereerId;
                                    giftGiveTrans.SkuId             = giftGive.SkuId;
                                    giftGiveTrans.ChangeType        = Enumeration.GiftGiveTransType.SignupGift;
                                    giftGiveTrans.ChangeQuantity    = gift.Quantity;
                                    giftGiveTrans.AvailableQuantity = giftGive.AvailableQuantity;
                                    giftGiveTrans.CurrentQuantity   = giftGive.CurrentQuantity;
                                    giftGiveTrans.LockQuantity      = giftGive.LockQuantity;
                                    giftGiveTrans.Description       = "您推荐的用户参与报名成功,得到奖品";
                                    giftGiveTrans.Creator           = GuidUtil.New();
                                    giftGiveTrans.CreateTime        = DateTime.Now;
                                    CurrentDb.GiftGiveTrans.Add(giftGiveTrans);
                                    CurrentDb.SaveChanges();
                                }
                            }
                        }
                    }



                    //var fund = CurrentDb.Fund.Where(m => m.ClientId == model.RefereerId).FirstOrDefault();

                    //if (fund == null)
                    //{
                    //    LogUtil.Info("用户:" + model.ClientId + ",找不到钱包");
                    //    return;
                    //}

                    //var wxUserInfo = CurrentDb.WxUserInfo.Where(m => m.ClientId == model.ClientId).FirstOrDefault();

                    //if (wxUserInfo == null)
                    //{
                    //    LogUtil.Info("用户:" + model.ClientId + ",找不到信息");
                    //    return;
                    //}

                    //var order = CurrentDb.Order.Where(m => m.Id == model.OrderId).FirstOrDefault();

                    //if (order == null)
                    //{
                    //    LogUtil.Info("订单:" + model.OrderId + ",找不到信息");
                    //    return;
                    //}

                    //if (order.BuyProfitIsSettled)
                    //{
                    //    LogUtil.Info("订单:" + model.OrderId + ",已经结算佣金");
                    //    return;
                    //}

                    //order.BuyProfitIsSettled = true;
                    //order.BuyProfitSettledTime = DateTime.Now;

                    //string nickname = "";
                    //string headImgUrl = IconUtil.BuyCoupon;
                    //if (wxUserInfo != null)
                    //{
                    //    nickname = wxUserInfo.Nickname;

                    //    if (!string.IsNullOrEmpty(wxUserInfo.HeadImgUrl))
                    //    {
                    //        headImgUrl = wxUserInfo.HeadImgUrl;
                    //    }
                    //}

                    //decimal profit = 0;

                    //fund.CurrentBalance += profit;
                    //fund.AvailableBalance += profit;
                    //fund.MendTime = DateTime.Now;
                    //fund.Mender = GuidUtil.Empty();

                    //var fundTrans = new FundTrans();
                    //fundTrans.Id = GuidUtil.New();
                    //fundTrans.Sn = SnUtil.Build(Enumeration.BizSnType.FundTrans, fund.ClientId);
                    //fundTrans.ClientId = fund.ClientId;
                    //fundTrans.ChangeType = Enumeration.FundTransChangeType.BuyCoupon;
                    //fundTrans.ChangeAmount = profit;
                    //fundTrans.CurrentBalance = fund.CurrentBalance;
                    //fundTrans.AvailableBalance = fund.AvailableBalance;
                    //fundTrans.LockBalance = fund.LockBalance;
                    //fundTrans.CreateTime = DateTime.Now;
                    //fundTrans.Creator = GuidUtil.Empty();
                    //fundTrans.Description = string.Format("分享给用户({0})购买入场券", nickname);
                    //fundTrans.TipsIcon = headImgUrl;
                    //fundTrans.IsNoDisplay = false;
                    //CurrentDb.FundTrans.Add(fundTrans);
                    CurrentDb.SaveChanges();
                    ts.Complete();

                    #endregion
                }
            }
        }
示例#4
0
        public CustomJsonResult PayCompleted(string operater, string orderSn, DateTime completedTime)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                var order = CurrentDb.Order.Where(m => m.Sn == orderSn).FirstOrDefault();

                if (order == null)
                {
                    return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, string.Format("找不到该订单号({0})", orderSn)));
                }

                if (order.Status == Enumeration.OrderStatus.Payed || order.Status == Enumeration.OrderStatus.Completed)
                {
                    return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, string.Format("订单号({0})已经支付通知成功", orderSn)));
                }

                if (order.Status != Enumeration.OrderStatus.WaitPay)
                {
                    return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, string.Format("找不到该订单号({0})", orderSn)));
                }

                order.Status       = Enumeration.OrderStatus.Payed;
                order.PayTime      = this.DateTime;
                order.MendTime     = this.DateTime;
                order.Mender       = operater;
                order.IsInVisiable = false;

                var orderDetails = CurrentDb.OrderDetails.Where(m => m.OrderId == order.Id).ToList();

                foreach (var orderDetail in orderDetails)
                {
                    orderDetail.Status = Enumeration.OrderDetailsStatus.Payed;

                    #region  活动处理
                    if (!string.IsNullOrEmpty(orderDetail.PromoteId))
                    {
                        var promoteSku = CurrentDb.PromoteSku.Where(m => m.PromoteId == order.PromoteId && m.SkuId == orderDetail.SkuId).FirstOrDefault();

                        if (promoteSku != null)
                        {
                            if (promoteSku.StockQuantity > 0)
                            {
                                promoteSku.LockQuantity  -= orderDetail.Quantity;
                                promoteSku.StockQuantity -= orderDetail.Quantity;
                            }

                            promoteSku.SaleQuantity += orderDetail.Quantity;;

                            if (promoteSku.IsCoupon)
                            {
                                #region 优惠券处理
                                var clientCoupon = CurrentDb.ClientCoupon.Where(m => m.ClientId == order.ClientId && m.PromoteId == order.PromoteId && m.SkuId == promoteSku.SkuId).FirstOrDefault();
                                if (clientCoupon == null)
                                {
                                    clientCoupon            = new ClientCoupon();
                                    clientCoupon.Id         = GuidUtil.New();
                                    clientCoupon.ClientId   = order.ClientId;
                                    clientCoupon.PromoteId  = order.PromoteId;
                                    clientCoupon.SkuId      = promoteSku.SkuId;
                                    clientCoupon.WxCouponId = promoteSku.WxCouponId;
                                    clientCoupon.IsBuy      = true;
                                    clientCoupon.BuyTime    = this.DateTime;
                                    clientCoupon.IsGet      = false;
                                    clientCoupon.IsConsume  = false;
                                    clientCoupon.Creator    = operater;
                                    clientCoupon.CreateTime = this.DateTime;
                                    clientCoupon.RefereerId = order.RefereerId;
                                    clientCoupon.OrderId    = order.Id;
                                    clientCoupon.OrderSn    = order.Sn;

                                    if (!string.IsNullOrEmpty(promoteSku.ExtAtrrs))
                                    {
                                        CouponModel couponModel = null;
                                        try
                                        {
                                            couponModel = Newtonsoft.Json.JsonConvert.DeserializeObject <CouponModel>(promoteSku.ExtAtrrs);
                                        }
                                        catch
                                        {
                                            couponModel = null;
                                        }

                                        if (couponModel != null)
                                        {
                                            clientCoupon.Name           = couponModel.Name;
                                            clientCoupon.Number         = couponModel.Number;
                                            clientCoupon.NumberType     = couponModel.NumberType;
                                            clientCoupon.NumberUnit     = couponModel.NumberUnit;
                                            clientCoupon.ValidStartTime = couponModel.ValidStartTime;
                                            clientCoupon.ValidEndTime   = couponModel.ValidEndTime;
                                            clientCoupon.Description    = couponModel.Description;
                                            clientCoupon.Discounttip    = couponModel.Discounttip;
                                        }
                                    }

                                    CurrentDb.ClientCoupon.Add(clientCoupon);
                                    CurrentDb.SaveChanges();
                                }
                                #endregion
                            }

                            if (promoteSku.IsGiftGive)
                            {
                                #region 奖品处理
                                var giftGive = CurrentDb.GiftGive.Where(m => m.ClientId == order.ClientId && m.SkuId == orderDetail.SkuId).FirstOrDefault();
                                if (giftGive == null)
                                {
                                    giftGive                   = new GiftGive();
                                    giftGive.Id                = GuidUtil.New();
                                    giftGive.ClientId          = order.ClientId;
                                    giftGive.CurrentQuantity   = orderDetail.Quantity;
                                    giftGive.AvailableQuantity = orderDetail.Quantity;
                                    giftGive.LockQuantity      = 0;
                                    giftGive.SkuId             = orderDetail.SkuId;
                                    giftGive.Creator           = operater;
                                    giftGive.CreateTime        = this.DateTime;
                                    CurrentDb.GiftGive.Add(giftGive);
                                    CurrentDb.SaveChanges();
                                }
                                else
                                {
                                    giftGive.CurrentQuantity   += orderDetail.Quantity;
                                    giftGive.AvailableQuantity += orderDetail.Quantity;
                                    giftGive.Mender             = operater;
                                    giftGive.MendTime           = this.DateTime;
                                }

                                var giftGiveTrans = new GiftGiveTrans();
                                giftGiveTrans.Id                = GuidUtil.New();
                                giftGiveTrans.Sn                = SnUtil.Build(Enumeration.BizSnType.GiftGiveTrans, order.ClientId);
                                giftGiveTrans.ClientId          = order.ClientId;
                                giftGiveTrans.SkuId             = giftGive.SkuId;
                                giftGiveTrans.ChangeType        = Enumeration.GiftGiveTransType.SignupGift;
                                giftGiveTrans.ChangeQuantity    = orderDetail.Quantity;
                                giftGiveTrans.AvailableQuantity = giftGive.AvailableQuantity;
                                giftGiveTrans.CurrentQuantity   = giftGive.CurrentQuantity;
                                giftGiveTrans.LockQuantity      = giftGive.LockQuantity;
                                giftGiveTrans.Description       = "参与报名成功,赠送";
                                giftGiveTrans.Creator           = operater;
                                giftGiveTrans.CreateTime        = this.DateTime;
                                CurrentDb.GiftGiveTrans.Add(giftGiveTrans);
                                CurrentDb.SaveChanges();
                                #endregion
                            }
                        }
                    }
                    #endregion
                }


                var refereerRefereeCount = CurrentDb.PromoteUser.Where(m => m.PromoteId == order.PromoteId && m.RefereerId == order.RefereerId && m.ClientId != m.RefereerId).Count();


                CurrentDb.SaveChanges();
                ts.Complete();

                var handlePms = new RedisMqHandlePms4PromoteRefereerRewardByBuyerBuy();
                handlePms.OrderId              = order.Id;
                handlePms.BuyerId              = order.ClientId;
                handlePms.PromoteId            = order.PromoteId;
                handlePms.RefereerId           = order.RefereerId;
                handlePms.RefereerRefereeCount = refereerRefereeCount;

                ReidsMqFactory.Global.Push(RedisMqHandleType.PromoteRefereerRewardByBuyerBuy, handlePms);

                result = new CustomJsonResult(ResultType.Success, ResultCode.Success, string.Format("支付完成通知:订单号({0})通知成功", orderSn));
            }

            return(result);
        }
示例#5
0
        public CustomJsonResult Audit(string pOperater, RopWithdrawAudit rop)
        {
            CustomJsonResult result = new CustomJsonResult();


            using (TransactionScope ts = new TransactionScope())
            {
                var withdraw = CurrentDb.Withdraw.Where(m => m.Id == rop.WithdrawId).FirstOrDefault();

                if (withdraw == null)
                {
                    return(new CustomJsonResult(ResultType.Failure, "找不到提现记录"));
                }

                if (withdraw.Status == Enumeration.WithdrawStatus.Handing)
                {
                    return(new CustomJsonResult(ResultType.Failure, "该提现申请正在处理中"));
                }

                if (withdraw.Status == Enumeration.WithdrawStatus.Success || withdraw.Status == Enumeration.WithdrawStatus.Failure)
                {
                    return(new CustomJsonResult(ResultType.Failure, "该提现申请已经被处理"));
                }

                withdraw.AuditComments = rop.AuditComments;

                switch (rop.Operate)
                {
                case RopWithdrawAuditOperate.Pass:
                    withdraw.Status    = Enumeration.WithdrawStatus.Handing;
                    withdraw.Mender    = pOperater;
                    withdraw.MendTime  = this.DateTime;
                    withdraw.Auditor   = pOperater;
                    withdraw.AuditTime = this.DateTime;

                    result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "审核通过");

                    break;

                case RopWithdrawAuditOperate.NoPass:

                    withdraw.Status        = Enumeration.WithdrawStatus.Failure;
                    withdraw.FailureReason = rop.AuditComments;
                    withdraw.Mender        = pOperater;
                    withdraw.MendTime      = this.DateTime;
                    withdraw.Auditor       = pOperater;
                    withdraw.AuditTime     = this.DateTime;

                    var fund = CurrentDb.Fund.Where(m => m.ClientId == withdraw.ClientId).FirstOrDefault();

                    fund.AvailableBalance += withdraw.Amount;
                    fund.LockBalance      -= withdraw.Amount;
                    fund.Mender            = pOperater;
                    fund.MendTime          = this.DateTime;

                    var fundTrans = new FundTrans();
                    fundTrans.Id               = GuidUtil.New();
                    fundTrans.Sn               = SnUtil.Build(Enumeration.BizSnType.FundTrans, withdraw.ClientId);
                    fundTrans.ClientId         = withdraw.ClientId;
                    fundTrans.ChangeType       = Enumeration.FundTransChangeType.WtihdrawFailure;
                    fundTrans.ChangeAmount     = withdraw.Amount;
                    fundTrans.CurrentBalance   = fund.CurrentBalance;
                    fundTrans.AvailableBalance = fund.AvailableBalance;
                    fundTrans.LockBalance      = fund.LockBalance;
                    fundTrans.Creator          = pOperater;
                    fundTrans.CreateTime       = this.DateTime;
                    fundTrans.Description      = string.Format("资金提现失败,原因:{0}", withdraw.FailureReason);
                    fundTrans.TipsIcon         = IconUtil.Withdraw;
                    fundTrans.IsNoDisplay      = false;
                    CurrentDb.FundTrans.Add(fundTrans);

                    result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "审核不通过");
                    break;

                default:
                    result = new CustomJsonResult(ResultType.Failure, "未知操作");
                    break;
                }

                CurrentDb.SaveChanges();
                ts.Complete();
            }


            return(result);
        }