예제 #1
0
 public InsuranceDomainService(IInsuranceOrderRepository iInsuranceOrderRepository, IInsuranceConfigRepository iInsuranceConfigRepository, IInsuranceDepositLogRepository iInsuranceDepositLogRepository, IOrderRepository iOrderRepository, IPaymentClientProxy iPayMentClientProxy, IBusinessmanRepository businessmanRepository, IInsurancePurchaseByBussinessmanRepository iInsurancePurchaseByBussinessmanRepository)
 {
     this._iInsuranceOrderRepository      = iInsuranceOrderRepository;
     this._iInsuranceConfigRepository     = iInsuranceConfigRepository;
     this._iInsuranceDepositLogRepository = iInsuranceDepositLogRepository;
     this._iOrderRepository      = iOrderRepository;
     this._iPayMentClientProxy   = iPayMentClientProxy;
     this._businessmanRepository = businessmanRepository;
     this._iInsurancePurchaseByBussinessmanRepository = iInsurancePurchaseByBussinessmanRepository;
 }
예제 #2
0
 public BusinessmanService(IBusinessmanRepository businessmanRepository, IPaymentClientProxy payMentClientProxy, IRoleRepository roleRepository, ISmsTemplateRepository smsTemplateRepository, ISMSChargeSetRepository smsChargeRepository, IOrderRepository orderRepository, IAfterSaleOrderRepository afterSaleOrderRepository, IOPENScanRepository openScanRepository, CustomerInfoDomainService customerInfoDomainService, StationBuyGroupDomainService stationBuyGroupDomainService)
 {
     this.businessmanRepository         = businessmanRepository;
     this.roleRepository                = roleRepository;
     this.payMentClientProxy            = payMentClientProxy;
     this.smsTemplateRepository         = smsTemplateRepository;
     this.smsChargeRepository           = smsChargeRepository;
     this.orderRepository               = orderRepository;
     this.afterSaleOrderRepository      = afterSaleOrderRepository;
     this.openScanRepository            = openScanRepository;
     this._customerInfoDomainService    = customerInfoDomainService;
     this._stationBuyGroupDomainService = stationBuyGroupDomainService;
 }
