Beispiel #1
0
        public static void SaveStoreAgentProduct(List <VendorAgentInfo> agentsInfoes, int sellerSysNo, string createUserName
                                                 , bool isRequest)
        {
            var singleAgentInfo = new List <VendorAgentInfo>();

            #region check 是否存在重复的代理,品牌,C3
            if (isRequest == false)
            {
                var message         = new StringBuilder();
                var originAgentInfo = StoreService.QueryStoreAgentInfos(sellerSysNo);
                agentsInfoes.ForEach(p =>
                {
                    var isExists = originAgentInfo.Any(q => q.C3Name == p.C3Name &&
                                                       q.BrandInfo.SysNo == p.BrandInfo.SysNo);
                    if (isExists)
                    {
                        message.AppendFormat("{0},{1},{2}已代理<br/>", p.BrandInfo.BrandNameLocal, p.C3Name, p.AgentLevel);
                    }
                    else
                    {
                        singleAgentInfo.Add(p);
                    }
                });
                if (message.Length > 0)
                {
                    throw new BusinessException(message.ToString());
                }
            }
            #endregion

            var agentedProduct = StoreDA.QueryStoreAgentInfos(sellerSysNo).Where(p => p.RequestType == VendorModifyRequestStatus.VerifyPass);

            using (var trans = TransactionManager.Create())
            {
                agentsInfoes.ForEach(p =>
                {
                    if (p.AgentSysNo.HasValue && agentedProduct.Any(q => q.AgentSysNo == p.AgentSysNo.Value))
                    {
                        return;
                    }
                    p.RequestType = VendorModifyRequestStatus.Apply;
                    //CreateVendorManufacturerInfo

                    VendorAgentInfo createdVendorAgentInfo;
                    if (p.AgentSysNo.HasValue)
                    {
                        //p.Status = VendorAgentStatus.Normal;
                        //提交审核需要将Status置零
                        if (isRequest)
                        {
                            p.Status = VendorAgentStatus.Normal;
                        }
                        createdVendorAgentInfo = StoreDA.UpdateVendorManufacturerInfo(p, sellerSysNo);
                    }
                    else
                    {
                        createdVendorAgentInfo = StoreDA.CreateVendorManufacturerInfo(p, sellerSysNo);
                    }
                    p.AgentSysNo = createdVendorAgentInfo.AgentSysNo;
                    //CreateVendorCommissionInfo
                    //根据C3和Brand获取佣金规则,设置VendorCommissionInfo
                    //p.BrandInfo.SysNo
                    //p.C3SysNo
                    if (p.BrandInfo != null && p.BrandInfo.SysNo.HasValue)
                    {
                        CommissionRule rule = StoreDA.QueryCommissionRule(p.BrandInfo.SysNo.Value, p.C3SysNo.Value);
                        if (rule != null)
                        {
                            if (p.VendorCommissionInfo == null)
                            {
                                p.VendorCommissionInfo = new VendorCommissionInfo();
                            }
                            p.VendorCommissionInfo.DeliveryFee = rule.DeliveryFee;
                            //p.VendorCommissionInfo.GuaranteedAmt=
                            p.VendorCommissionInfo.RentFee = rule.RentFee;

                            if (string.IsNullOrWhiteSpace(rule.SalesRule))
                            {
                                p.VendorCommissionInfo.SaleRuleEntity = new VendorStagedSaleRuleEntity();
                            }
                            else
                            {
                                p.VendorCommissionInfo.SaleRuleEntity = SerializationUtility.XmlDeserialize <VendorStagedSaleRuleEntity>(rule.SalesRule);
                            }



                            p.VendorCommissionInfo.OrderCommissionAmt = rule.OrderCommissionFee;
                        }
                    }
                    StoreDA.CreateVendorCommissionInfo(p, sellerSysNo, createUserName);

                    #region 写入品牌商检信息
                    //seller portal不需要些商检信息,在ecc中品牌审核通过后写品牌的商检信息

                    //var brandFiling = new StoreBrandFiling();
                    //brandFiling.AgentLevel = p.AgentLevel;
                    //brandFiling.BrandSysNo = p.BrandInfo.SysNo.Value;
                    //brandFiling.CompanyCode = p.CompanyCode;
                    //brandFiling.EditDate = DateTime.Now;
                    //brandFiling.EditUserName = createUserName;
                    //brandFiling.EditUserSysNo = sellerSysNo;
                    //brandFiling.InDate = DateTime.Now;
                    //brandFiling.InUserName = createUserName;
                    //brandFiling.InUserSysNo = sellerSysNo;
                    //brandFiling.Staus = 1;
                    //brandFiling.SellerSysNo = sellerSysNo;
                    //brandFiling.InspectionNo = CommonService.GenerateInspectionNo();
                    //StoreDA.InsertStoreBrandFiling(brandFiling);
                    #endregion

                    #region 写申请表
                    if (isRequest)
                    {
                        VendorModifyRequestInfo requestVendorAgentInfo = new VendorModifyRequestInfo
                        {
                            ActionType  = VendorModifyActionType.Add,
                            RequestType = VendorModifyRequestType.Manufacturer,
                            VendorSysNo = sellerSysNo,
                            //生产商的编号读取品牌对应的生产商
                            //ManufacturerSysNo = agentInfo.ManufacturerInfo.SysNo.Value,
                            VendorManufacturerSysNo = p.AgentSysNo.Value,
                            AgentLevel       = p.AgentLevel,
                            C2SysNo          = p.C2SysNo,
                            C3SysNo          = p.C3SysNo,
                            Status           = VendorModifyRequestStatus.Apply,
                            SettlePercentage = p.SettlePercentage,
                            SettleType       = p.SettleType,
                            BuyWeekDay       = p.BuyWeekDay,
                            SendPeriod       = p.SendPeriod,
                            BrandSysNo       = p.BrandInfo.SysNo,
                            CompanyCode      = p.CompanyCode,
                            //CRL20146 By Kilin
                            //写代销结算类型
                            //SettlePeriodType = vendorInfo.VendorFinanceInfo.SettlePeriodType,
                            SettlePeriodType     = null,
                            AutoAudit            = false,
                            MaxNoPayTimeForOrder = p.MaxNoPayTimeForOrder,
                            IsNeedConfirmOrder   = p.IsNeedConfirmOrder
                                                   //]]
                        };
                        //
                        StoreDA.CreateModifyRequest(requestVendorAgentInfo, sellerSysNo);
                    }
                    #endregion
                });
                trans.Complete();
            }
        }