Пример #1
0
        /// <summary>
        /// 处理冻结余额为已完成或作废
        /// </summary>
        /// <param name="transType">交易类型</param>
        /// <param name="orderId">订单ID/业务ID</param>
        /// <param name="toFrozeStatus">处理成作废或者完成</param>
        private TblCashWalletForzenDetail ProcessFrozeBalanceComplete(OrderTradeType transType, long orderId, BalanceFrozeStatus toFrozeStatus)
        {
            //1、根据处理后的状态来获取应要查询的状态

            TblCashWalletForzenDetail detail = _forzenRepository.Value.GetByBusinessId(this._schoolId, (int)transType, orderId, (int)BalanceFrozeStatus.Process);

            //2、钱包余额冻结金额完成
            TblCashWallet tblCashWallet = this.TblCashWallet;

            tblCashWallet.FrozenAmount = 0;
            tblCashWallet.UpdateTime   = DateTime.Now;
            //防止数据重复操作
            if (detail != null && toFrozeStatus == BalanceFrozeStatus.Cancel)
            {
                //如果取消,应将余额还回去
                tblCashWallet.Balance += detail.Amount * (-1);
            }

            //3、冻结明细记录处理
            //如果存在冻结明细,则记录冻结记录已完成
            if (detail != null)
            {
                detail.Status = (int)toFrozeStatus;
                _forzenRepository.Value.Update(detail);      //写入冻结明细
            }
            //4、钱包余额
            _repository.Value.Update(tblCashWallet);  //更新用户钱包余额
            return(detail);
        }
Пример #2
0
        /// <summary>
        /// 冻结交易取消
        /// </summary>
        /// <param name="sourceTradeType">原始订单交易类型</param>
        /// <param name="targetTradeType">目标订单交易类型</param>
        /// <param name="orderId"></param>
        internal void TradeFrozeCancel(OrderTradeType sourceTradeType, OrderTradeType targetTradeType, long orderId, string remark)
        {
            lock (LocalThreadLock.GetLockKeyName(LockKeyNames.LOCK_WALLET, this._studentId.ToString()))
            {
                TblCashWalletForzenDetail detail = this.ProcessFrozeBalanceComplete(sourceTradeType, orderId, BalanceFrozeStatus.Cancel);

                decimal transAmount = detail.Amount * (-1);

                //2、增加交易记录
                TblCashWallet tblCashWallet   = this.TblCashWallet;
                decimal       transBefBalance = tblCashWallet.Balance + transAmount; //交易前余额,同下
                decimal       transAftBalance = tblCashWallet.Balance;               //交易后余额,冻结交易,余额早已扣除,所以该余额即交易后余额
                //余额交易明细
                TblCashWalletTrade walletTrade = new TblCashWalletTrade()
                {
                    WalletTradeId   = IdGenerator.NextId(),
                    OrderId         = orderId,
                    StudentId       = this._studentId,
                    SchoolId        = this._schoolId,
                    TradeType       = (int)targetTradeType,
                    TransBefBalance = transBefBalance,
                    TransAftBalance = transAftBalance,
                    TransAmount     = transAmount,
                    TransDate       = DateTime.Now,
                    Remark          = remark
                };
                //写入数据
                _walletTradeRepository.Value.Add(walletTrade);
            }
        }
 /// <summary>
 /// 订单作废之后,对已核对/问题的收款交接进行删除
 /// <para>作    者:郭伟佳</para>
 /// <para>创建时间:2018-12-19</para>
 /// </summary>
 /// <param name="orderId">订单Id</param>
 /// <param name="tradeType">订单类型</param>
 /// <param name="unitOfWork">工作单元</param>
 public void DeleteHandleOver(long orderId, OrderTradeType tradeType, UnitOfWork unitOfWork = null)
 {
     if (unitOfWork != null)
     {
         _detailRepository = new Lazy <TblFinOrderHandoverDetailRepository>(() => { return(unitOfWork.GetCustomRepository <TblFinOrderHandoverDetailRepository, TblFinOrderHandoverDetail>()); });
     }
     _detailRepository.Value.DeleteDetailByOrderId(this._schoolId, orderId, tradeType);
 }
Пример #4
0
 /// <summary>
 /// 冻结交易成功
 /// </summary>
 /// <param name="transType"></param>
 /// <param name="orderId"></param>
 internal void TradeFrozeComplete(OrderTradeType transType, long orderId)
 {
     lock (LocalThreadLock.GetLockKeyName(LockKeyNames.LOCK_WALLET, this._studentId.ToString()))
     {
         //1、处理冻结余额数据
         TblCashWalletForzenDetail detail = ProcessFrozeBalanceComplete(transType, orderId, BalanceFrozeStatus.Finish);
     }
 }
