コード例 #1
0
        public ReturnValueInfo AccountCashReFund(IModelObject infoObject, string strReason)
        {
            ReturnValueInfo rvInfo = new ReturnValueInfo();
            CardUserAccountDetail_cuad_Info userDetailInfo = infoObject as CardUserAccountDetail_cuad_Info;
            if (userDetailInfo == null)
            {
                rvInfo.messageText = "对象类型不符合,参数需要为SystemAccountDetail_sad_Info类";
                rvInfo.isError = true;
                return rvInfo;
            }
            try
            {
                using (SIOTSDB_HHZXDataContext db = new SIOTSDB_HHZXDataContext())
                {
                    db.Connection.Open();
                    db.Transaction = db.Connection.BeginTransaction();
                    try
                    {
                        PreConsumeRecord_pcs preCost = new PreConsumeRecord_pcs();
                        preCost.pcs_cAccountID = userDetailInfo.cuad_cCUAID;
                        preCost.pcs_cAdd = userDetailInfo.cuad_cOpt;
                        preCost.pcs_dAddDate = DateTime.Now;
                        preCost.pcs_cConsumeType = userDetailInfo.cuad_cFlowType;
                        preCost.pcs_cRecordID = Guid.NewGuid();
                        CardUserAccount_cua userAccount = db.CardUserAccount_cua.Where(x => x.cua_cRecordID == userDetailInfo.cuad_cCUAID).FirstOrDefault();
                        preCost.pcs_cUserID = userAccount.cua_cCUSID;
                        preCost.pcs_dConsumeDate = DateTime.Now;
                        preCost.pcs_dSettleTime = DateTime.Now;
                        preCost.pcs_fCost = userDetailInfo.cuad_fFlowMoney;
                        preCost.pcs_lIsSettled = true;
                        db.PreConsumeRecord_pcs.InsertOnSubmit(preCost);
                        userAccount.cua_fCurrentBalance -= userDetailInfo.cuad_fFlowMoney;
                        db.SubmitChanges();

                        CardUserAccountDetail_cuad userDetail = Common.General.CopyObjectValue<CardUserAccountDetail_cuad_Info, CardUserAccountDetail_cuad>(userDetailInfo);
                        userDetail.cuad_cConsumeID = preCost.pcs_cRecordID;
                        db.CardUserAccountDetail_cuad.InsertOnSubmit(userDetail);
                        db.SubmitChanges();

                        SystemAccountDetail_sad sysDetail = new SystemAccountDetail_sad();
                        sysDetail.sad_cConsumeID = preCost.pcs_cRecordID;
                        sysDetail.sad_cDesc = strReason;
                        sysDetail.sad_cFLowMoney = userDetailInfo.cuad_fFlowMoney;
                        sysDetail.sad_cFlowType = userDetailInfo.cuad_cFlowType;
                        sysDetail.sad_cOpt = userDetailInfo.cuad_cOpt;
                        sysDetail.sad_cRecordID = Guid.NewGuid();
                        sysDetail.sad_dOptTime = DateTime.Now;
                        db.SystemAccountDetail_sad.InsertOnSubmit(sysDetail);
                        db.SubmitChanges();

                        db.Transaction.Commit();
                        db.Connection.Close();
                        rvInfo.boolValue = true;
                    }
                    catch (Exception exx)
                    {
                        db.Transaction.Rollback();
                        db.Connection.Close();
                        throw exx;
                    }
                }
            }
            catch (Exception ex)
            {
                rvInfo.isError = true;
                rvInfo.messageText = ex.Message;
            }
            return rvInfo;
        }
