コード例 #1
0
ファイル: CustomerService.cs プロジェクト: iJzFan/backup
        /// <summary>
        /// 添加一个用户
        /// </summary>
        /// <param name="cus"></param>
        /// <param name="health"></param>
        /// <returns></returns>
        public async Task <CHIS_Code_Customer> CreateCustomerAsync(CHIS_Code_Customer cus, CHIS_Code_Customer_HealthInfo health = null, int opId = 0, string opMan = "")
        {
            _db.BeginTransaction();
            try
            {
                cus.CustomerCreateDate = cus.sysLatestActiveTime = cus.OpTime = DateTime.Now;
                cus.IsVIP              = cus.IsVIP == true;
                cus.NamePY             = Ass.Data.Chinese2Spell.GetFstAndFullLettersLower(cus.CustomerName);
                cus.OpID               = opId;
                cus.CustomerCreateDate = cus.OpTime = cus.sysLatestActiveTime = DateTime.Now;
                cus.OpMan              = opMan;

                cus = _db.CHIS_Code_Customer.Add(cus).Entity;
                await _db.SaveChangesAsync();

                if (health == null)
                {
                    health = new CHIS_Code_Customer_HealthInfo();
                }
                health.CustomerId = cus.CustomerID;
                await _db.CHIS_Code_Customer_HealthInfo.AddAsync(health);

                await _db.SaveChangesAsync();

                var login = _db.CHIS_Sys_Login.FirstOrDefault(m => m.CustomerId == cus.CustomerID);
                if (login == null)
                {
                    await _db.CHIS_Sys_Login.AddAsync(new CHIS_Sys_Login
                    {
                        CustomerId    = cus.CustomerID,
                        Email         = cus.Email,
                        Mobile        = cus.CustomerMobile,
                        IdCardNumber  = cus.IDcard,
                        LoginName     = cus.LoginName,
                        LoginPassword = "******",
                        IsLock        = false
                    });

                    await _db.SaveChangesAsync();
                }
                _db.CommitTran();
                //注册用户赠送
                _pointsService.ChangePoints(new Models.InputModel.PointsDetailInputModel
                {
                    CustomerId  = cus.CustomerID,
                    Description = "注册赠送1000分",
                    Points      = 1000
                });
            }
            catch (Exception ex) { _db.RollbackTran(); throw ex; }
            return(cus);
        }
