DecreasePaymentsRepository.cs 18 KB

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