public CustomJsonResult GetPayTranSn(int operater, OrderPayTrans orderPayTrans)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {

                var order = CurrentDb.Order.Where(m => m.UserId == orderPayTrans.UserId && m.Id == orderPayTrans.OrderId && m.Sn == orderPayTrans.OrderSn).FirstOrDefault();
                if (order == null)
                {
                    return new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "跳转支付错误");
                }

                var l_orderPayTrans = new OrderPayTrans();

                l_orderPayTrans.UserId = orderPayTrans.UserId;
                l_orderPayTrans.MerchantId = orderPayTrans.MerchantId;
                l_orderPayTrans.PosMachineId = orderPayTrans.PosMachineId;
                l_orderPayTrans.OrderId = orderPayTrans.OrderId;
                l_orderPayTrans.OrderSn = orderPayTrans.OrderSn;
                l_orderPayTrans.TransType = orderPayTrans.TransType;


                if (BizFactory.AppSettings.IsTest)
                {
                    l_orderPayTrans.Amount = "1";
                }
                else
                {
                    l_orderPayTrans.Amount = Convert.ToInt32((order.Price * 100)).ToString();
                }

                l_orderPayTrans.CreateTime = DateTime.Now;
                l_orderPayTrans.Creator = operater;
                CurrentDb.OrderPayTrans.Add(l_orderPayTrans);
                CurrentDb.SaveChanges();

                SnModel snModel = Sn.Build(SnType.OrderPayTrans, l_orderPayTrans.Id);

                l_orderPayTrans.Sn = snModel.Sn;

                CurrentDb.SaveChanges();
                ts.Complete();


                var model = new { orderId = orderPayTrans.OrderId, orderSn = orderPayTrans.OrderSn, payTransSn = l_orderPayTrans.Sn, transType = l_orderPayTrans.TransType, amount = l_orderPayTrans.Amount };

                result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "获取成功", model);

            }

            return result;
        }
        public CustomJsonResult SubmitClaim(int operater, int userId, OrderToCarClaim orderToCarClaim)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                //用户信息
                var clientUser = CurrentDb.SysClientUser.Where(m => m.Id == userId).FirstOrDefault();
                //商户信息
                var merchant = CurrentDb.Merchant.Where(m => m.Id == clientUser.MerchantId).FirstOrDefault();

                var insuranceCompany = CurrentDb.Company.Where(m => m.Id == orderToCarClaim.InsuranceCompanyId).FirstOrDefault();


                orderToCarClaim.SalesmanId = merchant.SalesmanId ?? 0;
                orderToCarClaim.AgentId = merchant.AgentId ?? 0;

                orderToCarClaim.Type =  Enumeration.OrderType.InsureForCarForClaim;
                orderToCarClaim.TypeName = Enumeration.OrderType.InsureForCarForClaim.GetCnName();
                orderToCarClaim.MerchantId = merchant.Id;
                orderToCarClaim.PosMachineId = orderToCarClaim.PosMachineId;
                orderToCarClaim.UserId = merchant.UserId;
                orderToCarClaim.InsuranceCompanyName = insuranceCompany.Name;
                orderToCarClaim.Status = Enumeration.OrderStatus.Submitted;
                orderToCarClaim.SubmitTime = this.DateTime;
                orderToCarClaim.CreateTime = this.DateTime;
                orderToCarClaim.Creator = operater;
                CurrentDb.OrderToCarClaim.Add(orderToCarClaim);
                CurrentDb.SaveChanges();

                SnModel snModel = Sn.Build(SnType.OrderToCarClaim, orderToCarClaim.Id);

                orderToCarClaim.Sn = snModel.Sn;
                orderToCarClaim.TradeSnByWechat = snModel.TradeSnByWechat;
                orderToCarClaim.TradeSnByAlipay = snModel.TradeSnByAlipay;


                //状态改为待核实
                BizProcessesAudit bizProcessesAudit = BizFactory.BizProcessesAudit.Add(operater, Enumeration.BizProcessesAuditType.OrderToCarClaim, orderToCarClaim.Id, Enumeration.CarClaimDealtStatus.WaitVerifyOrder);
                BizFactory.BizProcessesAudit.ChangeAuditDetails(Enumeration.OperateType.Submit, Enumeration.CarClaimDealtStep.Submit, bizProcessesAudit.Id, operater, orderToCarClaim.ClientRequire, "商户提交理赔需求", this.DateTime);

                orderToCarClaim.BizProcessesAuditId = bizProcessesAudit.Id;

                CurrentDb.SaveChanges();
                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, "提交成功");
            }


            return result;
        }
        public CustomJsonResult Submit(int operater, OrderToInsurance orderToInsurance)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                var clientUser = CurrentDb.SysClientUser.Where(m => m.Id == orderToInsurance.UserId).FirstOrDefault();
                var merchant   = CurrentDb.Merchant.Where(m => m.Id == clientUser.MerchantId).FirstOrDefault();
                var productSku = CurrentDb.ProductSku.Where(m => m.Id == orderToInsurance.ProductSkuId).FirstOrDefault();
                var product    = CurrentDb.Product.Where(m => m.Id == productSku.ProductId).FirstOrDefault();

                orderToInsurance.SalesmanId           = merchant.SalesmanId ?? 0;
                orderToInsurance.AgentId              = merchant.AgentId ?? 0;
                orderToInsurance.Type                 = Enumeration.OrderType.Insure;
                orderToInsurance.TypeName             = Enumeration.OrderType.Insure.GetCnName();
                orderToInsurance.ProductId            = product.Id;
                orderToInsurance.ProductType          = product.Type;
                orderToInsurance.ProductName          = product.Name;
                orderToInsurance.ProductSkuId         = productSku.Id;
                orderToInsurance.ProductSkuName       = productSku.Name;
                orderToInsurance.InsuranceCompanyId   = product.SupplierId;
                orderToInsurance.InsuranceCompanyName = product.Supplier;
                orderToInsurance.Status               = Enumeration.OrderStatus.Submitted;
                orderToInsurance.SubmitTime           = this.DateTime;
                orderToInsurance.CreateTime           = this.DateTime;
                orderToInsurance.Creator              = operater;
                CurrentDb.OrderToInsurance.Add(orderToInsurance);
                CurrentDb.SaveChanges();


                SnModel snModel = Sn.Build(SnType.OrderToCredit, orderToInsurance.Id);

                orderToInsurance.Sn = snModel.Sn;
                orderToInsurance.TradeSnByWechat = snModel.TradeSnByWechat;
                orderToInsurance.TradeSnByAlipay = snModel.TradeSnByAlipay;

                var bizProcessesAudit = BizFactory.BizProcessesAudit.Add(operater, Enumeration.BizProcessesAuditType.OrderToInsurance, orderToInsurance.Id, Enumeration.AuditFlowV1Status.Submit);
                BizFactory.BizProcessesAudit.ChangeStatusByAuditFlowV1(bizProcessesAudit.Id, Enumeration.AuditFlowV1Status.Submit, operater, null, "提交订单,等待取单");

                orderToInsurance.BizProcessesAuditId = bizProcessesAudit.Id;

                CurrentDb.SaveChanges();
                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, "提交成功");
            }


            return(result);
        }
