DecreasePaymentsRepository.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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.Financial;
  8. using OASystem.Domain.ViewModels.Groups;
  9. using OASystem.Domain.ViewModels.QiYeWeChat;
  10. using OASystem.Domain.ViewModels.Resource;
  11. using OASystem.Infrastructure.Repositories.System;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Runtime.Intrinsics.Arm;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. namespace OASystem.Infrastructure.Repositories.Groups
  19. {
  20. public class DecreasePaymentsRepository : BaseRepository<Grp_DecreasePayments, Grp_DecreasePayments>
  21. {
  22. private readonly IMapper _mapper;
  23. private readonly TeamRateRepository _teamRateRep;
  24. public DecreasePaymentsRepository(SqlSugarClient sqlSugar, IMapper mapper, TeamRateRepository teamRateRep)
  25. : base(sqlSugar)
  26. {
  27. this._mapper = mapper;
  28. _teamRateRep = teamRateRep;
  29. }
  30. /// <summary>
  31. /// 根据团组Id查询数据
  32. /// </summary>
  33. /// <param name="dto"></param>
  34. /// <returns></returns>
  35. public async Task<Result> DecreasePaymentsList(DecreasePaymentsListDto dto)
  36. {
  37. Result result = new Result() { Code = -2, Msg = "未知错误" };
  38. try
  39. {
  40. //string UserId = "0";
  41. //List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 98).ToList();
  42. //UserId = string.Join(",", gtaUIdList.Select(it => it.UId).ToList());
  43. string sql = string.Format(@"select Id,DiId,PriceName,Price,(select name from Sys_SetData where id=s.Currency) as Currency,FilePath,
  44. (select CnName from Sys_Users where Id=s.CreateUserId) as 'CreateUserName',CreateTime,(select IsAuditGM from
  45. Grp_CreditCardPayment where CTable=98 and CId=s.Id and IsDel=0) as 'isAudit' from Grp_DecreasePayments s
  46. where DIID={0} and IsDel=0 and s.CreateUserId in ({1}) ", dto.DiId, dto.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 = ex.Message };
  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 = "0";
  71. foreach (var item in grp_GroupsTaskAssignment)
  72. {
  73. DiId += item.DIId + ",";
  74. }
  75. if (DiId!="0")
  76. {
  77. DiId = DiId.Substring(0, DiId.Length - 1);
  78. }
  79. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1} Order By CreateTime Desc", DiId, 0);
  80. List<Grp_DelegationInfo> grp_Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  81. if (grp_Delegations.Count == 0)
  82. {
  83. return result = new Result() { Code = -1, Msg = "查询失败!" };
  84. }
  85. #endregion
  86. #region 其他下拉框查询
  87. //支付方式
  88. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  89. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  90. #endregion
  91. var data = new
  92. {
  93. Payment = _Payment,
  94. GroupName = grp_Delegations,
  95. };
  96. return result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  97. }
  98. catch (Exception ex)
  99. {
  100. return result = new Result() { Code = -2, Msg = "程序错误" };
  101. throw;
  102. }
  103. }
  104. public async Task<Result> OpDecreasePayments(DecreasePaymentsOpDto dto)
  105. {
  106. Result result = new Result() { Code = -2, Msg = "未知错误" };
  107. BeginTran();
  108. try
  109. {
  110. int id = 0;
  111. Grp_DecreasePayments grp_Decrease = _mapper.Map<Grp_DecreasePayments>(dto);
  112. List<TeamRateDescAddCurrencyIdView> teamRates = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, dto.DiId, 98);
  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 = 0;
  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 = 100;
  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. TeamRateDescAddCurrencyIdView teamRate = teamRates.Where(it => it.CurrencyCode == grp_Decrease.Currency.ToString()).FirstOrDefault();
  182. //Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == grp_Decrease.DiId && a.IsDel == 0 && a.CTable == 98);
  183. if (teamRate != null)
  184. {
  185. if (teamRate.CurrencyCode.Equals("CNY"))
  186. {
  187. C.DayRate = 1.0000M;
  188. C.RMBPrice = C.PayMoney;
  189. }
  190. else
  191. {
  192. C.DayRate = teamRate.Rate;
  193. C.RMBPrice = C.PayMoney * C.DayRate;
  194. }
  195. }
  196. else
  197. {
  198. C.DayRate = 1.0000M;
  199. C.RMBPrice = C.PayMoney;
  200. }
  201. int cId = await _sqlSugar.Insertable(C).ExecuteReturnIdentityAsync();
  202. if (cId != 0)
  203. {
  204. result = new Result() { Code = 0, Msg = "添加成功!" };
  205. }
  206. else
  207. {
  208. RollbackTran();
  209. result = new Result() { Code = -1, Msg = "添加失败!" };
  210. }
  211. }
  212. else
  213. {
  214. result = new Result() { Code = -1, Msg = "添加失败!" };
  215. }
  216. }
  217. }
  218. else if (dto.Status == 2)
  219. {
  220. bool res = await UpdateAsync(a => a.Id == grp_Decrease.Id, a => new Grp_DecreasePayments
  221. {
  222. DiId = grp_Decrease.DiId,
  223. PriceName = grp_Decrease.PriceName,
  224. Price = grp_Decrease.Price,
  225. Currency = grp_Decrease.Currency,
  226. FilePath = grp_Decrease.FilePath,
  227. Remark = grp_Decrease.Remark,
  228. });
  229. if (res)
  230. {
  231. 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);
  232. if (grp_CreditCardPayment != null)
  233. {
  234. //设置该团组的汇率
  235. TeamRateDescAddCurrencyIdView teamRate = teamRates.Where(it => it.CurrencyCode == grp_Decrease.Currency.ToString()).FirstOrDefault();
  236. if (teamRate != null)
  237. {
  238. if (teamRate.CurrencyCode.Equals("CNY"))
  239. {
  240. grp_CreditCardPayment.DayRate = 1.0000M;
  241. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney;
  242. }
  243. else
  244. {
  245. grp_CreditCardPayment.DayRate = teamRate.Rate;
  246. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney * grp_CreditCardPayment.DayRate;
  247. }
  248. }
  249. else
  250. {
  251. grp_CreditCardPayment.DayRate = 1M;
  252. grp_CreditCardPayment.RMBPrice = grp_Decrease.Price;
  253. }
  254. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.Id == grp_CreditCardPayment.Id).SetColumns(a => new Grp_CreditCardPayment
  255. {
  256. PayDId = dto.PayDId,
  257. PayMoney = grp_Decrease.Price,
  258. PaymentCurrency = grp_Decrease.Currency,
  259. Payee = dto.Payee,
  260. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  261. DayRate = grp_CreditCardPayment.DayRate,
  262. RMBPrice = grp_CreditCardPayment.RMBPrice,
  263. }).ExecuteCommandAsync();
  264. if (CTable != 0)
  265. {
  266. result = new Result() { Code = 0, Msg = "修改成功!" };
  267. }
  268. else
  269. {
  270. result = new Result() { Code = -1, Msg = "修改失败!" };
  271. RollbackTran();
  272. }
  273. }
  274. else
  275. {
  276. RollbackTran();
  277. result = new Result() { Code = -1, Msg = "修改失败!" };
  278. }
  279. }
  280. else
  281. {
  282. result = new Result() { Code = -1, Msg = "修改失败!" };
  283. }
  284. }
  285. CommitTran();
  286. }
  287. catch (Exception ex)
  288. {
  289. RollbackTran();
  290. result = new Result() { Code = -2, Msg = "未知错误" };
  291. }
  292. return result;
  293. }
  294. public async Task<Result> PostGroupNameAndEasy(DecreasePaymentsDto dto)
  295. {
  296. Result result = new Result() { Code = -2, Msg = "未知错误" };
  297. try
  298. {
  299. #region 团组下拉框
  300. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  301. string DiId = "";
  302. foreach (var item in grp_GroupsTaskAssignment)
  303. {
  304. DiId += item.DIId + ",";
  305. }
  306. if (!string.IsNullOrWhiteSpace(DiId))
  307. {
  308. DiId = DiId.Substring(0, DiId.Length - 1);
  309. }
  310. else
  311. {
  312. DiId = "0";
  313. }
  314. 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);
  315. List<DelegationEasyView> grp_Delegations = _sqlSugar.SqlQueryable<DelegationEasyView>(sql).ToList();
  316. if (grp_Delegations.Count != 0)
  317. {
  318. int count = grp_Delegations.Count;
  319. float totalPage = (float)count / dto.PageSize;//总页数
  320. if (totalPage == 0) totalPage = 1;
  321. else totalPage = (int)Math.Ceiling((double)totalPage);
  322. List<DelegationEasyView> delegationEasyViews = new List<DelegationEasyView>();
  323. for (int i = 0; i < dto.PageSize; i++)
  324. {
  325. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  326. if (RowIndex < grp_Delegations.Count)
  327. {
  328. delegationEasyViews.Add(grp_Delegations[RowIndex]);
  329. }
  330. else
  331. {
  332. break;
  333. }
  334. }
  335. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  336. rst.DataList = delegationEasyViews;
  337. rst.DataCount = count;
  338. rst.CurrPageIndex = dto.PageIndex;
  339. rst.CurrPageSize = dto.PageSize;
  340. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  341. }
  342. else
  343. {
  344. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  345. rst.DataList=new List<DelegationEasyView>();
  346. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = rst };
  347. }
  348. #endregion
  349. }
  350. catch (Exception ex)
  351. {
  352. return result = new Result() { Code = -2, Msg = "程序错误" };
  353. throw;
  354. }
  355. }
  356. /// <summary>
  357. /// 根据团组增减款项表Id查询数据
  358. /// </summary>
  359. /// <param name="dto"></param>
  360. /// <returns></returns>
  361. /// <exception cref="NotImplementedException"></exception>
  362. public async Task<Result> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
  363. {
  364. Result result = new Result() { Code = -2, Msg = "程序错误" };
  365. try
  366. {
  367. Grp_DecreasePayments grp_Decrease = _sqlSugar.Queryable<Grp_DecreasePayments>().First(a=>a.Id==dto.Id && a.IsDel==0);
  368. Grp_CreditCardPayment grp_CreditCard= _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable==98);
  369. var data = new
  370. {
  371. _Decrease = grp_Decrease,
  372. _CreditCard = grp_CreditCard,
  373. };
  374. result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  375. }
  376. catch (Exception ex)
  377. {
  378. result = new Result() { Code = -2, Msg = "程序错误" };
  379. throw;
  380. }
  381. return result;
  382. }
  383. }
  384. }