DecreasePaymentsRepository.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Entities.Financial;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.Entities.Resource;
  7. using OASystem.Domain.ViewModels.Groups;
  8. using OASystem.Domain.ViewModels.QiYeWeChat;
  9. using OASystem.Domain.ViewModels.Resource;
  10. using OASystem.Infrastructure.Repositories.System;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Runtime.Intrinsics.Arm;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace OASystem.Infrastructure.Repositories.Groups
  18. {
  19. public class DecreasePaymentsRepository : BaseRepository<Grp_DecreasePayments, Grp_DecreasePayments>
  20. {
  21. private readonly IMapper _mapper;
  22. public DecreasePaymentsRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  23. {
  24. this._mapper = mapper;
  25. }
  26. /// <summary>
  27. /// 根据团组Id查询数据
  28. /// </summary>
  29. /// <param name="dto"></param>
  30. /// <returns></returns>
  31. public async Task<Result> DecreasePaymentsList(DecreasePaymentsListDto dto)
  32. {
  33. Result result = new Result() { Code = -2, Msg = "未知错误" };
  34. try
  35. {
  36. string UserId = "";
  37. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 98).ToList();
  38. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  39. UserId += gta.UId + ",";
  40. if (!string.IsNullOrWhiteSpace(UserId))
  41. {
  42. UserId = UserId.Substring(0, UserId.Length - 1);
  43. }
  44. else
  45. {
  46. UserId = "0";
  47. }
  48. string sql = string.Format(@"select Id,DiId,PriceName,Price,(select name from Sys_SetData where id=s.Currency) as Currency,FilePath,
  49. (select CnName from Sys_Users where Id=s.CreateUserId) as 'CreateUserName',CreateTime,(select IsAuditGM from
  50. Grp_CreditCardPayment where CTable=98 and CId=s.Id and IsDel=0) as 'isAudit' from Grp_DecreasePayments s where DIID={0} and IsDel=0 and s.CreateUserId in ({1}) ", dto.DiId,UserId);
  51. List<DecreasePaymentsView> _DecreasePayments = await _sqlSugar.SqlQueryable<DecreasePaymentsView>(sql).ToListAsync();
  52. if (_DecreasePayments.Count != 0)
  53. {
  54. result = new Result() { Code = 0, Msg = "查询成功!", Data = _DecreasePayments };
  55. }
  56. else
  57. {
  58. result = new Result() { Code = 0, Msg = "暂无数据!", Data = _DecreasePayments };
  59. }
  60. }
  61. catch (Exception ex)
  62. {
  63. result = new Result() { Code = -2, Msg = "未知错误" };
  64. }
  65. return result;
  66. }
  67. public async Task<Result> DecreasePaymentsSelect(DecreasePaymentsDto dto)
  68. {
  69. Result result = new Result() { Code = -2, Msg = "未知错误" };
  70. try
  71. {
  72. #region 团组下拉框
  73. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  74. string DiId = "0";
  75. foreach (var item in grp_GroupsTaskAssignment)
  76. {
  77. DiId += item.DIId + ",";
  78. }
  79. if (DiId!="0")
  80. {
  81. DiId = DiId.Substring(0, DiId.Length - 1);
  82. }
  83. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  84. List<Grp_DelegationInfo> grp_Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  85. if (grp_Delegations.Count == 0)
  86. {
  87. return result = new Result() { Code = -1, Msg = "查询失败!" };
  88. }
  89. #endregion
  90. #region 其他下拉框查询
  91. //支付方式
  92. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  93. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  94. #endregion
  95. var data = new
  96. {
  97. Payment = _Payment,
  98. GroupName = grp_Delegations,
  99. };
  100. return result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  101. }
  102. catch (Exception ex)
  103. {
  104. return result = new Result() { Code = -2, Msg = "程序错误" };
  105. throw;
  106. }
  107. }
  108. public async Task<Result> OpDecreasePayments(DecreasePaymentsOpDto dto)
  109. {
  110. Result result = new Result() { Code = -2, Msg = "未知错误" };
  111. BeginTran();
  112. try
  113. {
  114. int id = 0;
  115. Grp_DecreasePayments grp_Decrease = _mapper.Map<Grp_DecreasePayments>(dto);
  116. if (dto.Status == 1)//添加
  117. {
  118. string selectSql = string.Format(@"select * from Grp_DecreasePayments where PriceName='{0}' and IsDel={1} and DiId={2}"
  119. , dto.PriceName, 0, dto.DiId);
  120. var DecreasePayments = await _sqlSugar.SqlQueryable<Grp_DecreasePayments>(selectSql).FirstAsync();//查询是否存在
  121. if (DecreasePayments != null)
  122. {
  123. return result = new Result() { Code = -1, Msg = "该客户已存在,请勿重复添加!" };
  124. }
  125. else//不存在,可添加
  126. {
  127. id = await AddAsyncReturnId(grp_Decrease);
  128. if (id != 0)
  129. {
  130. result = new Result() { Code = 0, Msg = "添加成功!" };
  131. }
  132. else
  133. {
  134. result = new Result() { Code = 0, Msg = "添加失败!" };
  135. }
  136. if (result.Code == 0)
  137. {
  138. //进行C表添加
  139. Grp_CreditCardPayment C = new Grp_CreditCardPayment();
  140. C.PayDId = dto.PayDId;
  141. C.ConsumptionPatterns = "";
  142. C.ConsumptionDate = "";
  143. C.CTDId = 0;
  144. C.BankNo = "";
  145. C.CardholderName = "";
  146. C.PayMoney = grp_Decrease.Price;
  147. C.PaymentCurrency = grp_Decrease.Currency;
  148. //当天汇率
  149. //if (!string.IsNullOrEmpty(hfRate.Value))
  150. // C.DayRate = hfRate.Value;
  151. //else
  152. //C.DayRate = "";
  153. C.CompanyBankNo = "";
  154. C.OtherBankName = "";
  155. C.OtherSideNo = "";
  156. C.OtherSideName = "";
  157. C.Remark = "";
  158. C.CreateUserId = grp_Decrease.CreateUserId;
  159. C.MFOperator = 0;
  160. C.MFOperatorDate = "";
  161. C.IsAuditDM = 0;
  162. C.AuditDMOperate = 0;
  163. C.AuditDMDate = "";
  164. C.IsAuditMF = 0;
  165. C.AuditMFOperate = 0;
  166. C.AuditMFDate = "";
  167. C.IsAuditGM = 0;
  168. C.AuditGMOperate = 21;
  169. C.AuditGMDate = "";
  170. C.IsPay = 0;
  171. C.DIId = grp_Decrease.DiId;
  172. C.CId = id;
  173. C.CTable = 98;
  174. C.PayPercentage = 0;
  175. C.PayThenMoney = 0;
  176. C.PayPercentageOld = 0;
  177. C.PayThenMoneyOld = 0;
  178. C.UpdateDate = "";
  179. C.Payee = dto.Payee;
  180. C.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  181. C.ExceedBudget = 0;
  182. //C.RMBPrice = 0.00f;
  183. //设置该团组的汇率
  184. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == grp_Decrease.DiId && a.IsDel == 0 && a.CTable == 98);
  185. if (_TeamRate != null)
  186. {
  187. if (grp_Decrease.Currency == 49)
  188. {
  189. C.DayRate = _TeamRate.RateU;
  190. C.RMBPrice = C.PayMoney * Convert.ToDecimal(_TeamRate.RateU);
  191. //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateU);
  192. }
  193. else if (grp_Decrease.Currency == 51)
  194. {
  195. C.DayRate = _TeamRate.RateE;
  196. C.RMBPrice = C.PayMoney * Convert.ToDecimal(_TeamRate.RateE);
  197. //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateE);
  198. }
  199. else
  200. {
  201. C.DayRate = 1M;
  202. C.RMBPrice = C.PayMoney;
  203. }
  204. }
  205. else
  206. {
  207. C.DayRate = 1M;
  208. C.RMBPrice = C.PayMoney;
  209. }
  210. int cId = await _sqlSugar.Insertable(C).ExecuteReturnIdentityAsync();
  211. if (cId != 0)
  212. {
  213. result = new Result() { Code = 0, Msg = "添加成功!" };
  214. }
  215. else
  216. {
  217. RollbackTran();
  218. result = new Result() { Code = -1, Msg = "添加失败!" };
  219. }
  220. }
  221. else
  222. {
  223. result = new Result() { Code = -1, Msg = "添加失败!" };
  224. }
  225. }
  226. }
  227. else if (dto.Status == 2)
  228. {
  229. bool res = await UpdateAsync(a => a.Id == grp_Decrease.Id, a => new Grp_DecreasePayments
  230. {
  231. DiId = grp_Decrease.DiId,
  232. PriceName = grp_Decrease.PriceName,
  233. Price = grp_Decrease.Price,
  234. Currency = grp_Decrease.Currency,
  235. FilePath = grp_Decrease.FilePath,
  236. Remark = grp_Decrease.Remark,
  237. });
  238. if (res)
  239. {
  240. 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);
  241. if (grp_CreditCardPayment != null)
  242. {
  243. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == grp_Decrease.DiId && a.IsDel == 0 && a.CTable == 98);
  244. if (_TeamRate != null)
  245. {
  246. if (grp_Decrease.Currency == 49)
  247. {
  248. grp_CreditCardPayment.DayRate = _TeamRate.RateU;
  249. grp_CreditCardPayment.RMBPrice = grp_Decrease.Price * Convert.ToDecimal(_TeamRate.RateU);
  250. //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateU);
  251. }
  252. else if (grp_Decrease.Currency == 51)
  253. {
  254. grp_CreditCardPayment.DayRate = _TeamRate.RateE;
  255. grp_CreditCardPayment.RMBPrice = grp_Decrease.Price * Convert.ToDecimal(_TeamRate.RateE);
  256. //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateE);
  257. }
  258. else
  259. {
  260. grp_CreditCardPayment.DayRate = 1M;
  261. grp_CreditCardPayment.RMBPrice = grp_Decrease.Price;
  262. }
  263. }
  264. else
  265. {
  266. grp_CreditCardPayment.DayRate = 1M;
  267. grp_CreditCardPayment.RMBPrice = grp_Decrease.Price;
  268. }
  269. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.Id == grp_CreditCardPayment.Id).SetColumns(a => new Grp_CreditCardPayment
  270. {
  271. PayDId = dto.PayDId,
  272. PayMoney = grp_Decrease.Price,
  273. PaymentCurrency = grp_Decrease.Currency,
  274. Payee = dto.Payee,
  275. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  276. DayRate = grp_CreditCardPayment.DayRate,
  277. RMBPrice = grp_CreditCardPayment.RMBPrice,
  278. }).ExecuteCommandAsync();
  279. if (CTable != 0)
  280. {
  281. result = new Result() { Code = 0, Msg = "修改成功!" };
  282. }
  283. else
  284. {
  285. result = new Result() { Code = -1, Msg = "修改失败!" };
  286. RollbackTran();
  287. }
  288. }
  289. else
  290. {
  291. RollbackTran();
  292. result = new Result() { Code = -1, Msg = "修改失败!" };
  293. }
  294. }
  295. else
  296. {
  297. result = new Result() { Code = -1, Msg = "修改失败!" };
  298. }
  299. }
  300. CommitTran();
  301. }
  302. catch (Exception ex)
  303. {
  304. RollbackTran();
  305. result = new Result() { Code = -2, Msg = "未知错误" };
  306. }
  307. return result;
  308. }
  309. public async Task<Result> PostGroupNameAndEasy(DecreasePaymentsDto dto)
  310. {
  311. Result result = new Result() { Code = -2, Msg = "未知错误" };
  312. try
  313. {
  314. #region 团组下拉框
  315. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  316. string DiId = "";
  317. foreach (var item in grp_GroupsTaskAssignment)
  318. {
  319. DiId += item.DIId + ",";
  320. }
  321. if (!string.IsNullOrWhiteSpace(DiId))
  322. {
  323. DiId = DiId.Substring(0, DiId.Length - 1);
  324. }
  325. else
  326. {
  327. DiId = "0";
  328. }
  329. 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);
  330. List<DelegationEasyView> grp_Delegations = _sqlSugar.SqlQueryable<DelegationEasyView>(sql).ToList();
  331. if (grp_Delegations.Count != 0)
  332. {
  333. int count = grp_Delegations.Count;
  334. float totalPage = (float)count / dto.PageSize;//总页数
  335. if (totalPage == 0) totalPage = 1;
  336. else totalPage = (int)Math.Ceiling((double)totalPage);
  337. List<DelegationEasyView> delegationEasyViews = new List<DelegationEasyView>();
  338. for (int i = 0; i < dto.PageSize; i++)
  339. {
  340. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  341. if (RowIndex < grp_Delegations.Count)
  342. {
  343. delegationEasyViews.Add(grp_Delegations[RowIndex]);
  344. }
  345. else
  346. {
  347. break;
  348. }
  349. }
  350. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  351. rst.DataList = delegationEasyViews;
  352. rst.DataCount = count;
  353. rst.CurrPageIndex = dto.PageIndex;
  354. rst.CurrPageSize = dto.PageSize;
  355. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  356. }
  357. else
  358. {
  359. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  360. rst.DataList=new List<DelegationEasyView>();
  361. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = rst };
  362. }
  363. #endregion
  364. }
  365. catch (Exception ex)
  366. {
  367. return result = new Result() { Code = -2, Msg = "程序错误" };
  368. throw;
  369. }
  370. }
  371. /// <summary>
  372. /// 根据团组增减款项表Id查询数据
  373. /// </summary>
  374. /// <param name="dto"></param>
  375. /// <returns></returns>
  376. /// <exception cref="NotImplementedException"></exception>
  377. public async Task<Result> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
  378. {
  379. Result result = new Result() { Code = -2, Msg = "程序错误" };
  380. try
  381. {
  382. Grp_DecreasePayments grp_Decrease = _sqlSugar.Queryable<Grp_DecreasePayments>().First(a=>a.Id==dto.Id && a.IsDel==0);
  383. Grp_CreditCardPayment grp_CreditCard= _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable==98);
  384. var data = new
  385. {
  386. _Decrease = grp_Decrease,
  387. _CreditCard = grp_CreditCard,
  388. };
  389. result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  390. }
  391. catch (Exception ex)
  392. {
  393. result = new Result() { Code = -2, Msg = "程序错误" };
  394. throw;
  395. }
  396. return result;
  397. }
  398. }
  399. }