コード例 #2
0
ファイル: ChangePayService.cs プロジェクト: iJzFan/backup
        //更新到收款表
        private async Task <bool> UpdatePayAsync(CHIS_Charge_PayPre payPre, int opId, string opMan)
        {
            if (payPre.PayStatus == 0)
            {
                throw new Exception("该笔支付订单没有支付成功,请确认。");
            }
            var db = _db;

            db.BeginTransaction();
            try
            {
                var formed = db.CHIS_Charge_PayPre_Detail_Formed.AsNoTracking().Where(m => m.PayPreID == payPre.Id).ToList();   //成药
                var herb   = db.CHIS_Charge_PayPre_Detail_Herb.AsNoTracking().Where(m => m.PayPreID == payPre.Id).ToList();     //中药
                var extras = db.CHIS_Charge_PayPre_Detail_ExtraFee.AsNoTracking().Where(m => m.PayPreId == payPre.Id).ToList(); //附加费

                var find = db.CHIS_Charge_Pay.AsNoTracking().Where(m => m.PayOrderId == payPre.PayOrderId);
                if (find.Count() > 0)
                {
                    throw new PayException(PayExceptionType.PayedFinishAndSuccess, "该支付订单已经存在,已经支付,无需重复。");
                }
                //添加主表
                #region 添加主表

                var debuglog = _env.IsDevelopment() ? "[测试]" : "";

                var pay = (await db.CHIS_Charge_Pay.AddAsync(new CHIS_Charge_Pay
                {
                    TotalAmount = payPre.TotalAmount,
                    TreatId = payPre.treatId,
                    FeeTypeCode = payPre.FeeTypeCode,
                    PayedTime = payPre.PayedSuccessTime ?? DateTime.Now,
                    PayOrderId = payPre.PayOrderId,
                    StationId = payPre.StationId,
                    PayRemark = payPre.PayRemark + debuglog,
                    sysOpId = opId,
                    sysOpMan = opMan,
                    sysOpTime = DateTime.Now
                })).Entity;
                await db.SaveChangesAsync();

                #endregion


                //添加从表
                #region 添加一般从表
                //------------- 成药 ------------------------------
                foreach (var mm in formed)
                {
                    await db.CHIS_Charge_Pay_Detail_Formed.AddAsync(new CHIS_Charge_Pay_Detail_Formed
                    {
                        Amount         = mm.Amount,
                        PrescriptionNo = mm.PrescriptionNo,
                        TreatId        = mm.TreatId,
                        UnitId         = mm.UnitID,
                        Quantity       = mm.Quantity,
                        Price          = mm.Price,
                        PayId          = pay.PayId,
                        DoctorAdviceId = mm.DoctorAdviceId
                    });

                    //更新医嘱缴费状态
                    var ma = db.CHIS_DoctorAdvice_Formed.FirstOrDefault(m => m.PrescriptionNo == mm.PrescriptionNo);
                    if (ma == null)
                    {
                        throw new Exception("没有发现医嘱信息");
                    }
                    ma.ChargeStatus = (short)ChargeStatus.Payed;//设置为已经缴费
                }

                // ------------ 中药 -------------------------------
                foreach (var mm in herb)
                {
                    await db.CHIS_Charge_Pay_Detail_Herb.AddAsync(new CHIS_Charge_Pay_Detail_Herb
                    {
                        Amount         = mm.Amount,
                        PrescriptionNo = mm.PrescriptionNo,
                        TreatId        = mm.TreatId,
                        UnitID         = mm.UnitID,
                        Quantity       = mm.Quantity,
                        Price          = mm.Price,
                        PayId          = pay.PayId,
                        PayOrderId     = pay.PayOrderId,
                        DoctorAdviceId = mm.DoctorAdviceId
                    });

                    //更新医嘱缴费状态
                    var ma = db.CHIS_DoctorAdvice_Herbs.FirstOrDefault(m => m.PrescriptionNo == mm.PrescriptionNo);
                    if (ma == null)
                    {
                        throw new Exception("没有发现医嘱信息");
                    }
                    ma.ChargeStatus = (short)ChargeStatus.Payed;//设置为已经缴费
                }

                #endregion

                #region 添加附加费从表
                foreach (var mm in extras)
                {
                    await db.CHIS_Charge_Pay_Detail_ExtraFee.AddAsync(new CHIS_Charge_Pay_Detail_ExtraFee
                    {
                        DoctorExtraFeeId = mm.DoctorExtraFeeId,
                        ExtraFeeAmount   = mm.ExtraFeeAmount,
                        ExtraFeeTypeId   = mm.ExtraFeeTypeId,
                        PayId            = pay.PayId
                    });
                }
                await db.SaveChangesAsync();

                #endregion

                var treat = _treatSvr.FindTreat(pay.TreatId);
                treat.NeedPayAmount = 0;
                await db.SaveChangesAsync();

                db.CommitTran();

                //操作成功则赠送积分信息
                if (payPre.FeeTypeCode == FeeTypes.AliPay_QR ||
                    payPre.FeeTypeCode == FeeTypes.WeChat_H5 ||
                    payPre.FeeTypeCode == FeeTypes.WeChat_Pub ||
                    payPre.FeeTypeCode == FeeTypes.WeChat_QR)
                {
                    _pointsService.ChangePoints(new Models.InputModel.PointsDetailInputModel
                    {
                        CustomerId  = treat.CustomerId,
                        Description = FeeTypes.ToName(payPre.FeeTypeCode) + $"支付赠送(消费{pay.TotalAmount})",
                        Points      = (int)(payPre.TotalAmount * 100)
                    });
                }

                _logger.WriteSUCCESS($"订单支付更新数据成功:{payPre.PayOrderId}", opId, opMan);
            }
            catch (Exception ex)
            {
                db.RollbackTran();
                _logger.WriteError(ex, opId, opMan);
                throw ex;
            }
            return(true);
        }