Esempio n. 1
0
 internal void Delete(VipAmountDetailEntity dbEntity)
 {
     using (var conn = new SqlConnection(ConnectionString.XgxInsert))
     {
         conn.Open();
         conn.Delete(dbEntity);
     }
 }
Esempio n. 2
0
 internal void Update(VipAmountDetailEntity dbEntity)
 {
     using (var conn = new SqlConnection(ConnectionString.XgxInsert))
     {
         dbEntity.LastUpdateTime = System.DateTime.Now;
         //dbEntity.LastUpdateBy = "ERP";
         conn.Open();
         conn.Update(dbEntity);
     }
 }
Esempio n. 3
0
        private VipAmountDetailEntity ConvertToVipAmountDetailEntity(AmountIntergralContract contract)
        {
            var vipCardVipMappingFacade = new VipCardVipMappingFacade();
            var result = new VipAmountDetailEntity
            {
                VipAmountDetailId = Guid.NewGuid(),
                VipId             = contract.VipId,
                VipCardCode       = vipCardVipMappingFacade.GetVipCardCodeByVipId(contract.VipId),
                Amount            = contract.VipAmount,
                UsedReturnAmount  = 0,
                Reason            = "从新干线同步",
                CustomerID        = ConfigMgr.CustomerId,
                CreateTime        = contract.CreateTime == null ? DateTime.Now : contract.CreateTime,
                CreateBy          = "xgx",
                LastUpdateTime    = contract.ModifyTime == null ? DateTime.Now : contract.ModifyTime,
                LastUpdateBy      = "xgx",
                IsDelete          = 0,
                AmountSourceId    = "45"
            };

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// 计算超级分销商佣金分润
        /// </summary>
        /// <param name="loggingSessionInfo"></param>
        /// <param name="orderInfo"></param>
        public void CalculateSuperRetailTraderOrder(LoggingSessionInfo loggingSessionInfo, T_InoutEntity orderInfo)
        {
            if (orderInfo != null)
            {
                if (orderInfo.data_from_id == "35" || orderInfo.data_from_id == "36")
                {
                    T_SuperRetailTraderBLL bllSuperRetailTrader = new T_SuperRetailTraderBLL(loggingSessionInfo);
                    DataSet dsAllFather = bllSuperRetailTrader.GetAllFather(orderInfo.sales_user);
                    if (dsAllFather != null && dsAllFather.Tables.Count > 0 && dsAllFather.Tables[0].Rows.Count > 0)
                    {
                        T_SuperRetailTraderProfitConfigBLL bllSuperRetailTraderProfitConfig = new T_SuperRetailTraderProfitConfigBLL(loggingSessionInfo);
                        T_SuperRetailTraderConfigBLL       bllSuperRetailTraderConfig       = new T_SuperRetailTraderConfigBLL(loggingSessionInfo);
                        T_SuperRetailTraderProfitDetailBLL bllSuperRetailTraderProfitDetail = new T_SuperRetailTraderProfitDetailBLL(loggingSessionInfo);

                        VipAmountBLL       bllVipAmount       = new VipAmountBLL(loggingSessionInfo);
                        VipAmountDetailBLL bllVipAmountDetail = new VipAmountDetailBLL(loggingSessionInfo);

                        var entitySuperRetailTraderProfitConfig = bllSuperRetailTraderProfitConfig.QueryByEntity(new T_SuperRetailTraderProfitConfigEntity()
                        {
                            CustomerId = loggingSessionInfo.ClientID, IsDelete = 0, Status = "10"
                        }, null);
                        var entityConfig = bllSuperRetailTraderConfig.QueryByEntity(new T_SuperRetailTraderConfigEntity()
                        {
                            CustomerId = loggingSessionInfo.ClientID, IsDelete = 0
                        }, null).SingleOrDefault();
                        if (entityConfig != null && entitySuperRetailTraderProfitConfig != null)
                        {
                            //佣金比列
                            decimal SkuCommission = Convert.ToDecimal(entityConfig.SkuCommission) * Convert.ToDecimal(0.01);
                            //商品分润比列
                            decimal DistributionProfit = Convert.ToDecimal(entityConfig.DistributionProfit) * Convert.ToDecimal(0.01);


                            foreach (DataRow dr in dsAllFather.Tables[0].Rows)
                            {
                                decimal amount            = 0;
                                string  strAmountSourceId = string.Empty;
                                T_SuperRetailTraderProfitConfigEntity singlProfitConfig = new T_SuperRetailTraderProfitConfigEntity();
                                if (dr["level"].ToString() == "1")    //佣金
                                {
                                    strAmountSourceId = "34";
                                    singlProfitConfig = entitySuperRetailTraderProfitConfig.Where(a => a.Level == Convert.ToInt16(dr["level"].ToString())).SingleOrDefault();
                                    if (singlProfitConfig != null)
                                    {
                                        if (singlProfitConfig.ProfitType == "Percent")
                                        {
                                            amount = Convert.ToDecimal(orderInfo.actual_amount) * SkuCommission;
                                        }
                                    }
                                }
                                else    //分润
                                {
                                    strAmountSourceId = "33";
                                    singlProfitConfig = entitySuperRetailTraderProfitConfig.Where(a => a.Level == Convert.ToInt16(dr["level"].ToString())).SingleOrDefault();
                                    if (singlProfitConfig != null)
                                    {
                                        if (singlProfitConfig.ProfitType == "Percent")
                                        {
                                            amount = Convert.ToDecimal(orderInfo.actual_amount) * Convert.ToDecimal(singlProfitConfig.Profit) * Convert.ToDecimal(0.01);
                                        }
                                    }
                                }
                                if (amount > 0)
                                {
                                    IDbTransaction tran = new JIT.CPOS.BS.DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction();
                                    try
                                    {
                                        T_SuperRetailTraderProfitDetailEntity entitySuperRetailTraderProfitDetail = new T_SuperRetailTraderProfitDetailEntity()
                                        {
                                            SuperRetailTraderProfitConfigId = singlProfitConfig.SuperRetailTraderProfitConfigId,
                                            SuperRetailTraderID             = new Guid(dr["SuperRetailTraderID"].ToString()),
                                            Level             = Convert.ToInt16(dr["level"].ToString()),
                                            ProfitType        = "Cash",
                                            Profit            = amount,
                                            OrderType         = "Order",
                                            OrderId           = orderInfo.order_id,
                                            OrderDate         = Convert.ToDateTime(orderInfo.order_date),
                                            VipId             = orderInfo.vip_no,
                                            OrderActualAmount = orderInfo.actual_amount,
                                            SalesId           = new Guid(orderInfo.sales_user),
                                            OrderNo           = orderInfo.order_no,
                                            CustomerId        = loggingSessionInfo.ClientID
                                        };


                                        bllSuperRetailTraderProfitDetail.Create(entitySuperRetailTraderProfitDetail, (SqlTransaction)tran);


                                        VipAmountDetailEntity entityVipAmountDetail = new VipAmountDetailEntity();
                                        VipAmountEntity       entityVipAmount       = new VipAmountEntity();
                                        entityVipAmountDetail = new VipAmountDetailEntity
                                        {
                                            VipAmountDetailId = Guid.NewGuid(),
                                            VipId             = dr["SuperRetailTraderID"].ToString(),
                                            Amount            = amount,
                                            UsedReturnAmount  = 0,
                                            EffectiveDate     = DateTime.Now,
                                            DeadlineDate      = Convert.ToDateTime("9999-12-31 23:59:59"),
                                            AmountSourceId    = strAmountSourceId,
                                            ObjectId          = orderInfo.order_id,
                                            CustomerID        = loggingSessionInfo.ClientID,
                                            Reason            = "超级分销商"
                                        };
                                        bllVipAmountDetail.Create(entityVipAmountDetail, (SqlTransaction)tran);

                                        entityVipAmount = bllVipAmount.QueryByEntity(new VipAmountEntity()
                                        {
                                            VipId = dr["SuperRetailTraderID"].ToString(), IsDelete = 0, CustomerID = loggingSessionInfo.ClientID
                                        }, null).SingleOrDefault();
                                        if (entityVipAmount == null)
                                        {
                                            entityVipAmount = new VipAmountEntity
                                            {
                                                VipId                  = dr["SuperRetailTraderID"].ToString(),
                                                BeginAmount            = 0,
                                                InAmount               = amount,
                                                OutAmount              = 0,
                                                EndAmount              = amount,
                                                TotalAmount            = amount,
                                                BeginReturnAmount      = 0,
                                                InReturnAmount         = 0,
                                                OutReturnAmount        = 0,
                                                ReturnAmount           = 0,
                                                ImminentInvalidRAmount = 0,
                                                InvalidReturnAmount    = 0,
                                                ValidReturnAmount      = 0,
                                                TotalReturnAmount      = 0,
                                                IsLocking              = 0,
                                                CustomerID             = loggingSessionInfo.ClientID,
                                                VipCardCode            = ""
                                            };
                                            bllVipAmount.Create(entityVipAmount, tran);
                                        }
                                        else
                                        {
                                            entityVipAmount.InReturnAmount    = (entityVipAmount.InReturnAmount == null ? 0 : entityVipAmount.InReturnAmount.Value) + amount;
                                            entityVipAmount.TotalReturnAmount = (entityVipAmount.TotalReturnAmount == null ? 0 : entityVipAmount.TotalReturnAmount.Value) + amount;

                                            entityVipAmount.ValidReturnAmount = (entityVipAmount.ValidReturnAmount == null ? 0 : entityVipAmount.ValidReturnAmount.Value) + amount;
                                            entityVipAmount.ReturnAmount      = (entityVipAmount.ReturnAmount == null ? 0 : entityVipAmount.ReturnAmount.Value) + amount;

                                            bllVipAmount.Update(entityVipAmount);
                                        }
                                        tran.Commit();
                                    }
                                    catch (Exception)
                                    {
                                        tran.Rollback();
                                        throw;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="pEntity"></param>
 public void Delete(VipAmountDetailEntity pEntity)
 {
     _currentDAO.Delete(pEntity);
 }
Esempio n. 6
0
        /// <summary>
        /// 返现处理
        /// </summary>
        /// <param name="vipInfo">会员信息</param>
        /// <param name="unitInfo">门店信息</param>
        /// <param name="detailInfo">余额变更明细</param>
        /// <param name="tran">事务</param>
        /// <param name="loggingSessionInfo">登录信息</param>
        /// <param name="amountSourceId"></param>
        public string AddReturnAmount(VipEntity vipInfo, t_unitEntity unitInfo, VipAmountEntity vipAmountInfo, ref VipAmountDetailEntity detailInfo, SqlTransaction tran, LoggingSessionInfo loggingSessionInfo)
        {
            string vipAmountDetailId       = string.Empty;//变更明细ID
            var    vipAmountDao            = new VipAmountBLL(loggingSessionInfo);
            var    vipAmountDetailDao      = new VipAmountDetailBLL(loggingSessionInfo);
            var    customerBasicSettingBLL = new CustomerBasicSettingBLL(loggingSessionInfo);

            //获取返现有效期
            int cashValidPeriod     = 2; //默认为1,业务处理时会减去1
            var cashValidPeriodInfo = customerBasicSettingBLL.QueryByEntity(new CustomerBasicSettingEntity()
            {
                SettingCode = "CashValidPeriod", CustomerID = loggingSessionInfo.ClientID
            }, null).FirstOrDefault();

            if (cashValidPeriodInfo != null)
            {
                cashValidPeriod = int.Parse(cashValidPeriodInfo.SettingValue);
            }

            //var vipAmountInfo = vipAmountDao.GetByID(vipId);
            try
            {
                if (vipAmountInfo == null)  //无账户数据
                {
                    vipAmountInfo = new VipAmountEntity
                    {
                        VipId                  = vipInfo.VIPID,
                        VipCardCode            = vipInfo.VipCode,
                        BeginAmount            = 0,
                        InAmount               = 0,
                        OutAmount              = 0,
                        EndAmount              = 0,
                        TotalAmount            = 0,
                        BeginReturnAmount      = 0,
                        InReturnAmount         = detailInfo.Amount,
                        OutReturnAmount        = 0,
                        ReturnAmount           = detailInfo.Amount,
                        ImminentInvalidRAmount = 0,
                        InvalidReturnAmount    = 0,
                        ValidReturnAmount      = detailInfo.Amount,
                        TotalReturnAmount      = detailInfo.Amount,
                        IsLocking              = 0,
                        CustomerID             = loggingSessionInfo.ClientID
                    };
                    vipAmountDao.Create(vipAmountInfo, tran);
                }
                else
                {
                    if (detailInfo.Amount > 0)
                    {
                        vipAmountInfo.InReturnAmount    = (vipAmountInfo.InReturnAmount == null ? 0 : vipAmountInfo.InReturnAmount.Value) + detailInfo.Amount;
                        vipAmountInfo.TotalReturnAmount = (vipAmountInfo.TotalReturnAmount == null ? 0 : vipAmountInfo.TotalReturnAmount.Value) + detailInfo.Amount;
                    }
                    else
                    {
                        vipAmountInfo.OutReturnAmount = (vipAmountInfo.OutReturnAmount == null ? 0 : vipAmountInfo.OutReturnAmount.Value) + System.Math.Abs(detailInfo.Amount.Value);
                    }
                    vipAmountInfo.ValidReturnAmount = (vipAmountInfo.ValidReturnAmount == null ? 0 : vipAmountInfo.ValidReturnAmount.Value) + detailInfo.Amount;
                    vipAmountInfo.ReturnAmount      = (vipAmountInfo.ReturnAmount == null ? 0 : vipAmountInfo.ReturnAmount.Value) + detailInfo.Amount;

                    vipAmountDao.Update(vipAmountInfo);
                }
                //创建变更记录
                var vipamountDetailBll    = new VipAmountDetailBLL(loggingSessionInfo);
                var vipAmountDetailEntity = new VipAmountDetailEntity
                {
                    VipAmountDetailId = Guid.NewGuid(),
                    VipId             = vipInfo.VIPID,
                    VipCardCode       = vipInfo.VipCode,
                    UnitID            = unitInfo != null ? unitInfo.unit_id : "",
                    UnitName          = unitInfo != null ? unitInfo.unit_name : "",
                    Amount            = detailInfo.Amount,
                    UsedReturnAmount  = 0,
                    Reason            = detailInfo.Reason,
                    Remark            = detailInfo.Remark,
                    EffectiveDate     = DateTime.Now,
                    DeadlineDate      = Convert.ToDateTime((DateTime.Now.Year + cashValidPeriod - 1) + "-12-31 23:59:59 "),//失效时间,
                    AmountSourceId    = detailInfo.AmountSourceId,
                    ObjectId          = detailInfo.ObjectId,
                    CustomerID        = loggingSessionInfo.ClientID
                };
                vipamountDetailBll.Create(vipAmountDetailEntity, tran);

                vipAmountDetailId = vipAmountDetailEntity.VipAmountDetailId.ToString();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw new APIException(ex.ToString())
                      {
                          ErrorCode = 121
                      };
            }
            return(vipAmountDetailId);
        }
        /// <summary>
        /// 计算购卡分润
        /// </summary>
        public void CalculateSalesVipCardOrderJob()
        {
            var numCount = 50;

            var customerIDs = CustomerBLL.Instance.GetCustomerList();

            foreach (var customer in customerIDs)
            {
                string connString = customer.Value;
                var    count      = RedisOpenAPI.Instance.CCSalesCardOrder().GetSalesCardOrderLength(new CC_Order
                {
                    CustomerID = customer.Key
                });
                if (count.Code != ResponseCode.Success)
                {
                    BaseService.WriteLog("从redis获取vipcard订单数据失败");
                    continue;
                }
                if (count.Result <= 0)
                {
                    continue;
                }
                if (count.Result < numCount)
                {
                    numCount = Convert.ToInt32(count.Result);
                }
                //DataTable dtAmountDetail = CreateTableAmountDetail();
                //DataTable dtAmount = CreateTableAmount();
                //DataTable dtSplitProfitRecord = CreateTableSplitProfitRecord();

                for (var i = 0; i < numCount; i++)
                {
                    var response = RedisOpenAPI.Instance.CCSalesCardOrder().GetSalesCardOrder(new CC_Order
                    {
                        CustomerID = customer.Key
                    });
                    if (response.Code == ResponseCode.Success)
                    {
                        var        orderInfo          = response.Result.OrderInfo.JsonDeserialize <T_InoutEntity>();
                        var        loggingSessionInfo = CustomerBLL.Instance.GetBSLoggingSession(customer.Key, "RedisSystem");
                        T_InoutBLL inoutBLL           = new T_InoutBLL(loggingSessionInfo);
                        if (orderInfo != null)
                        {
                            VipBLL                      bllVip                    = new VipBLL(loggingSessionInfo);
                            T_Inout_DetailBLL           bllInoutDetail            = new T_Inout_DetailBLL(loggingSessionInfo);
                            T_VirtualItemTypeSettingBLL bllVirtualItemTypeSetting = new T_VirtualItemTypeSettingBLL(loggingSessionInfo);
                            VipCardUpgradeRuleBLL       bllVipCardUpgradeRule     = new VipCardUpgradeRuleBLL(loggingSessionInfo);
                            VipAmountBLL                bllVipAmount              = new VipAmountBLL(loggingSessionInfo);
                            VipAmountDetailBLL          bllVipAmountDetail        = new VipAmountDetailBLL(loggingSessionInfo);
                            T_SplitProfitRecordBLL      bllSplitProfitRecord      = new T_SplitProfitRecordBLL(loggingSessionInfo);

                            VipAmountEntity           entityVipAmount         = new VipAmountEntity();
                            VipAmountDetailEntity     entityVipAmountDetail   = new VipAmountDetailEntity();
                            T_SplitProfitRecordEntity entitySplitProfitRecord = new T_SplitProfitRecordEntity();

                            DataSet dsVipCardLevel    = bllVip.GetVipCardLevel(orderInfo.vip_no, loggingSessionInfo.ClientID);
                            var     entityInoutDetail = bllInoutDetail.QueryByEntity(new T_Inout_DetailEntity()
                            {
                                order_id = orderInfo.order_id
                            }, null).FirstOrDefault();
                            if (entityInoutDetail == null)
                            {
                                continue;
                            }
                            var vipCardType = bllVirtualItemTypeSetting.QueryByEntity(new T_VirtualItemTypeSettingEntity()
                            {
                                SkuId = entityInoutDetail.sku_id, IsDelete = 0
                            }, null).FirstOrDefault();
                            if (vipCardType != null)
                            {
                                int intVipCardTypeID         = Convert.ToInt32(vipCardType.ObjecetTypeId);
                                var entityVipCardUpgradeRule = bllVipCardUpgradeRule.QueryByEntity(new VipCardUpgradeRuleEntity()
                                {
                                    VipCardTypeID = intVipCardTypeID, IsPurchaseUpgrade = 1, IsDelete = 0
                                }, null).SingleOrDefault();
                                if (entityVipCardUpgradeRule != null)
                                {
                                    VipCardProfitRuleBLL bllVipCardProfitRule = new VipCardProfitRuleBLL(loggingSessionInfo);
                                    var entityVipCardProfitRule = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                                    {
                                        VipCardTypeID = intVipCardTypeID, IsDelete = 0
                                    }, null);
                                    foreach (var ProfitRule in entityVipCardProfitRule)
                                    {
                                        if (ProfitRule.IsApplyAllUnits == 0)
                                        {
                                            VipCardProfitRuleUnitMappingBLL bllVipCardProfitRuleUnitMapping = new VipCardProfitRuleUnitMappingBLL(loggingSessionInfo);
                                            var vipCardProfitRuleUnitMapping = bllVipCardProfitRuleUnitMapping.QueryByEntity(new VipCardProfitRuleUnitMappingEntity()
                                            {
                                                CardBuyToProfitRuleId = ProfitRule.CardBuyToProfitRuleId, UnitID = orderInfo.sales_unit_id, IsDelete = 0, CustomerID = loggingSessionInfo.ClientID
                                            }, null).SingleOrDefault();
                                            if (vipCardProfitRuleUnitMapping == null)
                                            {
                                                continue;
                                            }
                                        }
                                        decimal amount            = 0;
                                        string  strAmountSourceId = string.Empty;
                                        string  strVipId          = string.Empty;
                                        string  strUserType       = string.Empty;
                                        if (ProfitRule.ProfitOwner == "Employee")
                                        {
                                            strAmountSourceId = "37";
                                            strVipId          = orderInfo.sales_user;
                                            strUserType       = "User";
                                        }
                                        if (ProfitRule.ProfitOwner == "Unit")
                                        {
                                            strAmountSourceId = "40";
                                            strVipId          = orderInfo.sales_unit_id;
                                            strUserType       = "Unit";
                                        }
                                        amount = (decimal)ProfitRule.FirstCardSalesProfitPct * (decimal)orderInfo.actual_amount * (decimal)0.01;
                                        var vipAmountDetail = bllVipAmountDetail.QueryByEntity(new VipAmountDetailEntity()
                                        {
                                            ObjectId = orderInfo.order_id, AmountSourceId = strAmountSourceId
                                        }, null);
                                        if (vipAmountDetail != null && vipAmountDetail.Length > 0)
                                        {
                                            continue;
                                        }
                                        if (amount > 0)
                                        {
                                            IDbTransaction tran = new JIT.CPOS.BS.DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction();
                                            try {
                                                //                                 DataRow dr_SplitProfitRecord = dtSplitProfitRecord.NewRow();
                                                //                                 dr_SplitProfitRecord["Id"] = Guid.NewGuid();
                                                //                                 dr_SplitProfitRecord["SourceType"] = "Amount";
                                                //                                 dr_SplitProfitRecord["SourceId"] = strAmountSourceId;
                                                //                                 dr_SplitProfitRecord["ObjectId"] = orderInfo.order_id;
                                                //dr_SplitProfitRecord["UserType"] = strUserType;
                                                //                                 dr_SplitProfitRecord["UserId"] = orderInfo.sales_user;
                                                //                                 dr_SplitProfitRecord["SplitAmount"] = amount;
                                                //                                 dr_SplitProfitRecord["SplitSattus"] = "10";
                                                //                                 dr_SplitProfitRecord["CustomerId"] = loggingSessionInfo.ClientID;
                                                //                                 dr_SplitProfitRecord["CreateTime"] = DateTime.Now;
                                                //                                 dr_SplitProfitRecord["CreateBy"] = loggingSessionInfo.ClientID;
                                                //                                 dr_SplitProfitRecord["LastUpdateTime"] = DateTime.Now;
                                                //                                 dr_SplitProfitRecord["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                                //                                 dr_SplitProfitRecord["IsDelete"] = 0;
                                                //                                 dtSplitProfitRecord.Rows.Add(dr_SplitProfitRecord);

                                                //                                 DataRow dr_AmountDetail = dtAmountDetail.NewRow();
                                                //                                 dr_AmountDetail["VipAmountDetailId"] = Guid.NewGuid();
                                                //dr_AmountDetail["VipId"] = strVipId;
                                                //                                 dr_AmountDetail["VipCardCode"] = "";
                                                //                                 dr_AmountDetail["UnitID"] = "";
                                                //                                 dr_AmountDetail["UnitName"] = "";
                                                //                                 dr_AmountDetail["SalesAmount"] = 0;
                                                //                                 dr_AmountDetail["Amount"] = amount;
                                                //                                 dr_AmountDetail["UsedReturnAmount"] = 0;
                                                //                                 dr_AmountDetail["Reason"] = "首次售卡分润";
                                                //                                 dr_AmountDetail["EffectiveDate"] = DateTime.Now;
                                                //                                 dr_AmountDetail["DeadlineDate"] = Convert.ToDateTime("9999-12-31 23:59:59");
                                                //                                 dr_AmountDetail["AmountSourceId"] = strAmountSourceId;
                                                //                                 dr_AmountDetail["ObjectId"] = orderInfo.order_id;
                                                //                                 dr_AmountDetail["Remark"] = "首次售卡分润";
                                                //                                 dr_AmountDetail["IsValid"] = 0;
                                                //                                 dr_AmountDetail["IsWithdrawCash"] = 0;
                                                //                                 dr_AmountDetail["CustomerID"] = loggingSessionInfo.ClientID;
                                                //                                 dr_AmountDetail["CreateTime"] = DateTime.Now;
                                                //                                 dr_AmountDetail["CreateBy"] = loggingSessionInfo.ClientID;
                                                //                                 dr_AmountDetail["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                                //                                 dr_AmountDetail["LastUpdateTime"] = DateTime.Now;
                                                //                                 dr_AmountDetail["IsDelete"] = 0;
                                                //                                 //dr_AmountDetail["IsCalculated"] = 1;
                                                //                                 dtAmountDetail.Rows.Add(dr_AmountDetail);

                                                entitySplitProfitRecord = new T_SplitProfitRecordEntity()
                                                {
                                                    ID          = Guid.NewGuid().ToString(),
                                                    SourceType  = "Amount",
                                                    SourceId    = strAmountSourceId,
                                                    ObjectId    = orderInfo.order_id,
                                                    UserType    = strUserType,
                                                    UserId      = orderInfo.sales_user,
                                                    SplitAmount = amount,
                                                    SplitSattus = "10",
                                                    CustomerID  = loggingSessionInfo.ClientID
                                                };
                                                bllSplitProfitRecord.Create(entitySplitProfitRecord, tran);


                                                entityVipAmountDetail = new VipAmountDetailEntity {
                                                    VipAmountDetailId = Guid.NewGuid(),
                                                    VipId             = strVipId,
                                                    Amount            = amount,
                                                    UsedReturnAmount  = 0,
                                                    EffectiveDate     = DateTime.Now,
                                                    DeadlineDate      = Convert.ToDateTime("9999-12-31 23:59:59"),
                                                    AmountSourceId    = strAmountSourceId,
                                                    ObjectId          = orderInfo.order_id,
                                                    CustomerID        = loggingSessionInfo.ClientID,
                                                    Reason            = "首次售卡分润",
                                                    Remark            = "首次售卡分润",
                                                    IsWithdrawCash    = 0
                                                };
                                                bllVipAmountDetail.Create(entityVipAmountDetail, (SqlTransaction)tran);

                                                entityVipAmount = bllVipAmount.QueryByEntity(new VipAmountEntity()
                                                {
                                                    VipId = orderInfo.sales_user, IsDelete = 0
                                                }, null).SingleOrDefault();
                                                if (entityVipAmount == null)
                                                {
                                                    //DataRow dr_Amount = dtAmount.NewRow();
                                                    //dr_Amount["VipId"] = orderInfo.sales_user;
                                                    //dr_Amount["VipCardCode"] = "";
                                                    //dr_Amount["BeginAmount"] = 0;
                                                    //dr_Amount["InAmount"] = amount;
                                                    //dr_Amount["OutAmount"] = 0;
                                                    //dr_Amount["EndAmount"] = amount;
                                                    //dr_Amount["TotalAmount"] = amount;
                                                    //dr_Amount["BeginReturnAmount"] = 0;
                                                    //dr_Amount["InReturnAmount"] = 0;
                                                    //dr_Amount["OutReturnAmount"] = 0;
                                                    //dr_Amount["ReturnAmount"] = 0;
                                                    //dr_Amount["ImminentInvalidRAmount"] = 0;
                                                    //dr_Amount["InvalidReturnAmount"] = 0;
                                                    //dr_Amount["ValidReturnAmount"] = 0;
                                                    //dr_Amount["TotalReturnAmount"] = 0;
                                                    //dr_Amount["PayPassword"] = "";
                                                    //dr_Amount["IsLocking"] = 0;
                                                    //dr_Amount["CustomerID"] = loggingSessionInfo.ClientID;
                                                    //dr_Amount["CreateTime"] = DateTime.Now;
                                                    //dr_Amount["CreateBy"] = loggingSessionInfo.ClientID;
                                                    //dr_Amount["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                                    //dr_Amount["LastUpdateTime"] = DateTime.Now;
                                                    //dr_Amount["IsDelete"] = 0;
                                                    //dtAmount.Rows.Add(dr_Amount);
                                                    entityVipAmount = new VipAmountEntity {
                                                        VipId                  = strVipId,
                                                        BeginAmount            = 0,
                                                        InAmount               = amount,
                                                        OutAmount              = 0,
                                                        EndAmount              = amount,
                                                        TotalAmount            = amount,
                                                        BeginReturnAmount      = 0,
                                                        InReturnAmount         = 0,
                                                        OutReturnAmount        = 0,
                                                        ReturnAmount           = 0,
                                                        ImminentInvalidRAmount = 0,
                                                        InvalidReturnAmount    = 0,
                                                        ValidReturnAmount      = 0,
                                                        TotalReturnAmount      = 0,
                                                        IsLocking              = 0,
                                                        CustomerID             = loggingSessionInfo.ClientID,
                                                        VipCardCode            = ""
                                                    };
                                                    bllVipAmount.Create(entityVipAmount, tran);
                                                }
                                                else
                                                {
                                                    entityVipAmount.InReturnAmount    = (entityVipAmount.InReturnAmount == null ? 0 : entityVipAmount.InReturnAmount.Value) + amount;
                                                    entityVipAmount.TotalReturnAmount = (entityVipAmount.TotalReturnAmount == null ? 0 : entityVipAmount.TotalReturnAmount.Value) + amount;

                                                    entityVipAmount.ValidReturnAmount = (entityVipAmount.ValidReturnAmount == null ? 0 : entityVipAmount.ValidReturnAmount.Value) + amount;
                                                    entityVipAmount.ReturnAmount      = (entityVipAmount.ReturnAmount == null ? 0 : entityVipAmount.ReturnAmount.Value) + amount;

                                                    bllVipAmount.Update(entityVipAmount);
                                                }
                                                tran.Commit();
                                            }
                                            catch (Exception) {
                                                tran.Rollback();
                                                throw;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //if (dtAmount.Rows.Count > 0)
                //{
                //    Utils.SqlBulkCopy(connString, dtAmount, "VipAmount");
                //}
                //if (dtAmountDetail.Rows.Count > 0 && dtSplitProfitRecord.Rows.Count > 0)
                //{
                //    Utils.SqlBulkCopy(connString, dtSplitProfitRecord, "T_SplitProfitRecord");
                //    Utils.SqlBulkCopy(connString, dtAmountDetail, "VipAmountDetail");

                //}
            }
        }
Esempio n. 8
0
 public void Delete(VipAmountDetailEntity dbEntity)
 {
     _cmd.Delete(dbEntity);
 }
Esempio n. 9
0
        /// <summary>
        /// 充值订单循环队列计算
        /// </summary>
        public void CalculateRechargeOrderJob()
        {
            var numCount    = 50;
            var customerIDs = CustomerBLL.Instance.GetCustomerList();

            foreach (var customer in customerIDs)
            {
                string connString = customer.Value;
                var    count      = RedisOpenAPI.Instance.CCRechargeOrder().GetRechargeOrderLength(new CC_Order
                {
                    CustomerID = customer.Key
                });
                if (count.Code != ResponseCode.Success)
                {
                    BaseService.WriteLog("从redis获取充值订单数据失败");
                    continue;
                }
                if (count.Result <= 0)
                {
                    continue;
                }
                if (count.Result < numCount)
                {
                    numCount = Convert.ToInt32(count.Result);
                }
                var loggingSessionInfo = CustomerBLL.Instance.GetBSLoggingSession(customer.Key, "RedisSystem");
                VipCardProfitRuleBLL      bllVipCardProfitRule    = new VipCardProfitRuleBLL(loggingSessionInfo);
                VipCardProfitRuleEntity[] entityVipCardProfitRule = null;
                var                    bllVipCardGradeChangeLog   = new VipCardGradeChangeLogBLL(loggingSessionInfo);
                VipAmountBLL           bllVipAmount         = new VipAmountBLL(loggingSessionInfo);
                VipAmountDetailBLL     bllVipAmountDetail   = new VipAmountDetailBLL(loggingSessionInfo);
                T_SplitProfitRecordBLL bllSplitProfitRecord = new T_SplitProfitRecordBLL(loggingSessionInfo);

                for (var i = 0; i < numCount; i++)
                {
                    var response = RedisOpenAPI.Instance.CCRechargeOrder().GetRechargeOrder(new CC_Order
                    {
                        CustomerID = customer.Key
                    });
                    if (response.Code == ResponseCode.Success)
                    {
                        var rechargeOrderInfo = response.Result.OrderInfo.JsonDeserialize <RechargeOrderEntity>();

                        entityVipCardProfitRule = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                        {
                            VipCardTypeID = rechargeOrderInfo.VipCardTypeId, IsDelete = 0
                        }, null);
                        if (entityVipCardProfitRule != null)
                        {
                            //DataTable dtAmountDetail = CreateTableAmountDetail();
                            //DataTable dtAmount = CreateTableAmount();
                            //DataTable dtSplitProfitRecord = CreateTableSplitProfitRecord();



                            VipAmountEntity           entityVipAmount         = new VipAmountEntity();
                            VipAmountDetailEntity     entityVipAmountDetail   = new VipAmountDetailEntity();
                            T_SplitProfitRecordEntity entitySplitProfitRecord = new T_SplitProfitRecordEntity();

                            foreach (var ProfitRule in entityVipCardProfitRule)
                            {
                                decimal amount            = 0;
                                string  strAmountSourceId = string.Empty;
                                string  strVipId          = string.Empty;
                                string  strUserType       = string.Empty;
                                if (ProfitRule.IsApplyAllUnits == 0)
                                {
                                    VipCardProfitRuleUnitMappingBLL bllVipCardProfitRuleUnitMapping = new VipCardProfitRuleUnitMappingBLL(loggingSessionInfo);
                                    var vipCardProfitRuleUnitMapping = bllVipCardProfitRuleUnitMapping.QueryByEntity(new VipCardProfitRuleUnitMappingEntity()
                                    {
                                        CardBuyToProfitRuleId = ProfitRule.CardBuyToProfitRuleId, UnitID = rechargeOrderInfo.UnitId, IsDelete = 0, CustomerID = loggingSessionInfo.ClientID
                                    }, null).SingleOrDefault();
                                    if (vipCardProfitRuleUnitMapping == null)
                                    {
                                        continue;
                                    }
                                }
                                if (ProfitRule.ProfitOwner == "Employee")
                                {
                                    strAmountSourceId = "38";
                                    strVipId          = rechargeOrderInfo.UserId;
                                    strUserType       = "User";
                                }
                                if (ProfitRule.ProfitOwner == "Unit")
                                {
                                    strAmountSourceId = "42";
                                    strVipId          = rechargeOrderInfo.UnitId;
                                    strUserType       = "Unit";
                                }
                                var vipAmountDetail = bllVipAmountDetail.QueryByEntity(new VipAmountDetailEntity()
                                {
                                    ObjectId = rechargeOrderInfo.OrderID.ToString(), AmountSourceId = strAmountSourceId
                                }, null);
                                if (vipAmountDetail != null && vipAmountDetail.Length > 0)
                                {
                                    continue;
                                }
                                if (rechargeOrderInfo.OrderDesc == "Upgrade")                                //首充
                                {
                                    amount = (decimal)ProfitRule.FirstRechargeProfitPct * (decimal)rechargeOrderInfo.ActuallyPaid * (decimal)0.01;
                                }
                                if (rechargeOrderInfo.OrderDesc == "ReRecharge")//续充
                                {
                                    VipCardReRechargeProfitRuleBLL bllVipCardReRechargeProfitRule = new VipCardReRechargeProfitRuleBLL(loggingSessionInfo);
                                    var entityVipCardReRechargeProfitRule = bllVipCardReRechargeProfitRule.QueryByEntity(new VipCardReRechargeProfitRuleEntity()
                                    {
                                        VipCardTypeID = rechargeOrderInfo.VipCardTypeId, CardBuyToProfitRuleId = ProfitRule.CardBuyToProfitRuleId, IsDelete = 0
                                    }, null);
                                    if (entityVipCardReRechargeProfitRule != null)
                                    {
                                        decimal discount = 0;
                                        foreach (var ReRechargeProfitRule in entityVipCardReRechargeProfitRule.OrderByDescending(a => a.LimitAmount))
                                        {
                                            if (ReRechargeProfitRule.ProfitType == "Superposition")
                                            {
                                                discount = (decimal)(ReRechargeProfitRule.LimitAmount * ReRechargeProfitRule.ProfitPct) * (decimal)0.01;
                                                amount   = (decimal)(rechargeOrderInfo.ActuallyPaid / ReRechargeProfitRule.LimitAmount) * discount;
                                            }
                                            if (ReRechargeProfitRule.ProfitType == "Step")
                                            {
                                                if (rechargeOrderInfo.ActuallyPaid >= ReRechargeProfitRule.LimitAmount)
                                                {
                                                    if (discount == 0)
                                                    {
                                                        discount = (decimal)ReRechargeProfitRule.ProfitPct * (decimal)0.01;
                                                        amount   = (decimal)rechargeOrderInfo.ActuallyPaid * discount;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                //入库
                                if (amount > 0)
                                {
                                    IDbTransaction tran = new JIT.CPOS.BS.DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction();
                                    try {
                                        //                           DataRow dr_AmountDetail = dtAmountDetail.NewRow();
                                        //                           dr_AmountDetail["VipAmountDetailId"] = Guid.NewGuid();
                                        //                           dr_AmountDetail["VipId"] = strVipId;
                                        //                           dr_AmountDetail["VipCardCode"] = "";
                                        //                           dr_AmountDetail["UnitID"] = "";
                                        //                           dr_AmountDetail["UnitName"] = "";
                                        //                           dr_AmountDetail["SalesAmount"] = 0;
                                        //                           dr_AmountDetail["Amount"] = amount;
                                        //                           dr_AmountDetail["UsedReturnAmount"] = 0;
                                        //                           dr_AmountDetail["Reason"] = "充值";
                                        //                           dr_AmountDetail["EffectiveDate"] = DateTime.Now;
                                        //                           dr_AmountDetail["DeadlineDate"] = Convert.ToDateTime("9999-12-31 23:59:59");
                                        //                           dr_AmountDetail["AmountSourceId"] = strAmountSourceId;
                                        //                           dr_AmountDetail["ObjectId"] = rechargeOrderInfo.OrderID.ToString();
                                        //							 dr_AmountDetail["Remark"] = "充值";
                                        //                           dr_AmountDetail["IsValid"] = 0;
                                        //                           dr_AmountDetail["IsWithdrawCash"] = 0;
                                        //                           dr_AmountDetail["CustomerID"] = loggingSessionInfo.ClientID;
                                        //                           dr_AmountDetail["CreateTime"] = DateTime.Now;
                                        //                           dr_AmountDetail["CreateBy"] = loggingSessionInfo.ClientID;
                                        //                           dr_AmountDetail["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                        //                           dr_AmountDetail["LastUpdateTime"] = DateTime.Now;
                                        //                           dr_AmountDetail["IsDelete"] = 0;
                                        //                           //dr_AmountDetail["IsCalculated"] = 1;
                                        //                           dtAmountDetail.Rows.Add(dr_AmountDetail);

                                        //DataRow dr_SplitProfitRecord = dtSplitProfitRecord.NewRow();
                                        //dr_SplitProfitRecord["Id"] = Guid.NewGuid();
                                        //dr_SplitProfitRecord["SourceType"] = "Amount";
                                        //dr_SplitProfitRecord["SourceId"] = strAmountSourceId;
                                        //dr_SplitProfitRecord["ObjectId"] = rechargeOrderInfo.OrderID.ToString();
                                        //dr_SplitProfitRecord["UserType"] = strUserType;
                                        //dr_SplitProfitRecord["UserId"] = rechargeOrderInfo.UserId;
                                        //dr_SplitProfitRecord["SplitAmount"] = amount;
                                        //dr_SplitProfitRecord["SplitSattus"] = "10";
                                        //dr_SplitProfitRecord["CustomerId"] = loggingSessionInfo.ClientID;
                                        //dr_SplitProfitRecord["CreateTime"] = DateTime.Now;
                                        //dr_SplitProfitRecord["CreateBy"] = loggingSessionInfo.ClientID;
                                        //dr_SplitProfitRecord["LastUpdateTime"] = DateTime.Now;
                                        //dr_SplitProfitRecord["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                        //dr_SplitProfitRecord["IsDelete"] = 0;
                                        //dtSplitProfitRecord.Rows.Add(dr_SplitProfitRecord);

                                        entitySplitProfitRecord = new T_SplitProfitRecordEntity()
                                        {
                                            ID          = Guid.NewGuid().ToString(),
                                            SourceType  = "Amount",
                                            SourceId    = strAmountSourceId,
                                            ObjectId    = rechargeOrderInfo.OrderID.ToString(),
                                            UserType    = strUserType,
                                            UserId      = rechargeOrderInfo.UserId,
                                            SplitAmount = amount,
                                            SplitSattus = "10",
                                            CustomerID  = loggingSessionInfo.ClientID
                                        };
                                        bllSplitProfitRecord.Create(entitySplitProfitRecord, tran);


                                        entityVipAmountDetail = new VipAmountDetailEntity {
                                            VipAmountDetailId = Guid.NewGuid(),
                                            VipId             = strVipId,
                                            Amount            = amount,
                                            UsedReturnAmount  = 0,
                                            EffectiveDate     = DateTime.Now,
                                            DeadlineDate      = Convert.ToDateTime("9999-12-31 23:59:59"),
                                            AmountSourceId    = strAmountSourceId,
                                            ObjectId          = rechargeOrderInfo.OrderID.ToString(),
                                            CustomerID        = loggingSessionInfo.ClientID,
                                            Reason            = "充值",
                                            IsWithdrawCash    = 0
                                        };
                                        bllVipAmountDetail.Create(entityVipAmountDetail, (SqlTransaction)tran);


                                        entityVipAmount = bllVipAmount.QueryByEntity(new VipAmountEntity()
                                        {
                                            VipId = strVipId, IsDelete = 0
                                        }, null).SingleOrDefault();
                                        if (entityVipAmount == null)
                                        {
                                            entityVipAmount = new VipAmountEntity {
                                                VipId                  = strVipId,
                                                BeginAmount            = 0,
                                                InAmount               = amount,
                                                OutAmount              = 0,
                                                EndAmount              = amount,
                                                TotalAmount            = amount,
                                                BeginReturnAmount      = 0,
                                                InReturnAmount         = 0,
                                                OutReturnAmount        = 0,
                                                ReturnAmount           = 0,
                                                ImminentInvalidRAmount = 0,
                                                InvalidReturnAmount    = 0,
                                                ValidReturnAmount      = 0,
                                                TotalReturnAmount      = 0,
                                                IsLocking              = 0,
                                                CustomerID             = loggingSessionInfo.ClientID,
                                                VipCardCode            = ""
                                            };
                                            bllVipAmount.Create(entityVipAmount, tran);

                                            //DataRow dr_Amount = dtAmount.NewRow();
                                            //dr_Amount["VipId"] = strVipId;
                                            //dr_Amount["VipCardCode"] = "";
                                            //dr_Amount["BeginAmount"] = 0;
                                            //dr_Amount["InAmount"] = amount;
                                            //dr_Amount["OutAmount"] = 0;
                                            //dr_Amount["EndAmount"] = amount;
                                            //dr_Amount["TotalAmount"] = amount;
                                            //dr_Amount["BeginReturnAmount"] = 0;
                                            //dr_Amount["InReturnAmount"] = 0;
                                            //dr_Amount["OutReturnAmount"] = 0;
                                            //dr_Amount["ReturnAmount"] = 0;
                                            //dr_Amount["ImminentInvalidRAmount"] = 0;
                                            //dr_Amount["InvalidReturnAmount"] = 0;
                                            //dr_Amount["ValidReturnAmount"] = 0;
                                            //dr_Amount["TotalReturnAmount"] = 0;
                                            //dr_Amount["PayPassword"] = "";
                                            //dr_Amount["IsLocking"] = 0;
                                            //dr_Amount["CustomerID"] = loggingSessionInfo.ClientID;
                                            //dr_Amount["CreateTime"] = DateTime.Now;
                                            //dr_Amount["CreateBy"] = loggingSessionInfo.ClientID;
                                            //dr_Amount["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                            //dr_Amount["LastUpdateTime"] = DateTime.Now;
                                            //dr_Amount["IsDelete"] = 0;
                                            //dtAmount.Rows.Add(dr_Amount);
                                        }
                                        else
                                        {
                                            entityVipAmount.InReturnAmount    = (entityVipAmount.InReturnAmount == null ? 0 : entityVipAmount.InReturnAmount.Value) + amount;
                                            entityVipAmount.TotalReturnAmount = (entityVipAmount.TotalReturnAmount == null ? 0 : entityVipAmount.TotalReturnAmount.Value) + amount;

                                            entityVipAmount.ValidReturnAmount = (entityVipAmount.ValidReturnAmount == null ? 0 : entityVipAmount.ValidReturnAmount.Value) + amount;
                                            entityVipAmount.ReturnAmount      = (entityVipAmount.ReturnAmount == null ? 0 : entityVipAmount.ReturnAmount.Value) + amount;
                                            bllVipAmount.Update(entityVipAmount);
                                        }
                                        tran.Commit();
                                    }
                                    catch (Exception) {
                                        tran.Rollback();
                                        throw;
                                    }
                                }
                            }
                            //if (dtAmount.Rows.Count > 0 && dtAmountDetail.Rows.Count == dtAmount.Rows.Count)
                            //{
                            //    Utils.SqlBulkCopy(connString, dtAmount, "VipAmount");
                            //}
                            //if (dtAmountDetail.Rows.Count > 0 && dtSplitProfitRecord.Rows.Count > 0)
                            //{
                            //    Utils.SqlBulkCopy(connString, dtSplitProfitRecord, "T_SplitProfitRecord");
                            //    Utils.SqlBulkCopy(connString, dtAmountDetail, "VipAmountDetail");

                            //}
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        protected override EmptyResponseData ProcessRequest(DTO.Base.APIRequest <SetSalesReturnRP> pRequest)
        {
            var rd   = new EmptyResponseData();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var salesReturnBLL     = new T_SalesReturnBLL(loggingSessionInfo);
            var historyBLL         = new T_SalesReturnHistoryBLL(loggingSessionInfo);
            var refundOrderBLL     = new T_RefundOrderBLL(loggingSessionInfo);

            var inoutBLL     = new T_InoutBLL(loggingSessionInfo);
            var inoutService = new InoutService(loggingSessionInfo);

            var vipAmountBLL   = new VipAmountBLL(loggingSessionInfo);   //余额返现BLL实例化
            var vipIntegralBLL = new VipIntegralBLL(loggingSessionInfo); //积分BLL实例化

            var pTran = salesReturnBLL.GetTran();                        //事务
            T_SalesReturnEntity        salesReturnEntity = null;
            T_SalesReturnHistoryEntity historyEntity     = null;

            T_RefundOrderEntity refundEntity = null;

            var          vipBll     = new VipBLL(loggingSessionInfo);    //会员BLL实例化
            var          userBll    = new T_UserBLL(loggingSessionInfo); //店员BLL实例化
            T_UserEntity userEntity = null;                              //店员信息
            var          unitBLL    = new t_unitBLL(loggingSessionInfo);

            salesReturnEntity = salesReturnBLL.GetByID(para.SalesReturnID);
            //获取订单信息
            var inoutInfo = inoutBLL.GetInoutInfo(salesReturnEntity.OrderID, loggingSessionInfo);
            //获取会员信息
            var vipInfo = vipBll.GetByID(inoutInfo.vip_no);
            //获取门店信息
            t_unitEntity unitInfo = null;

            if (!string.IsNullOrEmpty(inoutInfo.sales_unit_id))
            {
                unitInfo = unitBLL.GetByID(inoutInfo.sales_unit_id);
            }
            userEntity = userBll.GetByID(loggingSessionInfo.UserID);
            using (pTran.Connection)
            {
                try
                {
                    switch (para.OperationType)
                    {
                    case 1:
                        #region 审核通过
                        salesReturnEntity.Status = 4;    //审核通过

                        #region 计算应退金额
                        decimal payable = 0;       //计算后应退金额

                        //根据订单ID获取订单明细[复用]
                        DataRow drItem     = inoutService.GetOrderDetailByOrderId(salesReturnEntity.OrderID).Tables[0].Select(" item_id= '" + salesReturnEntity.ItemID + "'").FirstOrDefault();
                        decimal salesPrice = Convert.ToDecimal(drItem["enter_price"]);
                        if (inoutInfo != null)
                        {
                            //订单总金额-运费
                            decimal tempAmount = inoutInfo.total_amount.Value - inoutInfo.DeliveryAmount;
                            //计算会员折扣
                            decimal discount = 1;
                            if (inoutInfo.discount_rate.Value > 0)
                            {
                                discount = inoutInfo.discount_rate.Value / 100;
                            }
                            //计算后应退金额
                            //payable = (((tempAmount - inoutInfo.CouponAmount) * discount) / tempAmount) * (salesPrice * salesReturnEntity.ActualQty.Value);
                            //公式:比例 =(应付金额 * 会员折扣 - 优惠券)/ 应付金额
                            //      应退金额 = 退货数量 * 销售价 * 比例
                            payable = ((tempAmount * discount - inoutInfo.CouponAmount) / tempAmount) * (salesPrice * salesReturnEntity.ActualQty.Value);
                        }
                        salesReturnEntity.RefundAmount  = payable;      //应退金额
                        salesReturnEntity.ConfirmAmount = payable;      //实退金额,默认为应退金额,可支持修改
                        #endregion

                        salesReturnBLL.Update(salesReturnEntity, pTran);

                        historyEntity = new T_SalesReturnHistoryEntity()
                        {
                            SalesReturnID = salesReturnEntity.SalesReturnID,
                            OperationType = 4,
                            OperationDesc = "审核",
                            OperatorID    = loggingSessionInfo.UserID,
                            HisRemark     = "您的服务单已审核通过,请将商品寄回",
                            OperatorName  = userEntity.user_name,
                            OperatorType  = 1
                        };
                        historyBLL.Create(historyEntity, pTran);

                        #endregion
                        break;

                    case 2:
                        #region 审核不通过
                        salesReturnEntity.Status = 3;    //审核不通过
                        salesReturnBLL.Update(salesReturnEntity, pTran);

                        historyEntity = new T_SalesReturnHistoryEntity()
                        {
                            SalesReturnID = salesReturnEntity.SalesReturnID,
                            OperationType = 3,
                            OperationDesc = "审核",
                            OperatorID    = loggingSessionInfo.UserID,
                            HisRemark     = para.Desc,
                            OperatorName  = userEntity.user_name,
                            OperatorType  = 1
                        };
                        historyBLL.Create(historyEntity, pTran);
                        break;

                        #endregion
                    case 3:
                        #region 确认收货
                        salesReturnEntity.Status = 6;    //确认收货
                        salesReturnBLL.Update(salesReturnEntity, pTran);

                        historyEntity = new T_SalesReturnHistoryEntity()
                        {
                            SalesReturnID = salesReturnEntity.SalesReturnID,
                            OperationType = 6,
                            OperationDesc = "收货",
                            OperatorID    = loggingSessionInfo.UserID,
                            HisRemark     = "您的服务单" + salesReturnEntity.SalesReturnNo + "的商品已经收到",
                            OperatorName  = userEntity.user_name,
                            OperatorType  = 1
                        };
                        historyBLL.Create(historyEntity, pTran);
                        //退货时生成退款单
                        if (salesReturnEntity.ServicesType == 1)
                        {
                            refundEntity = new T_RefundOrderEntity();
                            refundEntity.SalesReturnID = salesReturnEntity.SalesReturnID;
                            refundEntity.RefundNo      = DateTime.Now.ToString("yyyyMMddhhmmfff");
                            refundEntity.VipID         = salesReturnEntity.VipID;
                            refundEntity.DeliveryType  = salesReturnEntity.DeliveryType;
                            refundEntity.OrderID       = salesReturnEntity.OrderID;
                            refundEntity.ItemID        = salesReturnEntity.ItemID;
                            refundEntity.SkuID         = salesReturnEntity.SkuID;
                            refundEntity.Qty           = salesReturnEntity.Qty;
                            refundEntity.ActualQty     = salesReturnEntity.ActualQty;
                            refundEntity.UnitID        = salesReturnEntity.UnitID;
                            refundEntity.UnitName      = salesReturnEntity.UnitName;
                            refundEntity.UnitTel       = salesReturnEntity.UnitTel;
                            refundEntity.Address       = salesReturnEntity.Address;
                            refundEntity.Contacts      = salesReturnEntity.Contacts;
                            refundEntity.Phone         = salesReturnEntity.Phone;
                            refundEntity.RefundAmount  = salesReturnEntity.RefundAmount;        //退款金额
                            refundEntity.ConfirmAmount = salesReturnEntity.ConfirmAmount;       //确认退款金额

                            #region 计算应退现金金额、余额、积分、返现
                            var inoutDetail = inoutBLL.GetInoutInfo(salesReturnEntity.OrderID, loggingSessionInfo);
                            if (inoutDetail != null)
                            {
                                //订单实付金额-运费 >= 应退金额
                                if (inoutDetail.actual_amount - inoutDetail.DeliveryAmount >= salesReturnEntity.ConfirmAmount)
                                {
                                    refundEntity.ActualRefundAmount = salesReturnEntity.ConfirmAmount;
                                }
                                //订单实付金额-运费+余额抵扣 >= 应退金额
                                else if (inoutDetail.actual_amount - inoutDetail.DeliveryAmount + inoutDetail.VipEndAmount >= salesReturnEntity.ConfirmAmount)
                                {
                                    refundEntity.ActualRefundAmount = inoutDetail.actual_amount - inoutDetail.DeliveryAmount;     //实付金额
                                    //refundEntity.Amount = salesReturnEntity.ConfirmAmount - inoutDetail.actual_amount;  //退回余额
                                    refundEntity.Amount = salesReturnEntity.ConfirmAmount - refundEntity.ActualRefundAmount;      //退回余额
                                }
                                //订单实付金额-运费+余额抵扣+积分抵扣 >= 应退金额
                                else if (inoutDetail.actual_amount - inoutDetail.DeliveryAmount + inoutDetail.VipEndAmount + inoutDetail.IntegralAmount >= salesReturnEntity.ConfirmAmount)
                                {
                                    refundEntity.ActualRefundAmount = inoutDetail.actual_amount - inoutDetail.DeliveryAmount; //实付金额
                                    refundEntity.Amount             = inoutDetail.VipEndAmount;                               //退回余额
                                    //退回积分抵扣金额
                                    refundEntity.PointsAmount = salesReturnEntity.ConfirmAmount.Value - (inoutDetail.actual_amount.Value - inoutDetail.DeliveryAmount) - inoutDetail.VipEndAmount;
                                    //退回积分
                                    refundEntity.Points = (int)Math.Round(refundEntity.PointsAmount.Value * (inoutDetail.pay_points.Value / inoutDetail.IntegralAmount), 1);
                                }
                                else                                                                                    //订单实付金额-运费+余额抵扣+积分抵扣 < 应退金额
                                {
                                    refundEntity.Points             = (int)Math.Round(inoutDetail.pay_points.Value, 1); //退回积分
                                    refundEntity.PointsAmount       = inoutDetail.IntegralAmount;                       //退回积分抵扣金额
                                    refundEntity.Amount             = inoutDetail.VipEndAmount;                         //退回余额
                                    refundEntity.ActualRefundAmount = salesReturnEntity.ConfirmAmount;                  //实付金额
                                }
                                //订单实付金额-运费+余额抵扣+积分抵扣 >= 应退金额
                                //取消返现
                                //else if (inoutDetail.actual_amount - inoutDetail.DeliveryAmount + inoutDetail.VipEndAmount + inoutDetail.IntegralAmount + inoutDetail.ReturnAmount >= salesReturnEntity.ConfirmAmount)
                                //{
                                //    refundEntity.ActualRefundAmount = inoutDetail.actual_amount - inoutDetail.DeliveryAmount;//实付金额
                                //    refundEntity.Amount = inoutDetail.VipEndAmount;             //退回余额
                                //    refundEntity.Points = (int)Math.Round(inoutDetail.pay_points.Value, 1);//退回积分
                                //    refundEntity.PointsAmount = inoutDetail.IntegralAmount;       //退回积分抵扣金额
                                //    //退回的返现
                                //    refundEntity.ReturnAmount = salesReturnEntity.ConfirmAmount.Value - (inoutDetail.actual_amount.Value - inoutDetail.DeliveryAmount) - inoutDetail.VipEndAmount - inoutDetail.IntegralAmount;
                                //}
                            }
                            #endregion

                            refundEntity.Status     = 1;      //待退款
                            refundEntity.CustomerID = loggingSessionInfo.ClientID;
                            refundOrderBLL.Create(refundEntity, pTran);

                            var vipAmountEntity = vipAmountBLL.QueryByEntity(new VipAmountEntity()
                            {
                                VipId = vipInfo.VIPID, VipCardCode = vipInfo.VipCode
                            }, null).FirstOrDefault();

                            //退货返回余额
                            if (refundEntity.Amount > 0)
                            {
                                //变更余额和余额记录
                                var detailInfo = new VipAmountDetailEntity()
                                {
                                    Amount         = refundEntity.Amount.Value,
                                    AmountSourceId = "21",
                                    ObjectId       = refundEntity.RefundID.ToString()
                                };
                                var vipAmountDetailId = vipAmountBLL.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, detailInfo, pTran, loggingSessionInfo);
                                if (!string.IsNullOrWhiteSpace(vipAmountDetailId))
                                {    //发送微信账户余额变动模板消息
                                    var CommonBLL = new CommonBLL();
                                    CommonBLL.BalanceChangedMessage(inoutInfo.order_no, vipAmountEntity, detailInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, loggingSessionInfo);
                                }
                            }
                            //退货返回返现
                            if (refundEntity.ReturnAmount > 0)
                            {
                                var detailInfo = new VipAmountDetailEntity()
                                {
                                    Amount         = refundEntity.ReturnAmount.Value,
                                    ObjectId       = refundEntity.RefundID.ToString(),
                                    AmountSourceId = "22"
                                };
                                var vipAmountDetailId = vipAmountBLL.AddReturnAmount(vipInfo, unitInfo, vipAmountEntity, ref detailInfo, pTran, loggingSessionInfo);
                                if (!string.IsNullOrWhiteSpace(vipAmountDetailId))
                                {    //发送返现到账通知微信模板消息
                                    var CommonBLL = new CommonBLL();
                                    CommonBLL.CashBackMessage(salesReturnEntity.OrderNo, detailInfo.Amount, vipInfo.WeiXinUserId, vipInfo.VIPID, loggingSessionInfo);
                                }
                            }
                            //退货返回积分
                            if (refundEntity.Points > 0)
                            {
                                var IntegralDetail = new VipIntegralDetailEntity()
                                {
                                    Integral         = refundEntity.Points.Value,
                                    IntegralSourceID = "26",
                                    ObjectId         = refundEntity.RefundID.ToString()
                                };

                                if (IntegralDetail.Integral != 0)
                                {
                                    //变动前积分
                                    string OldIntegral = (vipInfo.Integration ?? 0).ToString();
                                    //变动积分
                                    string ChangeIntegral      = (IntegralDetail.Integral ?? 0).ToString();
                                    var    vipIntegralDetailId = vipIntegralBLL.AddIntegral(ref vipInfo, unitInfo, IntegralDetail, pTran, loggingSessionInfo);
                                    //发送微信积分变动通知模板消息
                                    if (!string.IsNullOrWhiteSpace(vipIntegralDetailId))
                                    {
                                        var CommonBLL = new CommonBLL();
                                        CommonBLL.PointsChangeMessage(OldIntegral, vipInfo, ChangeIntegral, vipInfo.WeiXinUserId, loggingSessionInfo);
                                    }
                                }
                            }
                            //确认收货时退回订单奖励积分、返现和佣金
                            vipIntegralBLL.CancelReward(inoutInfo, vipInfo, pTran);
                        }
                        #endregion
                        break;

                    case 4:
                        #region 拒绝收货
                        salesReturnEntity.Status = 5;    //拒绝收货
                        salesReturnBLL.Update(salesReturnEntity, pTran);

                        historyEntity = new T_SalesReturnHistoryEntity()
                        {
                            SalesReturnID = salesReturnEntity.SalesReturnID,
                            OperationType = 5,
                            OperationDesc = "收货",
                            OperatorID    = loggingSessionInfo.UserID,
                            HisRemark     = para.Desc,
                            OperatorName  = userEntity.user_name,
                            OperatorType  = 1
                        };
                        historyBLL.Create(historyEntity, pTran);
                        #endregion
                        break;

                    case 5:
                        #region 修改信息
                        if (para.ServicesType > 0)     //修改服务方式
                        {
                            salesReturnEntity.ServicesType = para.ServicesType;
                            string servicesTypeDesc = para.ServicesType == 1 ? "退货" : "换货";
                            historyEntity = new T_SalesReturnHistoryEntity()
                            {
                                SalesReturnID = salesReturnEntity.SalesReturnID,
                                OperationType = 11,
                                OperationDesc = "修改信息",
                                OperatorID    = loggingSessionInfo.UserID,
                                HisRemark     = "修改服务方式为" + servicesTypeDesc,
                                OperatorName  = userEntity.user_name,
                                OperatorType  = 1,
                                IsDelete      = 1
                            };
                            historyBLL.Create(historyEntity, pTran);
                        }
                        if (para.ActualQty > 0)    //修改申请数量
                        {
                            salesReturnEntity.ActualQty = para.ActualQty;
                            historyEntity = new T_SalesReturnHistoryEntity()
                            {
                                SalesReturnID = salesReturnEntity.SalesReturnID,
                                OperationType = 11,
                                OperationDesc = "修改信息",
                                OperatorID    = loggingSessionInfo.UserID,
                                HisRemark     = "修改确认退货数量为" + para.ActualQty,
                                OperatorName  = userEntity.user_name,
                                OperatorType  = 1,
                                IsDelete      = 1
                            };
                            historyBLL.Create(historyEntity, pTran);
                        }
                        if (para.ConfirmAmount >= 0)    //处理实退金额
                        {
                            salesReturnEntity.ConfirmAmount = para.ConfirmAmount;

                            historyEntity = new T_SalesReturnHistoryEntity()
                            {
                                SalesReturnID = salesReturnEntity.SalesReturnID,
                                OperationType = 13,
                                OperationDesc = "修改信息",
                                OperatorID    = loggingSessionInfo.UserID,
                                HisRemark     = "修改实退金额为" + para.ConfirmAmount,
                                OperatorName  = userEntity.user_name,
                                OperatorType  = 1,
                                IsDelete      = 1
                            };
                            historyBLL.Create(historyEntity, pTran);
                        }
                        salesReturnBLL.Update(salesReturnEntity, pTran);
                        #endregion
                        break;

                    case 6:
                        #region 取消
                        salesReturnEntity.Status = 2;    //取消申请
                        salesReturnBLL.Update(salesReturnEntity, pTran);
                        historyEntity = new T_SalesReturnHistoryEntity()
                        {
                            SalesReturnID = salesReturnEntity.SalesReturnID,
                            OperationType = 2,
                            OperationDesc = "取消申请",
                            OperatorID    = CurrentUserInfo.UserID,
                            HisRemark     = para.Desc,
                            OperatorName  = userEntity.user_name,
                            OperatorType  = 0
                        };
                        historyBLL.Create(historyEntity, pTran);
                        #endregion
                        break;

                    default:
                        break;
                    }
                    pTran.Commit();  //提交事物
                }
                catch (Exception ex)
                {
                    pTran.Rollback();//回滚事务
                    throw new APIException(ex.Message);
                }
            }
            return(rd);
        }
Esempio n. 11
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param>
 public void Update(VipAmountDetailEntity pEntity, IDbTransaction pTran)
 {
     _currentDAO.Update(pEntity, pTran);
 }
Esempio n. 12
0
 /// <summary>
 /// 创建一个新实例
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Create(VipAmountDetailEntity pEntity)
 {
     _currentDAO.Create(pEntity);
 }
Esempio n. 13
0
 /// <summary>
 /// 分页根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public PagedQueryResult <VipAmountDetailEntity> PagedQueryByEntity(VipAmountDetailEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex)
 {
     return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex));
 }
Esempio n. 14
0
 /// <summary>
 /// 根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public VipAmountDetailEntity[] QueryByEntity(VipAmountDetailEntity pQueryEntity, OrderBy[] pOrderBys)
 {
     return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys));
 }
Esempio n. 15
0
        /// <summary>
        /// 计算销售会员卡分润
        /// </summary>
        /// <param name="loggingSessionInfo"></param>
        /// <param name="orderInfo"></param>
        public void CalculateSalesVipCardOrder(LoggingSessionInfo loggingSessionInfo, T_InoutEntity orderInfo)
        {
            if (orderInfo != null)
            {
                if (orderInfo.Field17 != null && orderInfo.Field18 != null && orderInfo.Field17.Length > 0 && orderInfo.Field18.Length > 0)
                {
                    VipBLL bllVip = new VipBLL(loggingSessionInfo);

                    T_Inout_DetailBLL           bllInoutDetail            = new T_Inout_DetailBLL(loggingSessionInfo);
                    T_VirtualItemTypeSettingBLL bllVirtualItemTypeSetting = new T_VirtualItemTypeSettingBLL(loggingSessionInfo);

                    var entityInoutDetail = bllInoutDetail.QueryByEntity(new T_Inout_DetailEntity()
                    {
                        order_id = orderInfo.order_id
                    }, null).FirstOrDefault();
                    var vipCardType = bllVirtualItemTypeSetting.QueryByEntity(new T_VirtualItemTypeSettingEntity()
                    {
                        SkuId = entityInoutDetail.sku_id, IsDelete = 0
                    }, null).FirstOrDefault();
                    if (vipCardType != null)
                    {
                        VipCardUpgradeRuleBLL bllVipCardUpgradeRule = new VipCardUpgradeRuleBLL(loggingSessionInfo);

                        int intVipCardTypeID         = Convert.ToInt32(vipCardType.ObjecetTypeId);
                        var entityVipCardUpgradeRule = bllVipCardUpgradeRule.QueryByEntity(new VipCardUpgradeRuleEntity()
                        {
                            VipCardTypeID = intVipCardTypeID, IsPurchaseUpgrade = 1, IsDelete = 0
                        }, null).SingleOrDefault();
                        #region
                        //if (entityVipCardUpgradeRule != null)
                        //{
                        //    VipCardGradeChangeLogEntity entityVipCardGradeChangeLog = new VipCardGradeChangeLogEntity();
                        //    VipCardStatusChangeLogEntity entityVipCardStatusChangeLog = new VipCardStatusChangeLogEntity();

                        //    VipCardGradeChangeLogBLL bllVipCardGradeChangeLog = new VipCardGradeChangeLogBLL(loggingSessionInfo);
                        //    VipCardStatusChangeLogBLL bllVipCardStatusChangeLog = new VipCardStatusChangeLogBLL(loggingSessionInfo);
                        //    VipCardVipMappingBLL vipCardVipMappingBLL = new VipCardVipMappingBLL(loggingSessionInfo);

                        //    //会员等级改变以及如日志
                        //    DataSet dsVipInfo = bllVip.GetVipCardLevel(orderInfo.vip_no, loggingSessionInfo.ClientID);
                        //    if(dsVipInfo.Tables.Count>0 && dsVipInfo.Tables[0].Rows.Count>0)
                        //    {
                        //        //会员升级
                        //        vipCardVipMappingBLL.BindVirtualItem(orderInfo.vip_no, orderInfo.VipCardCode, "", intVipCardTypeID);
                        //        //日志
                        //        entityVipCardGradeChangeLog = new VipCardGradeChangeLogEntity()
                        //        {
                        //            ChangeLogID=Guid.NewGuid().ToString(),
                        //            VipCardUpgradeRuleId=entityVipCardUpgradeRule.VipCardUpgradeRuleId,
                        //            OrderType = "SalesCard",
                        //            OrderId=orderInfo.order_id,
                        //            VipCardID = dsVipInfo.Tables[0].Rows[0]["VipCardID"].ToString(),
                        //            ChangeBeforeVipCardID = dsVipInfo.Tables[0].Rows[0]["VipCardID"].ToString(),
                        //            ChangeBeforeGradeID = Convert.ToInt32(dsVipInfo.Tables[0].Rows[0]["VipCardTypeID"].ToString()),
                        //            NowGradeID = intVipCardTypeID,
                        //            ChangeReason="Upgrade",
                        //            OperationType = 2,
                        //            ChangeTime=DateTime.Now,
                        //            UnitID=orderInfo.sales_unit_id,
                        //            OperationUserID=orderInfo.sales_user
                        //        };
                        //        bllVipCardGradeChangeLog.Create(entityVipCardGradeChangeLog);
                        //    }
                        //}
                        #endregion
                        //计算分润
                        VipCardProfitRuleBLL bllVipCardProfitRule = new VipCardProfitRuleBLL(loggingSessionInfo);
                        var entityVipCardProfitRule = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
                        {
                            VipCardTypeID = intVipCardTypeID, IsDelete = 0
                        }, null);
                        if (entityVipCardProfitRule != null)
                        {
                            VipAmountBLL       bllVipAmount       = new VipAmountBLL(loggingSessionInfo);
                            VipAmountDetailBLL bllVipAmountDetail = new VipAmountDetailBLL(loggingSessionInfo);
                            VipAmountEntity    entityVipAmount    = new VipAmountEntity();

                            foreach (var ProfitRule in entityVipCardProfitRule)
                            {
                                decimal amount            = 0;
                                string  strAmountSourceId = string.Empty;
                                string  strVipId          = string.Empty;

                                if (ProfitRule.ProfitOwner == "Employee")
                                {
                                    strAmountSourceId = "37";
                                    strVipId          = orderInfo.sales_user;
                                }
                                if (ProfitRule.ProfitOwner == "Unit")
                                {
                                    strAmountSourceId = "40";
                                    strVipId          = orderInfo.sales_unit_id;
                                }
                                if (ProfitRule.IsApplyAllUnits == 0)
                                {
                                    VipCardProfitRuleUnitMappingBLL bllVipCardProfitRuleUnitMapping = new VipCardProfitRuleUnitMappingBLL(loggingSessionInfo);
                                    var vipCardProfitRuleUnitMapping = bllVipCardProfitRuleUnitMapping.QueryByEntity(new VipCardProfitRuleUnitMappingEntity()
                                    {
                                        CardBuyToProfitRuleId = ProfitRule.CardBuyToProfitRuleId, UnitID = orderInfo.sales_unit_id, IsDelete = 0, CustomerID = loggingSessionInfo.ClientID
                                    }, null).SingleOrDefault();
                                    if (vipCardProfitRuleUnitMapping != null)
                                    {
                                        amount = (decimal)ProfitRule.FirstCardSalesProfitPct * (decimal)orderInfo.actual_amount * (decimal)0.01;
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }

                                amount = (decimal)ProfitRule.FirstCardSalesProfitPct * (decimal)orderInfo.actual_amount * (decimal)0.01;
                                if (amount > 0)
                                {
                                    IDbTransaction tran = new JIT.CPOS.BS.DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction();

                                    VipAmountDetailEntity entityVipAmountDetail = new VipAmountDetailEntity
                                    {
                                        VipAmountDetailId = Guid.NewGuid(),
                                        VipId             = strVipId,
                                        Amount            = amount,
                                        UsedReturnAmount  = 0,
                                        EffectiveDate     = DateTime.Now,
                                        DeadlineDate      = Convert.ToDateTime("9999-12-31 23:59:59"),
                                        AmountSourceId    = strAmountSourceId,
                                        ObjectId          = orderInfo.order_id,
                                        CustomerID        = loggingSessionInfo.ClientID,
                                        Reason            = "超级分销商"
                                    };
                                    bllVipAmountDetail.Create(entityVipAmountDetail, (SqlTransaction)tran);

                                    entityVipAmount = new VipAmountEntity
                                    {
                                        VipId                  = strVipId,
                                        BeginAmount            = 0,
                                        InAmount               = amount,
                                        OutAmount              = 0,
                                        EndAmount              = amount,
                                        TotalAmount            = amount,
                                        BeginReturnAmount      = 0,
                                        InReturnAmount         = 0,
                                        OutReturnAmount        = 0,
                                        ReturnAmount           = 0,
                                        ImminentInvalidRAmount = 0,
                                        InvalidReturnAmount    = 0,
                                        ValidReturnAmount      = 0,
                                        TotalReturnAmount      = 0,
                                        IsLocking              = 0,
                                        CustomerID             = loggingSessionInfo.ClientID,
                                        VipCardCode            = ""
                                    };
                                    bllVipAmount.Create(entityVipAmount, tran);
                                }
                                else
                                {
                                    entityVipAmount.InReturnAmount    = (entityVipAmount.InReturnAmount == null ? 0 : entityVipAmount.InReturnAmount.Value) + amount;
                                    entityVipAmount.TotalReturnAmount = (entityVipAmount.TotalReturnAmount == null ? 0 : entityVipAmount.TotalReturnAmount.Value) + amount;

                                    entityVipAmount.ValidReturnAmount = (entityVipAmount.ValidReturnAmount == null ? 0 : entityVipAmount.ValidReturnAmount.Value) + amount;
                                    entityVipAmount.ReturnAmount      = (entityVipAmount.ReturnAmount == null ? 0 : entityVipAmount.ReturnAmount.Value) + amount;
                                    bllVipAmount.Update(entityVipAmount);
                                }
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 计算超级分销商佣金,分润用到的批处理
        /// </summary>
        public void CalculateSuperRetailTraderOrderJob()
        {
            var numCount = 50;

            var customerIDs = CustomerBLL.Instance.GetCustomerList();

            foreach (var customer in customerIDs)
            {
                string connString = customer.Value;
                var    count      = RedisOpenAPI.Instance.CCSuperRetailTraderOrder().GetSuperRetailTraderOrderLength(new CC_Order
                {
                    CustomerID = customer.Key
                });
                if (count.Code != ResponseCode.Success)
                {
                    BaseService.WriteLog("从redis获取待绑定优惠券数量失败");
                    continue;
                }
                if (count.Result <= 0)
                {
                    continue;
                }
                if (count.Result < numCount)
                {
                    numCount = Convert.ToInt32(count.Result);
                }

                DataTable dtProfitDetail = CreateTableProfitDetail();
                DataTable dtAmountDetail = CreateTableAmountDetail();
                DataTable dtAmount       = CreateTableAmount();

                for (var i = 0; i < numCount; i++)
                {
                    var response = RedisOpenAPI.Instance.CCSuperRetailTraderOrder().GetSuperRetailTraderOrder(new CC_Order
                    {
                        CustomerID = customer.Key
                    });
                    if (response.Code == ResponseCode.Success)
                    {
                        var orderInfo = response.Result.OrderInfo.JsonDeserialize <T_InoutEntity>();
                        //var loggingSessionInfo = response.Result.LogSession.JsonDeserialize<LoggingSessionInfo>();
                        var        loggingSessionInfo = CustomerBLL.Instance.GetBSLoggingSession(customer.Key, "1");
                        T_InoutBLL inoutBLL           = new T_InoutBLL(loggingSessionInfo);
                        //inoutBLL.CalculateSuperRetailTraderOrder(loggingSessionInfo, orderInfo);
                        if (orderInfo != null)
                        {
                            if (orderInfo.data_from_id == "35" || orderInfo.data_from_id == "36")
                            {
                                T_SuperRetailTraderBLL bllSuperRetailTrader = new T_SuperRetailTraderBLL(loggingSessionInfo);
                                DataSet dsAllFather = bllSuperRetailTrader.GetAllFather(orderInfo.sales_user);
                                if (dsAllFather != null && dsAllFather.Tables.Count > 0 && dsAllFather.Tables[0].Rows.Count > 0)
                                {
                                    T_SuperRetailTraderProfitConfigBLL bllSuperRetailTraderProfitConfig = new T_SuperRetailTraderProfitConfigBLL(loggingSessionInfo);
                                    T_SuperRetailTraderConfigBLL       bllSuperRetailTraderConfig       = new T_SuperRetailTraderConfigBLL(loggingSessionInfo);
                                    T_SuperRetailTraderProfitDetailBLL bllSuperRetailTraderProfitDetail = new T_SuperRetailTraderProfitDetailBLL(loggingSessionInfo);

                                    VipAmountBLL       bllVipAmount       = new VipAmountBLL(loggingSessionInfo);
                                    VipAmountDetailBLL bllVipAmountDetail = new VipAmountDetailBLL(loggingSessionInfo);

                                    var entitySuperRetailTraderProfitConfig = bllSuperRetailTraderProfitConfig.QueryByEntity(new T_SuperRetailTraderProfitConfigEntity()
                                    {
                                        CustomerId = loggingSessionInfo.ClientID, IsDelete = 0, Status = "10"
                                    }, null);
                                    var entityConfig = bllSuperRetailTraderConfig.QueryByEntity(new T_SuperRetailTraderConfigEntity()
                                    {
                                        CustomerId = loggingSessionInfo.ClientID, IsDelete = 0
                                    }, null).SingleOrDefault();
                                    if (entityConfig != null && entitySuperRetailTraderProfitConfig != null)
                                    {
                                        //佣金比列
                                        decimal SkuCommission = Convert.ToDecimal(entityConfig.SkuCommission) * Convert.ToDecimal(0.01);
                                        //商品分润比列
                                        decimal DistributionProfit = Convert.ToDecimal(entityConfig.DistributionProfit) * Convert.ToDecimal(0.01);


                                        foreach (DataRow dr in dsAllFather.Tables[0].Rows)
                                        {
                                            decimal amount            = 0;
                                            string  strAmountSourceId = string.Empty;
                                            T_SuperRetailTraderProfitConfigEntity singlProfitConfig = new T_SuperRetailTraderProfitConfigEntity();
                                            if (dr["level"].ToString() == "1")      //佣金
                                            {
                                                strAmountSourceId = "34";
                                                singlProfitConfig = entitySuperRetailTraderProfitConfig.Where(a => a.Level == Convert.ToInt16(dr["level"].ToString())).SingleOrDefault();
                                                if (singlProfitConfig != null)
                                                {
                                                    if (singlProfitConfig.ProfitType == "Percent")
                                                    {
                                                        amount = Convert.ToDecimal(orderInfo.actual_amount) * SkuCommission;
                                                    }
                                                }
                                            }
                                            else      //分润
                                            {
                                                strAmountSourceId = "33";
                                                singlProfitConfig = entitySuperRetailTraderProfitConfig.Where(a => a.Level == Convert.ToInt16(dr["level"].ToString())).SingleOrDefault();
                                                if (singlProfitConfig != null)
                                                {
                                                    if (singlProfitConfig.ProfitType == "Percent")
                                                    {
                                                        //amount = Convert.ToDecimal(orderInfo.actual_amount) * DistributionProfit * Convert.ToDecimal(singlProfitConfig.Profit) * Convert.ToDecimal(0.01);
                                                        amount = Convert.ToDecimal(orderInfo.actual_amount) * Convert.ToDecimal(singlProfitConfig.Profit) * Convert.ToDecimal(0.01);
                                                    }
                                                }
                                            }
                                            var vipAmountDetail = bllVipAmountDetail.QueryByEntity(new VipAmountDetailEntity()
                                            {
                                                ObjectId = orderInfo.order_id, AmountSourceId = strAmountSourceId
                                            }, null);
                                            if (vipAmountDetail != null && vipAmountDetail.Length > 0)
                                            {
                                                continue;
                                            }
                                            if (amount > 0)
                                            {
                                                IDbTransaction tran = new JIT.CPOS.BS.DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction();
                                                try
                                                {
                                                    T_SuperRetailTraderProfitDetailEntity entitySuperRetailTraderProfitDetail = new T_SuperRetailTraderProfitDetailEntity()
                                                    {
                                                        SuperRetailTraderProfitConfigId = singlProfitConfig.SuperRetailTraderProfitConfigId,
                                                        SuperRetailTraderID             = new Guid(dr["SuperRetailTraderID"].ToString()),
                                                        Level             = Convert.ToInt16(dr["level"].ToString()),
                                                        ProfitType        = "Cash",
                                                        Profit            = amount,
                                                        OrderType         = "Order",
                                                        OrderId           = orderInfo.order_id,
                                                        OrderDate         = Convert.ToDateTime(orderInfo.order_date),
                                                        VipId             = orderInfo.vip_no,
                                                        OrderActualAmount = orderInfo.actual_amount,
                                                        SalesId           = new Guid(orderInfo.sales_user),
                                                        OrderNo           = orderInfo.order_no,
                                                        CustomerId        = loggingSessionInfo.ClientID
                                                    };
                                                    bllSuperRetailTraderProfitDetail.Create(entitySuperRetailTraderProfitDetail, (SqlTransaction)tran);

                                                    VipAmountEntity       entityVipAmount       = new VipAmountEntity();
                                                    VipAmountDetailEntity entityVipAmountDetail = new VipAmountDetailEntity();
                                                    entityVipAmountDetail = new VipAmountDetailEntity {
                                                        VipAmountDetailId = Guid.NewGuid(),
                                                        VipId             = dr["SuperRetailTraderID"].ToString(),
                                                        Amount            = amount,
                                                        UsedReturnAmount  = 0,
                                                        EffectiveDate     = DateTime.Now,
                                                        DeadlineDate      = Convert.ToDateTime("9999-12-31 23:59:59"),
                                                        AmountSourceId    = strAmountSourceId,
                                                        ObjectId          = orderInfo.order_id,
                                                        CustomerID        = loggingSessionInfo.ClientID,
                                                        Reason            = "超级分销商",
                                                        IsWithdrawCash    = 0
                                                    };
                                                    bllVipAmountDetail.Create(entityVipAmountDetail, (SqlTransaction)tran);
                                                    //DataRow dr_ProfitDetail = dtProfitDetail.NewRow();
                                                    //dr_ProfitDetail["Id"] = Guid.NewGuid();
                                                    //dr_ProfitDetail["SuperRetailTraderProfitConfigId"] = new Guid(singlProfitConfig.SuperRetailTraderProfitConfigId.ToString());
                                                    //dr_ProfitDetail["SuperRetailTraderID"] = new Guid(dr["SuperRetailTraderID"].ToString());
                                                    //dr_ProfitDetail["Level"] = Convert.ToInt16(dr["level"].ToString());
                                                    //dr_ProfitDetail["ProfitType"] = "Cash";
                                                    //dr_ProfitDetail["Profit"] = amount;
                                                    //dr_ProfitDetail["OrderType"] = "Order";
                                                    //dr_ProfitDetail["OrderId"] = orderInfo.order_id;
                                                    //dr_ProfitDetail["OrderNo"] = orderInfo.order_no;
                                                    //dr_ProfitDetail["OrderDate"] = Convert.ToDateTime(orderInfo.order_date);
                                                    //dr_ProfitDetail["OrderActualAmount"] = orderInfo.actual_amount;
                                                    //dr_ProfitDetail["SalesId"] = new Guid(orderInfo.sales_user);
                                                    //dr_ProfitDetail["VipId"] = orderInfo.vip_no;
                                                    //dr_ProfitDetail["CreateBy"] = loggingSessionInfo.ClientID;
                                                    //dr_ProfitDetail["CreateTime"] = DateTime.Now;
                                                    //dr_ProfitDetail["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                                    //dr_ProfitDetail["LastUpdateTime"] = DateTime.Now;
                                                    //dr_ProfitDetail["CustomerId"] = loggingSessionInfo.ClientID;
                                                    //dr_ProfitDetail["IsDelete"] = 0;

                                                    //dtProfitDetail.Rows.Add(dr_ProfitDetail);

                                                    //DataRow dr_AmountDetail = dtAmountDetail.NewRow();
                                                    //dr_AmountDetail["VipAmountDetailId"] = Guid.NewGuid();
                                                    //dr_AmountDetail["VipId"] = dr["SuperRetailTraderID"].ToString();
                                                    //dr_AmountDetail["VipCardCode"] = "";
                                                    //dr_AmountDetail["UnitID"] = "";
                                                    //dr_AmountDetail["UnitName"] = "";
                                                    //dr_AmountDetail["SalesAmount"] = 0;
                                                    //dr_AmountDetail["Amount"] = amount;
                                                    //dr_AmountDetail["UsedReturnAmount"] = 0;
                                                    //dr_AmountDetail["Reason"] = "超级分销商";
                                                    //dr_AmountDetail["EffectiveDate"] = DateTime.Now;
                                                    //dr_AmountDetail["DeadlineDate"] = Convert.ToDateTime("9999-12-31 23:59:59");
                                                    //dr_AmountDetail["AmountSourceId"] = strAmountSourceId;
                                                    //dr_AmountDetail["ObjectId"] = orderInfo.order_id;
                                                    //dr_AmountDetail["Remark"] = "超级分销商";
                                                    //dr_AmountDetail["IsValid"] = 0;
                                                    //dr_AmountDetail["IsWithdrawCash"] = 0;
                                                    //dr_AmountDetail["CustomerID"] = loggingSessionInfo.ClientID;
                                                    //dr_AmountDetail["CreateTime"] = DateTime.Now;
                                                    //dr_AmountDetail["CreateBy"] = loggingSessionInfo.ClientID;
                                                    //dr_AmountDetail["LastUpdateBy"] = loggingSessionInfo.ClientID;
                                                    //dr_AmountDetail["LastUpdateTime"] = DateTime.Now;
                                                    //dr_AmountDetail["IsDelete"] = 0;
                                                    ////dr_AmountDetail["IsCalculated"] = 1;

                                                    //dtAmountDetail.Rows.Add(dr_AmountDetail);

                                                    entityVipAmount = bllVipAmount.QueryByEntity(new VipAmountEntity()
                                                    {
                                                        VipId = dr["SuperRetailTraderID"].ToString(), IsDelete = 0
                                                    }, null).SingleOrDefault();
                                                    if (entityVipAmount == null)
                                                    {
                                                        entityVipAmount = new VipAmountEntity {
                                                            VipId                  = dr["SuperRetailTraderID"].ToString(),
                                                            BeginAmount            = 0,
                                                            InAmount               = amount,
                                                            OutAmount              = 0,
                                                            EndAmount              = amount,
                                                            TotalAmount            = amount,
                                                            BeginReturnAmount      = 0,
                                                            InReturnAmount         = 0,
                                                            OutReturnAmount        = 0,
                                                            ReturnAmount           = 0,
                                                            ImminentInvalidRAmount = 0,
                                                            InvalidReturnAmount    = 0,
                                                            ValidReturnAmount      = 0,
                                                            TotalReturnAmount      = 0,
                                                            IsLocking              = 0,
                                                            CustomerID             = loggingSessionInfo.ClientID,
                                                            VipCardCode            = ""
                                                        };
                                                        bllVipAmount.Create(entityVipAmount, tran);
                                                        //DataRow dr_Amount = dtAmount.NewRow();
                                                        //dr_Amount["VipId"] = dr["SuperRetailTraderID"].ToString();
                                                        //dr_Amount["VipCardCode"] = "";
                                                        //dr_Amount["BeginAmount"] = 0;
                                                        //dr_Amount["InAmount"] = amount;
                                                        //dr_Amount["OutAmount"] = 0;
                                                        //dr_Amount["EndAmount"] = amount;
                                                        //dr_Amount["TotalAmount"] = amount;
                                                        //dr_Amount["BeginReturnAmount"] = 0;
                                                        //dr_Amount["InReturnAmount"] = 0;
                                                        //dr_Amount["OutReturnAmount"] = 0;
                                                        //dr_Amount["ReturnAmount"] = 0;
                                                        //dr_Amount["ImminentInvalidRAmount"] = 0;
                                                        //dr_Amount["InvalidReturnAmount"] = 0;
                                                        //dr_Amount["ValidReturnAmount"] = 0;
                                                        //dr_Amount["TotalReturnAmount"] = 0;
                                                        //dr_Amount["PayPassword"] = "";
                                                        //dr_Amount["IsLocking"] = 0;
                                                        //dr_Amount["CustomerID"] = loggingSessionInfo.ClientID;
                                                        //dr_Amount["CreateTime"] = DateTime.Now;
                                                        //dr_Amount["CreateBy"] = loggingSessionInfo.ClientID;
                                                        //dr_Amount["LastUpdateBy"] =loggingSessionInfo.ClientID;
                                                        //dr_Amount["LastUpdateTime"] = DateTime.Now;
                                                        //dr_Amount["IsDelete"] = 0;
                                                        //dtAmount.Rows.Add(dr_Amount);
                                                    }
                                                    else
                                                    {
                                                        entityVipAmount.InReturnAmount    = (entityVipAmount.InReturnAmount == null ? 0 : entityVipAmount.InReturnAmount.Value) + amount;
                                                        entityVipAmount.TotalReturnAmount = (entityVipAmount.TotalReturnAmount == null ? 0 : entityVipAmount.TotalReturnAmount.Value) + amount;

                                                        entityVipAmount.ValidReturnAmount = (entityVipAmount.ValidReturnAmount == null ? 0 : entityVipAmount.ValidReturnAmount.Value) + amount;
                                                        entityVipAmount.ReturnAmount      = (entityVipAmount.ReturnAmount == null ? 0 : entityVipAmount.ReturnAmount.Value) + amount;

                                                        bllVipAmount.Update(entityVipAmount);
                                                    }
                                                    tran.Commit();
                                                }
                                                catch (Exception)
                                                {
                                                    tran.Rollback();
                                                    throw;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //if (dtAmount.Rows.Count > 0)
                //{
                //    Utils.SqlBulkCopy(connString, dtAmount, "VipAmount");
                //}
                //if (dtAmountDetail.Rows.Count>0 && dtProfitDetail.Rows.Count>0)
                //{
                //    Utils.SqlBulkCopy(connString, dtProfitDetail, "T_SuperRetailTraderProfitDetail");
                //    Utils.SqlBulkCopy(connString, dtAmountDetail, "VipAmountDetail");

                //}
            }
        }
Esempio n. 17
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            var OrderID     = context.Request["OrderID"];
            var OrderStatus = context.Request["OrderStatus"];
            var CustomerID  = context.Request["CustomerID"];
            var UserID      = context.Request["UserID"];
            var ChannelID   = context.Request["ChannelID"];
            var SerialPay   = context.Request["SerialPay"];

            try
            {
                if (string.IsNullOrEmpty(OrderID) || string.IsNullOrEmpty(OrderStatus) || string.IsNullOrEmpty(CustomerID) || string.IsNullOrEmpty(UserID) || string.IsNullOrEmpty(ChannelID))
                {
                    throw new Exception("参数不全:OrderID,OrderStatus,CustomerID,UserID");
                }
                else
                {
                    if (OrderStatus == "2")
                    {
                        //支付成功,更新卡的支付状态
                        //OrderID就是VIPCardID
                        //
                        //var rp = pRequest.DeserializeJSONTo<APIRequest<SetVipCardRP>>();

                        //if (string.IsNullOrEmpty(rp.Parameters.PayID))
                        //{
                        //    throw new APIException("缺少参数【PayID】或参数值为空") { ErrorCode = 135 };
                        //}
                        var loggingSessionInfo = Default.GetBSLoggingSession(CustomerID, UserID);
                        //会员
                        var vipBll               = new VipBLL(loggingSessionInfo);
                        var vipAmountBll         = new VipAmountBLL(loggingSessionInfo);
                        var vipCardVipMappingBll = new VipCardVipMappingBLL(loggingSessionInfo);
                        //支付
                        var tPaymentTypeCustomerMappingBll = new TPaymentTypeCustomerMappingBLL(loggingSessionInfo);
                        var tPaymentTypeBll  = new T_Payment_TypeBLL(loggingSessionInfo);
                        var paymentDetailBll = new T_Payment_detailBLL(loggingSessionInfo);
                        //门店
                        var unitBLL = new t_unitBLL(loggingSessionInfo);
                        //商品订单支付
                        //更新积分和状态
                        //var loggingSessionInfo = Default.GetBSLoggingSession(CustomerID, "1");
                        var inoutBll = new T_InoutBLL(loggingSessionInfo);//订单业务对象实例化

                        var trrBll = new T_RewardRecordBLL(loggingSessionInfo);
                        //辨别打赏订单
                        var rewardOrderPrefix = "REWARD|";
                        if (OrderID.Contains(rewardOrderPrefix))
                        {
                            OrderID = OrderID.Substring(rewardOrderPrefix.Length, OrderID.Length - rewardOrderPrefix.Length);
                            var trrEntity = trrBll.GetByID(OrderID);
                            trrEntity.PayStatus      = 2;
                            trrEntity.LastUpdateTime = DateTime.Now;
                            trrEntity.LastUpdateBy   = loggingSessionInfo.UserID;
                            trrBll.Update(trrEntity);

                            #region 员工余额变更--需要独立出来处理
                            var userAmountBll = new VipAmountBLL(loggingSessionInfo);                                 //作为员工余额使用
                            var employeeId    = trrEntity.RewardedOP;
                            var rewardAmount  = trrEntity.RewardAmount == null ? 0 : (decimal)trrEntity.RewardAmount; //转为非null的decimal类型
                            //门店
                            var unitService = new UnitService(loggingSessionInfo);
                            var unitInfo    = unitService.GetUnitByUser(CustomerID, employeeId).FirstOrDefault();//获取员工所属门店

                            var tran = userAmountBll.GetTran();
                            using (tran.Connection)//事务
                            {
                                try
                                {
                                    var userAmountEntity = userAmountBll.GetByID(trrEntity.RewardedOP);
                                    if (userAmountEntity == null)
                                    {
                                        //创建
                                        userAmountEntity = new VipAmountEntity
                                        {
                                            VipId                  = employeeId,//员工ID
                                            VipCardCode            = string.Empty,
                                            BeginAmount            = 0,
                                            InAmount               = rewardAmount,
                                            OutAmount              = 0,
                                            EndAmount              = rewardAmount,
                                            TotalAmount            = rewardAmount,
                                            BeginReturnAmount      = 0,
                                            InReturnAmount         = 0,
                                            OutReturnAmount        = 0,
                                            ReturnAmount           = 0,
                                            ImminentInvalidRAmount = 0,
                                            InvalidReturnAmount    = 0,
                                            ValidReturnAmount      = 0,
                                            TotalReturnAmount      = 0,
                                            IsLocking              = 0,
                                            CustomerID             = CustomerID
                                        };
                                        userAmountBll.Create(userAmountEntity, tran);//创建员工余额表
                                    }
                                    else
                                    {
                                        //修改
                                        if (rewardAmount > 0)
                                        {
                                            userAmountEntity.InAmount    = (userAmountEntity.InAmount == null ? 0 : userAmountEntity.InAmount.Value) + rewardAmount;
                                            userAmountEntity.TotalAmount = (userAmountEntity.TotalAmount == null ? 0 : userAmountEntity.TotalAmount.Value) + rewardAmount;
                                        }
                                        else
                                        {
                                            userAmountEntity.OutAmount = (userAmountEntity.OutAmount == null ? 0 : userAmountEntity.OutAmount.Value) + Math.Abs(rewardAmount);
                                        }
                                        userAmountEntity.EndAmount = (userAmountEntity.EndAmount == null ? 0 : userAmountEntity.EndAmount.Value) + rewardAmount;

                                        userAmountBll.Update(userAmountEntity, tran);//更新余额
                                    }

                                    var vipamountDetailBll    = new VipAmountDetailBLL(loggingSessionInfo);
                                    var vipAmountDetailEntity = new VipAmountDetailEntity
                                    {
                                        VipAmountDetailId = Guid.NewGuid(),
                                        VipCardCode       = string.Empty,
                                        VipId             = employeeId,//员工ID
                                        UnitID            = unitInfo != null ? unitInfo.unit_id : string.Empty,
                                        UnitName          = unitInfo != null ? unitInfo.Name : string.Empty,
                                        Amount            = rewardAmount,
                                        UsedReturnAmount  = 0,
                                        EffectiveDate     = DateTime.Now,
                                        DeadlineDate      = Convert.ToDateTime("9999-12-31 23:59:59"),
                                        AmountSourceId    = "26",
                                        Reason            = "Reward",
                                        CustomerID        = CustomerID
                                    };
                                    vipamountDetailBll.Create(vipAmountDetailEntity, tran); //创建余额详情

                                    tran.Commit();                                          //提交事务
                                }
                                catch (Exception ex)
                                {
                                    tran.Rollback();
                                    Loggers.Debug(new DebugLogInfo()
                                    {
                                        Message = "异常-->支付成功回调时更新会员打赏金额出错(PayNotify.ashx):" + ex
                                    });
                                }
                            }
                            #endregion

                            if (trrEntity != null)
                            {
                                context.Response.Write("SUCCESS");
                            }
                            else
                            {
                                context.Response.Write("FAIL");
                            }
                            return;
                        }
                        //获取会员信息
                        var vipInfo = vipBll.GetByID(loggingSessionInfo.UserID);
                        //支付信息 Bear
                        //var tPaymentTypeCustomerMappingEntity = tPaymentTypeCustomerMappingBll.QueryByEntity(new TPaymentTypeCustomerMappingEntity(){ChannelId = ChannelID,CustomerId = loggingSessionInfo.ClientID },null).FirstOrDefault();
                        var paymentTypeList = tPaymentTypeBll.GetAll();
                        var tPaymentType    =
                            paymentTypeList.ToList()
                            .Find(t => t.Payment_Type_Code == "WXJS");

                        //var tPaymentType = tPaymentTypeBll.GetByID(tPaymentTypeCustomerMappingEntity.PaymentTypeID);
                        //获取订单信息
                        var inoutInfo = inoutBll.GetByID(OrderID);
                        if (inoutInfo != null)
                        {
                            var    bll = new TInOutStatusNodeBLL(loggingSessionInfo);
                            string msg;
                            if (!bll.SetOrderPayment(OrderID, out msg, ChannelID, SerialPay))
                            //if (!bll.SetOrderPayment(OrderID, out msg, ChannelID))
                            {
                                throw new Exception(msg);
                            }
                            else if (string.IsNullOrEmpty(inoutInfo.Field17) && string.IsNullOrEmpty(inoutInfo.Field18))
                            {
                                #region 发送订单支付成功微信模板消息
                                var SuccessCommonBLL = new CommonBLL();
                                //SuccessCommonBLL.SentPaymentMessage(inoutInfo, vipInfo.WeiXinUserId,vipInfo.VIPID, loggingSessionInfo);
                                new SendOrderPaySuccessMsgBLL().SentPaymentMessage(inoutInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, loggingSessionInfo);
                                #endregion
                                Loggers.Debug(new DebugLogInfo()
                                {
                                    Message = "调用SetOrderPayment方法更新订单成功"
                                });
                            }
                            //获取订单信息,根据Field3==1判断,如果是ALD订单,则调用ALD接口更新ALD订单的状态
                            #region 更新ALD状态
                            //var orderbll = new InoutService(loggingSessionInfo);
                            //var orderInfo = orderbll.GetInoutInfoById(OrderID);
                            //if (orderInfo.Field3 == "1")
                            //{
                            //    Loggers.Debug(new DebugLogInfo() { Message = string.Format("更新O2OMarketing订单状态成功[OrderID={0}].", OrderID) });
                            //    //更新阿拉丁的订单状态
                            //    JIT.CPOS.Web.OnlineShopping.data.DataOnlineShoppingHandler.ALDChangeOrderStatus aldChangeOrder = new data.DataOnlineShoppingHandler.ALDChangeOrderStatus();
                            //    if (string.IsNullOrEmpty(orderInfo.vip_no))
                            //        throw new Exception("会员ID不能为空,OrderID:" + OrderID);
                            //    aldChangeOrder.MemberID = new Guid(orderInfo.vip_no);
                            //    aldChangeOrder.SourceOrdersID = OrderID;
                            //    aldChangeOrder.Status = int.Parse(orderInfo.status);
                            //    aldChangeOrder.IsPaid = true;
                            //    JIT.CPOS.Web.OnlineShopping.data.DataOnlineShoppingHandler.ALDChangeOrderStatusRequest aldRequest = new data.DataOnlineShoppingHandler.ALDChangeOrderStatusRequest();
                            //    aldRequest.BusinessZoneID = 1;//写死
                            //    aldRequest.Locale = 1;

                            //    aldRequest.UserID = new Guid(orderInfo.vip_no);
                            //    aldRequest.Parameters = aldChangeOrder;
                            //    var url = ConfigurationManager.AppSettings["ALDGatewayURL"];
                            //    var postContent = string.Format("Action=ChangeOrderStatus&ReqContent={0}", aldRequest.ToJSON());
                            //    Loggers.Debug(new DebugLogInfo() { Message = "通知ALD更改状态:" + postContent });
                            //    var strAldRsp = HttpWebClient.DoHttpRequest(url, postContent);
                            //    var aldRsp = strAldRsp.DeserializeJSONTo<JIT.CPOS.Web.OnlineShopping.data.DataOnlineShoppingHandler.ALDResponse>();
                            //    if (!aldRsp.IsSuccess())
                            //    {
                            //        Loggers.Debug(new DebugLogInfo() { Message = string.Format("更新阿拉丁订单状态失败[Request ={0}][Response={1}]", aldRequest.ToJSON(), strAldRsp) });
                            //    }
                            //}
                            #endregion

                            #region 格力推送通知
                            //try
                            //{
                            //    GLServiceOrderBLL glsobll = new GLServiceOrderBLL(loggingSessionInfo);
                            //    if (glsobll.ValidateGree(CustomerID, "cpos_bs_lj"))//先写死
                            //        glsobll.GreePushPaymentOorder(CustomerID, OrderID, loggingSessionInfo);
                            //}
                            //catch (Exception ex)
                            //{
                            //    Loggers.Debug(new DebugLogInfo() { Message = string.Format("付款推送评价师傅链接失败[OrderID={0}].", OrderID) });
                            //}
                            #endregion

                            #region ALD生活服务处理
                            //var rechargeBll = new RechargeStrategyBLL(loggingSessionInfo);
                            //var vipAmountBll = new VipAmountBLL(loggingSessionInfo);
                            //var couponBll = new CouponBLL(loggingSessionInfo);
                            //var vipCouponMappingBll = new VipCouponMappingBLL(loggingSessionInfo);
                            //var unitBll = new UnitBLL(loggingSessionInfo);
                            //DataSet dsOrderInfo = rechargeBll.GetInoutOrderItems(OrderID);
                            //int itemSort = 0;            //商品业务分类
                            //string skuId = string.Empty; //商品SkuId
                            //string vipId = string.Empty; //会员ID
                            //string itemId = string.Empty;//商品ID
                            //string couponId = string.Empty;//优惠券ID
                            //if (dsOrderInfo.Tables[0].Rows.Count > 0)
                            //{
                            //    //if (dsOrderInfo.Tables[0].Rows[0]["ItemSort"] != DBNull.Value && Convert.ToString(dsOrderInfo.Tables[0].Rows[0]["ItemSort"]) != "0")
                            //    itemSort = int.Parse(dsOrderInfo.Tables[0].Rows[0]["ItemSort"].ToString());
                            //    switch (itemSort)
                            //    {
                            //        case 2://充
                            //            #region 充值金额处理

                            //            VipAmountDetailBLL vipAmountDetailBll = new VipAmountDetailBLL(loggingSessionInfo);

                            //            List<IWhereCondition> complexCondition = new List<IWhereCondition> { };
                            //            complexCondition.Add(new EqualsCondition() { FieldName = "ObjectId", Value = OrderID });

                            //            var vipAmountDetal = vipAmountDetailBll.Query(complexCondition.ToArray(), null);
                            //            if (vipAmountDetal.Count() == 0)//确认没有多次执行回调
                            //            {
                            //                ////查询
                            //                //RechargeStrategyEntity[] rechargeList = rechargeBll.Query(complexCondition.ToArray(), lstOrder.ToArray());

                            //                skuId = dsOrderInfo.Tables[0].Rows[0]["SkuId"].ToString();
                            //                //RechargeStrategyEntity rechargeEntity = rechargeBll.GetByID(skuId);
                            //                DataSet dsSkuPirce = unitBll.GetSkuPirce(skuId);
                            //                decimal salePrice = 0;//购买金额
                            //                decimal returnCash = 0;//奖励金额
                            //                if (dsSkuPirce.Tables[0].Rows.Count > 0)
                            //                {
                            //                    salePrice = Convert.ToDecimal(dsSkuPirce.Tables[0].Rows[0]["SalesPrice"].ToString());
                            //                    returnCash = Convert.ToDecimal(dsSkuPirce.Tables[0].Rows[0]["ReturnCash"].ToString());
                            //                    InoutService server = new InoutService(loggingSessionInfo);
                            //                    #region 充值金额
                            //                    var tran = server.GetTran();
                            //                    using (tran.Connection)//事物
                            //                    {
                            //                        try
                            //                        {
                            //                            //充值金额
                            //                            vipAmountBll.AddVipEndAmount(UserID, salePrice, tran, "4", OrderID, loggingSessionInfo);//4=充值
                            //                            tran.Commit();
                            //                        }
                            //                        catch (Exception)
                            //                        {
                            //                            tran.Rollback();
                            //                            throw;
                            //                        }
                            //                    }
                            //                    #endregion

                            //                    #region 奖励金额
                            //                    var tran2 = server.GetTran();
                            //                    using (tran2.Connection)//事物
                            //                    {
                            //                        try
                            //                        {
                            //                            //奖励金额
                            //                            vipAmountBll.AddVipEndAmount(UserID, returnCash, tran2, "6", OrderID, loggingSessionInfo);//6=奖励金额
                            //                            tran2.Commit();
                            //                        }
                            //                        catch (Exception)
                            //                        {
                            //                            tran2.Rollback();
                            //                            throw;
                            //                        }
                            //                    }
                            //                    #endregion
                            //                }
                            //            }
                            //            #endregion
                            //            break;
                            //        case 3://券
                            //            #region 券类商品绑定到会员
                            //            itemId = dsOrderInfo.Tables[0].Rows[0]["ItemId"].ToString();
                            //            vipId = dsOrderInfo.Tables[0].Rows[0]["VipId"].ToString();
                            //            couponId = couponBll.GetCouponByItemId(itemId);
                            //            if (!string.IsNullOrEmpty(couponId))
                            //            {
                            //                VipCouponMappingEntity coupon = new VipCouponMappingEntity
                            //                {
                            //                    VIPID = vipId,
                            //                    CouponID = couponId,
                            //                };
                            //                vipCouponMappingBll.Create(coupon);
                            //            }
                            //            #endregion
                            //            break;
                            //        default:
                            //            break;
                            //    }
                            //}

                            #endregion

                            #region 订单与分润关系处理 add by Henry 2014-10-10
                            //var orderSubBll = new OrderOrderSubRunObjectMappingBLL(loggingSessionInfo);
                            //dynamic o = orderSubBll.SetOrderSub(CustomerID, OrderID);
                            //Type t = o.GetType();
                            //var Desc = t.GetProperty("Desc").GetValue(o, null).ToString();
                            //var IsSuccess = t.GetProperty("IsSuccess").GetValue(o, null).ToString();
                            //if (int.Parse(IsSuccess.ToString()) == 0) //失败
                            //    Loggers.Debug(new DebugLogInfo() { Message = string.Format("订单与分润关系处理失败:{0}", Desc) });
                            #endregion

                            CustomerBasicSettingBLL customerBasicSettingBll = new CustomerBasicSettingBLL(loggingSessionInfo);
                            string AfterPaySetStock = customerBasicSettingBll.GetSettingValueByCode("AfterPaySetStock");
                            if (AfterPaySetStock == "1")
                            {
                                var inoutServiceBLL = new InoutService(loggingSessionInfo);
                                var inoutDetailList = inoutServiceBLL.GetInoutDetailInfoByOrderId(OrderID);
                                inoutBll.SetStock(OrderID, inoutDetailList, 1, loggingSessionInfo);
                            }
                            ///超级分销商订单入队列
                            if (inoutInfo.data_from_id == "35" || inoutInfo.data_from_id == "36")
                            {
                                BS.BLL.RedisOperationBLL.Order.SuperRetailTraderOrderBLL bllSuperRetailTraderOrder = new BS.BLL.RedisOperationBLL.Order.SuperRetailTraderOrderBLL();
                                bllSuperRetailTraderOrder.SetRedisToSuperRetailTraderOrder(loggingSessionInfo, inoutInfo);
                            }

                            //购卡
                            if (!string.IsNullOrEmpty(inoutInfo.Field17) && !string.IsNullOrEmpty(inoutInfo.Field18))
                            {
                                //更新订单状态
                                inoutInfo             = inoutBll.GetByID(OrderID);
                                inoutInfo.Field7      = "700";
                                inoutInfo.status      = "700";
                                inoutInfo.status_desc = "已完成";
                                inoutInfo.Field10     = "已完成";
                                inoutBll.Update(inoutInfo);
                                //会员卡升级
                                vipCardVipMappingBll.BindVirtualItem(vipInfo.VIPID, vipInfo.VipCode, inoutInfo.sales_unit_id, Convert.ToInt32(inoutInfo.Field18), orderId: inoutInfo.order_id);

                                //分润计算
                                RedisSalesVipCardOrderBLL redisSalesVipCardOrderBll = new RedisSalesVipCardOrderBLL();
                                redisSalesVipCardOrderBll.SetRedisSalesVipCardOrder(loggingSessionInfo, inoutInfo);

                                //售卡处理积分、返现、佣金[完成订单]
                                new SendOrderRewardMsgBLL().OrderReward(inoutInfo, loggingSessionInfo, null);//存入到缓存
                            }
                            else
                            {
                                //订单入队列
                                RedisCalculateVipConsumeForUpgrade redisCalculateVipConsumeForUpgrade = new RedisCalculateVipConsumeForUpgrade();
                                redisCalculateVipConsumeForUpgrade.SetVipConsumeForUpgradeList(loggingSessionInfo, inoutInfo);
                            }

                            // add by liangx 2016-09-27 获取订单中的虚拟商品 start
                            CouponTypeBLL            couponTypeBLL            = new CouponTypeBLL(loggingSessionInfo);
                            RedisVipMappingCouponBLL redisVipMappingCouponBLL = new RedisVipMappingCouponBLL();

                            var couponTypes = couponTypeBLL.GetVirtualItemCouponTypes(inoutInfo.order_id);

                            if (couponTypes.Any())
                            {
                                redisVipMappingCouponBLL.SetVipMappingCoupon(couponTypes, "", couponTypes.FirstOrDefault().VipId, "PayVirtualItem");
                            }

                            // add by liangx 2016-09-27 获取订单中的虚拟商品 end

                            //获取门店信息
                            t_unitEntity unitInfo = null;
                            if (!string.IsNullOrEmpty(inoutInfo.sales_unit_id))
                            {
                                unitInfo = unitBLL.GetByID(inoutInfo.sales_unit_id);
                            }
                            //入支付明细表
                            var paymentDetail = new T_Payment_detailEntity()
                            {
                                Payment_Id        = Guid.NewGuid().ToString(),
                                Inout_Id          = inoutInfo.order_id,
                                UnitCode          = unitInfo == null ? "" : unitInfo.unit_code,
                                Payment_Type_Id   = tPaymentType.Payment_Type_Id,
                                Payment_Type_Code = tPaymentType.Payment_Type_Code,
                                Payment_Type_Name = tPaymentType.Payment_Type_Name,
                                Price             = inoutInfo.actual_amount,
                                Total_Amount      = inoutInfo.total_amount,
                                Pay_Points        = inoutInfo.pay_points,
                                CustomerId        = loggingSessionInfo.ClientID
                            };
                            paymentDetailBll.Create(paymentDetail);

                            List <IWhereCondition> complexCondition = new List <IWhereCondition> {
                            };
                            complexCondition.Add(new EqualsCondition()
                            {
                                FieldName = "Inout_Id", Value = inoutInfo.order_id
                            });
                            var paymentDetailList = paymentDetailBll.Query(complexCondition.ToArray(), null);

                            try
                            {
                                var msgRabbitMQ = new EventContract
                                {
                                    Operation  = OptEnum.Create,
                                    EntityType = EntityTypeEnum.Order,
                                    Id         = inoutInfo.order_id
                                };
                                var service = new EventService();
                                service.PublishMsg(msgRabbitMQ);

                                foreach (var detail in paymentDetailList)
                                {
                                    var paymentMQ = new EventContract
                                    {
                                        Operation  = OptEnum.Create,
                                        EntityType = EntityTypeEnum.OrderPayment,
                                        Id         = detail.Payment_Id
                                    };
                                    service.PublishMsg(paymentMQ);
                                }
                            }
                            catch (Exception)
                            {
                                throw new Exception("RabbitMQ Error");
                            }
                        }
                        else//充值订单
                        {
                            var rechargeOrderBll   = new RechargeOrderBLL(loggingSessionInfo);
                            var vipamountDetailBll = new VipAmountDetailBLL(loggingSessionInfo);
                            var rechargeOrderInfo  = rechargeOrderBll.GetByID(OrderID);
                            if (rechargeOrderInfo != null)
                            {
                                //获取门店信息
                                t_unitEntity unitInfo = null;
                                if (!string.IsNullOrEmpty(rechargeOrderInfo.UnitId))
                                {
                                    unitInfo = unitBLL.GetByID(rechargeOrderInfo.UnitId);
                                }
                                //充值
                                rechargeOrderBll.Recharge(rechargeOrderInfo, vipInfo, unitInfo, tPaymentType.Payment_Type_Id);
                                //入支付明细表
                                var paymentDetail = new T_Payment_detailEntity()
                                {
                                    Payment_Id        = Guid.NewGuid().ToString(),
                                    Inout_Id          = rechargeOrderInfo.OrderID.ToString(),
                                    UnitCode          = unitInfo == null ? "" : unitInfo.unit_code,
                                    Payment_Type_Id   = tPaymentType.Payment_Type_Id,
                                    Payment_Type_Code = tPaymentType.Payment_Type_Code,
                                    Payment_Type_Name = tPaymentType.Payment_Type_Name,
                                    Price             = rechargeOrderInfo.ActuallyPaid,
                                    Total_Amount      = rechargeOrderInfo.TotalAmount,
                                    Pay_Points        = rechargeOrderInfo.PayPoints,
                                    CustomerId        = loggingSessionInfo.ClientID
                                };
                                paymentDetailBll.Create(paymentDetail);
                            }
                            else
                            {
                                var receiveAmountOrderBll    = new ReceiveAmountOrderBLL(loggingSessionInfo);
                                var receiveAmountOrderEntity = receiveAmountOrderBll.GetByID(OrderID);



                                //更新订单状态
                                if (receiveAmountOrderEntity != null)
                                {
                                    VipIntegralBLL vipIntegralBll = new VipIntegralBLL(loggingSessionInfo);
                                    //更新订单
                                    receiveAmountOrderEntity.PayStatus = "10";
                                    // Bear
                                    //receiveAmountOrderEntity.PayTypeId = tPaymentTypeCustomerMappingEntity.PaymentTypeID;
                                    receiveAmountOrderEntity.PayTypeId    = tPaymentType.Payment_Type_Id;
                                    receiveAmountOrderEntity.PayDatetTime = DateTime.Now;
                                    receiveAmountOrderBll.Update(receiveAmountOrderEntity);

                                    //获取门店信息
                                    t_unitEntity unitInfo = null;
                                    if (!string.IsNullOrEmpty(receiveAmountOrderEntity.ServiceUnitId))
                                    {
                                        unitInfo = unitBLL.GetByID(receiveAmountOrderEntity.ServiceUnitId);
                                    }


                                    //使用过积分,处理积分
                                    if (receiveAmountOrderEntity.PayPoints != 0 && receiveAmountOrderEntity.PayPoints != null)
                                    {
                                        string sourceId       = "20"; //积分抵扣
                                        var    IntegralDetail = new VipIntegralDetailEntity()
                                        {
                                            Integral         = -Convert.ToInt32(receiveAmountOrderEntity.PayPoints),
                                            IntegralSourceID = sourceId,
                                            ObjectId         = receiveAmountOrderEntity.OrderId.ToString()
                                        };
                                        if (IntegralDetail.Integral != 0)
                                        {
                                            //变动前积分
                                            string OldIntegral = (vipInfo.Integration ?? 0).ToString();
                                            //变动积分
                                            string ChangeIntegral      = (IntegralDetail.Integral ?? 0).ToString();
                                            var    vipIntegralDetailId = vipIntegralBll.AddIntegral(ref vipInfo, unitInfo, IntegralDetail, loggingSessionInfo);
                                            //发送微信积分变动通知模板消息
                                            if (!string.IsNullOrWhiteSpace(vipIntegralDetailId))
                                            {
                                                var CommonBLL = new CommonBLL();
                                                CommonBLL.PointsChangeMessage(OldIntegral, vipInfo, ChangeIntegral, vipInfo.WeiXinUserId, loggingSessionInfo);
                                            }
                                        }
                                    }
                                    //if (receiveAmountOrderEntity.CouponUsePay != 0 || receiveAmountOrderEntity.CouponUsePay != null)
                                    //{
                                    //    //更新使用记录
                                    //    var couponUseBll = new CouponUseBLL(loggingSessionInfo);
                                    //    var couponUseEntity = new CouponUseEntity()
                                    //    {
                                    //        CouponUseID = Guid.NewGuid(),
                                    //        CouponID = rp.CouponId,
                                    //        VipID = vipInfo.VIPID,
                                    //        UnitID = rp.UnitId,
                                    //        OrderID = orderId.ToString(),
                                    //        Comment = "商城使用电子券",
                                    //        CustomerID = CurrentUserInfo.ClientID,
                                    //        CreateBy = CurrentUserInfo.UserID,
                                    //        CreateTime = DateTime.Now,
                                    //        LastUpdateBy = CurrentUserInfo.UserID,
                                    //        LastUpdateTime = DateTime.Now,
                                    //        IsDelete = 0
                                    //    };
                                    //    couponUseBll.Create(couponUseEntity);

                                    //    var couponBll = new CouponBLL(CurrentUserInfo);
                                    //    var couponEntity = couponBll.GetByID(rp.CouponId);

                                    //    //更新CouponType数量
                                    //    var conponTypeBll = new CouponTypeBLL(CurrentUserInfo);
                                    //    var conponTypeEntity = conponTypeBll.QueryByEntity(new CouponTypeEntity() { CouponTypeID = new Guid(couponEntity.CouponTypeID), CustomerId = CurrentUserInfo.ClientID }, null).FirstOrDefault();
                                    //    conponTypeEntity.IsVoucher += 1;
                                    //    conponTypeBll.Update(conponTypeEntity);

                                    //    //停用该优惠券
                                    //    couponEntity.Status = 1;
                                    //    couponBll.Update(couponEntity);
                                    //}

                                    //处理余额
                                    if (receiveAmountOrderEntity.AmountAcctPay != null && receiveAmountOrderEntity.AmountAcctPay != 0)
                                    {
                                        var vipAmountDetailBll = new VipAmountDetailBLL(loggingSessionInfo);

                                        var vipAmountEntity = vipAmountBll.QueryByEntity(new VipAmountEntity()
                                        {
                                            VipId = vipInfo.VIPID, VipCardCode = vipInfo.VipCode
                                        }, null).FirstOrDefault();
                                        if (vipAmountEntity != null)
                                        {
                                            var detailInfo = new VipAmountDetailEntity()
                                            {
                                                Amount         = -receiveAmountOrderEntity.AmountAcctPay,
                                                AmountSourceId = "1",
                                                ObjectId       = receiveAmountOrderEntity.OrderId.ToString()
                                            };
                                            var vipAmountDetailId = vipAmountBll.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, detailInfo, loggingSessionInfo);
                                            if (!string.IsNullOrWhiteSpace(vipAmountDetailId))
                                            {//发送微信账户余额变动模板消息
                                                var CommonBLL = new CommonBLL();
                                                CommonBLL.BalanceChangedMessage(receiveAmountOrderEntity.OrderNo, vipAmountEntity, detailInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, loggingSessionInfo);
                                            }
                                        }
                                    }


                                    //收款订单积分奖励

                                    vipIntegralBll.OrderReward(receiveAmountOrderEntity, null);


                                    var paymentDetail = new T_Payment_detailEntity()
                                    {
                                        Payment_Id        = Guid.NewGuid().ToString(),
                                        Inout_Id          = receiveAmountOrderEntity.OrderId.ToString(),
                                        UnitCode          = unitInfo == null ? "" : unitInfo.unit_code,
                                        Payment_Type_Id   = tPaymentType.Payment_Type_Id,
                                        Payment_Type_Code = tPaymentType.Payment_Type_Code,
                                        Payment_Type_Name = tPaymentType.Payment_Type_Name,
                                        Price             = receiveAmountOrderEntity.TransAmount,
                                        Total_Amount      = receiveAmountOrderEntity.TotalAmount,
                                        Pay_Points        = receiveAmountOrderEntity.PayPoints,
                                        CustomerId        = loggingSessionInfo.ClientID
                                    };
                                    paymentDetailBll.Create(paymentDetail);
                                }
                            }
                        }
                        context.Response.Write("SUCCESS");
                    }
                }
            }
            catch (Exception ex)
            {
                Loggers.Exception(new ExceptionLogInfo(ex));
                context.Response.Write("ERROR:" + ex.Message);
            }
        }
        protected override SetReceiveAmountOrderRD ProcessRequest(APIRequest <SetReceiveAmountOrderRP> pRequest)
        {
            SetReceiveAmountOrderRP rp = pRequest.Parameters;
            SetReceiveAmountOrderRD rd = new SetReceiveAmountOrderRD();

            var receiveAmountOrderBll = new ReceiveAmountOrderBLL(CurrentUserInfo);
            var sysVipCardGradeBLL    = new SysVipCardGradeBLL(CurrentUserInfo); //获取折扣表
            var vipBLL  = new VipBLL(CurrentUserInfo);
            var unitBLL = new t_unitBLL(CurrentUserInfo);
            var vipInfo = vipBLL.GetByID(pRequest.UserID); //获取会员信息

            if (vipInfo == null)
            {
                throw new APIException("没有会员信息")
                      {
                          ErrorCode = 101
                      };
            }
            var unitInfo = unitBLL.GetByID(rp.UnitId);

            if (unitInfo == null)
            {
                throw new APIException("没有服务门店信息")
                      {
                          ErrorCode = 101
                      };
            }
            decimal discountAmount = 0;               //抵扣金额汇总
            decimal couponAmount   = 0;               //优惠券抵用金额
            decimal endAmount      = rp.VipEndAmount; //余额
            decimal integralAmount = rp.Integral;
            //获取订单号
            TUnitExpandBLL serviceUnitExpand = new TUnitExpandBLL(CurrentUserInfo);
            string         orderNo           = serviceUnitExpand.GetUnitOrderNo();
            //折扣
            decimal discount = 1;

            if (rp.VipDiscount > 0)
            {
                discount = sysVipCardGradeBLL.GetVipDiscount() / 10;//会员折扣
            }
            decimal tempAmount = Math.Round((discount == 0 ? 1 : discount) * rp.TotalAmount, 2, MidpointRounding.AwayFromZero);
            Guid    orderId    = Guid.NewGuid();

            //积分处理
            if (rp.IntegralFlag == 1)
            {
                //加入折扣金额
                discountAmount = discountAmount + rp.IntegralAmount;
            }
            else
            {
                integralAmount = 0;
            }

            //使用优惠券
            if (rp.CouponFlag == 1)
            {
                #region 判断优惠券是否是该会员的

                var vipcouponMappingBll = new VipCouponMappingBLL(CurrentUserInfo);

                var vipcouponmappingList = vipcouponMappingBll.QueryByEntity(new VipCouponMappingEntity()
                {
                    VIPID    = vipInfo.VIPID,
                    CouponID = rp.CouponId
                }, null);

                if (vipcouponmappingList == null || vipcouponmappingList.Length == 0)
                {
                    throw new APIException("此张优惠券不是该会员的")
                          {
                              ErrorCode = 103
                          };
                }

                #endregion

                #region 判断优惠券是否有效

                var couponBll = new CouponBLL(CurrentUserInfo);

                var couponEntity = couponBll.GetByID(rp.CouponId);

                if (couponEntity == null)
                {
                    throw new APIException("无效的优惠券")
                          {
                              ErrorCode = 103
                          };
                }

                if (couponEntity.Status == 1)
                {
                    throw new APIException("优惠券已使用")
                          {
                              ErrorCode = 103
                          };
                }

                if (couponEntity.EndDate < DateTime.Now)
                {
                    throw new APIException("优惠券已过期")
                          {
                              ErrorCode = 103
                          };
                }
                var couponTypeBll    = new CouponTypeBLL(CurrentUserInfo);
                var couponTypeEntity = couponTypeBll.GetByID(couponEntity.CouponTypeID);

                if (couponTypeEntity == null)
                {
                    throw new APIException("无效的优惠券类型")
                          {
                              ErrorCode = 103
                          };
                }

                #endregion

                discountAmount = discountAmount + couponTypeEntity.ParValue ?? 0;
                couponAmount   = couponTypeEntity.ParValue ?? 0;

                //更新使用记录
                var couponUseBll    = new CouponUseBLL(CurrentUserInfo);
                var couponUseEntity = new CouponUseEntity()
                {
                    CouponUseID    = Guid.NewGuid(),
                    CouponID       = rp.CouponId,
                    VipID          = vipInfo.VIPID,
                    UnitID         = rp.UnitId,
                    OrderID        = orderId.ToString(),
                    Comment        = "商城使用电子券",
                    CustomerID     = CurrentUserInfo.ClientID,
                    CreateBy       = CurrentUserInfo.UserID,
                    CreateTime     = DateTime.Now,
                    LastUpdateBy   = CurrentUserInfo.UserID,
                    LastUpdateTime = DateTime.Now,
                    IsDelete       = 0
                };
                couponUseBll.Create(couponUseEntity);

                //更新CouponType数量
                var conponTypeBll    = new CouponTypeBLL(CurrentUserInfo);
                var conponTypeEntity = conponTypeBll.QueryByEntity(new CouponTypeEntity()
                {
                    CouponTypeID = new Guid(couponEntity.CouponTypeID), CustomerId = CurrentUserInfo.ClientID
                }, null).FirstOrDefault();
                conponTypeEntity.IsVoucher += 1;
                conponTypeBll.Update(conponTypeEntity);

                //停用该优惠券
                couponEntity.Status = 1;
                couponBll.Update(couponEntity);
            }

            //使用余额
            if (rp.VipEndAmountFlag == 1)
            {
                var vipAmountBll       = new VipAmountBLL(CurrentUserInfo);
                var vipAmountDetailBll = new VipAmountDetailBLL(CurrentUserInfo);

                var vipAmountEntity = vipAmountBll.QueryByEntity(new VipAmountEntity()
                {
                    VipId = vipInfo.VIPID, VipCardCode = vipInfo.VipCode
                }, null).FirstOrDefault();
                if (vipAmountEntity != null)
                {
                    //判断该会员账户是否被冻结
                    if (vipAmountEntity.IsLocking == 1)
                    {
                        throw new APIException("账户已被冻结,请先解冻")
                              {
                                  ErrorCode = 103
                              }
                    }
                    ;

                    //判断该会员的账户余额是否大于本次使用的余额
                    if (vipAmountEntity.EndAmount < rp.VipEndAmount)
                    {
                        throw new APIException(string.Format("账户余额不足,当前余额为【{0}】", vipAmountEntity.EndAmount))
                              {
                                  ErrorCode = 103
                              }
                    }
                    ;

                    //所剩余额大于商品价格,扣除余额的数量为商品价格
                    if (tempAmount < rp.VipEndAmount)
                    {
                        rp.VipEndAmount = endAmount = Convert.ToDecimal(tempAmount);
                    }
                }
            }
            //不使用余额,余额为0
            else
            {
                endAmount = 0;
            }
            //实付金额
            decimal transAmount = tempAmount - discountAmount;
            //支付状态
            string payStatus = "0";
            //支付时间
            DateTime?PayDatetTime = null;

            //实付金额全是由余额支付,支付状态和支付时间全部更新,积分扣减、余额扣减、优惠券使用
            if (transAmount == endAmount || transAmount == 0)
            {
                payStatus    = "10";
                PayDatetTime = DateTime.Now;
                //处理积分抵扣
                if (rp.IntegralFlag == 1)
                {
                    var    vipIntegralBll = new VipIntegralBLL(CurrentUserInfo);
                    string sourceId       = "20"; //积分抵扣
                    var    IntegralDetail = new VipIntegralDetailEntity()
                    {
                        Integral         = -Convert.ToInt32(rp.Integral),
                        IntegralSourceID = sourceId,
                        ObjectId         = orderId.ToString()
                    };
                    if (IntegralDetail.Integral != 0)
                    {
                        //变动前积分
                        string OldIntegral = (vipInfo.Integration ?? 0).ToString();
                        //变动积分
                        string ChangeIntegral      = (IntegralDetail.Integral ?? 0).ToString();
                        var    vipIntegralDetailId = vipIntegralBll.AddIntegral(ref vipInfo, unitInfo, IntegralDetail, CurrentUserInfo);
                        //发送微信积分变动通知模板消息
                        if (!string.IsNullOrWhiteSpace(vipIntegralDetailId))
                        {
                            var CommonBLL = new CommonBLL();
                            CommonBLL.PointsChangeMessage(OldIntegral, vipInfo, ChangeIntegral, vipInfo.WeiXinUserId, CurrentUserInfo);
                        }
                    }
                }
                //处理余额抵扣
                if (rp.VipEndAmountFlag == 1)
                {
                    var vipAmountBll       = new VipAmountBLL(CurrentUserInfo);
                    var vipAmountDetailBll = new VipAmountDetailBLL(CurrentUserInfo);

                    var vipAmountEntity = vipAmountBll.QueryByEntity(new VipAmountEntity()
                    {
                        VipId = vipInfo.VIPID, VipCardCode = vipInfo.VipCode
                    }, null).FirstOrDefault();
                    if (vipAmountEntity != null)
                    {
                        var detailInfo = new VipAmountDetailEntity()
                        {
                            Amount         = -rp.VipEndAmount,
                            AmountSourceId = "1",
                            ObjectId       = orderId.ToString()
                        };
                        var vipAmountDetailId = vipAmountBll.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, detailInfo, CurrentUserInfo);
                        if (!string.IsNullOrWhiteSpace(vipAmountDetailId))
                        {//发送微信账户余额变动模板消息
                            var CommonBLL = new CommonBLL();
                            CommonBLL.BalanceChangedMessage(orderNo, vipAmountEntity, detailInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, CurrentUserInfo);
                        }
                    }
                }
            }
            //收款订单
            ReceiveAmountOrderEntity receiveAmountOrderEntity = new ReceiveAmountOrderEntity()
            {
                OrderId             = orderId,
                OrderNo             = orderNo,
                VipId               = vipInfo.VIPID,
                ServiceUnitId       = unitInfo.unit_id,
                ServiceUserId       = rp.EmployeeID,
                TotalAmount         = rp.TotalAmount,
                VipDiscount         = discount * 100,
                TransAmount         = transAmount,
                PayPoints           = integralAmount,
                AmountFromPayPoints = rp.IntegralAmount,
                CouponUsePay        = couponAmount,
                AmountAcctPay       = endAmount,
                PayStatus           = payStatus,
                TimeStamp           = rp.TimeStamp,
                PayDatetTime        = PayDatetTime,
                CustomerId          = CurrentUserInfo.ClientID
            };
            receiveAmountOrderBll.Create(receiveAmountOrderEntity);
            //订单奖励
            if (transAmount == endAmount || transAmount == 0)
            {
                var vipIntegralBll = new VipIntegralBLL(CurrentUserInfo);
                vipIntegralBll.OrderReward(receiveAmountOrderEntity, null);
            }
            rd.orderId = orderId.ToString();
            return(rd);
        }
    }
}
Esempio n. 19
0
        protected override EmptyResponseData ProcessRequest(DTO.Base.APIRequest <GetRefundOrderDetailRP> pRequest)
        {
            var rd   = new EmptyResponseData();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var salesReturnBLL     = new T_SalesReturnBLL(loggingSessionInfo);
            var historyBLL         = new T_SalesReturnHistoryBLL(loggingSessionInfo);
            var refundOrderBLL     = new T_RefundOrderBLL(loggingSessionInfo);
            var vipAmountBLL       = new VipAmountBLL(loggingSessionInfo);       //余额返现BLL实例化
            var vipAmountDetailBLL = new VipAmountDetailBLL(loggingSessionInfo); //余额返现BLL实例化


            var pTran = salesReturnBLL.GetTran();//事务
            T_SalesReturnEntity        salesReturnEntity = null;
            T_SalesReturnHistoryEntity historyEntity     = null;

            T_RefundOrderEntity refundEntity = null;

            var          vipBll     = new VipBLL(loggingSessionInfo);    //会员BLL实例化
            var          userBll    = new T_UserBLL(loggingSessionInfo); //店员BLL实例化
            T_UserEntity userEntity = null;                              //店员信息
            var          unitBLL    = new t_unitBLL(loggingSessionInfo);

            refundEntity = refundOrderBLL.GetByID(para.RefundID);
            userEntity   = userBll.GetByID(loggingSessionInfo.UserID);

            using (pTran.Connection)
            {
                try
                {
                    if (refundEntity != null)
                    {
                        //获取会员信息
                        var vipInfo = vipBll.GetByID(refundEntity.VipID);
                        //获取会员的会员上线
                        VipEntity userInfo = vipBll.GetByID(vipInfo.HigherVipID);
                        if (userInfo == null)
                        {
                            //获取会员的员工上线
                            var tempUser = userBll.GetByID(vipInfo.SetoffUserId);
                            if (tempUser != null)
                            {
                                userInfo       = new VipEntity();
                                userInfo.VIPID = tempUser.user_id;
                            }
                        }

                        //获取门店信息
                        t_unitEntity unitInfo = null;
                        if (!string.IsNullOrEmpty(refundEntity.UnitID))
                        {
                            unitInfo = unitBLL.GetByID(refundEntity.UnitID);
                        }
                        userEntity = userBll.GetByID(loggingSessionInfo.UserID);

                        refundEntity.Status = 2;//已退款
                        refundOrderBLL.Update(refundEntity, pTran);
                        salesReturnEntity = salesReturnBLL.GetByID(refundEntity.SalesReturnID);
                        if (salesReturnEntity != null)
                        {
                            salesReturnEntity.Status = 7;//已完成
                            salesReturnBLL.Update(salesReturnEntity, pTran);
                            historyEntity = new T_SalesReturnHistoryEntity()
                            {
                                SalesReturnID = salesReturnEntity.SalesReturnID,
                                OperationType = 7,
                                OperationDesc = "退款",
                                OperatorID    = loggingSessionInfo.UserID,
                                HisRemark     = "您的服务单财务已退款,请注意查收",
                                OperatorName  = userEntity.user_name,
                                OperatorType  = 1
                            };
                            historyBLL.Create(historyEntity, pTran);
                        }

                        #region 退回集客订单分润
                        //上线员工和线上会员不为空
                        if (userInfo != null)
                        {
                            var vipAmountEntity = vipAmountBLL.QueryByEntity(new VipAmountEntity()
                            {
                                VipId = userInfo.VIPID, VipCardCode = userInfo.VipCode
                            }, null).FirstOrDefault();
                            var vipAmountDetail = vipAmountDetailBLL.QueryByEntity(new VipAmountDetailEntity()
                            {
                                ObjectId = refundEntity.OrderID, AmountSourceId = "20"
                            }, null).FirstOrDefault();
                            if (vipAmountDetail != null)
                            {
                                var detailInfo = new VipAmountDetailEntity()
                                {
                                    Amount         = -vipAmountDetail.Amount.Value,
                                    ObjectId       = refundEntity.RefundID.ToString(),
                                    AmountSourceId = "25"
                                };
                                var vipAmountDetailId = vipAmountBLL.AddVipAmount(userInfo, unitInfo, ref vipAmountEntity, detailInfo, pTran, loggingSessionInfo);
                            }
                        }
                        #endregion
                    }

                    pTran.Commit();  //提交事物
                }
                catch (Exception ex)
                {
                    pTran.Rollback();//回滚事务
                    throw new APIException(ex.Message);
                }
            }
            return(rd);
        }
Esempio n. 20
0
 public void Update(VipAmountDetailEntity dbEntity)
 {
     _cmd.Update(dbEntity);
 }
Esempio n. 21
0
        /// <summary>
        /// 充值
        /// </summary>
        /// <param name="rechargeOrderInfo"></param>
        /// <param name="vipInfo"></param>
        /// <param name="unitInfo"></param>
        /// <param name="paymentTypeId"></param>
        public void Recharge(RechargeOrderEntity rechargeOrderInfo, VipEntity vipInfo, t_unitEntity unitInfo, string paymentTypeId)
        {
            var rechargeOrderBll = new RechargeOrderBLL(CurrentUserInfo);
            //会员
            var vipCardVipMappingBll = new VipCardVipMappingBLL(CurrentUserInfo);
            var vipAmountBll         = new VipAmountBLL(CurrentUserInfo);
            //门店
            var unitBLL = new t_unitBLL(CurrentUserInfo);

            rechargeOrderInfo.Status      = 1;//已支付
            rechargeOrderInfo.PayID       = paymentTypeId;
            rechargeOrderInfo.PayDateTime = DateTime.Now;
            rechargeOrderBll.Update(rechargeOrderInfo);

            //获取会员卡绑卡信息
            var vipCardVipMappingList = vipCardVipMappingBll.QueryByEntity(new VipCardVipMappingEntity()
            {
                VIPID = vipInfo.VIPID
            }, null);

            //会员无卡并且是续费充值的
            if (vipCardVipMappingList.Count() == 0 && rechargeOrderInfo.OrderDesc == "ReRecharge")
            {
                vipCardVipMappingBll.BindVipCard(vipInfo.VIPID, vipInfo.VipCardCode, rechargeOrderInfo.UnitId);
            }

            var vipAmountEntity = vipAmountBll.QueryByEntity(new VipAmountEntity()
            {
                VipId = vipInfo.VIPID, VipCardCode = vipInfo.VipCode
            }, null).FirstOrDefault();
            //充值
            var amountDetailInfo = new VipAmountDetailEntity()
            {
                Amount         = rechargeOrderInfo.TotalAmount.Value,
                AmountSourceId = "4",
                ObjectId       = rechargeOrderInfo.OrderID.ToString()
            };

            var vipAmountDetailId = vipAmountBll.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, amountDetailInfo, null, CurrentUserInfo);

            if (!string.IsNullOrWhiteSpace(vipAmountDetailId) && rechargeOrderInfo.TotalAmount.Value != 0)
            {
                //发送账户余额变动微信模板消息
                var CommonBLL = new CommonBLL();
                CommonBLL.BalanceChangedMessage(rechargeOrderInfo.OrderNo, vipAmountEntity, amountDetailInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, CurrentUserInfo);
            }

            //赠送
            if (rechargeOrderInfo.ReturnAmount.Value != 0)
            {
                var returnAmountInfo = new VipAmountDetailEntity()
                {
                    Amount         = rechargeOrderInfo.ReturnAmount.Value,
                    AmountSourceId = "6",
                    ObjectId       = rechargeOrderInfo.OrderID.ToString()
                };
                var vipReturnDetailId = vipAmountBll.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, returnAmountInfo, null, CurrentUserInfo);

                if (!string.IsNullOrWhiteSpace(vipReturnDetailId) && rechargeOrderInfo.ReturnAmount.Value != 0)
                {
                    //发送账户余额变动微信模板消息
                    var CommonBLL = new CommonBLL();
                    CommonBLL.BalanceChangedMessage(rechargeOrderInfo.OrderNo, vipAmountEntity, returnAmountInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, CurrentUserInfo);
                }
            }
            if (rechargeOrderInfo.OrderDesc == "Upgrade")
            {
                //会员卡升级
                vipCardVipMappingBll.BindVirtualItem(vipInfo.VIPID, vipInfo.VipCode, rechargeOrderInfo.UnitId, rechargeOrderInfo.VipCardTypeId ?? 0, "Recharge", orderId: rechargeOrderInfo.OrderID.ToString());
            }

            //充值分润
            RedisRechargeOrderBLL redisRechargeOrderBll = new RedisRechargeOrderBLL();

            redisRechargeOrderBll.SetRedisToRechargeOrder(CurrentUserInfo, rechargeOrderInfo);
        }
Esempio n. 22
0
 public void Create(VipAmountDetailEntity dbEntity)
 {
     _cmd.Create(dbEntity);
 }
Esempio n. 23
0
        /// <summary>
        /// 计算充值分润
        /// </summary>
        /// <param name="loggingSessionInfo"></param>
        /// <param name="rechargeOrderInfo"></param>
        public void CalculateRechargeOrder(LoggingSessionInfo loggingSessionInfo, RechargeOrderEntity rechargeOrderInfo)
        {
            VipCardProfitRuleBLL bllVipCardProfitRule = new VipCardProfitRuleBLL(loggingSessionInfo);

            VipCardProfitRuleEntity[] entityVipCardProfitRule = null;

            entityVipCardProfitRule = bllVipCardProfitRule.QueryByEntity(new VipCardProfitRuleEntity()
            {
                VipCardTypeID = rechargeOrderInfo.VipCardTypeId, IsDelete = 0
            }, null);
            if (entityVipCardProfitRule != null)
            {
                var                bllVipCardGradeChangeLog = new VipCardGradeChangeLogBLL(loggingSessionInfo);
                VipAmountBLL       bllVipAmount             = new VipAmountBLL(loggingSessionInfo);
                VipAmountDetailBLL bllVipAmountDetail       = new VipAmountDetailBLL(loggingSessionInfo);
                VipAmountEntity    entityVipAmount          = new VipAmountEntity();

                string connString = string.Empty;
                foreach (var ProfitRule in entityVipCardProfitRule)
                {
                    decimal amount            = 0;
                    string  strAmountSourceId = string.Empty;
                    string  strVipId          = string.Empty;
                    string  strUserType       = string.Empty;
                    if (ProfitRule.IsApplyAllUnits == 0)
                    {
                        VipCardProfitRuleUnitMappingBLL bllVipCardProfitRuleUnitMapping = new VipCardProfitRuleUnitMappingBLL(loggingSessionInfo);
                        var vipCardProfitRuleUnitMapping = bllVipCardProfitRuleUnitMapping.QueryByEntity(new VipCardProfitRuleUnitMappingEntity()
                        {
                            CardBuyToProfitRuleId = ProfitRule.CardBuyToProfitRuleId, UnitID = rechargeOrderInfo.UnitId, IsDelete = 0, CustomerID = loggingSessionInfo.ClientID
                        }, null).SingleOrDefault();
                        if (vipCardProfitRuleUnitMapping == null)
                        {
                            continue;
                        }
                    }
                    if (ProfitRule.ProfitOwner == "Employee")
                    {
                        strAmountSourceId = "38";
                        strVipId          = rechargeOrderInfo.UserId;
                        strUserType       = "User";
                    }
                    if (ProfitRule.ProfitOwner == "Unit")
                    {
                        strAmountSourceId = "42";
                        strVipId          = rechargeOrderInfo.UnitId;
                        strUserType       = "Unit";
                    }
                    var entityVipCardGradeChangeLog = bllVipCardGradeChangeLog.QueryByEntity(new VipCardGradeChangeLogEntity()
                    {
                        OrderId = rechargeOrderInfo.OrderID.ToString()
                    }, null).SingleOrDefault();
                    if (entityVipCardGradeChangeLog != null)//首充
                    {
                        amount = (decimal)ProfitRule.FirstRechargeProfitPct * (decimal)rechargeOrderInfo.ActuallyPaid * (decimal)0.01;
                    }
                    else//续充
                    {
                        VipCardReRechargeProfitRuleBLL bllVipCardReRechargeProfitRule = new VipCardReRechargeProfitRuleBLL(loggingSessionInfo);
                        var entityVipCardReRechargeProfitRule = bllVipCardReRechargeProfitRule.QueryByEntity(new VipCardReRechargeProfitRuleEntity()
                        {
                            VipCardTypeID = rechargeOrderInfo.VipCardTypeId, IsDelete = 0
                        }, null);
                        if (entityVipCardReRechargeProfitRule != null)
                        {
                            decimal discount = 0;
                            foreach (var ReRechargeProfitRule in entityVipCardReRechargeProfitRule)
                            {
                                if (ReRechargeProfitRule.ProfitType == "Superposition")
                                {
                                    discount = ((decimal)rechargeOrderInfo.ActuallyPaid / (decimal)ReRechargeProfitRule.LimitAmount) * (decimal)ReRechargeProfitRule.ProfitPct * (decimal)0.01;
                                }
                                if (ReRechargeProfitRule.ProfitType == "Step")
                                {
                                    if (rechargeOrderInfo.ActuallyPaid >= ReRechargeProfitRule.LimitAmount)
                                    {
                                        discount = (decimal)ReRechargeProfitRule.ProfitPct;
                                    }
                                }
                            }
                            amount = (decimal)rechargeOrderInfo.ActuallyPaid * discount;
                        }
                    }
                    //入库
                    if (amount > 0)
                    {
                        IDbTransaction tran = new DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction();

                        VipAmountDetailEntity entityVipAmountDetail = new VipAmountDetailEntity
                        {
                            VipAmountDetailId = Guid.NewGuid(),
                            VipId             = strVipId,
                            Amount            = amount,
                            UsedReturnAmount  = 0,
                            EffectiveDate     = DateTime.Now,
                            DeadlineDate      = Convert.ToDateTime("9999-12-31 23:59:59"),
                            AmountSourceId    = strAmountSourceId,
                            ObjectId          = rechargeOrderInfo.OrderID.ToString(),
                            CustomerID        = loggingSessionInfo.ClientID,
                            Reason            = "超级分销商"
                        };
                        bllVipAmountDetail.Create(entityVipAmountDetail, (SqlTransaction)tran);

                        T_SplitProfitRecordBLL    bllSplitProfitRecord    = new T_SplitProfitRecordBLL(loggingSessionInfo);
                        T_SplitProfitRecordEntity entitySplitProfitRecord = new T_SplitProfitRecordEntity()
                        {
                            ID          = Guid.NewGuid().ToString(),
                            SourceType  = "Amount",
                            SourceId    = strAmountSourceId,
                            ObjectId    = rechargeOrderInfo.OrderID.ToString(),
                            UserType    = strUserType,
                            UserId      = rechargeOrderInfo.UserId,
                            SplitAmount = amount,
                            SplitSattus = "10",
                            CustomerID  = loggingSessionInfo.ClientID,
                            IsDelete    = 0
                        };
                        bllSplitProfitRecord.Create(entitySplitProfitRecord);

                        entityVipAmount = bllVipAmount.QueryByEntity(new VipAmountEntity()
                        {
                            VipId = strVipId, IsDelete = 0, CustomerID = loggingSessionInfo.ClientID
                        }, null).SingleOrDefault();
                        if (entityVipAmount == null)
                        {
                            entityVipAmount = new VipAmountEntity
                            {
                                VipId                  = strVipId,
                                BeginAmount            = 0,
                                InAmount               = amount,
                                OutAmount              = 0,
                                EndAmount              = amount,
                                TotalAmount            = amount,
                                BeginReturnAmount      = 0,
                                InReturnAmount         = 0,
                                OutReturnAmount        = 0,
                                ReturnAmount           = 0,
                                ImminentInvalidRAmount = 0,
                                InvalidReturnAmount    = 0,
                                ValidReturnAmount      = 0,
                                TotalReturnAmount      = 0,
                                IsLocking              = 0,
                                CustomerID             = loggingSessionInfo.ClientID,
                                VipCardCode            = ""
                            };
                            bllVipAmount.Create(entityVipAmount, tran);
                        }
                        else
                        {
                            entityVipAmount.InReturnAmount    = (entityVipAmount.InReturnAmount == null ? 0 : entityVipAmount.InReturnAmount.Value) + amount;
                            entityVipAmount.TotalReturnAmount = (entityVipAmount.TotalReturnAmount == null ? 0 : entityVipAmount.TotalReturnAmount.Value) + amount;

                            entityVipAmount.ValidReturnAmount = (entityVipAmount.ValidReturnAmount == null ? 0 : entityVipAmount.ValidReturnAmount.Value) + amount;
                            entityVipAmount.ReturnAmount      = (entityVipAmount.ReturnAmount == null ? 0 : entityVipAmount.ReturnAmount.Value) + amount;
                            bllVipAmount.Update(entityVipAmount);
                        }
                    }
                }
            }
        }
Esempio n. 24
0
        protected override EmptyResponseData ProcessRequest(APIRequest <SetVipAmountRP> pRequest)
        {
            var rd   = new EmptyResponseData();
            var para = pRequest.Parameters;
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo; //登录状态信息
            var vipAmountBLL       = new VipAmountBLL(loggingSessionInfo);
            var vipAmountDetailBLL = new VipAmountDetailBLL(loggingSessionInfo);
            var objectImagesBLL    = new ObjectImagesBLL(loggingSessionInfo);    //图片表业务对象实例化
            var unitBLL            = new t_unitBLL(loggingSessionInfo);

            var vipBLL = new VipBLL(loggingSessionInfo);

            var vipInfo  = vipBLL.GetByID(para.VipID);
            var unitInfo = unitBLL.GetByID(loggingSessionInfo.CurrentUserRole.UnitId);
            var pTran    = vipAmountBLL.GetTran(); //事务

            var vipAmountEntity = vipAmountBLL.QueryByEntity(new VipAmountEntity()
            {
                VipId = vipInfo.VIPID, VipCardCode = vipInfo.VipCode
            }, null).FirstOrDefault();

            using (pTran.Connection)
            {
                try
                {
                    var amountDetail = new VipAmountDetailEntity()
                    {
                        Amount         = para.Amount,
                        AmountSourceId = para.AmountSourceID,
                        ObjectId       = "",
                        Reason         = para.Reason,
                        Remark         = para.Remark
                    };
                    string vipAmountDetailId = string.Empty;
                    if (para.AmountSourceID == "23")
                    {      //人工调整余额
                        vipAmountDetailId = vipAmountBLL.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, amountDetail, pTran, loggingSessionInfo);

                        if (!string.IsNullOrWhiteSpace(vipAmountDetailId))
                        {//发送微信账户余额变动模板消息
                            var CommonBLL = new CommonBLL();
                            CommonBLL.BalanceChangedMessage("人工调整", vipAmountEntity, amountDetail, vipInfo.WeiXinUserId, vipInfo.VIPID, loggingSessionInfo);
                        }
                    }
                    else if (para.AmountSourceID == "24")
                    {  //人工调整返现
                        vipAmountDetailId = vipAmountBLL.AddReturnAmount(vipInfo, unitInfo, vipAmountEntity, ref amountDetail, pTran, loggingSessionInfo);
                        if (!string.IsNullOrWhiteSpace(vipAmountDetailId))
                        {//发送返现到账通知微信模板消息
                            var CommonBLL = new CommonBLL();
                            CommonBLL.CashBackMessage("人工调整", amountDetail.Amount, vipInfo.WeiXinUserId, vipInfo.VIPID, loggingSessionInfo);
                        }
                    }
                    //增加图片上传
                    if (!string.IsNullOrEmpty(para.ImageUrl))
                    {
                        var objectImagesEntity = new ObjectImagesEntity()
                        {
                            ImageId  = Guid.NewGuid().ToString(),
                            ObjectId = vipAmountDetailId,
                            ImageURL = para.ImageUrl
                        };
                        objectImagesBLL.Create(objectImagesEntity);
                    }
                    pTran.Commit();  //提交事物
                }
                catch (APIException apiEx)
                {
                    pTran.Rollback();//回滚事物
                    throw new APIException(apiEx.ErrorCode, apiEx.Message);
                }
                catch (Exception ex)
                {
                    pTran.Rollback();//回滚事物
                    throw new Exception(ex.Message);
                }
            }
            return(rd);
        }
Esempio n. 25
0
        //<summary>
        //Pos订单入库
        //</summary>
        //<param name="pRequest"></param>
        //<returns></returns>
        protected override SetPosOrderRD ProcessRequest(APIRequest <SetPosOrderRP> pRequest)
        {
            //请求参数
            var rp = pRequest.Parameters;
            //返回参数
            var rd = new SetPosOrderRD();

            //订单
            var inoutBll    = new T_InoutBLL(CurrentUserInfo);
            var inoutDetail = new T_Inout_DetailBLL(CurrentUserInfo);
            //商品
            var itemCategoryBll = new T_Item_CategoryBLL(CurrentUserInfo);
            var itemBll         = new T_ItemBLL(CurrentUserInfo);
            var porpBll         = new T_PropBLL(CurrentUserInfo);
            var itemSkuPropBll  = new T_ItemSkuPropBLL(CurrentUserInfo);
            var skuBll          = new T_SkuBLL(CurrentUserInfo);
            var skuPriceBll     = new T_Sku_PriceBLL(CurrentUserInfo);
            var skuProperty     = new T_Sku_PropertyBLL(CurrentUserInfo);
            //获取会员信息
            var vipBll  = new VipBLL(CurrentUserInfo);
            var vipInfo = vipBll.GetByID(pRequest.UserID);
            var vipCardVipMappingBll    = new VipCardVipMappingBLL(CurrentUserInfo);
            var vipCardBll              = new VipCardBLL(CurrentUserInfo);
            var vipCardVipMappingEntity = vipCardVipMappingBll.QueryByEntity(new VipCardVipMappingEntity()
            {
                VIPID = vipInfo.VIPID, CustomerID = CurrentUserInfo.ClientID
            }, null).FirstOrDefault();
            string VipCardTypeID = ""; //卡类型Id

            if (vipCardVipMappingEntity != null)
            {
                var vipCardEntity = vipCardBll.GetByID(vipCardVipMappingEntity.VipCardID);
                VipCardTypeID = vipCardEntity.VipCardTypeID.ToString();
            }
            //员工
            var userBll = new T_UserBLL(CurrentUserInfo);

            //获取门店信息
            var          unitBll  = new t_unitBLL(CurrentUserInfo);
            t_unitEntity unitInfo = null;

            if (!string.IsNullOrEmpty(rp.UnitCode))
            {
                unitInfo = unitBll.QueryByEntity(new t_unitEntity()
                {
                    unit_code = rp.UnitCode, customer_id = CurrentUserInfo.ClientID
                }, null).FirstOrDefault();
                if (unitInfo == null)
                {
                    throw new APIException("请在正念商户后台录入相应门店")
                          {
                              ErrorCode = 100
                          };
                }
            }
            else
            {
                throw new APIException("缺少请求参数:门店编码")
                      {
                          ErrorCode = 102
                      };
            }

            //获取员工信息
            T_UserEntity userEntity = null;

            if (!string.IsNullOrEmpty(rp.MobliePhone))
            {
                userEntity = userBll.QueryByEntity(new T_UserEntity()
                {
                    user_telephone = rp.MobliePhone, customer_id = CurrentUserInfo.ClientID
                }, null).FirstOrDefault();
                //没有员工,新增默认员工(店员APP)
                if (userEntity == null)
                {
                    var roleBll    = new T_RoleBLL(CurrentUserInfo);
                    var roleEntity = roleBll.QueryByEntity(new T_RoleEntity()
                    {
                        role_code = "clerkAPP", customer_id = CurrentUserInfo.ClientID
                    }, null).FirstOrDefault();
                    if (roleEntity == null)
                    {
                        throw new APIException("请在正念商户后台录入相应角色")
                              {
                                  ErrorCode = 100
                              };
                    }
                    userEntity = new T_UserEntity();
                    userEntity.user_telephone = rp.MobliePhone;
                    userEntity.user_code      = rp.UserCode;
                    userEntity.user_name      = rp.UserCode;
                    userEntity.user_birthday  = rp.Birthday;
                    userEntity.user_email     = rp.EmailAddress;
                    userEntity.user_address   = rp.Address;
                    userEntity.user_postcode  = rp.Zip;
                    userBll.AddUser(ref userEntity, unitInfo, roleEntity);
                }
            }
            else
            {
                throw new APIException("缺少请求参数:员工手机号")
                      {
                          ErrorCode = 102
                      };
            }
            //获取会员折扣
            var     sysVipCardGradeBLL = new SysVipCardGradeBLL(CurrentUserInfo);
            decimal vipDiscount        = sysVipCardGradeBLL.GetVipDiscount() * 10;


            //订单号
            string        orderId      = BaseService.NewGuidPub();
            T_InoutEntity tInoutEntity = new T_InoutEntity();

            tInoutEntity.order_id = orderId;
            tInoutEntity.order_no = rp.OrderNo;

            //拼接ItemCodes
            //StringBuilder ItemCodes = new StringBuilder();
            //for (int j = 0; j < pRequest.Parameters.OrderDetailList.Count(); j++)
            //{
            //    if (j != 0)
            //    {
            //        ItemCodes.Append(",");
            //    }
            //    ItemCodes.Append(string.Format("{0}", pRequest.Parameters.OrderDetailList[j].ItemCode));
            //}

            ////通过itemCodes取出商品价格
            //SkuPriceService skuPriceService = new SkuPriceService(CurrentUserInfo);
            //List<SkuPrice> skuPriceList = skuPriceService.GetPriceListByItemCodes(ItemCodes.ToString(), CurrentUserInfo.ClientID);
            //if(skuPriceList.Count == 0)
            //{
            //    throw new APIException("未找到商品") { ErrorCode = 100 };
            //}

            //订单总金额
            decimal totalAmount = rp.TotalAmount;
            //订单实付金额
            decimal ActualAmount = rp.DiscountAmount;
            //订单折扣后金额
            decimal DiscountAmount = rp.DiscountAmount;
            //订单明细显示顺序
            int i = 1;

            //商品价格重新计算
            foreach (var item in pRequest.Parameters.OrderDetailList)
            {
                T_ItemEntity itemEntity = null; //商品
                T_SkuEntity  skuEntity  = null; //sku
                if (!string.IsNullOrEmpty(item.ItemCode))
                {
                    itemEntity = itemBll.QueryByEntity(new T_ItemEntity()
                    {
                        item_code = item.ItemCode, CustomerId = CurrentUserInfo.ClientID
                    }, null).FirstOrDefault();
                    if (itemEntity == null)
                    {
                        if (string.IsNullOrEmpty(item.ItemCategoryCode))
                        {
                            throw new APIException("缺少参数:商品类别名称")
                                  {
                                      ErrorCode = 200
                                  };
                        }
                        itemEntity           = new T_ItemEntity();
                        itemEntity.item_code = item.ItemCode;
                        itemEntity.item_name = item.ItemName;

                        itemBll.AddItem(itemEntity, out skuEntity, item.ItemCategoryName, item.ItemCategoryCode, item.SkuOriginPrice, item.SkuSalesPrice);
                    }
                    else
                    {
                        skuEntity = skuBll.QueryByEntity(new T_SkuEntity()
                        {
                            item_id = itemEntity.item_id
                        }, null).FirstOrDefault();
                    }
                }
                else
                {
                    throw new APIException("缺少参数:商品编码")
                          {
                              ErrorCode = 300
                          };
                }

                //订单明细相关处理
                T_Inout_DetailBLL    inoutDetailBll    = new T_Inout_DetailBLL(CurrentUserInfo);
                T_Inout_DetailEntity inoutDetailEntity = new T_Inout_DetailEntity()
                {
                    order_detail_id     = BaseService.NewGuidPub(),
                    order_id            = orderId,               //订单Id
                    sku_id              = skuEntity.sku_id,      //skuId
                    unit_id             = unitInfo.unit_id,      //门店Id
                    order_qty           = item.Qty,              //订单qty
                    enter_qty           = item.Qty,              //实际qty
                    enter_price         = item.price,            //折扣价
                    enter_amount        = item.price * item.Qty, //折扣价
                    std_price           = item.price,            //原价
                    discount_rate       = vipDiscount,           //折扣
                    retail_price        = item.price * item.Qty, //零售价
                    retail_amount       = item.price * item.Qty, //零售价
                    order_detail_status = "1",
                    display_index       = i,
                    if_flag             = 0
                };
                inoutDetailBll.Create(inoutDetailEntity);
                i++;
            }

            //优惠券使用
            if (!string.IsNullOrEmpty(rp.CouponId))
            {
                #region 判断优惠券是否是该会员的

                var vipcouponMappingBll = new VipCouponMappingBLL(CurrentUserInfo);

                var vipcouponmappingList = vipcouponMappingBll.QueryByEntity(new VipCouponMappingEntity()
                {
                    VIPID    = pRequest.UserID,
                    CouponID = rp.CouponId
                }, null);

                if (vipcouponmappingList == null || vipcouponmappingList.Length == 0)
                {
                    throw new APIException("此张优惠券不是该会员的")
                          {
                              ErrorCode = 103
                          };
                }

                #endregion

                #region 判断优惠券是否有效

                var couponBll = new CouponBLL(CurrentUserInfo);

                var couponEntity = couponBll.GetByID(rp.CouponId);

                if (couponEntity == null)
                {
                    throw new APIException("无效的优惠券")
                          {
                              ErrorCode = 103
                          };
                }

                if (couponEntity.Status == 1)
                {
                    throw new APIException("优惠券已使用")
                          {
                              ErrorCode = 103
                          };
                }

                if (couponEntity.EndDate < DateTime.Now)
                {
                    throw new APIException("优惠券已过期")
                          {
                              ErrorCode = 103
                          };
                }
                var couponTypeBll    = new CouponTypeBLL(CurrentUserInfo);
                var couponTypeEntity = couponTypeBll.GetByID(couponEntity.CouponTypeID);

                if (couponTypeEntity == null)
                {
                    throw new APIException("无效的优惠券类型")
                          {
                              ErrorCode = 103
                          };
                }

                #endregion

                #region 优惠券核销
                var couponUseBll    = new CouponUseBLL(CurrentUserInfo);
                var couponUseEntity = new CouponUseEntity()
                {
                    CouponUseID    = Guid.NewGuid(),
                    CouponID       = rp.CouponId,
                    VipID          = pRequest.UserID,
                    UnitID         = unitInfo.unit_id,
                    OrderID        = orderId,
                    Comment        = "商城使用电子券",
                    CustomerID     = pRequest.CustomerID,
                    CreateBy       = pRequest.UserID,
                    CreateTime     = DateTime.Now,
                    LastUpdateBy   = pRequest.UserID,
                    LastUpdateTime = DateTime.Now,
                    IsDelete       = 0
                };
                couponUseBll.Create(couponUseEntity);
                #endregion

                #region 更新CouponType数量
                var conponTypeBll    = new CouponTypeBLL(CurrentUserInfo);
                var conponTypeEntity = conponTypeBll.QueryByEntity(new CouponTypeEntity()
                {
                    CouponTypeID = new Guid(couponEntity.CouponTypeID), CustomerId = pRequest.CustomerID
                }, null).FirstOrDefault();
                conponTypeEntity.IsVoucher += 1;
                conponTypeBll.Update(conponTypeEntity);

                #endregion

                #region 更新优惠券状态

                couponEntity.Status = 1;
                couponBll.Update(couponEntity);

                #endregion

                ActualAmount -= couponTypeEntity.ParValue ?? 0;
            }

            #region 使用积分
            //使用积分
            if (rp.IntegralFlag == 1)
            {
                var vipIntegralBll = new VipIntegralBLL(CurrentUserInfo);

                string sourceId       = "20"; //积分抵扣
                var    IntegralDetail = new VipIntegralDetailEntity()
                {
                    Integral         = -Convert.ToInt32(rp.Integral),
                    IntegralSourceID = sourceId,
                    ObjectId         = orderId
                };
                if (IntegralDetail.Integral != 0)
                {
                    //变动前积分
                    string OldIntegral = (vipInfo.Integration ?? 0).ToString();
                    //变动积分
                    string ChangeIntegral      = (IntegralDetail.Integral ?? 0).ToString();
                    var    vipIntegralDetailId = vipIntegralBll.AddIntegral(ref vipInfo, unitInfo, IntegralDetail, CurrentUserInfo);
                    //发送微信积分变动通知模板消息
                    if (!string.IsNullOrWhiteSpace(vipIntegralDetailId))
                    {
                        var CommonBLL = new CommonBLL();
                        CommonBLL.PointsChangeMessage(OldIntegral, vipInfo, ChangeIntegral, vipInfo.WeiXinUserId, CurrentUserInfo);
                    }
                }
                tInoutEntity.pay_points     = rp.Integral;
                tInoutEntity.receive_points = rp.Integral;
                ActualAmount -= rp.IntegralAmount;
            }
            #endregion

            #region 余额和返现修改

            var vipAmountBll       = new VipAmountBLL(CurrentUserInfo);
            var vipAmountDetailBll = new VipAmountDetailBLL(CurrentUserInfo);

            var vipAmountEntity = vipAmountBll.QueryByEntity(new VipAmountEntity()
            {
                VipId = pRequest.UserID, VipCardCode = vipInfo.VipCode
            }, null).FirstOrDefault();
            if (vipAmountEntity != null)
            {
                //判断该会员账户是否被冻结
                if (vipAmountEntity.IsLocking == 1)
                {
                    throw new APIException("账户已被冻结,请先解冻")
                          {
                              ErrorCode = 103
                          }
                }
                ;

                //判断该会员的账户余额是否大于本次使用的余额
                if (vipAmountEntity.EndAmount < rp.EndAmount)
                {
                    throw new APIException(string.Format("账户余额不足,当前余额为【{0}】", vipAmountEntity.EndAmount))
                          {
                              ErrorCode = 103
                          }
                }
                ;
            }

            //使用余额
            if (rp.EndAmountFlag == 1)
            {
                var detailInfo = new VipAmountDetailEntity()
                {
                    Amount         = -rp.EndAmount,
                    AmountSourceId = "1",
                    ObjectId       = orderId
                };
                var vipAmountDetailId = vipAmountBll.AddVipAmount(vipInfo, unitInfo, ref vipAmountEntity, detailInfo, CurrentUserInfo);
                if (!string.IsNullOrWhiteSpace(vipAmountDetailId))
                {//发送微信账户余额变动模板消息
                    var CommonBLL = new CommonBLL();
                    CommonBLL.BalanceChangedMessage(tInoutEntity.order_no, vipAmountEntity, detailInfo, vipInfo.WeiXinUserId, vipInfo.VIPID, CurrentUserInfo);
                }
                tInoutEntity.Field3 = rp.EndAmount.ToString();
            }

            #endregion
            //订单主表更新
            tInoutEntity.VipCardCode      = vipInfo.VipCardCode;//会员卡号
            tInoutEntity.order_reason_id  = "2F6891A2194A4BBAB6F17B4C99A6C6F5";
            tInoutEntity.order_type_id    = "1F0A100C42484454BAEA211D4C14B80F";
            tInoutEntity.warehouse_id     = "67bb4c12785c42d4912aff7d34606592";
            tInoutEntity.data_from_id     = "";
            tInoutEntity.red_flag         = "1";
            tInoutEntity.order_date       = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //订单时间
            tInoutEntity.create_unit_id   = unitInfo.unit_id;                             //门店
            tInoutEntity.unit_id          = unitInfo.unit_id;                             //门店
            tInoutEntity.sales_unit_id    = unitInfo.unit_id;                             //门店
            tInoutEntity.purchase_unit_id = unitInfo.unit_id;
            tInoutEntity.sales_user       = userEntity.user_id;
            tInoutEntity.total_amount     = totalAmount;  //订单金额
            tInoutEntity.discount_rate    = vipDiscount;  //会员折扣
            tInoutEntity.actual_amount    = ActualAmount; //实付金额
            tInoutEntity.total_qty        = rp.qty;
            tInoutEntity.total_retail     = totalAmount;  //订单金额
            tInoutEntity.vip_no           = vipInfo.VIPID;
            tInoutEntity.Field6           = vipInfo.Phone;
            tInoutEntity.Field14          = vipInfo.VipName;
            tInoutEntity.Field17          = VipCardTypeID;
            tInoutEntity.Field12          = DiscountAmount.ToString();
            tInoutEntity.Field11          = "知行易";
            tInoutEntity.customer_id      = CurrentUserInfo.ClientID;

            tInoutEntity.Field1      = "1";   //支付完成
            tInoutEntity.Field7      = "700"; //已完成
            tInoutEntity.status      = "700"; //已完成
            tInoutEntity.status_desc = "已完成";
            tInoutEntity.Field10     = "已完成";
            rd.Amount = ActualAmount - rp.EndAmount;

            inoutBll.Create(tInoutEntity);

            //订单奖励
            new SendOrderRewardMsgBLL().OrderReward(tInoutEntity, this.CurrentUserInfo, null);//存入到缓存
            rd.orderId = orderId;
            return(rd);
        }
    }
}
Esempio n. 26
0
        /// <summary>
        /// 余额变更(不带事务)
        /// </summary>
        /// <param name="vipInfo">会员信息</param>
        /// <param name="unitInfo">门店信息</param>
        /// <param name="detailInfo">余额变更明细</param>
        /// <param name="loggingSessionInfo">登录信息</param>
        /// <returns></returns>
        public string AddVipAmount(VipEntity vipInfo, t_unitEntity unitInfo, ref VipAmountEntity vipAmountEntity, VipAmountDetailEntity detailInfo, LoggingSessionInfo loggingSessionInfo)
        {
            string vipAmountDetailId = string.Empty;//变更明细ID

            //更新个人账户的可使用余额
            try
            {
                var vipAmountBll = new VipAmountBLL(loggingSessionInfo);
                //var vipAmountEntity = vipAmountBll.GetByID(vipInfo);
                if (vipAmountEntity == null)
                {
                    vipAmountEntity = new VipAmountEntity
                    {
                        VipId                  = vipInfo.VIPID,
                        VipCardCode            = vipInfo.VipCode,
                        BeginAmount            = 0,
                        InAmount               = detailInfo.Amount,
                        OutAmount              = 0,
                        EndAmount              = detailInfo.Amount,
                        TotalAmount            = detailInfo.Amount,
                        BeginReturnAmount      = 0,
                        InReturnAmount         = 0,
                        OutReturnAmount        = 0,
                        ReturnAmount           = 0,
                        ImminentInvalidRAmount = 0,
                        InvalidReturnAmount    = 0,
                        ValidReturnAmount      = 0,
                        TotalReturnAmount      = 0,
                        IsLocking              = 0,
                        CustomerID             = loggingSessionInfo.ClientID
                    };
                    vipAmountBll.Create(vipAmountEntity);
                    // throw new APIException("您尚未开通付款账户") { ErrorCode = 121 };
                }
                else
                {
                    //账户已有余额 + 变更金额 > 0
                    if ((vipAmountEntity.EndAmount == null ? 0 : vipAmountEntity.EndAmount.Value) + detailInfo.Amount >= 0)
                    {
                        if (detailInfo.Amount > 0)
                        {
                            vipAmountEntity.InAmount    = (vipAmountEntity.InAmount == null ? 0 : vipAmountEntity.InAmount.Value) + detailInfo.Amount;
                            vipAmountEntity.TotalAmount = (vipAmountEntity.TotalAmount == null ? 0 : vipAmountEntity.TotalAmount.Value) + detailInfo.Amount;
                        }
                        else
                        {
                            vipAmountEntity.OutAmount = (vipAmountEntity.OutAmount == null ? 0 : vipAmountEntity.OutAmount.Value) + System.Math.Abs(detailInfo.Amount.Value);
                        }
                        vipAmountEntity.EndAmount = (vipAmountEntity.EndAmount == null ? 0 : vipAmountEntity.EndAmount.Value) + detailInfo.Amount;

                        vipAmountBll.Update(vipAmountEntity);
                    }
                }
                //Insert VipAmountDetail
                var vipamountDetailBll    = new VipAmountDetailBLL(loggingSessionInfo);
                var vipAmountDetailEntity = new VipAmountDetailEntity
                {
                    VipAmountDetailId = Guid.NewGuid(),
                    VipId             = vipInfo.VIPID,
                    VipCardCode       = vipInfo.VipCode,
                    UnitID            = unitInfo != null ? unitInfo.unit_id : "",
                    UnitName          = unitInfo != null ? unitInfo.unit_name : "",
                    Amount            = detailInfo.Amount,
                    UsedReturnAmount  = 0,
                    EffectiveDate     = DateTime.Now,
                    DeadlineDate      = Convert.ToDateTime("9999-12-31 23:59:59"),
                    AmountSourceId    = detailInfo.AmountSourceId,
                    ObjectId          = detailInfo.ObjectId,
                    Reason            = detailInfo.Reason,
                    Remark            = detailInfo.Remark,
                    CustomerID        = loggingSessionInfo.ClientID
                };
                vipamountDetailBll.Create(vipAmountDetailEntity);

                vipAmountDetailId = vipAmountDetailEntity.VipAmountDetailId.ToString();
            }
            catch (Exception ex)
            {
                throw new APIException(ex.ToString())
                      {
                          ErrorCode = 121
                      };
            }
            return(vipAmountDetailId);
        }
Esempio n. 27
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Update(VipAmountDetailEntity pEntity)
 {
     _currentDAO.Update(pEntity);
 }