DecreasePaymentsRepository.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. using AutoMapper;
  2. using NPOI.SS.Formula.Functions;
  3. using OASystem.Domain;
  4. using OASystem.Domain.Dtos.Groups;
  5. using OASystem.Domain.Entities.Financial;
  6. using OASystem.Domain.Entities.Groups;
  7. using OASystem.Domain.Entities.Resource;
  8. using OASystem.Domain.ViewModels.Financial;
  9. using OASystem.Domain.ViewModels.Groups;
  10. using OASystem.Domain.ViewModels.QiYeWeChat;
  11. using OASystem.Domain.ViewModels.Resource;
  12. using OASystem.Infrastructure.Repositories.System;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Runtime.Intrinsics.Arm;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. namespace OASystem.Infrastructure.Repositories.Groups
  20. {
  21. public class DecreasePaymentsRepository : BaseRepository<Grp_DecreasePayments, Grp_DecreasePayments>
  22. {
  23. private readonly IMapper _mapper;
  24. private readonly TeamRateRepository _teamRateRep;
  25. private readonly SetDataRepository _setDataRepository;
  26. public DecreasePaymentsRepository(SqlSugarClient sqlSugar, IMapper mapper, TeamRateRepository teamRateRep, SetDataRepository setDataRepository )
  27. : base(sqlSugar)
  28. {
  29. this._mapper = mapper;
  30. _teamRateRep = teamRateRep;
  31. this._setDataRepository = setDataRepository;
  32. }
  33. /// <summary>
  34. /// 根据团组Id查询数据
  35. /// </summary>
  36. /// <param name="dto"></param>
  37. /// <returns></returns>
  38. public async Task<JsonView> DecreasePaymentsList(DecreasePaymentsListDto dto)
  39. {
  40. string sqlWhere = "";
  41. if (dto.IsPaySign != -1)
  42. {
  43. sqlWhere += string.Format(@" And ccp.IsPay = {0} ", dto.IsPaySign);
  44. }
  45. //雷怡 2024-5-8 15:14 新增View字段 CreateTime
  46. string sql = string.Format(@" Select gdp.Id,gdp.DiId,gdp.PriceName,gdp.FeeTotal,sd1.[Name] as Currency,gdp.FilePath,su.CnName as CreateUserName,
  47. ccp.IsAuditGM as isAudit,ccp.IsPay,gdp.CreateTime
  48. From Grp_DecreasePayments as gdp With(Nolock) Left Join Grp_CreditCardPayment as ccp With(Nolock) On gdp.Id = ccp.CId
  49. Left Join Sys_SetData as sd1 On gdp.Currency = sd1.Id
  50. Left Join Sys_Users as su On gdp.CreateUserId = su.Id
  51. Where gdp.DiId = {0} And ccp.CTable = 98 {2} And ccp.IsDel = 0 And gdp.IsDel = 0 And gdp.CreateUserId in ({1}) ", dto.DiId, dto.UserId, sqlWhere);
  52. List<DecreasePaymentsView> _DecreasePayments = await _sqlSugar.SqlQueryable<DecreasePaymentsView>(sql).ToListAsync();
  53. return new JsonView() { Code = 200, Msg = MsgTips.Succeed, Data = _DecreasePayments };
  54. }
  55. public async Task<JsonView> DecreasePaymentsSelect(DecreasePaymentsDto dto)
  56. {
  57. #region 团组下拉框
  58. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  59. string DiId = "";
  60. List<DecreasePaymentGroupView> _Delegations = new List<DecreasePaymentGroupView>();
  61. if (grp_GroupsTaskAssignment.Count > 0)
  62. {
  63. foreach (var item in grp_GroupsTaskAssignment)
  64. {
  65. DiId += item.DIId + ",";
  66. }
  67. if (DiId != "0")
  68. {
  69. DiId = DiId.Substring(0, DiId.Length - 1);
  70. }
  71. string sql = string.Format($@"Select
  72. (select ssd.name from Sys_SetData ssd WHERE ssd.id = di.TeamLevSId) as TeamLevSId,
  73. di.Id,
  74. di.TeamName,
  75. di.ClientUnit,
  76. di.ClientName,
  77. di.TourCode,
  78. di.TeamDid,
  79. sd.[Name] As TeamTypeName,
  80. di.VisitCountry,
  81. di.VisitStartDate,
  82. di.VisitEndDate,
  83. di.VisitDays,
  84. di.VisitPNumber,
  85. di.CreateTime
  86. From Grp_DelegationInfo di With(NoLock)
  87. Left Join Sys_SetData sd On di.TeamDid = sd.Id
  88. Where di.Id in({DiId}) and di.IsDel=0
  89. Order By di.CreateTime Desc");
  90. //DecreasePaymentGroupView
  91. _Delegations = _sqlSugar.SqlQueryable<DecreasePaymentGroupView>(sql).ToList();
  92. }
  93. #endregion
  94. #region 其他下拉框查询
  95. //支付方式
  96. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  97. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  98. //供应商 supplier
  99. List<Sys_SetData> supplier = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 21 && a.IsDel == 0).ToList();
  100. List<SetDataInfoView> _supplier = _mapper.Map<List<SetDataInfoView>>(supplier);
  101. if (_supplier.Count > 0)
  102. {
  103. var d1 = _supplier.Find(it => it.Name.Equals("策划 公司"));
  104. if (d1 != null) _supplier.Remove(d1);
  105. var d2 = _supplier.Find(it => it.Name.Equals("礼仪"));
  106. if (d2 != null) _supplier.Remove(d2);
  107. var d3 = _supplier.Find(it => it.Name.Equals("日常办公用品"));
  108. if (d3 != null) _supplier.Remove(d3);
  109. var d4 = _supplier.Find(it => it.Name.Equals("其他"));
  110. if (d4 != null)
  111. {
  112. _supplier.Remove(d4);
  113. _supplier.Add(d4);
  114. }
  115. }
  116. List<dynamic> _supplierArea = new List<dynamic>() {
  117. new { id=1,name = "国内" },
  118. new { id=2,name = "国外" },
  119. };
  120. #endregion
  121. var data = new
  122. {
  123. payment = _Payment,
  124. groupName = _Delegations,
  125. supplier = _supplier,
  126. supplierArea = _supplierArea
  127. };
  128. return new JsonView() { Code = 200, Msg = MsgTips.Succeed, Data = data };
  129. }
  130. public async Task<JsonView> OpDecreasePayments(DecreasePaymentsOpDto dto)
  131. {
  132. BeginTran();
  133. int id = 0;
  134. var grp_Decrease = _mapper.Map<Grp_DecreasePayments>(dto);
  135. //处理费用总计
  136. if (grp_Decrease.FeeTotal == 0.00M)
  137. {
  138. grp_Decrease.FeeTotal = grp_Decrease.Price * grp_Decrease.Price;
  139. }
  140. List<TeamRateDescAddCurrencyIdView> teamRates = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, dto.DiId, 98);
  141. if (dto.Status == 1)//添加
  142. {
  143. string selectSql = string.Format(@"select * from Grp_DecreasePayments where PriceName='{0}' and IsDel={1} and DiId={2}"
  144. , dto.PriceName, 0, dto.DiId);
  145. var DecreasePayments = await _sqlSugar.SqlQueryable<Grp_DecreasePayments>(selectSql).FirstAsync();//查询是否存在
  146. if (DecreasePayments != null)
  147. {
  148. return new JsonView() { Code = 400, Msg = "该数据已存在,请勿重复添加!" };
  149. }
  150. else//不存在,可添加
  151. {
  152. id = await AddAsyncReturnId(grp_Decrease);
  153. if (id < 1)
  154. {
  155. RollbackTran();
  156. return new JsonView() { Code = 400, Msg = "添加失败!" };
  157. }
  158. //进行C表添加
  159. Grp_CreditCardPayment C = new Grp_CreditCardPayment();
  160. C.PayDId = dto.PayDId;
  161. C.ConsumptionPatterns = "";
  162. C.ConsumptionDate = "";
  163. C.CTDId = 0;
  164. C.BankNo = "";
  165. C.CardholderName = "";
  166. C.PayMoney = grp_Decrease.FeeTotal;
  167. C.PaymentCurrency = grp_Decrease.Currency;
  168. //当天汇率
  169. //if (!string.IsNullOrEmpty(hfRate.Value))
  170. // C.DayRate = hfRate.Value;
  171. //else
  172. //C.DayRate = "";
  173. C.CompanyBankNo = "";
  174. C.OtherBankName = dto.OtherBankName;
  175. C.OtherSideNo = dto.OtherSideNo;
  176. C.OtherSideName = dto.OtherSideName;
  177. C.Remark = "";
  178. C.CreateUserId = grp_Decrease.CreateUserId;
  179. C.MFOperator = 0;
  180. C.MFOperatorDate = "";
  181. C.IsAuditDM = 0;
  182. C.AuditDMOperate = 0;
  183. C.AuditDMDate = "";
  184. C.IsAuditMF = 0;
  185. C.AuditMFOperate = 0;
  186. C.AuditMFDate = "";
  187. C.IsAuditGM = 0;
  188. C.AuditGMOperate = 21;
  189. C.AuditGMDate = "";
  190. //注释 刷卡 = 已支付状态
  191. if (C.PayDId == 72) C.IsPay = 1;
  192. else C.IsPay = 0;
  193. C.DIId = grp_Decrease.DiId;
  194. C.CId = id;
  195. C.CTable = 98;
  196. C.PayPercentage = 100;
  197. C.PayThenMoney = 0;
  198. C.PayPercentageOld = 0;
  199. C.PayThenMoneyOld = 0;
  200. C.UpdateDate = "";
  201. C.Payee = dto.SupplierName;
  202. C.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  203. C.ExceedBudget = 0;
  204. //C.RMBPrice = 0.00f;
  205. //设置该团组的汇率
  206. var teamRate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
  207. //Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == grp_Decrease.DiId && a.IsDel == 0 && a.CTable == 98);
  208. if (teamRate != null)
  209. {
  210. if (teamRate.CurrencyCode.Equals("CNY"))
  211. {
  212. C.DayRate = 1.0000M;
  213. C.RMBPrice = C.PayMoney;
  214. }
  215. else
  216. {
  217. C.DayRate = teamRate.Rate;
  218. C.RMBPrice = C.PayMoney * C.DayRate;
  219. }
  220. }
  221. else
  222. {
  223. RollbackTran();
  224. return new JsonView() { Code = 400, Msg = $"添加失败!团组汇率未设置{_sqlSugar.Queryable<Sys_SetData>().First(it => it.IsDel == 0 && it.Id == grp_Decrease.Currency)?.Name ?? ""}该币种汇率!" };
  225. }
  226. int cId = await _sqlSugar.Insertable(C).ExecuteReturnIdentityAsync();
  227. if (cId != 0)
  228. {
  229. CommitTran();
  230. var data = new { ccpId = cId, sign = 1,dataId = id };
  231. return new JsonView() { Code = 200, Msg = "添加成功!", Data = data };
  232. }
  233. else
  234. {
  235. RollbackTran();
  236. return new JsonView() { Code = 400, Msg = "添加失败!" };
  237. }
  238. }
  239. }
  240. else if (dto.Status == 2)
  241. {
  242. bool res = await UpdateAsync(a => a.Id == grp_Decrease.Id, a => new Grp_DecreasePayments
  243. {
  244. DiId = grp_Decrease.DiId,
  245. SupplierArea = grp_Decrease.SupplierArea,
  246. SupplierTypeId = grp_Decrease.SupplierTypeId,
  247. SupplierName = grp_Decrease.SupplierName,
  248. SupplierContact = grp_Decrease.SupplierContact,
  249. SupplierContactNumber = grp_Decrease.SupplierContactNumber,
  250. SupplierSocialAccount = grp_Decrease.SupplierSocialAccount,
  251. SupplierEmail = grp_Decrease.SupplierEmail,
  252. SupplierAddress = grp_Decrease.SupplierAddress,
  253. PriceName = grp_Decrease.PriceName,
  254. Price = grp_Decrease.Price,
  255. Quantity = grp_Decrease.Quantity,
  256. FeeTotal = grp_Decrease.FeeTotal,
  257. Currency = grp_Decrease.Currency,
  258. FilePath = grp_Decrease.FilePath,
  259. OTAOrderNo = grp_Decrease.OTAOrderNo,
  260. Remark = grp_Decrease.Remark,
  261. });
  262. if (res)
  263. {
  264. var grp_CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == grp_Decrease.Id && a.CTable == 98 && a.CId == grp_Decrease.Id && a.IsDel == 0);
  265. if (grp_CreditCardPayment != null)
  266. {
  267. //设置该团组的汇率
  268. var teamRate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
  269. if (teamRate != null)
  270. {
  271. if (teamRate.CurrencyCode.Equals("CNY"))
  272. {
  273. grp_CreditCardPayment.DayRate = 1.0000M;
  274. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney;
  275. }
  276. else
  277. {
  278. grp_CreditCardPayment.DayRate = teamRate.Rate;
  279. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney * grp_CreditCardPayment.DayRate;
  280. }
  281. }
  282. else
  283. {
  284. RollbackTran();
  285. return new JsonView() { Code = 400, Msg = "修改失败!" };
  286. }
  287. int ispay = 0;
  288. if (dto.PayDId == 72) ispay = 1;
  289. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  290. .Where(a => a.Id == grp_CreditCardPayment.Id)
  291. .SetColumns(a => new Grp_CreditCardPayment
  292. {
  293. OtherSideName = dto.OtherSideName,
  294. OtherSideNo = dto.OtherSideNo,
  295. OtherBankName = dto.OtherBankName,
  296. PayDId = dto.PayDId,
  297. IsPay = ispay,
  298. PayMoney = grp_Decrease.FeeTotal,
  299. PaymentCurrency = grp_Decrease.Currency,
  300. Payee = dto.SupplierName,
  301. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  302. DayRate = grp_CreditCardPayment.DayRate,
  303. RMBPrice = grp_CreditCardPayment.RMBPrice,
  304. //IsAuditGM = auto ? 3 : grp_CreditCardPayment.IsAuditGM
  305. })
  306. .ExecuteCommandAsync();
  307. if (CTable > 0)
  308. {
  309. CommitTran();
  310. var data = new { ccpId = grp_CreditCardPayment.Id, sign = 2,dataId = grp_Decrease.Id };
  311. return new JsonView() { Code = 200, Msg = "修改成功!", Data = data };
  312. }
  313. }
  314. }
  315. RollbackTran();
  316. return new JsonView() { Code = 400, Msg = "修改失败!" };
  317. }
  318. RollbackTran();
  319. return new JsonView() { Code = 400, Msg = MsgTips.Fail }; ;
  320. }
  321. public async Task<Result> PostGroupNameAndEasy(DecreasePaymentsDto dto)
  322. {
  323. Result result = new Result() { Code = -2, Msg = "未知错误" };
  324. try
  325. {
  326. #region 团组下拉框
  327. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  328. string DiId = "";
  329. foreach (var item in grp_GroupsTaskAssignment)
  330. {
  331. DiId += item.DIId + ",";
  332. }
  333. if (!string.IsNullOrWhiteSpace(DiId))
  334. {
  335. DiId = DiId.Substring(0, DiId.Length - 1);
  336. }
  337. else
  338. {
  339. DiId = "0";
  340. }
  341. string sql = string.Format(@"select Id,TourCode,TeamName,ClientName,VisitStartDate,VisitEndDate,VisitCountry,VisitDays,VisitPNumber from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  342. List<DelegationEasyView> grp_Delegations = _sqlSugar.SqlQueryable<DelegationEasyView>(sql).ToList();
  343. if (grp_Delegations.Count != 0)
  344. {
  345. int count = grp_Delegations.Count;
  346. float totalPage = (float)count / dto.PageSize;//总页数
  347. if (totalPage == 0) totalPage = 1;
  348. else totalPage = (int)Math.Ceiling((double)totalPage);
  349. List<DelegationEasyView> delegationEasyViews = new List<DelegationEasyView>();
  350. for (int i = 0; i < dto.PageSize; i++)
  351. {
  352. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  353. if (RowIndex < grp_Delegations.Count)
  354. {
  355. delegationEasyViews.Add(grp_Delegations[RowIndex]);
  356. }
  357. else
  358. {
  359. break;
  360. }
  361. }
  362. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  363. rst.DataList = delegationEasyViews;
  364. rst.DataCount = count;
  365. rst.CurrPageIndex = dto.PageIndex;
  366. rst.CurrPageSize = dto.PageSize;
  367. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  368. }
  369. else
  370. {
  371. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  372. rst.DataList = new List<DelegationEasyView>();
  373. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = rst };
  374. }
  375. #endregion
  376. }
  377. catch (Exception ex)
  378. {
  379. return result = new Result() { Code = -2, Msg = "程序错误" };
  380. throw;
  381. }
  382. }
  383. /// <summary>
  384. /// 根据团组增减款项表Id查询数据
  385. /// </summary>
  386. /// <param name="dto"></param>
  387. /// <returns></returns>
  388. /// <exception cref="NotImplementedException"></exception>
  389. public async Task<JsonView> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
  390. {
  391. string sql = string.Format($@"Select
  392. dp.Id,
  393. dp.DiId,
  394. dp.SupplierArea,
  395. dp.SupplierTypeId,
  396. dp.SupplierName,
  397. dp.SupplierContact,
  398. dp.SupplierContactNumber,
  399. dp.SupplierSocialAccount,
  400. dp.SupplierEmail,
  401. dp.SupplierAddress,
  402. dp.PriceName,
  403. dp.Price,
  404. dp.Quantity,
  405. dp.FeeTotal,
  406. dp.Currency,
  407. dp.FilePath,
  408. dp.OTAOrderNo,
  409. dp.Remark,
  410. ccp.PayDId,
  411. ccp.OrbitalPrivateTransfer,
  412. ccp.OtherBankName,
  413. ccp.OtherSideName,
  414. ccp.OtherSideNo,
  415. ccp.IsAuditGM
  416. From Grp_DecreasePayments dp With(NoLock)
  417. Left Join Grp_CreditCardPayment ccp With(NoLock) On dp.Id = ccp.CId And dp.DiId = ccp.DIId And ccp.CTable = 98
  418. Where dp.IsDel = 0 And dp.Id = {dto.Id}");
  419. var info = await _sqlSugar.SqlQueryable<DecreasePaymentsInfoView>(sql).FirstAsync();
  420. return new JsonView() { Code = 200, Msg = MsgTips.Succeed, Data = info };
  421. }
  422. /// <summary>
  423. /// Del
  424. /// </summary>
  425. /// <param name="dto"></param>
  426. /// <returns></returns>
  427. /// <exception cref="NotImplementedException"></exception>
  428. public async Task<Result> _Del(int id, int userId)
  429. {
  430. Result result = new Result() { Code = -2, Msg = "删除失败!" };
  431. _sqlSugar.BeginTran();
  432. var del = await _sqlSugar.Updateable<Grp_DecreasePayments>()
  433. .SetColumns(it => new Grp_DecreasePayments()
  434. {
  435. IsDel = 1,
  436. DeleteUserId = userId,
  437. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  438. }).Where(it => it.Id == id)
  439. .ExecuteCommandAsync();
  440. if (del > 0)
  441. {
  442. var del1 = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  443. .SetColumns(a => new Grp_CreditCardPayment()
  444. {
  445. IsDel = 1,
  446. DeleteUserId = userId,
  447. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  448. })
  449. .Where(a => a.CId == id && a.CTable == 98)
  450. .ExecuteCommandAsync();
  451. if (del1 > 0)
  452. {
  453. _sqlSugar.CommitTran();
  454. result.Code = 0;
  455. result.Msg = "删除成功!";
  456. return result;
  457. }
  458. }
  459. _sqlSugar.RollbackTran();
  460. return result;
  461. }
  462. }
  463. }