PaymentRefundAndOtherMoneyRepository.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. using AutoMapper;
  2. using Newtonsoft.Json;
  3. using NPOI.SS.Formula.Functions;
  4. using OASystem.Domain;
  5. using OASystem.Domain.Dtos;
  6. using OASystem.Domain.Dtos.Financial;
  7. using OASystem.Domain.Dtos.UserDto;
  8. using OASystem.Domain.Entities.Financial;
  9. using OASystem.Domain.Entities.Groups;
  10. using OASystem.Domain.ViewModels.Financial;
  11. using OASystem.Infrastructure.Repositories.Groups;
  12. using OASystem.Infrastructure.Repositories.System;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Security.Cryptography;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. namespace OASystem.Infrastructure.Repositories.Financial
  20. {
  21. /// <summary>
  22. /// 财务 - 收款退还与其他款项
  23. /// </summary>
  24. public class PaymentRefundAndOtherMoneyRepository:BaseRepository<Fin_PaymentRefundAndOtherMoney, Fin_PaymentRefundAndOtherMoneyView>
  25. {
  26. private readonly IMapper _mapper;
  27. private readonly Result _result;
  28. private readonly SetDataRepository _setDataRep;
  29. private readonly TeamRateRepository _teamRateRep;
  30. /// <summary>
  31. /// 初始化
  32. /// </summary>
  33. /// <param name="sqlSugar"></param>
  34. /// <param name="mapper"></param>
  35. public PaymentRefundAndOtherMoneyRepository(SqlSugarClient sqlSugar, IMapper mapper, SetDataRepository setDataRep, TeamRateRepository teamRateRep)
  36. : base(sqlSugar)
  37. {
  38. _mapper = mapper;
  39. _result = new Result() { Code = -2 };
  40. _setDataRep = setDataRep;
  41. _teamRateRep = teamRateRep;
  42. }
  43. /// <summary>
  44. /// 根据团组ID 查询
  45. /// </summary>
  46. /// <param name="diId"></param>
  47. /// <returns></returns>
  48. public async Task<Result> _ItemByDiId(int diId)
  49. {
  50. string sql = string.Format(@"Select prom.Id,prom.PriceName,prom.Price,sd.Name As CurrencyCode,
  51. prom.Remark,u.CnName As CreateUserName,prom.CreateTime,ccp.IsAuditGM,
  52. u1.CnName As AuditGMName,ccp.AuditGMDate
  53. From Fin_PaymentRefundAndOtherMoney prom
  54. Left Join Grp_CreditCardPayment ccp On ccp.CTable = 285 And
  55. ccp.CId = prom.Id And ccp.DIId = prom.DiId
  56. Left Join Sys_SetData sd On prom.CurrencyId = sd.Id
  57. Left Join Sys_Users u On u.Id = prom.CreateUserId
  58. Left Join Sys_Users u1 On u1.Id = ccp.AuditGMOperate
  59. Where prom.IsDel = 0 And ccp.IsDel = 0 And prom.DiId = {0}", diId);
  60. var data = await _sqlSugar.SqlQueryable<Fin_PaymentRefundAndOtherMoneyItemView>(sql).ToListAsync();
  61. _result.Data = data;
  62. _result.Code = 0;
  63. _result.Msg = "查询成功!";
  64. return _result;
  65. }
  66. /// <summary>
  67. /// 删除
  68. /// </summary>
  69. /// <param name="diId"></param>
  70. /// <returns></returns>
  71. public async Task<Result> _Del(PaymentRefundAndOtherMoneyDelDto dto)
  72. {
  73. Fin_PaymentRefundAndOtherMoney _PaymentRefundAndOtherMoney = new Fin_PaymentRefundAndOtherMoney() {
  74. Id = dto.Id,
  75. DeleteUserId = dto.UserId,
  76. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  77. IsDel = 1
  78. };
  79. _sqlSugar.BeginTran();
  80. var prom_del = await _sqlSugar.Updateable( _PaymentRefundAndOtherMoney )
  81. .UpdateColumns(it => new { it.DeleteUserId,it.DeleteTime,it.IsDel })
  82. .WhereColumns(it => new { it.Id})
  83. .ExecuteCommandAsync();
  84. Fin_PaymentRefundAndOtherMoney _PaymentRefundAndOtherMoneyInfo = new Fin_PaymentRefundAndOtherMoney();
  85. _PaymentRefundAndOtherMoneyInfo = await _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>().Where(it => it.Id == dto.Id).FirstAsync();
  86. if (_PaymentRefundAndOtherMoneyInfo != null)
  87. {
  88. Grp_CreditCardPayment _CreditCardPayment = new Grp_CreditCardPayment() {
  89. CId = _PaymentRefundAndOtherMoneyInfo.Id,
  90. DIId = _PaymentRefundAndOtherMoneyInfo.DiId,
  91. DeleteUserId = dto.UserId,
  92. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  93. IsDel = 1
  94. };
  95. var ccp_del = await _sqlSugar.Updateable(_CreditCardPayment)
  96. .UpdateColumns(it => new { it.DeleteUserId, it.DeleteTime, it.IsDel })
  97. .WhereColumns(it => new { it.CId,it.DIId })
  98. .ExecuteCommandAsync();
  99. }
  100. if (prom_del > 0 )
  101. {
  102. _result.Code = 0;
  103. _result.Msg = "操作成功!";
  104. }
  105. else
  106. {
  107. _result.Msg = "操作失败!";
  108. }
  109. _sqlSugar.CommitTran();
  110. return _result;
  111. }
  112. /// <summary>
  113. /// 详情 数据源
  114. /// </summary>
  115. /// <param name="diId"></param>
  116. /// <returns></returns>
  117. public async Task<Result> _InfoDataSource(PortDtoBase dto)
  118. {
  119. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //1 Web 2 Android 3 Ios
  120. {
  121. var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToList();
  122. dynamic _currencyData = null, _payTypeData = null;
  123. _currencyData = setDatas.Where(it => it.STid == 66).Select(it => new { it.Id, it.Name, it.Remark }); //币种类型
  124. _payTypeData = setDatas.Where(it => it.STid == 14).Select(it => new { it.Id, it.Name, it.Remark }); //支付类型
  125. List<dynamic> _priceTypeDatas = new List<dynamic>();
  126. _priceTypeDatas.Add(new { Id = 0, Name = "其他", Remark = "" });
  127. _priceTypeDatas.Add(new { Id = 1, Name = "退多付款", Remark = "" });
  128. List<dynamic> _orbitalPrivateTransferDatas = new List<dynamic>();
  129. _orbitalPrivateTransferDatas.Add(new { Id = 0, Name = "公转", Remark = "" });
  130. _orbitalPrivateTransferDatas.Add(new { Id = 1, Name = "私转", Remark = "" });
  131. dynamic _InfoDataSource = new
  132. {
  133. CurrencyDatas = _currencyData,
  134. PayTypeDatas = _payTypeData,
  135. OrbitalPrivateTransferDatas = _orbitalPrivateTransferDatas,
  136. PriceTypeDatas = _priceTypeDatas
  137. };
  138. _result.Data = _InfoDataSource;
  139. _result.Code = 0;
  140. _result.Msg = "查询成功!";
  141. }
  142. else
  143. {
  144. _result.Msg = "请输入正确的端口号! 1 Web 2 Android 3 Ios;";
  145. }
  146. return _result;
  147. }
  148. /// <summary>
  149. /// 详情
  150. /// </summary>
  151. /// <param name="diId"></param>
  152. /// <returns></returns>
  153. public async Task<JsonView> _Info(PaymentRefundAndOtherMoneyInfoDto dto)
  154. {
  155. var _view = new JsonView() { Code = StatusCodes.Status204NoContent };
  156. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //1 Web 2 Android 3 Ios
  157. {
  158. var data = await _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>()
  159. .LeftJoin<Grp_CreditCardPayment>((prom, ccp) => prom.Id == ccp.CId && ccp.CTable == 285 && ccp.IsDel == 0)
  160. .Where((prom, ccp) => prom.IsDel == 0 && ccp.DIId == prom.DiId && prom.Id == dto.Id)
  161. .Select((prom, ccp) => new Fin_PaymentRefundAndOtherMoneyInfoView()
  162. {
  163. Id = prom.Id,
  164. DiId = prom.DiId,
  165. CcpId = ccp.Id,
  166. PriceName = prom.PriceName,
  167. Price = prom.Price,
  168. CurrencyId = prom.CurrencyId,
  169. Payee = ccp.Payee,
  170. PayDId = ccp.PayDId,
  171. OrbitalPrivateTransfer = ccp.OrbitalPrivateTransfer,
  172. ConsumptionPatterns = ccp.ConsumptionPatterns,
  173. PayType = prom.PayType,
  174. Remark = prom.Remark,
  175. OtherBankName = ccp.OtherBankName,
  176. OtherSideNo = ccp.OtherSideNo,
  177. })
  178. .FirstAsync();
  179. if (data != null)
  180. {
  181. _view.Data = data;
  182. _view.Code = 200;
  183. _view.Msg = "查询成功!";
  184. }
  185. else _result.Msg = "查询失败!";
  186. }
  187. else _view.Msg = "请输入正确的端口号! 1 Web 2 Android 3 Ios;";
  188. return _view;
  189. }
  190. /// <summary>
  191. /// 操作(Add Or Edit)
  192. /// </summary>
  193. /// <param name="diId"></param>
  194. /// <returns></returns>
  195. public async Task<JsonView> _AddOrEdit(PaymentRefundAndOtherMoneyAddOrEditDto dto)
  196. {
  197. var _view = new JsonView() { Code = StatusCodes.Status204NoContent };
  198. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //1 Web 2 Android 3 Ios
  199. {
  200. #region 参数处理
  201. Fin_PaymentRefundAndOtherMoney _PaymentRefundAndOtherMoney = new Fin_PaymentRefundAndOtherMoney() {
  202. //Id = dto.Id,
  203. DiId = dto.DiId,
  204. PriceName = dto.PriceName.Trim(),
  205. Price = dto.Price,
  206. CurrencyId = dto.CurrencyId,
  207. PayType = dto.PayType,
  208. //PriceType = dto.PriceType,
  209. CreateUserId = dto.UserId,
  210. Remark = dto.Remark
  211. };
  212. //处理团组汇率
  213. decimal dayRate = 0.00M;
  214. decimal CNY_Price = 0.00M;
  215. decimal payThenMoney = 0.00M;
  216. #region 收款退还 团组汇率 验证 暂时注释
  217. if (dto.CurrencyId == 836) //人民币币种Id
  218. {
  219. dayRate = 1.0000M;
  220. CNY_Price = dto.Price;
  221. payThenMoney = dto.Price;
  222. }
  223. //else //其他币种Id
  224. //{
  225. // List<TeamRateModelView> teamReteDatas = await _teamRateRep.PostGroupRateInfoByDiId(dto.DiId);
  226. // if (teamReteDatas.Count <= 0)
  227. // {
  228. // _result.Msg = "该团未设置团组汇率,请先设置!";
  229. // return _result;
  230. // }
  231. // var teamReteData1 = teamReteDatas.Where(it => it.CTableId == 98).FirstOrDefault();
  232. // if (teamReteData1 == null)
  233. // {
  234. // _result.Msg = "该团下的“其他款项”未设置团组汇率,请先设置!";
  235. // return _result;
  236. // }
  237. // var teamReteData2 = teamReteData1.TeamRates.Where(it => it.CurrencyCode == dto.CurrencyCode).FirstOrDefault();
  238. // if (teamReteData2 == null)
  239. // {
  240. // _result.Msg = $"该团下的“其他款项”币种 “{dto.CurrencyCode}”未设置团组汇率,请先设置!";
  241. // return _result;
  242. // }
  243. // dayRate = teamReteData2.Rate;
  244. // CNY_Price = dayRate * dayRate;
  245. // payThenMoney = dayRate * dayRate;
  246. //}
  247. #endregion
  248. int ispay = 0;
  249. if (dto.PayDId == 72) ispay = 1;
  250. Grp_CreditCardPayment _CreditCardPayment = new Grp_CreditCardPayment() {
  251. //Id = dto.CcpId,
  252. //CId = dto.CcpId,
  253. DIId = dto.DiId,
  254. CTable = 285,// 285
  255. PayDId = dto.PayDId,
  256. ConsumptionPatterns = dto.ConsumptionPatterns,
  257. ConsumptionDate = string.Empty,
  258. CTDId = 0,
  259. BankNo = string.Empty,
  260. CardholderName = string.Empty,
  261. PayMoney = dto.Price,
  262. PaymentCurrency = dto.CurrencyId,
  263. DayRate = dayRate,
  264. CompanyBankNo = string.Empty,
  265. OtherBankName = dto.OtherBankName,
  266. OtherSideNo = dto.OtherSideNo,
  267. OtherSideName = string.Empty,
  268. MFOperator = 0,
  269. MFOperatorDate = string.Empty,
  270. IsAuditDM = 0,
  271. AuditDMOperate = 0,
  272. AuditDMDate = string.Empty,
  273. IsAuditMF = 0,
  274. AuditMFOperate = 0,
  275. AuditMFDate = string.Empty,
  276. IsAuditGM = 0,
  277. AuditGMOperate = 0,
  278. AuditGMDate = string.Empty,
  279. IsPay = ispay,
  280. PayPercentage = 100.00M,
  281. PayThenMoney = payThenMoney,
  282. PayPercentageOld = 0.00M,
  283. PayThenMoneyOld = 0.00M,
  284. UpdateDate = string.Empty,
  285. Payee = dto.Payee,
  286. RMBPrice = CNY_Price,
  287. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  288. ExceedBudget = 0.00M,
  289. CreateUserId = dto.UserId,
  290. DeleteUserId = null,
  291. DeleteTime = string.Empty,
  292. Remark = string.Empty,
  293. IsDel = 0
  294. };
  295. #endregion
  296. if (dto.Status == 1) //添加
  297. {
  298. #region 添加数据验证
  299. string sql = string.Format(@"
  300. SELECT
  301. prom.Id,
  302. ccp.Id CcpId,
  303. prom.DiId,
  304. prom.PriceName,
  305. prom.Price,
  306. prom.CurrencyId,
  307. ccp.Payee,
  308. ccp.PayDId,
  309. ccp.OrbitalPrivateTransfer,
  310. ccp.ConsumptionPatterns,
  311. prom.PayType,
  312. prom.Remark
  313. FROM
  314. Fin_PaymentRefundAndOtherMoney prom
  315. LEFT JOIN Grp_CreditCardPayment ccp ON ccp.CId = prom.id
  316. AND ccp.CTable = 285
  317. WHERE
  318. prom.IsDel = 0
  319. AND ccp.IsDel = 0
  320. AND ccp.DIId = prom.DiId
  321. AND ccp.DIId = {0}
  322. AND prom.PriceName = '{1}'", _PaymentRefundAndOtherMoney.DiId,_PaymentRefundAndOtherMoney.PriceName);
  323. //var data = await _sqlSugar.SqlQueryable<Fin_PaymentRefundAndOtherMoneyInfoView>(sql).FirstAsync();
  324. //if (data != null)
  325. //{
  326. // _view.Msg = "费用名称已存在,请勿重新添加!";
  327. // return _view;
  328. //}
  329. #endregion
  330. _sqlSugar.BeginTran();
  331. var addReturnId = await _sqlSugar.Insertable(_PaymentRefundAndOtherMoney).ExecuteReturnIdentityAsync();
  332. if (addReturnId <= 0)
  333. {
  334. _view.Msg = "操作失败!收款退还与其他款项添加失败!";
  335. _sqlSugar.RollbackTran();
  336. return _view;
  337. }
  338. _CreditCardPayment.CId = addReturnId;
  339. var addStatus = await _sqlSugar.Insertable(_CreditCardPayment).ExecuteReturnIdentityAsync();
  340. if (addStatus <= 0)
  341. {
  342. _view.Msg = "操作失败!付款类型添加失败!";
  343. _sqlSugar.RollbackTran();
  344. return _view;
  345. }
  346. _sqlSugar.CommitTran();
  347. _view.Msg = "操作成功!";
  348. _view.Code = 200;
  349. }
  350. else if (dto.Status == 2) //修改
  351. {
  352. _PaymentRefundAndOtherMoney.Id = dto.Id;
  353. _CreditCardPayment.Id = dto.CcpId;
  354. _CreditCardPayment.CId = dto.Id;
  355. _sqlSugar.BeginTran();
  356. var prom_update = await _sqlSugar.Updateable(_PaymentRefundAndOtherMoney)
  357. .IgnoreColumns(it => new { it.CreateUserId, it.CreateTime, it.DeleteUserId, it.DeleteTime, it.IsDel })
  358. .WhereColumns(it => new { it.Id })
  359. .ExecuteCommandAsync();
  360. if (prom_update <= 0)
  361. {
  362. _view.Msg = "操作失败!收款退还与其他款项修改失败!";
  363. _sqlSugar.RollbackTran();
  364. return _view;
  365. }
  366. var ccp_update = await _sqlSugar.Updateable(_CreditCardPayment)
  367. .UpdateColumns(it => new
  368. {
  369. it.PayDId,
  370. it.IsPay,
  371. it.ConsumptionPatterns,
  372. it.PayMoney,
  373. it.PaymentCurrency,
  374. it.DayRate,
  375. it.PayThenMoney,
  376. it.Payee,
  377. it.OrbitalPrivateTransfer,
  378. it.OtherSideNo,
  379. it.OtherBankName
  380. })
  381. .WhereColumns(it => new { it.Id })
  382. .ExecuteCommandAsync();
  383. if (ccp_update <= 0)
  384. {
  385. _view.Msg = "操作失败!付款信息修改失败!";
  386. _sqlSugar.RollbackTran();
  387. return _view;
  388. }
  389. _sqlSugar.CommitTran();
  390. _view.Msg = "操作成功!";
  391. _view.Code = 200;
  392. }
  393. else _view.Msg = "请输入正确的操作状态! 1 添加 2 修改;";
  394. }
  395. else _view.Msg = "请输入正确的端口号! 1 Web 2 Android 3 Ios;";
  396. return _view;
  397. }
  398. }
  399. }