コード例 #2
0
        public ReturnValueInfo ResetAccountOverdraft(RechargeRecord_rcr_Info OverdraftInfo)
        {
            ReturnValueInfo rvInfo = new ReturnValueInfo();
            if (OverdraftInfo == null)
            {
                rvInfo.isError = true;
                rvInfo.messageText = Common.DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull;
                return rvInfo;
            }
            try
            {
                //获取已发卡用户列表
                ICardUserMasterDA userDA = MasterDAFactory.GetDAL<ICardUserMasterDA>(MasterDAFactory.CardUserMaster);
                CardUserMaster_cus_Info userSearch = new CardUserMaster_cus_Info();
                userSearch.cus_cIdentityNum = Common.DefineConstantValue.CodeMasterDefine.KEY2_SIOT_CardUserIdentity_Student;
                List<CardUserMaster_cus_Info> listUsers = userDA.SearchRecordsWithCardInfo(userSearch);
                if (listUsers != null)
                {
                    listUsers = listUsers.Where(x => x.cus_lValid && x.PairCardNo != null).ToList();
                }

                //获取透支额列表
                IRechargeRecordDA rechargeDA = MasterDAFactory.GetDAL<IRechargeRecordDA>(MasterDAFactory.RechargeRecord);
                RechargeRecord_rcr_Info rechargeSearch = new RechargeRecord_rcr_Info();
                rechargeSearch.rcr_cRechargeType = Common.DefineConstantValue.ConsumeMoneyFlowType.Recharge_AdvanceMoney.ToString();
                List<RechargeRecord_rcr_Info> listRecharge = rechargeDA.SearchRecords(rechargeSearch);
                List<RechargeRecord_rcr> listRechargeRec = new List<RechargeRecord_rcr>();

                List<PreConsumeRecord_pcs> listInsertPreCost = new List<PreConsumeRecord_pcs>();
                if (listRecharge != null && listRecharge.Count > 0)
                {
                    IEnumerable<IGrouping<Guid, RechargeRecord_rcr_Info>> groupRecharge = listRecharge.GroupBy(x => x.rcr_cUserID);
                    foreach (var itemRecharge in groupRecharge)
                    {
                        Guid userID = itemRecharge.Key;
                        CardUserMaster_cus_Info userInfo = listUsers.Find(x => x.cus_cRecordID == userID);
                        if (userInfo == null)
                        {
                            continue;
                        }

                        RechargeRecord_rcr_Info userRecharge = itemRecharge.OrderByDescending(x => x.rcr_dRechargeTime).FirstOrDefault();
                        if (userRecharge != null)
                        {
                            Guid sourceID = Guid.NewGuid();
                            if (OverdraftInfo.rcr_fRechargeMoney > userRecharge.rcr_fRechargeMoney)
                            {
                                //新的透支额大于当前透支额
                            }
                            else if (OverdraftInfo.rcr_fRechargeMoney < userRecharge.rcr_fRechargeMoney)
                            {
                                //新的透支额小于当前透支额 eg: 0, 50
                                PreConsumeRecord_pcs preCost = new PreConsumeRecord_pcs();
                                preCost.pcs_cRecordID = Guid.NewGuid();
                                preCost.pcs_cSourceID = sourceID;
                                preCost.pcs_cAccountID = userInfo.AccountID.Value;
                                preCost.pcs_cAdd = OverdraftInfo.rcr_cAdd;
                                preCost.pcs_cConsumeType = Common.DefineConstantValue.ConsumeMoneyFlowType.Recharge_AdvanceMoney.ToString();
                                preCost.pcs_cUserID = userID;
                                preCost.pcs_dAddDate = DateTime.Now;
                                preCost.pcs_dConsumeDate = DateTime.Now;
                                preCost.pcs_fCost = Math.Abs(OverdraftInfo.rcr_fRechargeMoney - userRecharge.rcr_fRechargeMoney);

                                listInsertPreCost.Add(preCost);
                            }
                            else
                            {
                                continue;
                            }

                            RechargeRecord_rcr insertRechrage = Common.General.CopyObjectValue<RechargeRecord_rcr_Info, RechargeRecord_rcr>(userRecharge);
                            insertRechrage.rcr_cRecordID = sourceID;
                            insertRechrage.rcr_fRechargeMoney = OverdraftInfo.rcr_fRechargeMoney;
                            insertRechrage.rcr_fBalance = 0;
                            insertRechrage.rcr_dRechargeTime = DateTime.Now;
                            insertRechrage.rcr_cAdd = OverdraftInfo.rcr_cAdd;
                            insertRechrage.rcr_cLast = OverdraftInfo.rcr_cLast;
                            insertRechrage.rcr_cDesc = OverdraftInfo.rcr_cDesc;
                            insertRechrage.rcr_cStatus = Common.DefineConstantValue.ConsumeMoneyFlowStatus.Finished.ToString();

                            listRechargeRec.Add(insertRechrage);
                        }
                    }
                }

                if (listInsertPreCost.Count == listRechargeRec.Count && listRechargeRec.Count > 0)
                {
                    using (SIOTSDB_HHZXDataContext db = new SIOTSDB_HHZXDataContext())
                    {
                        db.Connection.Open();
                        db.Transaction = db.Connection.BeginTransaction();
                        try
                        {
                            db.RechargeRecord_rcr.InsertAllOnSubmit(listRechargeRec);
                            db.PreConsumeRecord_pcs.InsertAllOnSubmit(listInsertPreCost);
                            db.SubmitChanges();
                            db.Transaction.Commit();
                            rvInfo.boolValue = true;
                        }
                        catch (Exception exx)
                        {
                            db.Transaction.Rollback();
                            db.Connection.Close();
                            throw exx;
                        }
                    }
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return rvInfo;
        }
コード例 #3
0
        public ReturnValueInfo CashRefund(RechargeRecord_rcr_Info refundRecord, decimal fPreCostRecharge)
        {
            ReturnValueInfo rvInfo = new ReturnValueInfo();
            try
            {
                #region  数据检验

                if (refundRecord == null)
                {
                    rvInfo.messageText = Common.DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull;
                    rvInfo.isError = true;
                    return rvInfo;
                }
                RechargeRecord_rcr refundInfo = Common.General.CopyObjectValue<RechargeRecord_rcr_Info, RechargeRecord_rcr>(refundRecord);
                if (refundInfo == null)
                {
                    rvInfo.messageText = Common.DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull;
                    rvInfo.isError = true;
                    return rvInfo;
                }

                #endregion

                using (SIOTSDB_HHZXDataContext db = new SIOTSDB_HHZXDataContext())
                {
                    //用于批量统一插数
                    List<PreConsumeRecord_pcs> listToInsertPreCost = new List<PreConsumeRecord_pcs>();
                    List<CardUserAccountDetail_cuad> listToInsertAccountDetail = new List<CardUserAccountDetail_cuad>();
                    List<SystemAccountDetail_sad> listToInsertSysDetail = new List<SystemAccountDetail_sad>();
                    List<RechargeRecord_rcr> listToInsertRecharge = new List<RechargeRecord_rcr>();

                    //获取账户信息
                    CardUserAccount_cua account = db.CardUserAccount_cua.Where(x => x.cua_cCUSID == refundRecord.rcr_cUserID).FirstOrDefault();
                    #region 账户信息丢失时,自动创建账户信息

                    if (account == null)
                    {
                        account = new CardUserAccount_cua();
                        account.cua_cRecordID = Guid.NewGuid();
                        account.cua_cCUSID = refundRecord.rcr_cUserID;
                        account.cua_cAdd = refundRecord.rcr_cLast;
                        account.cua_dAddDate = DateTime.Now;
                        account.cua_dLastSyncTime = DateTime.Now;
                        account.cua_lIsActive = true;
                        account.cua_fCurrentBalance = decimal.Zero;
                        account.cua_fOriginalBalance = decimal.Zero;
                        db.CardUserAccount_cua.InsertOnSubmit(account);
                        db.SubmitChanges();
                    }

                    #endregion

                    if (account != null)
                    {
                        if (Math.Abs(fPreCostRecharge) > 0)
                        {
                            #region 检查未付款记录,并更新状态

                            List<PreConsumeRecord_pcs> listPreCosts = db.PreConsumeRecord_pcs.Where(x =>
                               x.pcs_cAccountID == account.cua_cRecordID
                               && x.pcs_cUserID == refundInfo.rcr_cUserID
                               && x.pcs_lIsSettled == false
                            ).ToList();

                            //筛选预付款的消费类型
                            listPreCosts = filterRecord_CanComputePreCost(listPreCosts);

                            if (listPreCosts != null && listPreCosts.Count > 0)
                            {
                                decimal fSumPreCost = listPreCosts.Sum(x => x.pcs_fCost);
                                fSumPreCost = Math.Abs(fSumPreCost);

                                if (fSumPreCost != Math.Abs(fPreCostRecharge))
                                {
                                    rvInfo.messageText = "未结算款项记录异常。";
                                    db.Transaction.Rollback();
                                    rvInfo.isError = true;
                                    return rvInfo;
                                }
                                else
                                {
                                    List<CardUserAccountDetail_cuad> listAccountPreCost = new List<CardUserAccountDetail_cuad>();
                                    List<SystemAccountDetail_sad> listSysAccountPreCost = new List<SystemAccountDetail_sad>();
                                    foreach (PreConsumeRecord_pcs preCostItem in listPreCosts)
                                    {
                                        preCostItem.pcs_lIsSettled = true;
                                        preCostItem.pcs_dSettleTime = DateTime.Now;

                                        #region 插入欠费缴费记录

                                        //插入用户账户记录
                                        CardUserAccountDetail_cuad accountDetailPreCost = new CardUserAccountDetail_cuad();
                                        accountDetailPreCost.cuad_cRecordID = Guid.NewGuid();
                                        accountDetailPreCost.cuad_cConsumeID = refundInfo.rcr_cRecordID;
                                        accountDetailPreCost.cuad_cCUAID = account.cua_cRecordID;
                                        accountDetailPreCost.cuad_cFlowType = preCostItem.pcs_cConsumeType;
                                        accountDetailPreCost.cuad_cOpt = refundInfo.rcr_cLast;
                                        accountDetailPreCost.cuad_dOptTime = DateTime.Now;
                                        accountDetailPreCost.cuad_fFlowMoney = preCostItem.pcs_fCost;
                                        listAccountPreCost.Add(accountDetailPreCost);

                                        //插入系统账户记录
                                        SystemAccountDetail_sad sysAccountDetailPreCost = new SystemAccountDetail_sad();
                                        sysAccountDetailPreCost.sad_cRecordID = Guid.NewGuid();
                                        sysAccountDetailPreCost.sad_cConsumeID = refundInfo.rcr_cRecordID;
                                        sysAccountDetailPreCost.sad_cDesc = DefineConstantValue.GetMoneyFlowDesc(preCostItem.pcs_cConsumeType);
                                        sysAccountDetailPreCost.sad_cFLowMoney = preCostItem.pcs_fCost;
                                        sysAccountDetailPreCost.sad_cFlowType = preCostItem.pcs_cConsumeType;
                                        sysAccountDetailPreCost.sad_cOpt = refundInfo.rcr_cLast;
                                        sysAccountDetailPreCost.sad_dOptTime = DateTime.Now;
                                        listSysAccountPreCost.Add(sysAccountDetailPreCost);

                                        #endregion
                                    }

                                    if (listAccountPreCost.Count > 0)
                                    {
                                        listToInsertAccountDetail.AddRange(listAccountPreCost);
                                        listToInsertSysDetail.AddRange(listSysAccountPreCost);
                                    }
                                }
                            }
                            else
                            {
                                if (listPreCosts == null)
                                {
                                    rvInfo.messageText = "未结算款项记录异常。";
                                    rvInfo.isError = true;
                                    return rvInfo;
                                }
                            }

                            #endregion
                        }

                        #region 插入退款记录

                        //插入用户账户退款记录
                        CardUserAccountDetail_cuad accountDetail = new CardUserAccountDetail_cuad();
                        accountDetail.cuad_cRecordID = Guid.NewGuid();
                        accountDetail.cuad_cConsumeID = refundInfo.rcr_cRecordID;
                        accountDetail.cuad_cCUAID = account.cua_cRecordID;
                        accountDetail.cuad_cFlowType = refundInfo.rcr_cRechargeType;
                        accountDetail.cuad_cOpt = refundInfo.rcr_cLast;
                        accountDetail.cuad_dOptTime = DateTime.Now;
                        accountDetail.cuad_fFlowMoney = refundInfo.rcr_fRechargeMoney;
                        listToInsertAccountDetail.Add(accountDetail);

                        //插入系统账户退款记录
                        SystemAccountDetail_sad sysAccountDetail = new SystemAccountDetail_sad();
                        sysAccountDetail.sad_cRecordID = Guid.NewGuid();
                        sysAccountDetail.sad_cConsumeID = refundInfo.rcr_cRecordID;
                        sysAccountDetail.sad_cDesc = refundInfo.rcr_cDesc;
                        sysAccountDetail.sad_cFLowMoney = refundInfo.rcr_fRechargeMoney;
                        sysAccountDetail.sad_cFlowType = refundInfo.rcr_cRechargeType;
                        sysAccountDetail.sad_cOpt = refundInfo.rcr_cLast;
                        sysAccountDetail.sad_dOptTime = DateTime.Now;
                        listToInsertSysDetail.Add(sysAccountDetail);

                        #endregion

                        decimal fAdvanceCost = decimal.Zero;
                        #region 获取透支金额

                        List<RechargeRecord_rcr> listAdvanceCost = db.RechargeRecord_rcr.Where(x =>
                             x.rcr_cUserID == refundInfo.rcr_cUserID
                            && x.rcr_cRechargeType == Common.DefineConstantValue.ConsumeMoneyFlowType.Recharge_AdvanceMoney.ToString()).ToList();
                        if (listAdvanceCost != null && listAdvanceCost.Count > 0)
                        {
                            RechargeRecord_rcr advanceCost = listAdvanceCost.OrderByDescending(x => x.rcr_dRechargeTime).FirstOrDefault();
                            if (advanceCost != null)
                            {
                                fAdvanceCost = advanceCost.rcr_fRechargeMoney;
                            }
                        }

                        #endregion

                        decimal fAccountCurrentBalance = account.cua_fCurrentBalance - fPreCostRecharge - refundInfo.rcr_fRechargeMoney;//退款后的最新账户余额
                        decimal fCardCurrentBalance = refundInfo.rcr_fBalance - fAdvanceCost;//退款后的卡余额
                        if (fAccountCurrentBalance > fCardCurrentBalance)
                        {
                            //账户余额比卡余额大,则需要插入补充金额
                            #region 插入补充消费记录

                            decimal fInsert = fAccountCurrentBalance - fCardCurrentBalance;

                            //【系统账户余额】 大于 【卡实际余额】
                            // 新增一条平数的预扣费记录
                            PreConsumeRecord_pcs unconfirmRecord = new PreConsumeRecord_pcs();
                            unconfirmRecord.pcs_cAccountID = account.cua_cRecordID;
                            unconfirmRecord.pcs_cRecordID = Guid.NewGuid();
                            unconfirmRecord.pcs_cConsumeType = DefineConstantValue.ConsumeMoneyFlowType.HedgeFund.ToString();
                            unconfirmRecord.pcs_cUserID = refundInfo.rcr_cUserID;
                            unconfirmRecord.pcs_cAdd = refundInfo.rcr_cLast;
                            unconfirmRecord.pcs_dAddDate = DateTime.Now;
                            unconfirmRecord.pcs_dConsumeDate = DateTime.Now;
                            unconfirmRecord.pcs_fCost = fInsert;
                            unconfirmRecord.pcs_lIsSettled = false;
                            listToInsertPreCost.Add(unconfirmRecord);

                            //用户账户
                            CardUserAccountDetail_cuad userAccount = new CardUserAccountDetail_cuad();
                            userAccount.cuad_cConsumeID = unconfirmRecord.pcs_cRecordID;
                            userAccount.cuad_cCUAID = account.cua_cRecordID;
                            userAccount.cuad_cFlowType = unconfirmRecord.pcs_cConsumeType;
                            userAccount.cuad_cOpt = refundInfo.rcr_cLast;
                            userAccount.cuad_cRecordID = Guid.NewGuid();
                            userAccount.cuad_dOptTime = DateTime.Now;
                            userAccount.cuad_fFlowMoney = fInsert;
                            listToInsertAccountDetail.Add(userAccount);

                            //系统账户
                            SystemAccountDetail_sad sysAccount = new SystemAccountDetail_sad();
                            sysAccount.sad_cRecordID = Guid.NewGuid();
                            sysAccount.sad_cConsumeID = unconfirmRecord.pcs_cRecordID;
                            sysAccount.sad_cDesc = DefineConstantValue.GetMoneyFlowDesc(unconfirmRecord.pcs_cConsumeType);
                            sysAccount.sad_cFLowMoney = fInsert;
                            sysAccount.sad_cFlowType = unconfirmRecord.pcs_cConsumeType;
                            sysAccount.sad_cOpt = refundInfo.rcr_cLast;
                            sysAccount.sad_dOptTime = DateTime.Now;
                            listToInsertSysDetail.Add(sysAccount);

                            #endregion
                        }

                        try
                        {
                            db.Connection.Open();
                            db.Transaction = db.Connection.BeginTransaction();

                            refundInfo.rcr_dRechargeTime = DateTime.Now;
                            refundInfo.rcr_dLastDate = DateTime.Now;
                            db.RechargeRecord_rcr.InsertOnSubmit(refundInfo);

                            account.cua_fCurrentBalance = fCardCurrentBalance;
                            account.cua_dLastSyncTime = DateTime.Now;

                            if (listToInsertPreCost != null && listToInsertPreCost.Count > 0)
                                db.PreConsumeRecord_pcs.InsertAllOnSubmit(listToInsertPreCost);
                            if (listToInsertAccountDetail != null && listToInsertAccountDetail.Count > 0)
                                db.CardUserAccountDetail_cuad.InsertAllOnSubmit(listToInsertAccountDetail);
                            if (listToInsertSysDetail != null && listToInsertSysDetail.Count > 0)
                                db.SystemAccountDetail_sad.InsertAllOnSubmit(listToInsertSysDetail);
                            if (listToInsertRecharge != null && listToInsertRecharge.Count > 0)
                                db.RechargeRecord_rcr.InsertAllOnSubmit(listToInsertRecharge);

                            db.SubmitChanges();
                            db.Transaction.Commit();
                            rvInfo.boolValue = true;
                        }
                        catch (Exception exx)
                        {
                            db.Transaction.Rollback();
                            db.Connection.Close();
                            throw exx;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                rvInfo.isError = true;
                rvInfo.messageText = ex.Message;
            }
            return rvInfo;
        }
コード例 #4
0
        public ReturnValueInfo InsertRechargeRecord(IModelObject itemEntity)
        {
            ReturnValueInfo rvInfo = new ReturnValueInfo();
            try
            {
                RechargeRecord_rcr_Info sourceInfo = itemEntity as RechargeRecord_rcr_Info;
                if (sourceInfo == null)
                {
                    rvInfo.messageText = DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull;
                    rvInfo.isError = true;
                    return rvInfo;
                }

                //判断是否为需要录入用户账户中的记录
                bool isUserDetail = IsUserAccountRecord(sourceInfo);
                // 判断是否为需要录入到系统账户中的记录
                bool isSysDetail = IsSysAccountRecord(sourceInfo);

                //使用服务器时间更新记录时间
                sourceInfo.rcr_dRechargeTime = DateTime.Now;
                sourceInfo.rcr_dLastDate = sourceInfo.rcr_dRechargeTime;

                RechargeRecord_rcr rechargeRecord = Common.General.CopyObjectValue<RechargeRecord_rcr_Info, RechargeRecord_rcr>(sourceInfo);
                if (rechargeRecord == null)
                {
                    rvInfo.isError = true;
                    rvInfo.messageText = DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull;
                    return rvInfo;
                }

                using (SIOTSDB_HHZXDataContext db = new SIOTSDB_HHZXDataContext())
                {
                    //用于批量统一插数
                    List<PreConsumeRecord_pcs> listToInsertPreCost = new List<PreConsumeRecord_pcs>();
                    List<CardUserAccountDetail_cuad> listToInsertAccountDetail = new List<CardUserAccountDetail_cuad>();
                    List<SystemAccountDetail_sad> listToInsertSysDetail = new List<SystemAccountDetail_sad>();

                    //获取账户信息
                    CardUserAccount_cua account = db.CardUserAccount_cua.Where(x => x.cua_cCUSID == sourceInfo.rcr_cUserID).FirstOrDefault();
                    #region 账户信息丢失时,自动创建账户信息

                    if (account == null)
                    {
                        account = new CardUserAccount_cua();
                        account.cua_cRecordID = Guid.NewGuid();
                        account.cua_cCUSID = sourceInfo.rcr_cUserID;
                        account.cua_cAdd = sourceInfo.rcr_cLast;
                        account.cua_dAddDate = DateTime.Now;
                        account.cua_dLastSyncTime = DateTime.Now;
                        account.cua_lIsActive = true;
                        account.cua_fCurrentBalance = decimal.Zero;
                        account.cua_fOriginalBalance = decimal.Zero;
                        db.CardUserAccount_cua.InsertOnSubmit(account);
                        db.SubmitChanges();
                    }

                    #endregion

                    if (isUserDetail)
                    {
                        //同步插入一条用户资金流动记录
                        #region 同步用户资金流动记录

                        CardUserAccountDetail_cuad accountDetail = new CardUserAccountDetail_cuad();
                        accountDetail.cuad_cRecordID = Guid.NewGuid();
                        accountDetail.cuad_cConsumeID = sourceInfo.rcr_cRecordID;//消费源ID
                        accountDetail.cuad_cCUAID = account.cua_cRecordID;//账户ID
                        accountDetail.cuad_fFlowMoney = sourceInfo.rcr_fRechargeMoney + Math.Abs(sourceInfo.PreCostMoney);//账户当次充值金额=卡实际充值金额+应付欠款
                        accountDetail.cuad_cFlowType = sourceInfo.rcr_cRechargeType;
                        accountDetail.cuad_cOpt = sourceInfo.rcr_cAdd;
                        accountDetail.cuad_dOptTime = sourceInfo.rcr_dRechargeTime;
                        listToInsertAccountDetail.Add(accountDetail);

                        #endregion
                    }

                    if (isSysDetail)
                    {
                        //同步插入一条系统资金现金流
                        #region 同步系统资金流动记录

                        SystemAccountDetail_sad sysAccountInfo = new SystemAccountDetail_sad();
                        sysAccountInfo.sad_cRecordID = Guid.NewGuid();
                        sysAccountInfo.sad_cConsumeID = sourceInfo.rcr_cRecordID;//消费源ID
                        sysAccountInfo.sad_cDesc = sourceInfo.rcr_cDesc;//充值或退款描述
                        sysAccountInfo.sad_cFLowMoney = sourceInfo.rcr_fRechargeMoney + Math.Abs(sourceInfo.PreCostMoney);
                        sysAccountInfo.sad_cFlowType = sourceInfo.rcr_cRechargeType;
                        sysAccountInfo.sad_cOpt = sourceInfo.rcr_cAdd;
                        sysAccountInfo.sad_dOptTime = sourceInfo.rcr_dRechargeTime;
                        listToInsertSysDetail.Add(sysAccountInfo);
                        #endregion
                    }

                    //找出该用户最后一条透支充值记录
                    decimal fAdvance = 0;
                    #region 获取用户的预充值金额(透支款)

                    List<RechargeRecord_rcr> listRechargeRecord = db.RechargeRecord_rcr.Where(x =>
                        x.rcr_cRechargeType == DefineConstantValue.ConsumeMoneyFlowType.Recharge_AdvanceMoney.ToString()
                        && x.rcr_cUserID == sourceInfo.rcr_cUserID
                        ).ToList();
                    if (listRechargeRecord != null && listRechargeRecord.Count > 0)
                    {
                        listRechargeRecord = listRechargeRecord.OrderByDescending(x => x.rcr_dRechargeTime).ToList();
                        fAdvance = listRechargeRecord[0].rcr_fRechargeMoney;
                    }

                    #endregion

                    decimal fCurrentBalance = decimal.Zero;
                    //判断是否需要同步处理欠款结算
                    if (Math.Abs(sourceInfo.PreCostMoney) > 0 || sourceInfo.IsNeedSyncAccount)//需要欠款金额大于零及标识为需要同步
                    {
                        //若预付款还款值大于0,则存入充值账户
                        #region 存入预付款还款

                        List<PreConsumeRecord_pcs> listPreCost = db.PreConsumeRecord_pcs.Where(x =>
                            x.pcs_lIsSettled == false//状态为未结算
                            && x.pcs_cAccountID == account.cua_cRecordID//配对用户账号ID
                            && x.pcs_cUserID == sourceInfo.rcr_cUserID//配对用户ID
                            && x.pcs_cConsumeType != DefineConstantValue.ConsumeMoneyFlowType.IndeterminateCost.ToString()//非未确定扣费款项
                            && x.pcs_cConsumeType != DefineConstantValue.ConsumeMoneyFlowType.AdvanceMealCost.ToString()//非待扣费款项
                            && x.pcs_cConsumeType != DefineConstantValue.ConsumeMoneyFlowType.HedgeFund.ToString()//非对冲款项
                            ).ToList();

                        decimal sumPreCost = listPreCost.Sum(x => x.pcs_fCost);
                        if (Math.Abs(sourceInfo.PreCostMoney) < Math.Abs(sumPreCost))//判断该次充值时缴纳的应付款总额是否足以扣除当前全部欠款
                        {
                            //不足以扣除
                            db.Transaction.Rollback();
                            db.Connection.Close();
                            rvInfo.messageText = "支付额不足以支付待结算的预付款。";
                            return rvInfo;
                        }

                        //用户需要结算的欠款记录
                        List<CardUserAccountDetail_cuad> listPreUserCost = new List<CardUserAccountDetail_cuad>();
                        List<SystemAccountDetail_sad> listPreSysIncome = new List<SystemAccountDetail_sad>();
                        foreach (PreConsumeRecord_pcs preItem in listPreCost)
                        {
                            preItem.pcs_lIsSettled = true;
                            preItem.pcs_dSettleTime = DateTime.Now;

                            //结算的同时插入一条账户支出记录
                            CardUserAccountDetail_cuad userAccount = new CardUserAccountDetail_cuad();
                            userAccount.cuad_cRecordID = Guid.NewGuid();
                            userAccount.cuad_cConsumeID = preItem.pcs_cRecordID;
                            userAccount.cuad_cCUAID = account.cua_cRecordID;
                            userAccount.cuad_cFlowType = preItem.pcs_cConsumeType;
                            userAccount.cuad_cOpt = sourceInfo.rcr_cLast;
                            userAccount.cuad_dOptTime = DateTime.Now;
                            userAccount.cuad_fFlowMoney = preItem.pcs_fCost;
                            listPreUserCost.Add(userAccount);

                            //结算的同时插入一条系统账户收入记录
                            SystemAccountDetail_sad sysAccount = new SystemAccountDetail_sad();
                            sysAccount.sad_cRecordID = Guid.NewGuid();
                            sysAccount.sad_cConsumeID = preItem.pcs_cRecordID;
                            sysAccount.sad_cDesc = DefineConstantValue.GetMoneyFlowDesc(preItem.pcs_cConsumeType);
                            sysAccount.sad_cFLowMoney = preItem.pcs_fCost;
                            sysAccount.sad_cFlowType = preItem.pcs_cConsumeType;
                            sysAccount.sad_cOpt = sourceInfo.rcr_cLast;
                            sysAccount.sad_dOptTime = DateTime.Now;
                            listPreSysIncome.Add(sysAccount);
                        }

                        if (listPreUserCost.Count > 0)
                        {
                            listToInsertAccountDetail.AddRange(listPreUserCost);
                            listToInsertSysDetail.AddRange(listPreSysIncome);
                        }

                        #endregion

                        //更新账户余额
                        decimal fAccountUpdate = account.cua_fCurrentBalance + sourceInfo.rcr_fRechargeMoney;//充值后账户余额=当前账户余额+实际充值金额
                        decimal fCardBalance = sourceInfo.rcr_fBalance - fAdvance;//充值后卡余额 = 卡当前余额 - 透支金额

                        if (fAccountUpdate > fCardBalance)//【系统账户余额】 大于 【卡实际余额】
                        {
                            #region 进行平数处理

                            // 新增一条平数的预扣费记录
                            decimal fUnconfirmCost = fAccountUpdate - fCardBalance;//需要对冲款 = 账户当前余额 - 卡当前余额

                            PreConsumeRecord_pcs unconfirmRecord = new PreConsumeRecord_pcs();
                            unconfirmRecord.pcs_cRecordID = Guid.NewGuid();
                            unconfirmRecord.pcs_cAccountID = account.cua_cRecordID;
                            unconfirmRecord.pcs_cUserID = sourceInfo.rcr_cUserID;
                            unconfirmRecord.pcs_cConsumeType = DefineConstantValue.ConsumeMoneyFlowType.HedgeFund.ToString();
                            unconfirmRecord.pcs_dConsumeDate = DateTime.Now;
                            unconfirmRecord.pcs_fCost = fUnconfirmCost;
                            unconfirmRecord.pcs_lIsSettled = false;//状态设置为未结算,等待账户同步服务同步时结算清数
                            unconfirmRecord.pcs_cAdd = sourceInfo.rcr_cLast;
                            unconfirmRecord.pcs_dAddDate = DateTime.Now;
                            listToInsertPreCost.Add(unconfirmRecord);

                            //用户账户
                            CardUserAccountDetail_cuad userAccount = new CardUserAccountDetail_cuad();
                            userAccount.cuad_cRecordID = Guid.NewGuid();
                            userAccount.cuad_cConsumeID = unconfirmRecord.pcs_cRecordID;
                            userAccount.cuad_cCUAID = account.cua_cRecordID;
                            userAccount.cuad_cFlowType = unconfirmRecord.pcs_cConsumeType;
                            userAccount.cuad_cOpt = sourceInfo.rcr_cLast;
                            userAccount.cuad_dOptTime = DateTime.Now;
                            userAccount.cuad_fFlowMoney = fUnconfirmCost;
                            listToInsertAccountDetail.Add(userAccount);

                            //系统账户
                            SystemAccountDetail_sad sysAccount = new SystemAccountDetail_sad();
                            sysAccount.sad_cRecordID = Guid.NewGuid();
                            sysAccount.sad_cConsumeID = unconfirmRecord.pcs_cRecordID;
                            sysAccount.sad_cDesc = DefineConstantValue.GetMoneyFlowDesc(unconfirmRecord.pcs_cConsumeType);
                            sysAccount.sad_cFLowMoney = fUnconfirmCost;
                            sysAccount.sad_cFlowType = unconfirmRecord.pcs_cConsumeType;
                            sysAccount.sad_cOpt = sourceInfo.rcr_cLast;
                            sysAccount.sad_dOptTime = DateTime.Now;
                            listToInsertSysDetail.Add(sysAccount);

                            #endregion
                        }
                        fCurrentBalance = fCardBalance;
                    }
                    else
                    {
                        fCurrentBalance = sourceInfo.rcr_fBalance - fAdvance;
                    }

                    db.Connection.Open();
                    db.Transaction = db.Connection.BeginTransaction();
                    try
                    {

                        db.RechargeRecord_rcr.InsertOnSubmit(rechargeRecord);//插入卡实际金额充值记录
                        db.PreConsumeRecord_pcs.InsertAllOnSubmit(listToInsertPreCost);
                        db.CardUserAccountDetail_cuad.InsertAllOnSubmit(listToInsertAccountDetail);
                        db.SystemAccountDetail_sad.InsertAllOnSubmit(listToInsertSysDetail);
                        CardUserAccount_cua accountUpdate = db.CardUserAccount_cua.Where(x => x.cua_cRecordID == account.cua_cRecordID).FirstOrDefault();
                        accountUpdate.cua_fCurrentBalance = fCurrentBalance;
                        accountUpdate.cua_dLastSyncTime = DateTime.Now;

                        db.SubmitChanges();
                        db.Transaction.Commit();
                        rvInfo.boolValue = true;
                        rvInfo.ValueObject = DateTime.Now;
                    }
                    catch (Exception exx)
                    {
                        db.Transaction.Rollback();
                        db.Connection.Close();
                        throw exx;
                    }
                }
            }
            catch (Exception ex)
            {
                rvInfo.isError = true;
                rvInfo.messageText = ex.Message;
            }
            return rvInfo;
        }
コード例 #5
0
        public ReturnValueInfo UpdateRechargeRecord(List<PreRechargeRecord_prr_Info> listRecord, List<RechargeRecord_rcr_Info> listRecharges, decimal fPreCostRecharge)
        {
            ReturnValueInfo rvInfo = new ReturnValueInfo();
            #region 检查条件合法性

            if (listRecord == null)
            {
                rvInfo.isError = true;
                rvInfo.messageText = Common.DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull + Environment.NewLine + "预充值记录。";
                return rvInfo;
            }
            if (listRecharges == null)
            {
                rvInfo.isError = true;
                rvInfo.messageText = Common.DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull + Environment.NewLine + "实际充值记录。";
                return rvInfo;
            }
            if (listRecharges != null && listRecharges.Count < 1)
            {
                rvInfo.isError = true;
                rvInfo.messageText = "需要录入的充值记录不能为空。";
                return rvInfo;
            }
            if (listRecord != null && listRecord.Count < 1)
            {
                rvInfo.isError = true;
                rvInfo.messageText = "需要更新的充值记录不能为空。";
                return rvInfo;
            }

            #endregion

            try
            {
                using (SIOTSDB_HHZXDataContext db = new SIOTSDB_HHZXDataContext())
                {
                    //用于批量统一插数
                    List<PreConsumeRecord_pcs> listToInsertPreCost = new List<PreConsumeRecord_pcs>();
                    List<CardUserAccountDetail_cuad> listToInsertAccountDetail = new List<CardUserAccountDetail_cuad>();
                    List<SystemAccountDetail_sad> listToInsertSysDetail = new List<SystemAccountDetail_sad>();
                    List<RechargeRecord_rcr> listToInsertRecharge = new List<RechargeRecord_rcr>();

                    //获取账户信息
                    CardUserAccount_cua account = db.CardUserAccount_cua.Where(x => x.cua_cCUSID == listRecharges[0].rcr_cUserID).FirstOrDefault();
                    #region 账户信息丢失时,自动创建账户信息

                    if (account == null)
                    {
                        account = new CardUserAccount_cua();
                        account.cua_cRecordID = Guid.NewGuid();
                        account.cua_cCUSID = listRecharges[0].rcr_cUserID;
                        account.cua_cAdd = listRecharges[0].rcr_cLast;
                        account.cua_dAddDate = DateTime.Now;
                        account.cua_dLastSyncTime = DateTime.Now;
                        account.cua_lIsActive = true;
                        account.cua_fCurrentBalance = decimal.Zero;
                        account.cua_fOriginalBalance = decimal.Zero;
                        db.CardUserAccount_cua.InsertOnSubmit(account);
                        db.SubmitChanges();
                    }

                    #endregion

                    //充值总额
                    decimal fSumRecharge = decimal.Zero;

                    //待添加的实际充值记录
                    List<RechargeRecord_rcr> listRechargeInserts = new List<RechargeRecord_rcr>();
                    //待添加的的用户账户数据
                    List<CardUserAccountDetail_cuad> listUserAccountInfos = new List<CardUserAccountDetail_cuad>();
                    //待添加的系统账户数据
                    List<SystemAccountDetail_sad> listSysAccountInfos = new List<SystemAccountDetail_sad>();
                    //更新已经使用的转账充值记录
                    #region 更新已被使用的预充值记录状态为已完成,并插入实际充值记录并记录账户收入记录

                    foreach (PreRechargeRecord_prr_Info preRechargeItem in listRecord)
                    {
                        if (preRechargeItem == null)
                        {
                            continue;
                        }

                        PreRechargeRecord_prr preRecord = db.PreRechargeRecord_prr.Where(x => x.prr_cRecordID == preRechargeItem.prr_cRecordID).FirstOrDefault();
                        if (preRecord != null)
                        {
                            //添加实际消费记录
                            RechargeRecord_rcr_Info rechargeInfo = listRecharges.Find(x => x.rcr_cRecordID == preRechargeItem.prr_cRCRID);
                            if (rechargeInfo != null)
                            {
                                RechargeRecord_rcr recharge = Common.General.CopyObjectValue<RechargeRecord_rcr_Info, RechargeRecord_rcr>(rechargeInfo);
                                if (recharge != null)
                                {
                                    rechargeInfo.rcr_dRechargeTime = DateTime.Now;
                                    rechargeInfo.rcr_dLastDate = DateTime.Now;
                                    listRechargeInserts.Add(recharge);
                                }
                            }

                            preRecord.prr_cRCRID = rechargeInfo.rcr_cRecordID;
                            preRecord.prr_cStatus = Common.DefineConstantValue.ConsumeMoneyFlowStatus.Finished.ToString();
                            preRecord.prr_cLast = preRechargeItem.prr_cLast;
                            preRecord.prr_dLastDate = preRechargeItem.prr_dLastDate;

                            //累积充值记录
                            fSumRecharge += preRechargeItem.prr_fRechargeMoney;

                            //用户账户
                            CardUserAccountDetail_cuad userAccountDetail = new CardUserAccountDetail_cuad();
                            userAccountDetail.cuad_cRecordID = Guid.NewGuid();
                            userAccountDetail.cuad_cConsumeID = rechargeInfo.rcr_cRecordID;
                            userAccountDetail.cuad_cCUAID = account.cua_cRecordID;
                            userAccountDetail.cuad_cFlowType = rechargeInfo.rcr_cRechargeType;
                            userAccountDetail.cuad_cOpt = rechargeInfo.rcr_cLast;
                            userAccountDetail.cuad_dOptTime = DateTime.Now;
                            userAccountDetail.cuad_fFlowMoney = preRechargeItem.prr_fRechargeMoney;//金额与预充值额全额一致
                            listUserAccountInfos.Add(userAccountDetail);

                            //系统账户
                            SystemAccountDetail_sad sysAccount = new SystemAccountDetail_sad();
                            sysAccount.sad_cRecordID = Guid.NewGuid();
                            sysAccount.sad_cConsumeID = rechargeInfo.rcr_cRecordID;
                            sysAccount.sad_cDesc = Common.DefineConstantValue.GetMoneyFlowDesc(rechargeInfo.rcr_cRechargeType);
                            sysAccount.sad_cFLowMoney = preRechargeItem.prr_fRechargeMoney;//金额与预充值额全额一致
                            sysAccount.sad_cFlowType = rechargeInfo.rcr_cRechargeType;
                            sysAccount.sad_cOpt = rechargeInfo.rcr_cLast;
                            sysAccount.sad_dOptTime = DateTime.Now;
                            listSysAccountInfos.Add(sysAccount);
                        }
                    }

                    #endregion
                    if (listUserAccountInfos.Count > 0)
                    {
                        //插入由充值记录产生的账户记录
                        listToInsertRecharge.AddRange(listRechargeInserts);
                        listToInsertAccountDetail.AddRange(listUserAccountInfos);
                        listToInsertSysDetail.AddRange(listSysAccountInfos);
                    }

                    //查找用户是否含有透支预存款记录
                    decimal fAdvance = decimal.Zero;
                    #region 获取用户的透支金额

                    List<RechargeRecord_rcr> listAdvance = db.RechargeRecord_rcr.Where(x =>
                        x.rcr_cUserID == listRechargeInserts[0].rcr_cUserID
                        && x.rcr_cRechargeType == Common.DefineConstantValue.ConsumeMoneyFlowType.Recharge_AdvanceMoney.ToString()
                        ).ToList();
                    if (listAdvance != null && listAdvance.Count > 0)
                    {
                        fAdvance = listAdvance.OrderByDescending(x => x.rcr_dRechargeTime).FirstOrDefault().rcr_fRechargeMoney;
                    }

                    #endregion

                    decimal fCurrentBalance = decimal.Zero;
                    fPreCostRecharge = Math.Abs(fPreCostRecharge);
                    decimal fSumPreCost = decimal.Zero;//记录欠款总额
                    //获取本次充值的最后余额
                    //decimal fCardBalance = listRechargeInserts.Max(x => x.rcr_fBalance);
                    decimal fCardBalance = listRechargeInserts.OrderByDescending(x => x.rcr_dRechargeTime).FirstOrDefault().rcr_fBalance;
                    if (fPreCostRecharge >= 0 && listRechargeInserts.Count > 0)//若存在需要支付预付款的金额,则进行平数处理
                    {
                        //若预付款还款值大于0,则更新被支付的未结算预付款记录
                        #region 结算预付款项

                        List<PreConsumeRecord_pcs> listPreCost = db.PreConsumeRecord_pcs.Where(x =>
                            x.pcs_lIsSettled == false //需为未支付金额
                            && x.pcs_cAccountID == account.cua_cRecordID//需要账户对口
                            && x.pcs_cUserID == listRechargeInserts[0].rcr_cUserID  //需要对口人员ID
                            ).ToList();

                        //筛选预付款的消费类型
                        listPreCost = filterRecord_CanComputePreCost(listPreCost);

                        fSumPreCost = listPreCost.Sum(x => x.pcs_fCost);
                        if (Math.Abs(fPreCostRecharge) < Math.Abs(fSumPreCost))
                        {
                            rvInfo.messageText = "支付额不足以支付待结算的预付款。";
                            return rvInfo;
                        }

                        List<CardUserAccountDetail_cuad> listPreUserCost = new List<CardUserAccountDetail_cuad>();
                        List<SystemAccountDetail_sad> listPreSysIncome = new List<SystemAccountDetail_sad>();
                        foreach (PreConsumeRecord_pcs preItem in listPreCost)
                        {
                            preItem.pcs_lIsSettled = true;
                            preItem.pcs_dSettleTime = DateTime.Now;

                            //结算的同时插入一条用户账户支出记录
                            CardUserAccountDetail_cuad userAccountDetail = new CardUserAccountDetail_cuad();
                            userAccountDetail.cuad_cConsumeID = preItem.pcs_cRecordID;
                            userAccountDetail.cuad_cCUAID = account.cua_cRecordID;
                            userAccountDetail.cuad_cFlowType = preItem.pcs_cConsumeType;
                            userAccountDetail.cuad_cOpt = listRechargeInserts[0].rcr_cLast;
                            userAccountDetail.cuad_cRecordID = Guid.NewGuid();
                            userAccountDetail.cuad_dOptTime = DateTime.Now;
                            userAccountDetail.cuad_fFlowMoney = preItem.pcs_fCost;
                            listPreUserCost.Add(userAccountDetail);

                            //结算的同时插入一条系统账户收入记录
                            SystemAccountDetail_sad sysAccount = new SystemAccountDetail_sad();
                            sysAccount.sad_cConsumeID = preItem.pcs_cRecordID;
                            sysAccount.sad_cDesc = Common.DefineConstantValue.GetMoneyFlowDesc(preItem.pcs_cConsumeType);
                            sysAccount.sad_cFLowMoney = preItem.pcs_fCost;
                            sysAccount.sad_cFlowType = preItem.pcs_cConsumeType;
                            sysAccount.sad_cOpt = listRechargeInserts[0].rcr_cLast;
                            sysAccount.sad_cRecordID = Guid.NewGuid();
                            sysAccount.sad_dOptTime = DateTime.Now;
                            listPreSysIncome.Add(sysAccount);
                        }

                        if (listPreUserCost.Count > 0)
                        {
                            listToInsertAccountDetail.AddRange(listPreUserCost);
                            listToInsertSysDetail.AddRange(listPreSysIncome);
                        }

                        #endregion

                        //扣减预支款
                        fCardBalance -= fAdvance;
                        //账户余额
                        decimal fAccountUpdate = account.cua_fCurrentBalance + fSumRecharge - fSumPreCost;
                        if (fAccountUpdate > fCardBalance)
                        {
                            #region 平数处理

                            //【系统账户余额】 大于 【卡实际余额】
                            // 新增一条平数的预扣费记录
                            decimal fUnconfirmCost = fAccountUpdate - fCardBalance;

                            PreConsumeRecord_pcs unconfirmRecord = new PreConsumeRecord_pcs();
                            unconfirmRecord.pcs_cRecordID = Guid.NewGuid();
                            unconfirmRecord.pcs_cAccountID = account.cua_cRecordID;
                            unconfirmRecord.pcs_cAdd = listRechargeInserts[0].rcr_cLast;
                            unconfirmRecord.pcs_cConsumeType = DefineConstantValue.ConsumeMoneyFlowType.HedgeFund.ToString();
                            unconfirmRecord.pcs_cUserID = listRechargeInserts[0].rcr_cUserID;
                            unconfirmRecord.pcs_dAddDate = DateTime.Now;
                            unconfirmRecord.pcs_dConsumeDate = DateTime.Now;
                            unconfirmRecord.pcs_fCost = fUnconfirmCost;
                            unconfirmRecord.pcs_lIsSettled = false;
                            listToInsertPreCost.Add(unconfirmRecord);

                            //用户账户
                            CardUserAccountDetail_cuad userAccountDetail = new CardUserAccountDetail_cuad();
                            userAccountDetail.cuad_cRecordID = Guid.NewGuid();
                            userAccountDetail.cuad_cConsumeID = unconfirmRecord.pcs_cRecordID;
                            userAccountDetail.cuad_cCUAID = account.cua_cRecordID;
                            userAccountDetail.cuad_cFlowType = unconfirmRecord.pcs_cConsumeType;
                            userAccountDetail.cuad_cOpt = listRechargeInserts[0].rcr_cLast;
                            userAccountDetail.cuad_dOptTime = DateTime.Now;
                            userAccountDetail.cuad_fFlowMoney = fUnconfirmCost;
                            listToInsertAccountDetail.Add(userAccountDetail);

                            //系统账户
                            SystemAccountDetail_sad sysAccount = new SystemAccountDetail_sad();
                            sysAccount.sad_cRecordID = Guid.NewGuid();
                            sysAccount.sad_cConsumeID = unconfirmRecord.pcs_cRecordID;
                            sysAccount.sad_cDesc = DefineConstantValue.GetMoneyFlowDesc(unconfirmRecord.pcs_cConsumeType);
                            sysAccount.sad_cFLowMoney = fUnconfirmCost;
                            sysAccount.sad_cFlowType = unconfirmRecord.pcs_cConsumeType;
                            sysAccount.sad_cOpt = listRechargeInserts[0].rcr_cLast;
                            sysAccount.sad_dOptTime = DateTime.Now;
                            listToInsertSysDetail.Add(sysAccount);

                            #endregion
                        }
                        fCurrentBalance = fCardBalance;
                    }
                    else
                    {
                        fCurrentBalance = fCardBalance - fAdvance;
                    }
                    try
                    {
                        db.Connection.Open();
                        db.Transaction = db.Connection.BeginTransaction();

                        if (listToInsertRecharge != null && listToInsertRecharge.Count > 0)
                            db.RechargeRecord_rcr.InsertAllOnSubmit(listToInsertRecharge);
                        if (listToInsertPreCost != null && listToInsertPreCost.Count > 0)
                            db.PreConsumeRecord_pcs.InsertAllOnSubmit(listToInsertPreCost);
                        if (listToInsertAccountDetail != null && listToInsertAccountDetail.Count > 0)
                            db.CardUserAccountDetail_cuad.InsertAllOnSubmit(listToInsertAccountDetail);
                        if (listToInsertSysDetail != null && listToInsertSysDetail.Count > 0)
                            db.SystemAccountDetail_sad.InsertAllOnSubmit(listToInsertSysDetail);

                        account.cua_dLastSyncTime = DateTime.Now;
                        account.cua_fCurrentBalance = fCurrentBalance;

                        db.SubmitChanges();
                        db.Transaction.Commit();
                        rvInfo.boolValue = true;
                        rvInfo.ValueObject = DateTime.Now;
                        return rvInfo;
                    }
                    catch (Exception exx)
                    {
                        db.Transaction.Rollback();
                        db.Connection.Close();
                        throw exx;
                    }
                }
            }
            catch (Exception ex)
            {
                rvInfo.isError = true;
                rvInfo.messageText = ex.Message;
            }
            return rvInfo;
        }
コード例 #6
0
        public ReturnValueInfo UpdateRecordWithPreCost(MealBookingHistory_mbh_Info infoObject)
        {
            ReturnValueInfo rvInfo = new ReturnValueInfo();
            try
            {
                if (infoObject != null)
                {
                    using (SIOTSDB_HHZXDataContext db = new SIOTSDB_HHZXDataContext())
                    {
                        db.Connection.Open();
                        db.Transaction = db.Connection.BeginTransaction();
                        try
                        {
                            MealBookingHistory_mbh history = db.MealBookingHistory_mbh.Where(x => x.mbh_cRecordID == infoObject.mbh_cRecordID).FirstOrDefault();

                            if (history != null)
                            {
                                history.mbh_cAdd = infoObject.mbh_cAdd;
                                history.mbh_cMealType = infoObject.mbh_cMealType;
                                history.mbh_cTargetID = infoObject.mbh_cTargetID;
                                history.mbh_cTargetType = infoObject.mbh_cTargetType;
                                history.mbh_dAddDate = infoObject.mbh_dAddDate;
                                history.mbh_dMealDate = infoObject.mbh_dMealDate;
                                history.mbh_lIsSet = infoObject.mbh_lIsSet;
                                history.mbh_fMealCost = infoObject.mbh_fMealCost;

                                CardUserAccount_cua accountInfo = db.CardUserAccount_cua.Where(x => x.cua_cCUSID == infoObject.mbh_cTargetID).FirstOrDefault();

                                PreConsumeRecord_pcs preCostInfo = new PreConsumeRecord_pcs();
                                preCostInfo.pcs_cAccountID = accountInfo.cua_cRecordID;
                                preCostInfo.pcs_cAdd = infoObject.mbh_cAdd;
                                preCostInfo.pcs_cConsumeType = Common.DefineConstantValue.ConsumeMoneyFlowType.AdvanceMealCost.ToString();
                                preCostInfo.pcs_cRecordID = Guid.NewGuid();
                                preCostInfo.pcs_cSourceID = history.mbh_cRecordID;
                                preCostInfo.pcs_cUserID = history.mbh_cTargetID;
                                preCostInfo.pcs_dAddDate = DateTime.Now;
                                preCostInfo.pcs_dConsumeDate = DateTime.Now;
                                preCostInfo.pcs_fCost = history.mbh_fMealCost;
                                preCostInfo.pcs_lIsSettled = false;
                                db.PreConsumeRecord_pcs.InsertOnSubmit(preCostInfo);

                                db.SubmitChanges();
                                db.Transaction.Commit();
                                rvInfo.boolValue = true;
                                return rvInfo;
                            }
                            else
                            {
                                rvInfo.messageText = "GetEntity is null";
                            }
                            db.Transaction.Rollback();
                            db.Connection.Close();
                        }
                        catch (Exception exx)
                        {
                            db.Transaction.Rollback();
                            db.Connection.Close();
                            throw exx;
                        }
                    }
                }
                else
                {
                    rvInfo.messageText = Common.DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull;
                }
            }
            catch (Exception ex)
            {
                rvInfo.isError = true;
                rvInfo.messageText = ex.Message;
            }
            return rvInfo;
        }
コード例 #7
0
        public ReturnValueInfo InsertBatchRecords(List<MealBookingHistory_mbh_Info> listHistory)
        {
            ReturnValueInfo rvInfo = new ReturnValueInfo();
            try
            {
                if (listHistory == null)
                {
                    rvInfo.messageText = Common.DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull;
                    rvInfo.isError = true;
                    return rvInfo;
                }

                using (SIOTSDB_HHZXDataContext db = new SIOTSDB_HHZXDataContext())
                {
                    try
                    {

                        List<PreConsumeRecord_pcs> listPreMealCost = new List<PreConsumeRecord_pcs>();
                        List<MealBookingHistory_mbh> listHistoryInfo = new List<MealBookingHistory_mbh>();
                        List<MealBookingHistory_mbh_Info> listReturnHistoryInfo = new List<MealBookingHistory_mbh_Info>();

                        DateTime dtMinChkDate = listHistory.Min(x => x.mbh_dMealDate);
                        List<MealBookingHistory_mbh> listChkAll = db.MealBookingHistory_mbh.Where(x => x.mbh_dMealDate.Date >= dtMinChkDate.Date).ToList();

                        foreach (MealBookingHistory_mbh_Info item in listHistory)
                        {
                            MealBookingHistory_mbh hisComp = listChkAll.Where(x =>
                                x.mbh_cMealType == item.mbh_cMealType
                                && x.mbh_cTargetID == item.mbh_cTargetID
                                && x.mbh_dMealDate.Date == item.mbh_dMealDate.Date).FirstOrDefault();
                            if (hisComp != null)//检查到有同一天、同一人、同一餐种的记录,则进行更新操作
                            {
                                hisComp.mbh_fMealCost = item.mbh_fMealCost;//餐费用
                                hisComp.mbh_cAdd = item.mbh_cAdd;
                                hisComp.mbh_cTargetType = item.mbh_cTargetType;//设置源类型
                                hisComp.mbh_dAddDate = item.mbh_dAddDate;
                                hisComp.mbh_lIsSet = item.mbh_lIsSet;//是否定餐
                            }
                            else
                            {
                                //插入新纪录
                                MealBookingHistory_mbh history = Common.General.CopyObjectValue<MealBookingHistory_mbh_Info, MealBookingHistory_mbh>(item);
                                if (history != null)
                                {
                                    history.mbh_dAddDate = DateTime.Now;

                                    //开餐则预添加待付款消费记录
                                    if (history.mbh_lIsSet)
                                    {
                                        CardUserAccount_cua userAccount = db.CardUserAccount_cua.Where(x => x.cua_cCUSID == item.mbh_cTargetID).FirstOrDefault();
                                        if (userAccount == null)
                                        {
                                            rvInfo.messageText = "用户账户信息缺失。";
                                            rvInfo.isError = true;
                                            return rvInfo;
                                        }

                                        //同步插入一条待扣费记录,待餐后收数时再根据收数结果更新此条记录的状态
                                        PreConsumeRecord_pcs preCost = new PreConsumeRecord_pcs();
                                        preCost.pcs_cAccountID = userAccount.cua_cRecordID;
                                        preCost.pcs_cAdd = item.mbh_cAdd;
                                        //类型为【定餐待扣费】
                                        preCost.pcs_cConsumeType = Common.DefineConstantValue.ConsumeMoneyFlowType.AdvanceMealCost.ToString();
                                        preCost.pcs_cRecordID = Guid.NewGuid();
                                        preCost.pcs_cSourceID = item.mbh_cRecordID;
                                        preCost.pcs_cUserID = userAccount.cua_cCUSID;
                                        preCost.pcs_dAddDate = DateTime.Now;
                                        preCost.pcs_dConsumeDate = DateTime.Now;
                                        preCost.pcs_fCost = item.mbh_fMealCost;
                                        listPreMealCost.Add(preCost);
                                    }
                                    #region 多余逻辑
                                    //else
                                    //{
                                    //    //如果原来没有定餐历史记录,且请求添加的历史记录的设置类型为欠款自动停餐时,需要再次检查用户的余额是否正常
                                    //    if (history.mbh_cTargetType == Common.DefineConstantValue.MealType.DebtAuto.ToString())
                                    //    {
                                    //        //查余额
                                    //        CardUserAccount_cua userAccount = db.CardUserAccount_cua.Where(x => x.cua_cCUSID == item.mbh_cTargetID).FirstOrDefault();
                                    //        if (userAccount == null)
                                    //        {
                                    //            rvInfo.messageText = "用户账户信息缺失。";
                                    //            rvInfo.isError = true;
                                    //            return rvInfo;
                                    //        }
                                    //        decimal fBalance = userAccount.cua_fCurrentBalance;

                                    //        RechargeRecord_rcr advanceRecharge = db.RechargeRecord_rcr.Where(x => x.rcr_cUserID == userAccount.cua_cCUSID && x.rcr_cRechargeType == Common.DefineConstantValue.ConsumeMoneyFlowType.Recharge_AdvanceMoney.ToString()).OrderByDescending(x => x.rcr_dRechargeTime).FirstOrDefault();
                                    //        decimal fAdvanceRecharge = decimal.Zero;
                                    //        if (advanceRecharge != null)
                                    //        {
                                    //            fAdvanceRecharge = advanceRecharge.rcr_fRechargeMoney;
                                    //        }

                                    //        decimal fPreCost = decimal.Zero;
                                    //        var query = db.PreConsumeRecord_pcs.Where(x => x.pcs_lIsSettled == false
                                    //    && x.pcs_cConsumeType != Common.DefineConstantValue.ConsumeMoneyFlowType.HedgeFund.ToString()
                                    //    && x.pcs_cConsumeType != Common.DefineConstantValue.ConsumeMoneyFlowType.AdvanceMealCost.ToString()
                                    //    && x.pcs_cConsumeType != Common.DefineConstantValue.ConsumeMoneyFlowType.Recharge_AdvanceMoney.ToString()
                                    //    && x.pcs_cUserID == userAccount.cua_cCUSID);
                                    //        var listQuery = query.ToList();
                                    //        if (listQuery != null && listQuery.Count > 0)
                                    //        {
                                    //            fPreCost = query.Sum(x => x.pcs_fCost);
                                    //        }

                                    //        if ((fBalance + fAdvanceRecharge - Math.Abs(fPreCost)) > 0)
                                    //        {
                                    //            history.mbh_lIsSet = true;

                                    //            //同步插入一条待扣费记录,待餐后收数时再根据收数结果更新此条记录的状态
                                    //            PreConsumeRecord_pcs preCost = new PreConsumeRecord_pcs();
                                    //            preCost.pcs_cAccountID = userAccount.cua_cRecordID;
                                    //            preCost.pcs_cAdd = item.mbh_cAdd;
                                    //            //类型为【定餐待扣费】
                                    //            preCost.pcs_cConsumeType = Common.DefineConstantValue.ConsumeMoneyFlowType.AdvanceMealCost.ToString();
                                    //            preCost.pcs_cRecordID = Guid.NewGuid();
                                    //            preCost.pcs_cSourceID = item.mbh_cRecordID;
                                    //            preCost.pcs_cUserID = userAccount.cua_cCUSID;
                                    //            preCost.pcs_dAddDate = DateTime.Now;
                                    //            preCost.pcs_dConsumeDate = DateTime.Now;
                                    //            preCost.pcs_fCost = item.mbh_fMealCost;
                                    //            listPreMealCost.Add(preCost);

                                    //            MealBookingHistory_mbh_Info mealReturn = Common.General.CopyObjectValue<MealBookingHistory_mbh, MealBookingHistory_mbh_Info>(history);
                                    //            listReturnHistoryInfo.Add(mealReturn);
                                    //        }
                                    //    }
                                    //}

                                    #endregion

                                    listHistoryInfo.Add(history);//最后才添加定餐计划记录
                                }
                            }
                        }

                        db.Connection.Open();
                        db.Transaction = db.Connection.BeginTransaction();

                        if (listHistoryInfo.Count > 0)
                        {
                            db.MealBookingHistory_mbh.InsertAllOnSubmit(listHistoryInfo);
                            db.SubmitChanges();
                        }
                        if (listPreMealCost.Count > 0)
                        {
                            db.PreConsumeRecord_pcs.InsertAllOnSubmit(listPreMealCost);
                            db.SubmitChanges();
                        }

                        db.Transaction.Commit();
                        db.Connection.Close();

                        rvInfo.boolValue = true;
                        rvInfo.ValueObject = listReturnHistoryInfo;
                    }
                    catch (Exception exx)
                    {
                        db.Transaction.Rollback();
                        db.Connection.Close();
                        throw exx;
                    }
                }
            }
            catch (Exception ex)
            {
                rvInfo.isError = true;
                rvInfo.messageText = ex.Message;
            }
            return rvInfo;
        }
コード例 #8
0
ファイル: UserCardPairDA.cs プロジェクト: Klutzdon/SIOTS_HHZX
        public ReturnValueInfo InsertNewCard(UserCardPair_ucp_Info infoObject, decimal dCost)
        {
            ReturnValueInfo rvInfo = new ReturnValueInfo();
            try
            {
                if (infoObject == null)
                {
                    rvInfo.isError = true;
                    rvInfo.messageText = Common.DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull;
                    return rvInfo;
                }
                using (SIOTSDB_HHZXDataContext db = new SIOTSDB_HHZXDataContext())
                {
                    try
                    {
                        db.Connection.Open();
                        db.Transaction = db.Connection.BeginTransaction();

                        ConsumeCardMaster_ccm cardInfo = db.ConsumeCardMaster_ccm.Where(x => x.ccm_cCardID == infoObject.ucp_cCardID).FirstOrDefault();
                        if (cardInfo == null)
                        {
                            //如未有卡主档信息,则添加
                            cardInfo = new ConsumeCardMaster_ccm();
                            cardInfo.ccm_cCardID = infoObject.ucp_cCardID;
                            cardInfo.ccm_cCardState = Common.DefineConstantValue.CardUseState.InUse.ToString();
                            cardInfo.ccm_cAdd = infoObject.ucp_cLast;
                            cardInfo.ccm_dAddDate = DateTime.Now;
                            cardInfo.ccm_cLast = infoObject.ucp_cLast;
                            cardInfo.ccm_dLastDate = DateTime.Now;
                            cardInfo.ccm_lIsActive = true;
                            db.ConsumeCardMaster_ccm.InsertOnSubmit(cardInfo);
                        }
                        else
                        {
                            //如已有卡主档信息,则更新卡的使用状态
                            cardInfo.ccm_cCardState = Common.DefineConstantValue.CardUseState.InUse.ToString();
                            cardInfo.ccm_cLast = infoObject.ucp_cLast;
                            cardInfo.ccm_dLastDate = DateTime.Now;
                        }

                        //检查是否已发卡
                        UserCardPair_ucp pair = db.UserCardPair_ucp.Where(x => x.ucp_cCUSID == infoObject.ucp_cCUSID && x.ucp_cUseStatus == Common.DefineConstantValue.ConsumeCardStatus.Normal.ToString()).FirstOrDefault();
                        if (pair != null)
                        {
                            rvInfo.isError = true;
                            rvInfo.messageText = "本用户已发卡,现用卡号为:" + pair.ucp_iCardNo.ToString();
                            return rvInfo;
                        }

                        pair = Common.General.CopyObjectValue<UserCardPair_ucp_Info, UserCardPair_ucp>(infoObject);
                        if (pair != null)
                        {
                            pair.ucp_dAddDate = DateTime.Now;
                            pair.ucp_dLastDate = DateTime.Now;
                            db.UserCardPair_ucp.InsertOnSubmit(pair);
                            db.SubmitChanges();

                            //查看是否已经创建账户
                            CardUserAccount_cua account = db.CardUserAccount_cua.Where(x => x.cua_cCUSID == pair.ucp_cCUSID).FirstOrDefault();
                            if (account == null)
                            {
                                //如未创建账户,则自动创建
                                account = new CardUserAccount_cua();
                                account.cua_cRecordID = Guid.NewGuid();
                                account.cua_cCUSID = pair.ucp_cCUSID;
                                account.cua_fCurrentBalance = 0;
                                account.cua_fOriginalBalance = 0;
                                account.cua_dLastSyncTime = DateTime.Now;
                                account.cua_lIsActive = true;
                                account.cua_cAdd = pair.ucp_cAdd;
                                account.cua_dAddDate = DateTime.Now;
                                db.CardUserAccount_cua.InsertOnSubmit(account);
                                db.SubmitChanges();
                            }
                            decimal fFormula = -1;
                            CodeMaster_cmt codeFormula = db.CodeMaster_cmt.Where(x => x.cmt_cKey1 == Common.DefineConstantValue.EnumFormulaKey.PRECOSTFORMULA.ToString() && x.cmt_cKey2 == Common.DefineConstantValue.ConsumeMoneyFlowType.NewCardCost.ToString()).FirstOrDefault();
                            if (codeFormula != null)
                            {
                                fFormula = codeFormula.cmt_fNumber;
                            }
                            //account.cua_fCurrentBalance += dCost * fFormula;
                            //account.cua_dLastSyncTime = DateTime.Now;
                            //db.SubmitChanges();

                            //插入【预消费记录】

                            PreConsumeRecord_pcs preConsume = new PreConsumeRecord_pcs();
                            preConsume.pcs_cAccountID = account.cua_cRecordID;
                            preConsume.pcs_cRecordID = Guid.NewGuid();
                            preConsume.pcs_cUserID = infoObject.ucp_cCUSID;
                            preConsume.pcs_cConsumeType = Common.DefineConstantValue.ConsumeMoneyFlowType.NewCardCost.ToString();
                            preConsume.pcs_dConsumeDate = DateTime.Now;
                            preConsume.pcs_fCost = dCost;
                            preConsume.pcs_cAdd = pair.ucp_cAdd;
                            preConsume.pcs_dAddDate = DateTime.Now;
                            if (dCost == 0)
                            {
                                preConsume.pcs_lIsSettled = true;
                                preConsume.pcs_dSettleTime = DateTime.Now;
                            }
                            else
                            {
                                preConsume.pcs_lIsSettled = false;
                            }
                            preConsume.pcs_cSourceID = pair.ucp_cRecordID;
                            db.PreConsumeRecord_pcs.InsertOnSubmit(preConsume);
                            db.SubmitChanges();

                            db.Transaction.Commit();
                            rvInfo.boolValue = true;

                        }
                        else
                        {
                            rvInfo.isError = true;
                            rvInfo.messageText = Common.DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull;
                            return rvInfo;
                        }
                    }
                    catch (Exception exx)
                    {
                        db.Transaction.Rollback();
                        db.Connection.Close();
                        throw exx;
                    }
                }
            }
            catch (Exception ex)
            {
                rvInfo.isError = true;
                rvInfo.messageText = ex.Message;
            }
            return rvInfo;
        }
コード例 #9
0
ファイル: UserCardPairDA.cs プロジェクト: Klutzdon/SIOTS_HHZX
        public ReturnValueInfo InsertExchargeCard(UserCardPair_ucp_Info infoObject, decimal dCost)
        {
            ReturnValueInfo rvInfo = new ReturnValueInfo();
            try
            {
                if (infoObject != null)
                {
                    using (SIOTSDB_HHZXDataContext db = new SIOTSDB_HHZXDataContext())
                    {
                        db.Connection.Open();
                        db.Transaction = db.Connection.BeginTransaction();
                        try
                        {
                            UserCardPair_ucp pair = Common.General.CopyObjectValue<UserCardPair_ucp_Info, UserCardPair_ucp>(infoObject);
                            if (pair != null)
                            {
                                db.UserCardPair_ucp.InsertOnSubmit(pair);
                                db.SubmitChanges();

                                // 用户账户不存在时,自动创建对应账户信息
                                CardUserAccount_cua accountInfo = db.CardUserAccount_cua.Where(x => x.cua_cCUSID == pair.ucp_cCUSID).FirstOrDefault();
                                if (accountInfo == null)
                                {
                                    accountInfo = new CardUserAccount_cua();
                                    accountInfo.cua_cCUSID = pair.ucp_cCUSID;
                                    accountInfo.cua_cRecordID = Guid.NewGuid();
                                    accountInfo.cua_cAdd = pair.ucp_cLast;
                                    accountInfo.cua_dAddDate = DateTime.Now;
                                    accountInfo.cua_dLastSyncTime = DateTime.Now;
                                    accountInfo.cua_fCurrentBalance = 0;
                                    accountInfo.cua_fOriginalBalance = 0;
                                    accountInfo.cua_lIsActive = true;

                                    db.CardUserAccount_cua.InsertOnSubmit(accountInfo);
                                    db.SubmitChanges();
                                }

                                //插入【预消费记录】
                                PreConsumeRecord_pcs preConsume = new PreConsumeRecord_pcs();
                                preConsume.pcs_cAccountID = accountInfo.cua_cRecordID;
                                preConsume.pcs_cRecordID = Guid.NewGuid();
                                preConsume.pcs_cUserID = infoObject.ucp_cCUSID;
                                preConsume.pcs_cConsumeType = Common.DefineConstantValue.ConsumeMoneyFlowType.ReplaceCardCost.ToString();
                                preConsume.pcs_dConsumeDate = DateTime.Now;
                                preConsume.pcs_fCost = dCost;
                                if (dCost == 0)
                                {
                                    preConsume.pcs_lIsSettled = true;
                                    preConsume.pcs_dSettleTime = DateTime.Now;
                                }
                                else
                                {
                                    preConsume.pcs_lIsSettled = false;
                                }
                                preConsume.pcs_cAdd = pair.ucp_cAdd;
                                preConsume.pcs_cSourceID = pair.ucp_cRecordID;
                                preConsume.pcs_dAddDate = DateTime.Now;
                                preConsume.pcs_cSourceID = pair.ucp_cRecordID;
                                db.PreConsumeRecord_pcs.InsertOnSubmit(preConsume);
                                db.SubmitChanges();

                                db.Transaction.Commit();

                                rvInfo.boolValue = true;
                                rvInfo.ValueObject = Common.General.CopyObjectValue<UserCardPair_ucp, UserCardPair_ucp_Info>(pair);
                            }
                            else
                            {
                                rvInfo.messageText = "TransEntity is null";
                                db.Transaction.Rollback();
                            }
                        }
                        catch (Exception exx)
                        {
                            db.Transaction.Rollback();
                            throw exx;
                        }
                    }
                }
                else
                {
                    rvInfo.messageText = Common.DefineConstantValue.SystemMessageText.strMessageText_E_ObjectNull;
                }
            }
            catch (Exception ex)
            {
                rvInfo.isError = true;
                rvInfo.messageText = ex.Message;
            }
            return rvInfo;
        }