DecreasePaymentsRepository.cs 22 KB

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