DecreasePaymentsRepository.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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 new Result() { Code = -1, Msg = "该数据已存在,请勿重复添加!" };
  121. }
  122. else//不存在,可添加
  123. {
  124. id = await AddAsyncReturnId(grp_Decrease);
  125. if (id < 1)
  126. {
  127. RollbackTran();
  128. return new Result() { Code = -1, Msg = "添加失败!" };
  129. }
  130. //进行C表添加
  131. Grp_CreditCardPayment C = new Grp_CreditCardPayment();
  132. C.PayDId = dto.PayDId;
  133. C.ConsumptionPatterns = "";
  134. C.ConsumptionDate = "";
  135. C.CTDId = 0;
  136. C.BankNo = "";
  137. C.CardholderName = "";
  138. C.PayMoney = grp_Decrease.Price;
  139. C.PaymentCurrency = grp_Decrease.Currency;
  140. //当天汇率
  141. //if (!string.IsNullOrEmpty(hfRate.Value))
  142. // C.DayRate = hfRate.Value;
  143. //else
  144. //C.DayRate = "";
  145. C.CompanyBankNo = "";
  146. C.OtherBankName = "";
  147. C.OtherSideNo = "";
  148. C.OtherSideName = "";
  149. C.Remark = "";
  150. C.CreateUserId = grp_Decrease.CreateUserId;
  151. C.MFOperator = 0;
  152. C.MFOperatorDate = "";
  153. C.IsAuditDM = 0;
  154. C.AuditDMOperate = 0;
  155. C.AuditDMDate = "";
  156. C.IsAuditMF = 0;
  157. C.AuditMFOperate = 0;
  158. C.AuditMFDate = "";
  159. C.IsAuditGM = 0;
  160. C.AuditGMOperate = 21;
  161. C.AuditGMDate = "";
  162. C.IsPay = 0;
  163. C.DIId = grp_Decrease.DiId;
  164. C.CId = id;
  165. C.CTable = 98;
  166. C.PayPercentage = 100;
  167. C.PayThenMoney = 0;
  168. C.PayPercentageOld = 0;
  169. C.PayThenMoneyOld = 0;
  170. C.UpdateDate = "";
  171. C.Payee = dto.Payee;
  172. C.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  173. C.ExceedBudget = 0;
  174. //C.RMBPrice = 0.00f;
  175. //设置该团组的汇率
  176. TeamRateDescAddCurrencyIdView teamRate = teamRates.Where(it => it.CurrencyCode == grp_Decrease.Currency.ToString()).FirstOrDefault();
  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 (teamRate.CurrencyCode.Equals("CNY"))
  181. {
  182. C.DayRate = 1.0000M;
  183. C.RMBPrice = C.PayMoney;
  184. }
  185. else
  186. {
  187. C.DayRate = teamRate.Rate;
  188. C.RMBPrice = C.PayMoney * C.DayRate;
  189. }
  190. }
  191. else
  192. {
  193. C.DayRate = 1.0000M;
  194. C.RMBPrice = C.PayMoney;
  195. }
  196. int cId = await _sqlSugar.Insertable(C).ExecuteReturnIdentityAsync();
  197. if (cId != 0)
  198. {
  199. CommitTran();
  200. return new Result() { Code = 0, Msg = "添加成功!" };
  201. }
  202. else
  203. {
  204. RollbackTran();
  205. return new Result() { Code = -1, Msg = "添加失败!" };
  206. }
  207. }
  208. }
  209. else if (dto.Status == 2)
  210. {
  211. bool res = await UpdateAsync(a => a.Id == grp_Decrease.Id, a => new Grp_DecreasePayments
  212. {
  213. DiId = grp_Decrease.DiId,
  214. PriceName = grp_Decrease.PriceName,
  215. Price = grp_Decrease.Price,
  216. Currency = grp_Decrease.Currency,
  217. FilePath = grp_Decrease.FilePath,
  218. Remark = grp_Decrease.Remark,
  219. });
  220. if (res)
  221. {
  222. 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);
  223. if (grp_CreditCardPayment != null)
  224. {
  225. //设置该团组的汇率
  226. TeamRateDescAddCurrencyIdView teamRate = teamRates.Where(it => it.CurrencyCode == grp_Decrease.Currency.ToString()).FirstOrDefault();
  227. if (teamRate != null)
  228. {
  229. if (teamRate.CurrencyCode.Equals("CNY"))
  230. {
  231. grp_CreditCardPayment.DayRate = 1.0000M;
  232. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney;
  233. }
  234. else
  235. {
  236. grp_CreditCardPayment.DayRate = teamRate.Rate;
  237. grp_CreditCardPayment.RMBPrice = grp_CreditCardPayment.PayMoney * grp_CreditCardPayment.DayRate;
  238. }
  239. }
  240. else
  241. {
  242. grp_CreditCardPayment.DayRate = 1M;
  243. grp_CreditCardPayment.RMBPrice = grp_Decrease.Price;
  244. }
  245. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  246. .Where(a => a.Id == grp_CreditCardPayment.Id)
  247. .SetColumns(a => new Grp_CreditCardPayment
  248. {
  249. PayDId = dto.PayDId,
  250. PayMoney = grp_Decrease.Price,
  251. PaymentCurrency = grp_Decrease.Currency,
  252. Payee = dto.Payee,
  253. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  254. DayRate = grp_CreditCardPayment.DayRate,
  255. RMBPrice = grp_CreditCardPayment.RMBPrice,
  256. }).ExecuteCommandAsync();
  257. if (CTable > 0)
  258. {
  259. CommitTran();
  260. return new Result() { Code = 0, Msg = "修改成功!" };
  261. }
  262. else
  263. {
  264. RollbackTran();
  265. return new Result() { Code = -1, Msg = "修改失败!" };
  266. }
  267. }
  268. else
  269. {
  270. RollbackTran();
  271. return new Result() { Code = -1, Msg = "修改失败!" };
  272. }
  273. }
  274. else
  275. {
  276. RollbackTran();
  277. return new Result() { Code = -1, Msg = "修改失败!" };
  278. }
  279. }
  280. }
  281. catch (Exception ex)
  282. {
  283. RollbackTran();
  284. return new Result() { Code = -2, Msg = ex.Message };
  285. }
  286. return result;
  287. }
  288. public async Task<Result> PostGroupNameAndEasy(DecreasePaymentsDto dto)
  289. {
  290. Result result = new Result() { Code = -2, Msg = "未知错误" };
  291. try
  292. {
  293. #region 团组下拉框
  294. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == dto.CTId).ToList();
  295. string DiId = "";
  296. foreach (var item in grp_GroupsTaskAssignment)
  297. {
  298. DiId += item.DIId + ",";
  299. }
  300. if (!string.IsNullOrWhiteSpace(DiId))
  301. {
  302. DiId = DiId.Substring(0, DiId.Length - 1);
  303. }
  304. else
  305. {
  306. DiId = "0";
  307. }
  308. 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);
  309. List<DelegationEasyView> grp_Delegations = _sqlSugar.SqlQueryable<DelegationEasyView>(sql).ToList();
  310. if (grp_Delegations.Count != 0)
  311. {
  312. int count = grp_Delegations.Count;
  313. float totalPage = (float)count / dto.PageSize;//总页数
  314. if (totalPage == 0) totalPage = 1;
  315. else totalPage = (int)Math.Ceiling((double)totalPage);
  316. List<DelegationEasyView> delegationEasyViews = new List<DelegationEasyView>();
  317. for (int i = 0; i < dto.PageSize; i++)
  318. {
  319. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  320. if (RowIndex < grp_Delegations.Count)
  321. {
  322. delegationEasyViews.Add(grp_Delegations[RowIndex]);
  323. }
  324. else
  325. {
  326. break;
  327. }
  328. }
  329. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  330. rst.DataList = delegationEasyViews;
  331. rst.DataCount = count;
  332. rst.CurrPageIndex = dto.PageIndex;
  333. rst.CurrPageSize = dto.PageSize;
  334. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  335. }
  336. else
  337. {
  338. ListViewBase<DelegationEasyView> rst = new ListViewBase<DelegationEasyView>();
  339. rst.DataList=new List<DelegationEasyView>();
  340. return result = new Result() { Code = 0, Msg = "暂无数据!", Data = rst };
  341. }
  342. #endregion
  343. }
  344. catch (Exception ex)
  345. {
  346. return result = new Result() { Code = -2, Msg = "程序错误" };
  347. throw;
  348. }
  349. }
  350. /// <summary>
  351. /// 根据团组增减款项表Id查询数据
  352. /// </summary>
  353. /// <param name="dto"></param>
  354. /// <returns></returns>
  355. /// <exception cref="NotImplementedException"></exception>
  356. public async Task<Result> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
  357. {
  358. Result result = new Result() { Code = -2, Msg = "程序错误" };
  359. try
  360. {
  361. Grp_DecreasePayments grp_Decrease = _sqlSugar.Queryable<Grp_DecreasePayments>().First(a=>a.Id==dto.Id && a.IsDel==0);
  362. Grp_CreditCardPayment grp_CreditCard= _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable==98);
  363. var data = new
  364. {
  365. _Decrease = grp_Decrease,
  366. _CreditCard = grp_CreditCard,
  367. };
  368. result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  369. }
  370. catch (Exception ex)
  371. {
  372. result = new Result() { Code = -2, Msg = "程序错误" };
  373. throw;
  374. }
  375. return result;
  376. }
  377. }
  378. }