예제 #3
0
        /// <summary>
        /// 运营商批发保险
        /// </summary>
        /// <param name="buyCount">购买保险的数量</param>
        /// <param name="pwd"></param>
        /// <param name="carrierCode"></param>
        /// <param name="carrierName"></param>
        /// <param name="payUser"></param>
        public void BuyInsuranceByCashByCarrier(int buyCount, string pwd, string carrierCode, string carrierName, string operatorCode, string operatorName, CurrentUserInfo payUser, string remark = "")
        {
            //获取保险配置
            var cfg = InsuranceSection.GetInsuranceConfigurationSection();

            if (!cfg.CtrlInsuranceCollection.IsEnabled)
            {
                throw new CustomException(11112, "保险功能未开启");
            }
            //最大能够购买的数量
            var canBuyMaxCount =
                (from InsuranceElement ctrl in cfg.CtrlInsuranceCollection
                 select ctrl).Where(m => m.IsCurrent).FirstOrDefault().LeaveCount;

            if (buyCount > canBuyMaxCount)
            {
                string type = payUser == null ? "赠送" : "购买";
                throw new CustomException(11113, "最多仅可" + type + canBuyMaxCount + "份保险。");
            }

            //获取当前运营商保险信息
            var model = this._iInsuranceConfigRepository.FindAll(p => p.BusinessmanCode == carrierCode).FirstOrDefault();

            //获取单价
            decimal singlePrice = payUser == null ? 0 : cfg.CtrlInsuranceCollection.SinglePrice;

            //运营商购买记录
            var logBuiler = AggregationFactory.CreateBuiler <InsuranceDepositLogBuilder>();
            var log       = logBuiler.CreateInsuranceDepositLog();

            log.PayNo            = log.GetPayNo();
            log.BeforeLeaveCount = model == null ? 0 : model.LeaveCount;                                               //购买前剩余
            log.AfterLeaveCount  = log.BeforeLeaveCount + buyCount;                                                    //购买后剩余
            log.DepositCount     = buyCount;                                                                           //购买数量
            log.TotalPrice       = Math.Round((singlePrice * buyCount), 2);                                            //总价
            log.SinglePrice      = singlePrice;                                                                        //单价
            log.BusinessmanCode  = carrierCode;                                                                        //商户号
            log.BusinessmanName  = carrierName;                                                                        //商户名称
            log.PayWay           = EnumPayMethod.Account;                                                              //支付类别
            log.Remark           = remark;
            log.RecordType       = payUser == null ? EnumInsuranceDepositType.Offer : EnumInsuranceDepositType.Normal; //记录类别
            log.OperatorAccount  = operatorCode;
            log.OperatorName     = operatorName;
            log.PayFee           = Math.Round(SystemConsoSwitch.Rate * log.TotalPrice, 2);
            if (_iPayMentClientProxy == null)
            {
                _iPayMentClientProxy = new CashbagPaymentClientProxy();
            }
            var payResult = string.Empty;

            if (payUser != null)
            {
                //现金账户
                //payResult = _iPayMentClientProxy.PaymentByCashAccount(payUser.CashbagCode, payUser.CashbagKey,
                //    log.PayNo, "购买保险", log.TotalPrice, pwd);
                var resultc = _iPayMentClientProxy.PaymentByCashAccount(payUser.CashbagCode, payUser.CashbagKey, log.PayNo, "购买保险", log.TotalPrice, pwd);
                if (resultc.Item1)
                {
                    //该订单已经被在线支付时写入日志
                    Logger.WriteLog(LogType.INFO, "订单已经支付,交易号为" + resultc.Item2 + "支付方式为" + resultc.Item3);
                    throw new CustomException(0001, "订单已经支付,交易号为" + resultc.Item2 + "支付方式为" + resultc.Item3);
                }
                payResult = resultc.Item2;
            }
            //如果存在交易号,即支付成功
            if (!string.IsNullOrEmpty(payResult))
            {
                log.OutTradeNo = payResult;                 //设置交易号
                log.BuyState   = EnumInsurancePayStatus.OK; //设置交易状态
                //设置剩余数量
                foreach (var m in (from InsuranceElement ctrl in cfg.CtrlInsuranceCollection
                                   select ctrl).Where(m => m.IsCurrent))
                {
                    m.LeaveCount -= buyCount;
                    break;
                }
                //保存配置信息
                InsuranceSection.Save();
                //保存当前分销商商户保险配置
                if (model != null)
                {
                    model.LeaveCount = log.AfterLeaveCount;
                    this.unitOfWorkRepository.PersistUpdateOf(model);
                }
                else
                {
                    var builder = AggregationFactory.CreateBuiler <InsuranceConfigBuilder>();
                    var m       = builder.CreateInsuranceConfig();
                    m.BusinessmanCode = carrierCode;
                    m.BusinessmanName = carrierName;
                    m.IsOpen          = true;
                    m.SinglePrice     = singlePrice;
                    m.LeaveCount      = buyCount;
                    m.ConfigType      = EnumInsuranceConfigType.Carrier;
                    this.unitOfWorkRepository.PersistCreationOf(m);
                }
            }
            else if (payUser == null)
            {
                log.BuyState = EnumInsurancePayStatus.Offer;
                //设置剩余数量
                foreach (var m in (from InsuranceElement ctrl in cfg.CtrlInsuranceCollection
                                   select ctrl).Where(m => m.IsCurrent))
                {
                    m.LeaveCount -= buyCount;
                    break;
                }
                //保存配置信息
                InsuranceSection.Save();
                //保存当前分销商商户保险配置
                if (model != null)
                {
                    model.LeaveCount = log.AfterLeaveCount;
                    this.unitOfWorkRepository.PersistUpdateOf(model);
                }
                else
                {
                    var builder = AggregationFactory.CreateBuiler <InsuranceConfigBuilder>();
                    var m       = builder.CreateInsuranceConfig();
                    m.BusinessmanCode = carrierCode;
                    m.BusinessmanName = carrierName;
                    m.IsOpen          = true;
                    m.SinglePrice     = singlePrice;
                    m.LeaveCount      = buyCount;
                    m.ConfigType      = EnumInsuranceConfigType.Carrier;
                    this.unitOfWorkRepository.PersistCreationOf(m);
                }
            }
            //否则交易失败
            else
            {
                log.BuyState = EnumInsurancePayStatus.NoPay;
            }

            log.BuyTime = DateTime.Now;
            this.unitOfWorkRepository.PersistCreationOf(log);
        }
