Ejemplo n.º 1
0
        /// <summary>
        /// 更新预支付数据
        /// </summary>
        /// <param name="payOrderId"></param>
        /// <param name="payStatus"></param>
        /// <param name="payTime"></param>
        /// <returns></returns>
        private async Task <CHIS_Charge_PayPre> UpdatePayPreAsync(string payOrderId, string feeTypeCode, string payRmk = null, bool isCash = false, int payStatus = 1, DateTime?payTime = null, CHISEntitiesSqlServer db = null)
        {
            db = db ?? _db;
            if (payOrderId.IsEmpty())
            {
                throw new Exception("更新付款信息没有传入付款单号。");
            }
            if (!FeeTypes.IsValidFeeType(feeTypeCode))
            {
                throw new Exception("传入费用类型错误");
            }
            var finds = db.CHIS_Charge_PayPre.AsNoTracking().Where(u => u.PayOrderId == payOrderId);
            var count = finds.Count();

            if (count == 0)
            {
                throw new Exception("没有找到预付款信息数据");
            }
            if (count > 1)
            {
                throw new Exception("发现多个数据");
            }
            if (payTime == null)
            {
                payTime = DateTime.Now;
            }
            var m = finds.FirstOrDefault();

            if (m == null)
            {
                throw new Exception($"没有找到单号({payOrderId})的预付款信息。");
            }
            if (isCash)
            {
                if (!m.IsAllowedCashPay)
                {
                    throw new Exception("该订单不允许现金支付!");
                }
            }
            m.FeeTypeCode      = feeTypeCode;
            m.PayStatus        = payStatus;
            m.PayedSuccessTime = payTime;
            m.PayRemark        = m.PayRemark + payRmk;
            db.Update(m);
            await db.SaveChangesAsync();

            return(m);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新Paypere和更新Pay 并写入日志
        /// </summary>
        /// <param name="payOrderId"></param>
        public async Task UpdatePayedAsync(string payOrderId, string feeTypeCode, string payRmk, bool isCash, int opId, string opMan)
        {
            _db.BeginTransaction();
            try
            {
                if (!FeeTypes.IsValidFeeType(feeTypeCode))
                {
                    throw new Exception("传入费用类型错误");
                }
                if (_db.CHIS_Charge_Pay.Where(m => m.PayOrderId == payOrderId).Count() > 0)
                {
                    throw new SuccessedException("该订单已经支付过了");
                }
                var paypre = await UpdatePayPreAsync(payOrderId, feeTypeCode, payRmk, isCash, db : _db);

                if (paypre.PayStatus == 1)
                {
                    await UpdatePayAsync(paypre, opId, opMan);

                    await _logger.WriteSUCCESSAsync("ChargePayService", "UpdatePayed", "支付成功:" + payOrderId, opId, opMan, payOrderId);
                }
                _db.CommitTran();
            }
            catch (Exception ex)
            {
                _db.RollbackTran();

                //如果是历史成功了,则直接抛出历史成功错误
                if (ex is SuccessedException)
                {
                    throw ex;
                }
                //否则记录错误
                await _logger.WriteErrorAsync("ChargePayService", "UpdatePayed", ex, opId, opMan);

                throw ex;
            }
        }