コード例 #1
0
        public int ActiveCard(APIRequest <ActiveCardRP> rp)
        {
            var cardDepositBLL = new CardDepositBLL(CurrentUserInfo);
            var cardDeposit    = PagedSearch(new GetCardRP()
            {
                CardNo = rp.Parameters.CardNo, UseStatus = "0"
            }, CurrentUserInfo.ClientID);

            int result = 0;

            if (cardDeposit != null && cardDeposit.Tables.Count > 0 && cardDeposit.Tables[0].Rows.Count > 0)
            {
                DataRow dr = cardDeposit.Tables[0].Rows[0];
                if (rp.Parameters.CardPassword == System.Text.Encoding.UTF8.GetString(cardDepositBLL.DecryptCardPassword((byte[])dr["CardPassword"])).Replace("\0", ""))
                {
                    System.Data.SqlClient.SqlTransaction tran = GetTran();
                    using (tran.Connection)
                    {
                        string       errorMessage = "";
                        VipAmountBLL vipAmountBLL = new VipAmountBLL(CurrentUserInfo);
                        vipAmountBLL.SetVipAmountChange(CurrentUserInfo.ClientID, 4, rp.Parameters.VipID, decimal.Parse(dr["Amount"].ToString()) + decimal.Parse(dr["Bonus"].ToString()), dr["CardDepositId"].ToString(), "Prepaid card charge", "In", out errorMessage, tran);
                        result = this._currentDAO.ActiveCard(rp.Parameters.CardNo, rp.Parameters.VipID, this.CurrentUserInfo.UserID, this.CurrentUserInfo.ClientID, tran);

                        tran.Commit();
                    }
                }
            }

            return(result);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #5
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;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #6
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);
                        }
                    }
                }
            }
        }
コード例 #7
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);
        }
コード例 #8
0
        public SuccessResponse <IAPIResponseData> VipConsume(APIRequest <VipConsumeRP> rp)
        {
            var cardDepositBLL            = new CardDepositBLL(CurrentUserInfo);
            var registerValidationCodeBLL = new RegisterValidationCodeBLL(CurrentUserInfo);
            var vipBLL = new VipBLL(CurrentUserInfo);
            var rd     = new EmptyRD();
            var rsp    = new SuccessResponse <IAPIResponseData>(rd);

            string phone = "";

            var vip = vipBLL.Query(new IWhereCondition[] { new EqualsCondition()
                                                           {
                                                               FieldName = "VipID", Value = rp.Parameters.VipID
                                                           } }, null);

            if (vip.Length > 0)
            {
                phone = vip[0].Phone;

                if (string.IsNullOrEmpty(phone))
                {
                    rsp.ResultCode = 202;
                    rsp.Message    = "会员未注册手机号!";
                }
                else if (string.IsNullOrEmpty(rp.Parameters.SMSCode))
                {
                    //发送验证码
                    registerValidationCodeBLL.SendCode(phone);
                }
                else
                {
                    //验证验证码
                    var codeEntity = registerValidationCodeBLL.Query(new IWhereCondition[] {
                        new EqualsCondition()
                        {
                            FieldName = "Mobile", Value = phone
                        }
                        , new EqualsCondition()
                        {
                            FieldName = "Code", Value = rp.Parameters.SMSCode
                        }
                        , new EqualsCondition()
                        {
                            FieldName = "IsValidated", Value = 0
                        }
                        , new EqualsCondition()
                        {
                            FieldName = "IsDelete", Value = 0
                        }
                    }, new OrderBy[] {
                        new OrderBy()
                        {
                            FieldName = "CreateTime", Direction = OrderByDirections.Desc
                        }
                    });

                    if (codeEntity != null && codeEntity.Length > 0)
                    {
                        System.Data.SqlClient.SqlTransaction tran = GetTran();
                        using (tran.Connection)
                        {
                            registerValidationCodeBLL.DeleteByMobile(phone, 1, tran);

                            string       errorMessage = "";
                            VipAmountBLL vipAmountBLL = new VipAmountBLL(CurrentUserInfo);
                            vipAmountBLL.SetVipAmountChange(CurrentUserInfo.ClientID, 5, rp.Parameters.VipID, rp.Parameters.Amount, CurrentUserInfo.CurrentUserRole.UnitId, "Prepaid card consumption" + "~" + (rp.Parameters.DocumentCode ?? ""), "Out", out errorMessage, tran);

                            tran.Commit();
                        }
                    }
                    else
                    {
                        rsp.ResultCode = 203;
                        rsp.Message    = "请先获取验证码!";
                    }
                }
            }
            else
            {
                rsp.ResultCode = 201;
                rsp.Message    = "会员不存在!";
            }

            return(rsp);
        }