DecreasePaymentsRepository.cs 19 KB

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