DecreasePaymentsRepository.cs 19 KB

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