PaymentRefundAndOtherMoneyRepository.cs 17 KB

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