Пример #5
0
        /// <summary>
        /// 钱包交易金额冻结
        /// </summary>
        /// <param name="transType"></param>
        /// <param name="transAmount"></param>
        /// <param name="unitOfWork">事务工作单元</param>
        internal void TradeFroze(OrderTradeType transType, long orderId, decimal transAmount, string remark)
        {
            if (transAmount == 0)
            {
                return;
            }
            //TODO 以后应用分布式锁
            lock (LocalThreadLock.GetLockKeyName(LockKeyNames.LOCK_WALLET, this._studentId.ToString()))
            {
                //1、钱包余额冻结金额
                TblCashWallet tblCashWallet   = this.TblCashWallet;
                decimal       transBefBalance = tblCashWallet.Balance;               //交易前余额
                decimal       transAftBalance = tblCashWallet.Balance + transAmount; //交易后余额
                tblCashWallet.Balance      = transAftBalance;
                tblCashWallet.FrozenAmount = transAmount;
                tblCashWallet.UpdateTime   = DateTime.Now;

                //2、冻结明细记录
                TblCashWalletForzenDetail detail = new TblCashWalletForzenDetail()
                {
                    BusinessId           = orderId,
                    BusinessType         = (int)transType,
                    SchoolId             = this._schoolId,
                    Status               = 1,
                    Amount               = transAmount,
                    StudentId            = this._studentId,
                    WalletForzenDetailId = IdGenerator.NextId(),
                    CreateTime           = DateTime.Now
                };

                //3、余额交易明细
                TblCashWalletTrade walletTrade = new TblCashWalletTrade()
                {
                    WalletTradeId   = IdGenerator.NextId(),
                    OrderId         = orderId,
                    StudentId       = this._studentId,
                    SchoolId        = this._schoolId,
                    TradeType       = (int)transType,
                    TransBefBalance = transBefBalance,
                    TransAftBalance = transAftBalance,
                    TransAmount     = transAmount,
                    TransDate       = DateTime.Now,
                    Remark          = remark
                };

                //4、写入数据

                _walletTradeRepository.Value.Add(walletTrade);
                _repository.Value.Update(tblCashWallet);  //更新用户钱包余额
                _forzenRepository.Value.Add(detail);      //写入冻结明细
            }
        }
Пример #6
0
        /// <summary>
        /// 余额交易
        /// 余额交易分两种
        /// </summary>
        /// <param name="transType">交易类型</param>
        /// <param name="transAmount">交易的金额</param>
        public void Trade(OrderTradeType transType, long orderId, decimal transAmount, string remark)
        {
            if (transAmount == 0)
            {
                return;
            }

            //TODO 以后应用分布式锁
            lock (LocalThreadLock.GetLockKeyName(LockKeyNames.LOCK_WALLET, this._studentId.ToString()))
            {
                //钱包汇总
                TblCashWallet tblCashWallet   = this.TblCashWallet;
                decimal       transBefBalance = tblCashWallet.Balance;               //交易前余额
                decimal       transAftBalance = tblCashWallet.Balance + transAmount; //交易后余额
                tblCashWallet.Balance    = transAftBalance;
                tblCashWallet.UpdateTime = DateTime.Now;


                //余额交易明细
                TblCashWalletTrade walletTrade = new TblCashWalletTrade()
                {
                    WalletTradeId   = IdGenerator.NextId(),
                    OrderId         = orderId,
                    StudentId       = this._studentId,
                    SchoolId        = this._schoolId,
                    TradeType       = (int)transType,
                    TransBefBalance = transBefBalance,
                    TransAftBalance = transAftBalance,
                    TransAmount     = transAmount,
                    TransDate       = DateTime.Now,
                    Remark          = remark
                };
                //写入数据
                _walletTradeRepository.Value.Add(walletTrade);
                _repository.Value.Update(tblCashWallet);
            }
        }
 /// <summary>
 /// 根据订单编号获取收款交接详情
 /// 作     者:Huang GaoLiang 2018年11月23日
 /// </summary>
 /// <param name="orderId">订单编号</param>
 /// <param name="orderType">订单类型</param>
 /// <returns>收款交接明细信息</returns>
 public TblFinOrderHandoverDetail GetDetailById(long orderId, OrderTradeType orderType)
 {
     return(Load(m => m.OrderId == orderId && m.OrderTradeType == (int)orderType));
 }
 /// <summary>
 /// 删除对应的收款交接明细
 /// <para>作    者:郭伟佳</para>
 /// <para>创建时间:2018-12-20</para>
 /// </summary>
 /// <param name="schoolId">校区Id</param>
 /// <param name="orderId">收款交接明细对象</param>
 /// <param name="tradeType">收款交接明细对象</param>
 public void DeleteDetailByOrderId(string schoolId, long orderId, OrderTradeType tradeType)
 {
     this.Delete(a => a.SchoolId == schoolId && a.OrderId == orderId && a.OrderTradeType == (int)tradeType);
 }
