예제 #1
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);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 我的小店增加商品
        /// </summary>
        /// <param name="pRequest"></param>
        /// <returns></returns>
        private string VipStoreAddItem(string pRequest)
        {
            var rp = pRequest.DeserializeJSONTo <APIRequest <VipStoreRP> >();
            LoggingSessionInfo loggingSessionInfo = Default.GetBSLoggingSession(rp.CustomerID, "1");


            //先判断商品是否存在
            if (string.IsNullOrWhiteSpace(rp.Parameters.ItemID))
            {
                return(new ErrorResponse(500, "没有添加商品信息").ToJSON());
            }

            //要传入的商品id组
            string[] items = rp.Parameters.ItemID.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);


            //给用户增加商品
            VipStoreBLL vipStoreBlll = new VipStoreBLL(loggingSessionInfo);



            List <string> arrItem = new List <string>();

            for (int i = 0; i < items.Length; i++)
            {
                string         itemID          = items[i];
                VipStoreEntity vipstoreEntityO = vipStoreBlll.QueryByEntity(
                    new VipStoreEntity()
                {
                    ItemID = itemID,
                    VIPID  = rp.UserID
                },
                    null
                    ).FirstOrDefault();

                //如果加入该商品就加入
                if (vipstoreEntityO == null && !arrItem.Contains(itemID))
                {
                    arrItem.Add(itemID);
                }
            }

            IDbTransaction tran = new JIT.CPOS.BS.DataAccess.Base.TransactionHelper(loggingSessionInfo).CreateTransaction();

            foreach (var item in arrItem)
            {
                VipStoreEntity vipStoreEntity = new VipStoreEntity()
                {
                    vipStoreID = Guid.NewGuid().ToString(),
                    VIPID      = rp.UserID,
                    ItemID     = item,
                    SoldCount  = 0
                };

                vipStoreBlll.Create(vipStoreEntity, tran);
            }

            tran.Commit();

            //用户是否开通小店
            VipBLL vipBll = new VipBLL(loggingSessionInfo);

            VipEntity vipEntity = vipBll.GetByID(rp.UserID);

            vipEntity.IsSotre = vipEntity.IsSotre ?? 0;
            if (vipEntity != null && vipEntity.IsSotre == 0)
            {
                vipEntity.IsSotre = 1;
                vipBll.Update(vipEntity);
            }

            return(new SuccessResponse <IAPIResponseData>().ToJSON());
        }
예제 #3
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;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }