/// <summary> /// 增 /// </summary> /// <param name="model"></param> /// <returns></returns> public JsonRsp Add(ChargeCardsModel model) { model.ChargeCardNo = "H" + model.CustomId + DateTime.Now.ToString("yyyyMMddHHmmss"); //开启事务 PWMIS.DataProvider.Data.AdoHelper db = PWMIS.DataProvider.Adapter.MyDB.GetDBHelper(); int returnvalue = 0; try { db.BeginTransaction(); //客户财务信息操作 //获取当前客户财务信息 CustomFinancialModel financialModel = OQL.FromObject <CustomFinancialModel>().Select().Where((cmp, m) => cmp.Comparer(m.CustomId, "=", model.CustomId) & cmp.Comparer(m.TenantId, "=", TenantId)).END.ToObject(db); if (financialModel == null) { db.Rollback(); return(new JsonRsp { success = false, retmsg = "获取客户合同信息失败" }); } decimal amount = model.CurrentAmount; string remark = "客户充卡"; if (model.MoneyType == (int)MoneyTypeEnum.应收) { if (financialModel.MoneyTypeOneAmount < amount) { db.Rollback(); return(new JsonRsp { success = false, retmsg = "余额只有" + financialModel.MoneyTypeOneAmount + "" }); } financialModel.MoneyTypeOneAmount -= amount; CustomFinancialDetailModel financialDetail = new CustomFinancialDetailModel(); financialDetail.CustomFinancialId = financialModel.ID; financialDetail.FinanciaOpeType = (int)FinanciaOpeTypeEnum.减少; financialDetail.Remark = remark; financialDetail.MoneyType = (int)BaseEnum.MoneyTypeEnum.应收; financialDetail.CurrentAmount = amount; financialDetail.Balance = financialModel.MoneyTypeOneAmount; returnvalue += Add <CustomFinancialDetailModel>(financialDetail, db); } else if (model.MoneyType == (int)BaseEnum.MoneyTypeEnum.赠送) { if (financialModel.MoneyTypeTwoAmount < amount) { db.Rollback(); return(new JsonRsp { success = false, retmsg = "余额只有" + financialModel.MoneyTypeTwoAmount + "" }); } financialModel.MoneyTypeTwoAmount -= amount; CustomFinancialDetailModel financialDetail = new CustomFinancialDetailModel(); financialDetail.CustomFinancialId = financialModel.ID; financialDetail.FinanciaOpeType = (int)FinanciaOpeTypeEnum.减少; financialDetail.Remark = remark; financialDetail.MoneyType = (int)BaseEnum.MoneyTypeEnum.赠送; financialDetail.CurrentAmount = amount; financialDetail.Balance = financialModel.MoneyTypeTwoAmount;; returnvalue += Add <CustomFinancialDetailModel>(financialDetail, db); } else if (model.MoneyType == (int)BaseEnum.MoneyTypeEnum.置换) { if (financialModel.MoneyTypeThreeAmount < amount) { db.Rollback(); return(new JsonRsp { success = false, retmsg = "余额只有" + financialModel.MoneyTypeThreeAmount + "" }); } financialModel.MoneyTypeThreeAmount -= amount; CustomFinancialDetailModel financialDetail = new CustomFinancialDetailModel(); financialDetail.CustomFinancialId = financialModel.ID; financialDetail.FinanciaOpeType = (int)FinanciaOpeTypeEnum.减少; financialDetail.Remark = remark; financialDetail.MoneyType = (int)BaseEnum.MoneyTypeEnum.置换; financialDetail.CurrentAmount = amount; financialDetail.Balance = financialModel.MoneyTypeThreeAmount; returnvalue += Add <CustomFinancialDetailModel>(financialDetail, db); } returnvalue += Update <CustomFinancialModel>(financialModel, db); returnvalue += Add <ChargeCardsModel>(model, db); //新增客户应付 CustomAccReceiptModel customAR = new CustomAccReceiptModel(); customAR.CustomId = model.CustomId; customAR.ChargeCardNo = model.ChargeCardNo; customAR.CurrentAmount = model.MoneyType == (int)MoneyTypeEnum.应收 ? model.CurrentAmount : 0; customAR.Status = (int)ARStatusEnum.已确认; customAR.CreateId = AdminId; customAR.CreateUser = AdminName; customAR.CreateIP = Util.GetLocalIP; customAR.CreateTime = DateTime.Now; returnvalue += Add <CustomAccReceiptModel>(customAR, db); //事务提交 if (returnvalue == 4) { db.Commit(); } else { returnvalue = 0; db.Rollback(); } } catch (Exception ex) { //事务回滚 db.Rollback(); return(new JsonRsp { success = false, retmsg = ex.Message.ToString() }); } return(new JsonRsp { success = returnvalue > 0, code = returnvalue }); }
/// <summary> /// 审核 /// </summary> /// <param name="model"></param> /// <returns></returns> public JsonRsp Audit(long[] Ids, int status) { #region if (Ids == null) { return(new JsonRsp { success = false, retmsg = "请选择要操作的数据" }); } int returnvalue = 0; PWMIS.DataProvider.Data.AdoHelper db = PWMIS.DataProvider.Adapter.MyDB.GetDBHelper(); try { //开始事务 db.BeginTransaction(); //更新状态 ContractModel model = new ContractModel(); OQL qList = OQL.From(model) .Select() .OrderBy(model.Sort, "asc") .END; List <ContractModel> items = qList.ToList <ContractModel>(); foreach (ContractModel item in items) { if (item.Status != 0) { return(new JsonRsp { success = false, retmsg = "只能审核待审核合同,该合同当前状态为:" + Util.getStatus(item.Status, typeof(BaseEnum.ProtocolTypeEnum)) }); } //更新合同状态 item.Status = status; returnvalue += Update <ContractModel>(item, db, false); string remark = "合同/协议号:" + item.ContractNo + "审核通过"; //获取当前客户财务信息 CustomFinancialModel financialModel = OQL.FromObject <CustomFinancialModel>().Select().Where((cmp, m) => cmp.Comparer(m.CustomId, "=", item.CustomId) & cmp.Comparer(m.TenantId, "=", item.TenantId)).END.ToObject(db); if (financialModel == null) { financialModel = new CustomFinancialModel(); //客户财务信息初始化 financialModel.CustomId = item.CustomId; financialModel.MoneyTypeOneAmount = item.MoneyTypeOneAmount; financialModel.MoneyTypeOneTotalAmount = item.MoneyTypeOneAmount; financialModel.MoneyTypeTwoAmount = item.MoneyTypeTwoAmount; financialModel.MoneyTypeTwoTotalAmount = item.MoneyTypeTwoAmount; financialModel.MoneyTypeThreeAmount = item.MoneyTypeThreeAmount; financialModel.MoneyTypeThreeTotalAmount = item.MoneyTypeThreeAmount; financialModel.Status = 1; returnvalue += Add <CustomFinancialModel>(financialModel, db); } else { //客户财务信息修改 financialModel.CustomId = item.CustomId; financialModel.MoneyTypeOneAmount += item.MoneyTypeOneAmount; financialModel.MoneyTypeOneTotalAmount += item.MoneyTypeOneAmount; financialModel.MoneyTypeTwoAmount += item.MoneyTypeTwoAmount; financialModel.MoneyTypeTwoTotalAmount += item.MoneyTypeTwoAmount; financialModel.MoneyTypeThreeAmount += item.MoneyTypeThreeAmount; financialModel.MoneyTypeThreeTotalAmount += item.MoneyTypeThreeAmount; financialModel.Status = 1; returnvalue += Update <CustomFinancialModel>(financialModel, db); } //新增客户财务信息日志 //应收明细 CustomFinancialDetailModel financialDetailOne = new CustomFinancialDetailModel(); financialDetailOne.CustomFinancialId = financialModel.ID; financialDetailOne.FinanciaOpeType = (int)FinanciaOpeTypeEnum.增加; financialDetailOne.CurrentAmount += item.MoneyTypeOneAmount; financialDetailOne.Balance += item.MoneyTypeOneAmount; financialDetailOne.Remark = remark; financialDetailOne.Status = 1; financialDetailOne.MoneyType = (int)BaseEnum.MoneyTypeEnum.应收; returnvalue += Add <CustomFinancialDetailModel>(financialDetailOne, db); //赠送明细 CustomFinancialDetailModel financialDetailTwo = new CustomFinancialDetailModel(); financialDetailTwo.CustomFinancialId = financialModel.ID; financialDetailTwo.FinanciaOpeType = (int)FinanciaOpeTypeEnum.增加; financialDetailTwo.CurrentAmount += item.MoneyTypeTwoAmount; financialDetailTwo.Balance += item.MoneyTypeTwoAmount; financialDetailTwo.Remark = remark; financialDetailTwo.Status = 1; financialDetailTwo.MoneyType = (int)BaseEnum.MoneyTypeEnum.赠送; returnvalue += Add <CustomFinancialDetailModel>(financialDetailTwo, db); //置换明细 CustomFinancialDetailModel financialDetailThree = new CustomFinancialDetailModel(); financialDetailThree.CustomFinancialId = financialModel.ID; financialDetailThree.FinanciaOpeType = (int)FinanciaOpeTypeEnum.增加; financialDetailThree.CurrentAmount += item.MoneyTypeThreeAmount; financialDetailThree.Balance += item.MoneyTypeThreeAmount; financialDetailThree.Remark = remark; financialDetailThree.Status = 1; financialDetailThree.MoneyType = (int)BaseEnum.MoneyTypeEnum.置换; returnvalue += Add <CustomFinancialDetailModel>(financialDetailThree); //事务提交 if (returnvalue == 5) { db.Commit(); } else { returnvalue = 0; db.Rollback(); } } } catch (Exception ex) { //事务回滚 db.Rollback(); return(new JsonRsp { success = false, retmsg = ex.Message.ToString() }); } return(new JsonRsp { success = returnvalue > 0, code = returnvalue }); #endregion }