Пример #9
0
 /// <summary>
 /// 交易类型-tradeType代表取消类型
 /// caiyakang 2018-10-06
 /// </summary>
 /// <param name="tradeType"></param>
 /// <returns></returns>
 protected OrderTradeType GetCancelTradeType(OrderTradeType tradeType)
 {
     return((OrderTradeType)(Convert.ToInt32(tradeType) * -1));
 }
        /// <summary>
        /// 根据订单编号获取已交接的订单明细
        /// <para>作     者:Huang GaoLiang </para>
        /// <para>创建时间:2018-11-16</para>
        /// </summary>
        /// <param name="orderId">订单编号</param>
        /// <param name="orderType">订单类型</param>
        /// <returns>返回已交接的订单明细</returns>
        internal FinOrderHandoverResponse GetFinOrderHandoverDetailByOrderId(long orderId, OrderTradeType orderType)
        {
            FinOrderHandoverResponse finOrderHandover = new FinOrderHandoverResponse();

            // 1、获取已交接的收款详情信息
            TblFinOrderHandoverDetail d = _detailRepository.Value.GetDetailById(orderId, orderType);

            if (d != null && d.HandoverStatus == (int)HandoverStatus.Handover)
            {
                //2、附件
                List <TblDatAttchment> urls = _datAttchmentRepository.Value.LoadList(m => m.SchoolId == _schoolId).OrderBy(m => m.CreateTime).ToList();
                finOrderHandover.OrderHandoverId = d.OrderHandoverDetailId;
                finOrderHandover.CreateTime      = d.CreateTime;
                finOrderHandover.PayDate         = d.PayDate;
                finOrderHandover.CreatorName     = d.CreatorName;
                finOrderHandover.HandoverDate    = d.HandoverDate;
                finOrderHandover.Url             = urls.Where(y => y.BusinessId == d.OrderHandoverDetailId).Select(z => z.Url).ToList();
                return(finOrderHandover);
            }
            return(finOrderHandover);
        }
Пример #11
0
        protected readonly Lazy <TblFinOrderHandoverDetailRepository> _detailRepository = new Lazy <TblFinOrderHandoverDetailRepository>();           //订单交接核对明细仓储

        /// <summary>
        /// 获取已核对的未交接的订单信息
        /// <para>作    者:郭伟佳</para>
        /// <para>创建时间:2018-12-28</para>
        /// </summary>
        /// <param name="handoverDetails">收款交接明细</param>
        /// <param name="tradeType">订单类型</param>
        /// <returns>订单类型的交接核对信息</returns>
        protected virtual OrderHandoverTradeResponse GetOrderHandoverTrade(IEnumerable <TblFinOrderHandoverDetail> handoverDetails, OrderTradeType tradeType)
        {
            //获取招生专员对应已核对的未交接的定金订单信息
            var handoverTradeSummary = handoverDetails.Where(a => a.OrderTradeType == (int)tradeType);

            if (handoverTradeSummary != null && handoverTradeSummary.Any())
            {
                //无现金支付(刷卡/支付宝/微信)
                List <int> payNoCashType = new List <int>()
                {
                    (int)PayType.AliPay,
                    (int)PayType.Pos,
                    (int)PayType.WxPay
                };
                var result = new OrderHandoverTradeResponse()
                {
                    OrderTradeType     = (int)tradeType,
                    OrderTradeTypeName = EnumName.GetDescription(typeof(OrderTradeType), tradeType),
                    Cash           = handoverTradeSummary.Where(a => a.PayType == (int)PayType.Cash).Sum(b => b.PayAmount),
                    BalanceAmount  = handoverTradeSummary.Sum(a => a.UseBalanceAmount),
                    CouponAmount   = handoverTradeSummary.Sum(a => a.TotalDiscountFee),
                    HandoverNumber = handoverTradeSummary.Count(),
                    OtherAmount    = handoverTradeSummary.Where(a => a.PayType == (int)PayType.Other).Sum(b => b.PayAmount),
                    PayAmount      = handoverTradeSummary.Where(a => payNoCashType.Contains(a.PayType)).Sum(b => b.PayAmount),
                    TransferAmount = handoverTradeSummary.Where(a => a.PayType == (int)PayType.BankTransfer).Sum(b => b.PayAmount)
                };
                //合计 = 现钞 + 刷卡 / 微信 / 支付宝 + 转账 + 其他 + 使用余额 + 使用奖学金
                result.TotalAmount = result.Cash + result.BalanceAmount + result.CouponAmount + result.OtherAmount + result.PayAmount + result.TransferAmount;
                return(result);
            }
            return(null);
        }