예제 #4
0
        /// <summary>
        /// 分销商购买保险
        /// </summary>
        /// <param name="buyCount"></param>
        /// <param name="pwd"></param>
        /// <param name="businessmanCode"></param>
        /// <param name="businessmanName"></param>
        /// <param name="carrierCode"></param>
        /// <param name="payUser"></param>
        public void PurchaseInsuranceFromCarrier(int buyCount, string pwd, EnumPayMethod payMethod, string businessmanCode, string businessmanName, string carrierCode, string operatorCode, string operatorName, CurrentUserInfo payUser, string remark = "")
        {
            var carrier = this._businessmanRepository.FindAll(p => p.Code == carrierCode && p is Carrier).OfType <Carrier>().FirstOrDefault();
            //获取当前运营商保险配置
            var carrierCfg = this._iInsuranceConfigRepository.FindAll(p => p.BusinessmanCode == carrierCode).FirstOrDefault();
            //获取分销商保险配置
            var buyerCfg = this._iInsuranceConfigRepository.FindAll(p => p.BusinessmanCode == businessmanCode).FirstOrDefault();

            if (carrierCfg == null || !carrierCfg.IsOpen)
            {
                throw new CustomException(11114, "运营商保险功能未开启");
            }
            if (buyCount > carrierCfg.LeaveCount)
            {
                string type = payUser == null ? "赠送" : "购买";
                throw new CustomException(11115, "最多仅可" + type + carrierCfg.LeaveCount + "份保险。");
            }
            //单价
            decimal singlePrice = payUser == null ? 0 : carrierCfg.SinglePrice;

            //运营商购买记录
            var logBuiler = AggregationFactory.CreateBuiler <InsurancePurchaseByBussinessmanBuilder>();
            var log       = logBuiler.CreateInsurancePurchaseByBussinessman();

            log.PayNo            = log.GetPayNo();
            log.BeforeLeaveCount = buyerCfg == null ? 0 : buyerCfg.LeaveCount;                                           //购买前剩余
            log.AfterLeaveCount  = log.BeforeLeaveCount + buyCount;                                                      //购买后剩余
            log.DepositCount     = buyCount;                                                                             //购买数量
            log.TotalPrice       = Math.Round((singlePrice * buyCount), 2);                                              //总价
            log.SinglePrice      = singlePrice;                                                                          //单价
            log.BusinessmanCode  = businessmanCode;                                                                      //商户号
            log.BusinessmanName  = businessmanName;                                                                      //商户名称
            log.PayWay           = payMethod;                                                                            //支付类别
            log.RecordType       = payUser == null ? EnumInsurancePurchaseType.Offer : EnumInsurancePurchaseType.Normal; //记录类别
            log.CarrierCode      = carrierCode;
            log.CarrierName      = carrier.Name;
            log.OperatorAccount  = operatorCode;
            log.OperatorName     = operatorName;
            log.Remark           = remark;
            log.PayFee           = Math.Round(log.TotalPrice * SystemConsoSwitch.Rate, 2);

            #region 支付

            DataBill databill = new DataBill();
            CashbagConfigurationElement setting = SettingSection.GetInstances().Cashbag;
            string  moneyDispatch = "";
            decimal infMoney      = databill.Round(log.TotalPrice * carrier.Rate, 2);
            //支出配置,分销商,支出保险全额
            //moneyDispatch += currentUser.CashbagCode + "^" + insuranceOrder.PayMoney + "^" + EnumOperationType.Insurance.ToEnumDesc();
            //收入配置
            moneyDispatch += "|" + carrier.CashbagCode + "^" + log.TotalPrice + "^" + EnumOperationType.InsuranceReceivables.ToEnumDesc();
            //保险手续费支出
            moneyDispatch += "|" + carrier.CashbagCode + "^" + (-infMoney) + "^" + EnumOperationType.InsuranceServer.ToEnumDesc();
            //手续费收入配置
            moneyDispatch += "|" + setting.CashbagCode + "^" + infMoney + "^" + EnumOperationType.InsuranceServer.ToEnumDesc();

            var payResult = string.Empty;

            if (payUser != null)
            {
                if (_iPayMentClientProxy == null)
                {
                    _iPayMentClientProxy = new CashbagPaymentClientProxy();
                }
                switch (log.PayWay)
                {
                //现金账户
                case EnumPayMethod.Account:
                    //    payResult = _iPayMentClientProxy.PaymentByCashAccount(payUser.CashbagCode, payUser.CashbagKey,
                    //log.PayNo, "购买保险", log.TotalPrice, pwd, moneyDispatch);
                    var resultc = _iPayMentClientProxy.PaymentByCashAccount(payUser.CashbagCode, payUser.CashbagKey, log.PayNo, "购买保险", log.TotalPrice, pwd, moneyDispatch);
                    if (resultc.Item1)
                    {
                        //该订单已经被在线支付时写入日志
                        Logger.WriteLog(LogType.INFO, "订单已经支付,交易号为" + resultc.Item2 + "支付方式为" + resultc.Item3);
                        throw new CustomException(0001, "订单已经支付,交易号为" + resultc.Item2 + "支付方式为" + resultc.Item3);
                    }
                    payResult = resultc.Item2;
                    break;

                //信用账户
                case EnumPayMethod.Credit:
                    var result = _iPayMentClientProxy.PaymentByCreditAccount(payUser.CashbagCode, payUser.CashbagKey, log.PayNo, "购买保险", log.TotalPrice, pwd, moneyDispatch);
                    if (result.Item1)
                    {
                        //该订单已经被在线支付时写入日志
                        Logger.WriteLog(LogType.INFO, "订单已经支付,交易号为" + result.Item2 + "支付方式为" + result.Item3);
                        throw new CustomException(0001, "订单已经支付,交易号为" + result.Item2 + "支付方式为" + result.Item3);
                    }
                    payResult = result.Item2;
                    break;
                }
            }
            #endregion

            //如果存在交易号,即支付成功
            if (!string.IsNullOrEmpty(payResult))
            {
                log.OutTradeNo = payResult;                 //设置交易号
                log.BuyState   = EnumInsurancePayStatus.OK; //设置交易状态
                //设置运营商剩余数量
                carrierCfg.LeaveCount -= buyCount;
                this.unitOfWorkRepository.PersistUpdateOf(carrierCfg);
                //设置分销商剩余数量
                if (buyerCfg != null)
                {
                    buyerCfg.LeaveCount = log.AfterLeaveCount;
                    this.unitOfWorkRepository.PersistUpdateOf(buyerCfg);
                }
                else
                {
                    var builder = AggregationFactory.CreateBuiler <InsuranceConfigBuilder>();
                    var m       = builder.CreateInsuranceConfig();
                    m.BusinessmanCode = businessmanCode;
                    m.BusinessmanName = businessmanName;
                    m.IsOpen          = true;
                    m.SinglePrice     = carrierCfg.SinglePrice;
                    m.LeaveCount      = buyCount;
                    m.ConfigType      = EnumInsuranceConfigType.Buyer;
                    this.unitOfWorkRepository.PersistCreationOf(m);
                }
            }
            else if (payUser == null)
            {
                log.BuyState = EnumInsurancePayStatus.Offer;
                //设置运营商剩余数量
                carrierCfg.LeaveCount -= buyCount;
                this.unitOfWorkRepository.PersistUpdateOf(carrierCfg);
                //设置分销商剩余数量
                if (buyerCfg != null)
                {
                    buyerCfg.LeaveCount = log.AfterLeaveCount;
                    this.unitOfWorkRepository.PersistUpdateOf(buyerCfg);
                }
                else
                {
                    var builder = AggregationFactory.CreateBuiler <InsuranceConfigBuilder>();
                    var m       = builder.CreateInsuranceConfig();
                    m.BusinessmanCode = businessmanCode;
                    m.BusinessmanName = businessmanName;
                    m.IsOpen          = true;
                    m.SinglePrice     = carrierCfg.SinglePrice;
                    m.LeaveCount      = buyCount;
                    m.ConfigType      = EnumInsuranceConfigType.Buyer;
                    this.unitOfWorkRepository.PersistCreationOf(m);
                }
            }
            //否则交易失败
            else
            {
                log.BuyState = EnumInsurancePayStatus.NoPay;
            }

            log.BuyTime = DateTime.Now;
            this.unitOfWorkRepository.PersistCreationOf(log);
        }