Esempio n. 4
0
        public static SnModel Build(SnType type, int id)
        {
            SnModel model  = new SnModel();
            string  prefix = "";
            //switch (type)
            //{
            //    case SnType.CarInsure:
            //        prefix = "A";
            //        break;
            //    case SnType.CarClaim:
            //        prefix = "B";
            //        break;
            //    case SnType.Withdraw:
            //        prefix = "C";
            //        break;
            //    case SnType.FundTrans:
            //        prefix = "D";
            //        break;
            //    case SnType.ServiceFee:
            //        prefix = "E";
            //        break;
            //    case SnType.TalentDemand:
            //        prefix = "F";
            //        break;
            //    case SnType.ApplyLossAssess:
            //        prefix = "G";
            //        break;
            //    case SnType.LllegalQueryScoreTrans:
            //        prefix = "H";
            //        break;
            //    case SnType.LllegalQueryRecharge:
            //        prefix = "I";
            //        break;
            //    case SnType.LllegalDealt:
            //        prefix = "J";
            //        break;
            //}

            string dateTime = DateTime.Now.ToString("yyMMddHHmm");

            string sId = id.ToString().PadLeft(10, '0');

            string sn = prefix + dateTime + sId;

            model.Sn = sn;
            //model.TradeSnByWechat = string.Format("{0}W", sn);
            //model.TradeSnByAlipay = string.Format("{0}A", sn);
            return(model);
        }
        public CustomJsonResult Submit(int operater, OrderToTalentDemand orderToTalentDemand)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                //用户信息
                var clientUser = CurrentDb.SysClientUser.Where(m => m.Id == orderToTalentDemand.UserId).FirstOrDefault();
                //商户信息
                var merchant = CurrentDb.Merchant.Where(m => m.Id == clientUser.MerchantId).FirstOrDefault();

                orderToTalentDemand.SalesmanId  = merchant.SalesmanId ?? 0;
                orderToTalentDemand.AgentId     = merchant.AgentId ?? 0;
                orderToTalentDemand.Type        = Enumeration.OrderType.TalentDemand;
                orderToTalentDemand.TypeName    = Enumeration.OrderType.TalentDemand.GetCnName();
                orderToTalentDemand.WorkJobName = orderToTalentDemand.WorkJob.GetCnName();
                orderToTalentDemand.Status      = Enumeration.OrderStatus.Submitted;
                orderToTalentDemand.SubmitTime  = this.DateTime;
                orderToTalentDemand.CreateTime  = this.DateTime;
                orderToTalentDemand.Creator     = operater;
                CurrentDb.OrderToTalentDemand.Add(orderToTalentDemand);
                CurrentDb.SaveChanges();


                SnModel snModel = Sn.Build(SnType.OrderToTalentDemand, orderToTalentDemand.Id);

                orderToTalentDemand.Sn = snModel.Sn;
                orderToTalentDemand.TradeSnByWechat = snModel.TradeSnByWechat;
                orderToTalentDemand.TradeSnByAlipay = snModel.TradeSnByAlipay;

                var bizProcessesAudit = BizFactory.BizProcessesAudit.Add(operater, Enumeration.BizProcessesAuditType.OrderToTalentDemand, orderToTalentDemand.Id, Enumeration.AuditFlowV1Status.Submit);
                BizFactory.BizProcessesAudit.ChangeStatusByAuditFlowV1(bizProcessesAudit.Id, Enumeration.AuditFlowV1Status.Submit, operater, null, "提交订单,等待取单");

                orderToTalentDemand.BizProcessesAuditId = bizProcessesAudit.Id;

                CurrentDb.SaveChanges();
                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, "提交成功");
            }


            return(result);
        }
        public CustomJsonResult SubmitLllegalQueryScoreRecharge(int operater, OrderToLllegalQueryRecharge orderToLllegalQueryRecharge)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                var clientUser = CurrentDb.SysClientUser.Where(m => m.Id == orderToLllegalQueryRecharge.UserId).FirstOrDefault();
                var merchant = CurrentDb.Merchant.Where(m => m.Id == clientUser.MerchantId).FirstOrDefault();
     
                orderToLllegalQueryRecharge.SalesmanId = merchant.SalesmanId ?? 0;
                orderToLllegalQueryRecharge.AgentId = merchant.AgentId ?? 0;

                orderToLllegalQueryRecharge.Type = Enumeration.OrderType.LllegalQueryRecharge;
                orderToLllegalQueryRecharge.TypeName = Enumeration.OrderType.LllegalQueryRecharge.GetCnName();
                orderToLllegalQueryRecharge.Status = Enumeration.OrderStatus.WaitPay;
                orderToLllegalQueryRecharge.SubmitTime = this.DateTime;
                orderToLllegalQueryRecharge.CreateTime = this.DateTime;
                orderToLllegalQueryRecharge.Creator = operater;
                CurrentDb.OrderToLllegalQueryRecharge.Add(orderToLllegalQueryRecharge);
                CurrentDb.SaveChanges();



                SnModel snModel = Sn.Build(SnType.OrderToLllegalQueryRecharge, orderToLllegalQueryRecharge.Id);

                orderToLllegalQueryRecharge.Sn = snModel.Sn;
                orderToLllegalQueryRecharge.TradeSnByWechat = snModel.TradeSnByWechat;
                orderToLllegalQueryRecharge.TradeSnByAlipay = snModel.TradeSnByAlipay;
                CurrentDb.SaveChanges();



                OrderConfirmInfo yOrder = new OrderConfirmInfo();


                yOrder.OrderId = orderToLllegalQueryRecharge.Id;
                yOrder.OrderSn = orderToLllegalQueryRecharge.Sn;
                yOrder.remarks = orderToLllegalQueryRecharge.Remarks;
                yOrder.orderType = orderToLllegalQueryRecharge.Type;
                yOrder.orderTypeName = orderToLllegalQueryRecharge.TypeName;

                // yOrder.confirmField.Add(new Entity.AppApi.OrderField("订单编号", orderToLllegalQueryRecharge.Sn.NullToEmpty()));
                yOrder.confirmField.Add(new Entity.AppApi.OrderField("积分", string.Format("{0}", orderToLllegalQueryRecharge.Score)));
                yOrder.confirmField.Add(new Entity.AppApi.OrderField("支付金额", string.Format("{0}元", orderToLllegalQueryRecharge.Price.NullToEmpty())));


                #region 支持的支付方式
                int[] payMethods = new int[1] { 1 };

                foreach (var payWayId in payMethods)
                {
                    var payWay = new PayWay();
                    payWay.id = payWayId;
                    yOrder.payMethod.Add(payWay);
                }
                #endregion


                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "提交成功", yOrder);
            }


            return result;
        }
        public CustomJsonResult ReCarInsureOffer(int operater, int userId, int merchantId, int orderId)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                var oldOrder = CurrentDb.OrderToCarInsure.Where(m => m.Id == orderId).FirstOrDefault();

                var newOrder = new OrderToCarInsure();
                newOrder.MerchantId = oldOrder.MerchantId;
                newOrder.PosMachineId = oldOrder.PosMachineId;
                newOrder.UserId = oldOrder.UserId;
         
                //newOrder.ProductName = oldOrder.ProductName;
                //newOrder.ProductType = oldOrder.ProductType;
                newOrder.ClientRequire = oldOrder.ClientRequire;
                newOrder.InsuranceCompanyId = oldOrder.InsuranceCompanyId;
                newOrder.InsuranceCompanyName = oldOrder.InsuranceCompanyName;
                newOrder.CarOwner = oldOrder.CarOwner;
                newOrder.CarOwnerIdNumber = oldOrder.CarOwnerIdNumber;
                newOrder.CarOwnerAddress = oldOrder.CarOwnerAddress;
                newOrder.CarModel = oldOrder.CarModel;
                newOrder.CarModelName = oldOrder.CarModelName;
                newOrder.CarOwner = oldOrder.CarOwner;
                newOrder.CarPlateNo = oldOrder.CarPlateNo;
                newOrder.CarEngineNo = oldOrder.CarEngineNo;
                newOrder.CarVin = oldOrder.CarVin;
                newOrder.CarVechicheType = oldOrder.CarVechicheType;
                newOrder.CarRegisterDate = oldOrder.CarRegisterDate;
                newOrder.CarIssueDate = oldOrder.CarIssueDate;
                newOrder.CarPurchasePrice = oldOrder.CarPurchasePrice;
                newOrder.InsurePlanId = oldOrder.InsurePlanId;
                newOrder.CZ_CL_XSZ_ImgUrl = oldOrder.CZ_CL_XSZ_ImgUrl;
                newOrder.CZ_SFZ_ImgUrl = oldOrder.CZ_SFZ_ImgUrl;
                newOrder.YCZ_CLDJZ_ImgUrl = oldOrder.YCZ_CLDJZ_ImgUrl;
                newOrder.CCSJM_WSZM_ImgUrl = oldOrder.CCSJM_WSZM_ImgUrl;
                newOrder.ZJ1_ImgUrl = oldOrder.ZJ1_ImgUrl;
                newOrder.ZJ2_ImgUrl = oldOrder.ZJ2_ImgUrl;
                newOrder.ZJ3_ImgUrl = oldOrder.ZJ3_ImgUrl;
                newOrder.ZJ4_ImgUrl = oldOrder.ZJ4_ImgUrl;

                newOrder.Status = Enumeration.OrderStatus.Submitted;

                newOrder.SubmitTime = this.DateTime;
                newOrder.CreateTime = this.DateTime;
                newOrder.Creator = operater;
                newOrder.IsLastYearNewCar = oldOrder.IsLastYearNewCar;
                newOrder.IsSameLastYear = oldOrder.IsSameLastYear;
                newOrder.AutoCancelByHour = 24;
                CurrentDb.OrderToCarInsure.Add(newOrder);
                CurrentDb.SaveChanges();

                SnModel snModel = Sn.Build(SnType.OrderToCarInsure, newOrder.Id);

                newOrder.Sn = snModel.Sn;
                newOrder.TradeSnByWechat = snModel.TradeSnByWechat;
                newOrder.TradeSnByAlipay = snModel.TradeSnByAlipay;




                var oldOrderToCarInsureOfferCompany = CurrentDb.OrderToCarInsureOfferCompany.Where(m => m.OrderId == oldOrder.Id).ToList();
                if (oldOrderToCarInsureOfferCompany != null)
                {
                    foreach (var m in oldOrderToCarInsureOfferCompany)
                    {
                        var newOrderToCarInsureOfferCompany = new OrderToCarInsureOfferCompany();

                        newOrderToCarInsureOfferCompany.OrderId = newOrder.Id;
                        newOrderToCarInsureOfferCompany.InsuranceCompanyId = m.InsuranceCompanyId;
                        newOrderToCarInsureOfferCompany.InsuranceCompanyName = m.InsuranceCompanyName;
                        newOrderToCarInsureOfferCompany.CreateTime = this.DateTime;
                        newOrderToCarInsureOfferCompany.Creator = operater;
                        CurrentDb.OrderToCarInsureOfferCompany.Add(newOrderToCarInsureOfferCompany);
                    }
                }


                var oldKinds = CurrentDb.OrderToCarInsureOfferKind.Where(m => m.OrderId == oldOrder.Id).ToList();

                if (oldKinds != null)
                {
                    foreach (var m in oldKinds)
                    {
                        var newKinds = new OrderToCarInsureOfferKind();
                        newKinds.OrderId = newOrder.Id;
                        newKinds.KindId = m.KindId;
                        newKinds.KindValue = m.KindValue;
                        newKinds.KindDetails = m.KindDetails;
                        newKinds.IsWaiverDeductible = m.IsWaiverDeductible;
                        newKinds.CreateTime = this.DateTime;
                        newKinds.Creator = operater;
                        CurrentDb.OrderToCarInsureOfferKind.Add(newKinds);
                    }
                }

                BizProcessesAudit bizProcessesAudit = BizFactory.BizProcessesAudit.Add(operater, Enumeration.BizProcessesAuditType.OrderToCarInsure, newOrder.Id, Enumeration.CarInsureOfferDealtStatus.WaitOffer);

                BizFactory.BizProcessesAudit.ChangeAuditDetails(Enumeration.OperateType.Submit, Enumeration.CarInsureOfferDealtStep.Submit, bizProcessesAudit.Id, operater, newOrder.ClientRequire, "商户重新报价,等待报价", this.DateTime);

                CurrentDb.SaveChanges();
                ts.Complete();


                result = new CustomJsonResult(ResultType.Success, "重新报价");

            }

            return result;
        }
        public CustomJsonResult VerifyClaimOrder(int operater, Enumeration.OperateType operate, OrderToCarClaim orderToCarClaim, int estimateMerchantId, string estimateMerchantRemarks, BizProcessesAudit bizProcessesAudit)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {

                var l_bizProcessesAudit = CurrentDb.BizProcessesAudit.Where(m => m.Id == bizProcessesAudit.CurrentDetails.BizProcessesAuditId && (m.Status == (int)Enumeration.CarClaimDealtStatus.WaitVerifyOrder || m.Status == (int)Enumeration.CarClaimDealtStatus.InVerifyOrder)).FirstOrDefault();

                if (bizProcessesAudit == null)
                {
                    return new CustomJsonResult(ResultType.Success, "该订单已经处理完成");
                }

                if (bizProcessesAudit.Auditor != null)
                {
                    if (bizProcessesAudit.Auditor.Value != operater)
                    {
                        return new CustomJsonResult(ResultType.Failure, "该订单其他用户正在处理");
                    }
                }


                var l_orderToCarClaim = CurrentDb.OrderToCarClaim.Where(m => m.Id == orderToCarClaim.Id).FirstOrDefault();

                l_orderToCarClaim.HandMerchantId = estimateMerchantId;
                l_orderToCarClaim.HandMerchantType = Enumeration.HandMerchantType.Supply;

                l_orderToCarClaim.Remarks = orderToCarClaim.Remarks;

                bizProcessesAudit.CurrentDetails.AuditComments = orderToCarClaim.Remarks;

                switch (operate)
                {
                    case Enumeration.OperateType.Save:

                        result = new CustomJsonResult(ResultType.Success, "保存成功");

                        BizFactory.BizProcessesAudit.ChangeAuditDetails(operate, Enumeration.CarClaimDealtStep.VerifyOrder, bizProcessesAudit.CurrentDetails.BizProcessesAuditId, operater, bizProcessesAudit.CurrentDetails.AuditComments, null);

                        break;
                    case Enumeration.OperateType.Cancle:

                        l_orderToCarClaim.Status = Enumeration.OrderStatus.Cancled;
                        l_orderToCarClaim.CancleTime = this.DateTime;

                        BizFactory.BizProcessesAudit.ChangeAuditDetails(operate, Enumeration.CarClaimDealtStep.VerifyOrder, bizProcessesAudit.CurrentDetails.BizProcessesAuditId, operater, bizProcessesAudit.CurrentDetails.AuditComments, "后台人员撤销订单", this.DateTime);

                        BizFactory.BizProcessesAudit.ChangeCarInsureOfferDealtStatus(operater, bizProcessesAudit.CurrentDetails.BizProcessesAuditId, Enumeration.CarInsureOfferDealtStatus.StaffCancle);

                        result = new CustomJsonResult(ResultType.Success, "撤销成功");

                        break;
                    case Enumeration.OperateType.Submit:

                        l_orderToCarClaim.Status = Enumeration.OrderStatus.Follow;

                        l_orderToCarClaim.FollowStatus = (int)Enumeration.OrderToCarClaimFollowStatus.WaitEstimate;


                        var merchant = CurrentDb.Merchant.Where(m => m.Id == l_orderToCarClaim.HandMerchantId).FirstOrDefault();

                        var estimateOrderToCarClaim = new OrderToCarClaim();
                        estimateOrderToCarClaim.RepairsType = l_orderToCarClaim.RepairsType;
                        estimateOrderToCarClaim.SalesmanId = merchant.SalesmanId ?? 0;
                        estimateOrderToCarClaim.AgentId = merchant.AgentId ?? 0;
                        estimateOrderToCarClaim.MerchantId = merchant.Id;
                        estimateOrderToCarClaim.PosMachineId = l_orderToCarClaim.PosMachineId;
                        estimateOrderToCarClaim.UserId = merchant.UserId;
                        estimateOrderToCarClaim.HandPerson = l_orderToCarClaim.HandPerson;
                        estimateOrderToCarClaim.HandPersonPhone = l_orderToCarClaim.HandPersonPhone;
                        estimateOrderToCarClaim.InsuranceCompanyId = l_orderToCarClaim.InsuranceCompanyId;
                        estimateOrderToCarClaim.InsuranceCompanyName = l_orderToCarClaim.InsuranceCompanyName;
                        estimateOrderToCarClaim.CarPlateNo = l_orderToCarClaim.CarPlateNo;
                        estimateOrderToCarClaim.Status = Enumeration.OrderStatus.Follow;
                        estimateOrderToCarClaim.FollowStatus = (int)Enumeration.OrderToCarClaimFollowStatus.WaitUploadEstimateList;
                        estimateOrderToCarClaim.SubmitTime = this.DateTime;
                        estimateOrderToCarClaim.Creator = operater;
                        estimateOrderToCarClaim.CreateTime = this.DateTime;

                        estimateOrderToCarClaim.HandMerchantId = l_orderToCarClaim.MerchantId;
                        estimateOrderToCarClaim.HandMerchantType = Enumeration.HandMerchantType.Demand;


                        estimateOrderToCarClaim.Remarks = estimateMerchantRemarks;//告知维修厂备注


                        estimateOrderToCarClaim.Type = l_orderToCarClaim.Type;
                        estimateOrderToCarClaim.TypeName = l_orderToCarClaim.TypeName;
                        estimateOrderToCarClaim.PId = l_orderToCarClaim.Id;
                        estimateOrderToCarClaim.ClientRequire = l_orderToCarClaim.ClientRequire;


                        estimateOrderToCarClaim.HandOrderId = l_orderToCarClaim.Id;

                        CurrentDb.OrderToCarClaim.Add(estimateOrderToCarClaim);
                        CurrentDb.SaveChanges();

                        SnModel snModel = Sn.Build(SnType.OrderToCarClaim, estimateOrderToCarClaim.Id);

                        estimateOrderToCarClaim.Sn = snModel.Sn;
                        estimateOrderToCarClaim.TradeSnByWechat = snModel.TradeSnByWechat;
                        estimateOrderToCarClaim.TradeSnByAlipay = snModel.TradeSnByAlipay;



                        l_orderToCarClaim.HandOrderId = estimateOrderToCarClaim.Id;

                        BizFactory.BizProcessesAudit.ChangeAuditDetails(operate, Enumeration.CarClaimDealtStep.VerifyOrder, bizProcessesAudit.CurrentDetails.BizProcessesAuditId, operater, bizProcessesAudit.CurrentDetails.AuditComments, "后台人员派单完成", this.DateTime);

                        BizFactory.BizProcessesAudit.ChangeCarClaimDealtStatus(operater, bizProcessesAudit.CurrentDetails.BizProcessesAuditId, Enumeration.CarClaimDealtStatus.FllowUploadEstimateListImg, "等待商户上传定损单");

                        result = new CustomJsonResult(ResultType.Success, "提交成功");
                        break;

                }



                CurrentDb.SaveChanges();
                ts.Complete();
            }

            return result;

        }
        public CustomJsonResult SubmitCarInsure(int operater, OrderToCarInsure orderToCarInsure, List<OrderToCarInsureOfferCompany> orderToCarInsureOfferCompany, List<OrderToCarInsureOfferKind> orderToCarInsureOfferKind)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                OrderToCarInsure order = new OrderToCarInsure();

                //用户信息
                var clientUser = CurrentDb.SysClientUser.Where(m => m.Id == orderToCarInsure.UserId).FirstOrDefault();
                //商户信息
                var merchant = CurrentDb.Merchant.Where(m => m.Id == clientUser.MerchantId).FirstOrDefault();



                order.MerchantId = merchant.Id;
                order.PosMachineId = orderToCarInsure.PosMachineId;
                order.UserId = merchant.UserId;
                order.SalesmanId = merchant.SalesmanId ?? 0;
                order.AgentId = merchant.AgentId ?? 0;
                order.Type = Enumeration.OrderType.InsureForCarForInsure;
                order.TypeName = Enumeration.OrderType.InsureForCarForInsure.GetCnName();
                order.ClientRequire = orderToCarInsure.ClientRequire;
                order.InsuranceCompanyId = orderToCarInsure.InsuranceCompanyId;
                order.InsuranceCompanyName = orderToCarInsure.InsuranceCompanyName;
                order.CarOwner = orderToCarInsure.CarOwner;
                order.CarOwnerIdNumber = orderToCarInsure.CarOwnerIdNumber;
                order.CarOwnerAddress = orderToCarInsure.CarOwnerAddress;
                order.CarModel = orderToCarInsure.CarModel;
                order.CarOwner = orderToCarInsure.CarOwner;
                order.CarPlateNo = orderToCarInsure.CarPlateNo;
                order.CarEngineNo = orderToCarInsure.CarEngineNo;
                order.CarVin = orderToCarInsure.CarVin;
                order.CarVechicheType = orderToCarInsure.CarVechicheType;
                order.CarRegisterDate = orderToCarInsure.CarRegisterDate;
                order.CarIssueDate = orderToCarInsure.CarIssueDate;
                order.InsurePlanId = orderToCarInsure.InsurePlanId;
                order.CZ_CL_XSZ_ImgUrl = orderToCarInsure.CZ_CL_XSZ_ImgUrl;
                order.CZ_SFZ_ImgUrl = orderToCarInsure.CZ_SFZ_ImgUrl;
                order.YCZ_CLDJZ_ImgUrl = orderToCarInsure.YCZ_CLDJZ_ImgUrl;
                order.CCSJM_WSZM_ImgUrl = orderToCarInsure.CCSJM_WSZM_ImgUrl;
                order.Status = Enumeration.OrderStatus.Submitted;
                order.StartOfferTime = this.DateTime;
                order.SubmitTime = this.DateTime;
                order.CreateTime = this.DateTime;
                order.Creator = operater;
                order.IsLastYearNewCar = orderToCarInsure.IsLastYearNewCar;
                order.IsSameLastYear = orderToCarInsure.IsSameLastYear;
                order.AutoCancelByHour = 24;
                CurrentDb.OrderToCarInsure.Add(order);
                CurrentDb.SaveChanges();

                SnModel snModel = Sn.Build(SnType.OrderToCarInsure, order.Id);

                order.Sn = snModel.Sn;
                order.TradeSnByWechat = snModel.TradeSnByWechat;
                order.TradeSnByAlipay = snModel.TradeSnByAlipay;


                if (orderToCarInsureOfferCompany != null)
                {
                    foreach (var m in orderToCarInsureOfferCompany)
                    {
                        m.OrderId = order.Id;
                        m.CreateTime = this.DateTime;
                        m.Creator = operater;
                        CurrentDb.OrderToCarInsureOfferCompany.Add(m);
                    }
                }

                if (orderToCarInsureOfferKind != null)
                {
                    foreach (var m in orderToCarInsureOfferKind)
                    {
                        m.OrderId = order.Id;
                        m.CreateTime = this.DateTime;
                        m.Creator = operater;
                        CurrentDb.OrderToCarInsureOfferKind.Add(m);
                    }
                }


                BizProcessesAudit bizProcessesAudit = BizFactory.BizProcessesAudit.Add(operater, Enumeration.BizProcessesAuditType.OrderToCarInsure, order.Id, Enumeration.CarInsureOfferDealtStatus.WaitOffer);

                BizFactory.BizProcessesAudit.ChangeAuditDetails(Enumeration.OperateType.Submit, Enumeration.CarInsureOfferDealtStep.Submit, bizProcessesAudit.Id, operater, orderToCarInsure.ClientRequire, "商户提交投保订单,等待报价", this.DateTime);


                order.BizProcessesAuditId = bizProcessesAudit.Id;

                CurrentDb.SaveChanges();
                ts.Complete();


                result = new CustomJsonResult(ResultType.Success, "提交成功");
            }

            return result;
        }
        public CustomJsonResult Submit(int operater, bool isGetConfirmInfo, OrderToLllegalDealt orderToLllegalDealt, List <OrderToLllegalDealtDetails> orderToLllegalDealtDetails)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                var clientUser = CurrentDb.SysClientUser.Where(m => m.Id == orderToLllegalDealt.UserId).FirstOrDefault();
                var merchant   = CurrentDb.Merchant.Where(m => m.Id == clientUser.MerchantId).FirstOrDefault();


                orderToLllegalDealt.SalesmanId = merchant.SalesmanId ?? 0;
                orderToLllegalDealt.AgentId    = merchant.AgentId ?? 0;
                orderToLllegalDealt.Type       = Enumeration.OrderType.LllegalDealt;
                orderToLllegalDealt.TypeName   = Enumeration.OrderType.LllegalDealt.GetCnName();
                orderToLllegalDealt.SubmitTime = this.DateTime;
                orderToLllegalDealt.CreateTime = this.DateTime;
                orderToLllegalDealt.Creator    = operater;
                orderToLllegalDealt.SumCount   = orderToLllegalDealtDetails.Count();
                orderToLllegalDealt.SumFine    = orderToLllegalDealtDetails.Sum(m => m.Fine);
                orderToLllegalDealt.SumPoint   = orderToLllegalDealtDetails.Sum(m => m.Point);



                orderToLllegalDealt.SumServiceFees = orderToLllegalDealtDetails.Sum(m => m.ServiceFee);
                orderToLllegalDealt.SumLateFees    = orderToLllegalDealtDetails.Sum(m => m.Late_fees);
                orderToLllegalDealt.Price          = orderToLllegalDealt.SumFine + orderToLllegalDealt.SumServiceFees + orderToLllegalDealt.SumLateFees;
                CurrentDb.OrderToLllegalDealt.Add(orderToLllegalDealt);
                CurrentDb.SaveChanges();

                SnModel snModel = Sn.Build(SnType.OrderToLllegalQueryRecharge, orderToLllegalDealt.Id);

                orderToLllegalDealt.Sn = snModel.Sn;
                orderToLllegalDealt.TradeSnByWechat = snModel.TradeSnByWechat;
                orderToLllegalDealt.TradeSnByAlipay = snModel.TradeSnByAlipay;
                CurrentDb.SaveChanges();


                foreach (var item in orderToLllegalDealtDetails)
                {
                    item.OrderId    = orderToLllegalDealt.Id;
                    item.Status     = Enumeration.OrderToLllegalDealtDetailsStatus.WaitPay;
                    item.CreateTime = this.DateTime;
                    item.Creator    = operater;

                    CurrentDb.OrderToLllegalDealtDetails.Add(item);
                    CurrentDb.SaveChanges();
                }



                OrderConfirmInfo yOrder = new OrderConfirmInfo();
                var bizProcessesAudit   = BizFactory.BizProcessesAudit.Add(operater, Enumeration.BizProcessesAuditType.OrderToLllegalDealt, orderToLllegalDealt.Id, Enumeration.AuditFlowV1Status.Submit);
                if (isGetConfirmInfo)
                {
                    orderToLllegalDealt.Status = Enumeration.OrderStatus.WaitPay;

                    yOrder.OrderId       = orderToLllegalDealt.Id;
                    yOrder.OrderSn       = orderToLllegalDealt.Sn;
                    yOrder.remarks       = orderToLllegalDealt.Remarks;
                    yOrder.orderType     = orderToLllegalDealt.Type;
                    yOrder.orderTypeName = orderToLllegalDealt.TypeName;



                    //yOrder.confirmField.Add(new Entity.AppApi.OrderField("订单编号", orderToLllegalDealt.Sn.NullToEmpty()));
                    yOrder.confirmField.Add(new Entity.AppApi.OrderField("车牌号码", orderToLllegalDealt.CarNo.NullToEmpty()));
                    yOrder.confirmField.Add(new Entity.AppApi.OrderField("违章", string.Format("{0}次", orderToLllegalDealt.SumCount)));
                    yOrder.confirmField.Add(new Entity.AppApi.OrderField("扣分", orderToLllegalDealt.SumPoint.NullToEmpty()));
                    yOrder.confirmField.Add(new Entity.AppApi.OrderField("罚款", orderToLllegalDealt.SumFine.NullToEmpty()));
                    yOrder.confirmField.Add(new Entity.AppApi.OrderField("支付金额", string.Format("{0}元", orderToLllegalDealt.Price.NullToEmpty())));


                    #region 支持的支付方式
                    int[] payMethods = new int[1] {
                        1
                    };

                    foreach (var payWayId in payMethods)
                    {
                        var payWay = new PayWay();
                        payWay.id = payWayId;
                        yOrder.payMethod.Add(payWay);
                    }
                    #endregion

                    BizFactory.BizProcessesAudit.ChangeStatusByAuditFlowV1(bizProcessesAudit.Id, Enumeration.AuditFlowV1Status.waitGoDealt, operater, null, "提交订单,等待支付");
                }
                else
                {
                    orderToLllegalDealt.Status = Enumeration.OrderStatus.Submitted;
                    BizFactory.BizProcessesAudit.ChangeStatusByAuditFlowV1(bizProcessesAudit.Id, Enumeration.AuditFlowV1Status.Submit, operater, null, "提交订单,等待取单");
                }

                orderToLllegalDealt.BizProcessesAuditId = bizProcessesAudit.Id;


                CurrentDb.SaveChanges();

                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "提交成功", yOrder);
            }


            return(result);
        }
        public CustomJsonResult CreateAccount(int operater, string token, string validCode, string userName, string password, string deviceId)
        {
            CustomJsonResult result = new CustomJsonResult();

            using (TransactionScope ts = new TransactionScope())
            {
                var code = CurrentDb.SysSmsSendHistory.Where(m => m.Token == token && m.ValidCode == validCode && m.IsUse == false && m.ExpireTime >= DateTime.Now).FirstOrDefault();
                if (code == null)
                {
                    return(new CustomJsonResult(ResultType.Failure, "验证码错误"));
                }

                code.IsUse = true;

                var isExists = CurrentDb.SysUser.Where(m => m.UserName == userName).FirstOrDefault();

                if (isExists != null)
                {
                    return(new CustomJsonResult(ResultType.Failure, "账号已经存在"));
                }

                var sysClientUser = new SysClientUser();
                sysClientUser.UserName          = userName;
                sysClientUser.PhoneNumber       = userName;
                sysClientUser.PasswordHash      = PassWordHelper.HashPassword(password);
                sysClientUser.SecurityStamp     = Guid.NewGuid().ToString();
                sysClientUser.RegisterTime      = this.DateTime;
                sysClientUser.CreateTime        = this.DateTime;
                sysClientUser.Creator           = operater;
                sysClientUser.ClientAccountType = Enumeration.ClientAccountType.MasterAccount;
                sysClientUser.Status            = Enumeration.UserStatus.Normal;
                sysClientUser.Type = Enumeration.UserType.Client;

                CurrentDb.SysClientUser.Add(sysClientUser);
                CurrentDb.SaveChanges();

                var clientCode = CurrentDb.SysClientCode.Where(m => m.Id == sysClientUser.Id).FirstOrDefault();

                var merchant = new Merchant();
                merchant.ClientCode = clientCode.Code;
                merchant.UserId     = sysClientUser.Id;
                merchant.CreateTime = this.DateTime;
                merchant.Creator    = operater;
                merchant.Status     = Enumeration.MerchantStatus.WaitFill;
                CurrentDb.Merchant.Add(merchant);
                CurrentDb.SaveChanges();

                sysClientUser.ClientCode = clientCode.Code;
                sysClientUser.MerchantId = merchant.Id;

                var posMachine = CurrentDb.PosMachine.Where(m => m.DeviceId == deviceId).FirstOrDefault();

                if (posMachine == null)
                {
                    return(new CustomJsonResult(ResultType.Failure, "POS机未登记,请联系客服"));

                    //posMachine = new PosMachine();
                    //posMachine.DeviceId = deviceId;
                    //posMachine.Creator = operater;
                    //posMachine.CreateTime = this.DateTime;
                    //CurrentDb.PosMachine.Add(posMachine);
                    //CurrentDb.SaveChanges();
                }
                else
                {
                    if (posMachine.IsUse)
                    {
                        return(new CustomJsonResult(ResultType.Failure, "POS机已被注册"));
                    }

                    if (posMachine.SalesmanId == null)
                    {
                        return(new CustomJsonResult(ResultType.Failure, "POS机未出库,请联系客服"));
                    }

                    posMachine.IsUse          = false;
                    posMachine.Mender         = operater;
                    posMachine.LastUpdateTime = this.DateTime;
                    CurrentDb.SaveChanges();
                }

                var bankCard = new BankCard();
                bankCard.MerchantId = merchant.Id;
                bankCard.UserId     = merchant.UserId;
                bankCard.CreateTime = this.DateTime;
                bankCard.Creator    = operater;
                CurrentDb.BankCard.Add(bankCard);
                CurrentDb.SaveChanges();

                CalculateServiceFee calculateServiceFee = new CalculateServiceFee();

                var merchantPosMachine = new MerchantPosMachine();
                merchantPosMachine.BankCardId       = bankCard.Id;
                merchantPosMachine.UserId           = sysClientUser.Id;
                merchantPosMachine.MerchantId       = merchant.Id;
                merchantPosMachine.PosMachineId     = posMachine.Id;
                merchantPosMachine.Deposit          = calculateServiceFee.Deposit;
                merchantPosMachine.MobileTrafficFee = calculateServiceFee.MobileTrafficFee;
                merchantPosMachine.Status           = Enumeration.MerchantPosMachineStatus.NoActive;
                merchantPosMachine.CreateTime       = this.DateTime;
                merchantPosMachine.Creator          = operater;
                CurrentDb.MerchantPosMachine.Add(merchantPosMachine);
                CurrentDb.SaveChanges();

                var orderToServiceFee = new OrderToServiceFee();
                orderToServiceFee.MerchantId       = merchant.Id;
                orderToServiceFee.PosMachineId     = posMachine.Id;
                orderToServiceFee.UserId           = sysClientUser.Id;
                orderToServiceFee.SubmitTime       = this.DateTime;
                orderToServiceFee.Type             = Enumeration.OrderType.PosMachineServiceFee;
                orderToServiceFee.TypeName         = Enumeration.OrderType.PosMachineServiceFee.GetCnName();
                orderToServiceFee.Deposit          = calculateServiceFee.Deposit;
                orderToServiceFee.MobileTrafficFee = calculateServiceFee.MobileTrafficFee;
                orderToServiceFee.PriceVersion     = calculateServiceFee.Version;
                orderToServiceFee.Price            = calculateServiceFee.Deposit + calculateServiceFee.MobileTrafficFee;
                orderToServiceFee.Status           = Enumeration.OrderStatus.WaitPay;
                orderToServiceFee.CreateTime       = this.DateTime;
                orderToServiceFee.Creator          = operater;
                CurrentDb.OrderToServiceFee.Add(orderToServiceFee);
                CurrentDb.SaveChanges();

                SnModel snModel = Sn.Build(SnType.OrderToServiceFee, orderToServiceFee.Id);
                orderToServiceFee.Sn = snModel.Sn;
                orderToServiceFee.TradeSnByWechat = snModel.TradeSnByWechat;
                orderToServiceFee.TradeSnByAlipay = snModel.TradeSnByAlipay;



                var sysItemCacheUpdateTime = new SysItemCacheUpdateTime();

                sysItemCacheUpdateTime.Name           = sysClientUser.UserName;
                sysItemCacheUpdateTime.Type           = Enumeration.SysItemCacheType.User;
                sysItemCacheUpdateTime.ReferenceId    = sysClientUser.Id;
                sysItemCacheUpdateTime.Creator        = operater;
                sysItemCacheUpdateTime.CreateTime     = this.DateTime;
                sysItemCacheUpdateTime.Mender         = operater;
                sysItemCacheUpdateTime.LastUpdateTime = this.DateTime;

                CurrentDb.SysItemCacheUpdateTime.Add(sysItemCacheUpdateTime);
                CurrentDb.SaveChanges();


                var fund = new Fund();

                fund.UserId     = sysClientUser.Id;
                fund.MerchantId = merchant.Id;
                fund.Balance    = 0;
                fund.Creator    = operater;
                fund.CreateTime = this.DateTime;
                CurrentDb.Fund.Add(fund);
                CurrentDb.SaveChanges();


                var lllegalQueryScore = new LllegalQueryScore();
                lllegalQueryScore.UserId     = sysClientUser.Id;
                lllegalQueryScore.MerchantId = merchant.Id;
                lllegalQueryScore.Score      = 50;
                lllegalQueryScore.Creator    = operater;
                lllegalQueryScore.CreateTime = this.DateTime;
                CurrentDb.LllegalQueryScore.Add(lllegalQueryScore);
                CurrentDb.SaveChanges();


                var lllegalQueryScoreTrans = new LllegalQueryScoreTrans();
                lllegalQueryScoreTrans.UserId      = sysClientUser.Id;
                lllegalQueryScoreTrans.ChangeScore = lllegalQueryScore.Score;
                lllegalQueryScoreTrans.Score       = lllegalQueryScore.Score;
                lllegalQueryScoreTrans.Type        = Enumeration.LllegalQueryScoreTransType.IncreaseByInit;
                lllegalQueryScoreTrans.Description = string.Format("初始违章查询积分:{0}", lllegalQueryScore.Score);
                lllegalQueryScoreTrans.Creator     = operater;
                lllegalQueryScoreTrans.CreateTime  = this.DateTime;
                CurrentDb.LllegalQueryScoreTrans.Add(lllegalQueryScoreTrans);
                CurrentDb.SaveChanges();
                lllegalQueryScoreTrans.Sn = Sn.Build(SnType.LllegalQueryScoreTrans, lllegalQueryScoreTrans.Id).Sn;
                CurrentDb.SaveChanges();


                ts.Complete();

                result = new CustomJsonResult(ResultType.Success, "注册成功");
            }

            return(result);
        }