DecreasePaymentsRepository.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Entities.Groups;
  5. using OASystem.Domain.Entities.Resource;
  6. using OASystem.Domain.ViewModels.Groups;
  7. using OASystem.Infrastructure.Repositories.System;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Runtime.Intrinsics.Arm;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace OASystem.Infrastructure.Repositories.Groups
  15. {
  16. public class DecreasePaymentsRepository : BaseRepository<Grp_DecreasePayments, Grp_DecreasePayments>
  17. {
  18. private readonly IMapper _mapper;
  19. public DecreasePaymentsRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  20. {
  21. this._mapper = mapper;
  22. }
  23. /// <summary>
  24. /// 根据团组Id查询数据
  25. /// </summary>
  26. /// <param name="dto"></param>
  27. /// <returns></returns>
  28. public async Task<Result> DecreasePaymentsList(DecreasePaymentsListDto dto)
  29. {
  30. Result result = new Result() { Code = -2, Msg = "未知错误" };
  31. try
  32. {
  33. string sql = string.Format(@"select Id,DiId,PriceName,Price,(select name from Sys_SetData where id=s.Currency) as Currency,FilePath,
  34. (select CnName from Sys_Users where Id=s.CreateUserId) as 'CreateUserName',CreateTime,(select IsAuditGM from
  35. 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);
  36. List<DecreasePaymentsView> _DecreasePayments = await _sqlSugar.SqlQueryable<DecreasePaymentsView>(sql).ToListAsync();
  37. if (_DecreasePayments.Count != 0)
  38. {
  39. result = new Result() { Code = 0, Msg = "查询成功!", Data = _DecreasePayments };
  40. }
  41. else
  42. {
  43. result = new Result() { Code = 0, Msg = "暂无数据!", Data = _DecreasePayments };
  44. }
  45. }
  46. catch (Exception ex)
  47. {
  48. result = new Result() { Code = -2, Msg = "未知错误" };
  49. }
  50. return result;
  51. }
  52. public async Task<Result> DecreasePaymentsSelect(DecreasePaymentsDto dto)
  53. {
  54. Result result = new Result() { Code = -2, Msg = "未知错误" };
  55. try
  56. {
  57. #region 团组下拉框
  58. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == a.CTId).ToList();
  59. string DiId = "";
  60. foreach (var item in grp_GroupsTaskAssignment)
  61. {
  62. DiId += item.DIId + ",";
  63. }
  64. DiId = DiId.Substring(0, DiId.Length - 1);
  65. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  66. List<Grp_DelegationInfo> grp_Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  67. if (grp_Delegations.Count == 0)
  68. {
  69. return result = new Result() { Code = -1, Msg = "查询失败!" };
  70. }
  71. #endregion
  72. #region 其他下拉框查询
  73. //支付方式
  74. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  75. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  76. #endregion
  77. var data = new
  78. {
  79. Payment = _Payment,
  80. GroupName = grp_Delegations,
  81. };
  82. return result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  83. }
  84. catch (Exception ex)
  85. {
  86. return result = new Result() { Code = -2, Msg = "程序错误" };
  87. throw;
  88. }
  89. }
  90. public async Task<Result> OpDecreasePayments(DecreasePaymentsOpDto dto)
  91. {
  92. Result result = new Result() { Code = -2, Msg = "未知错误" };
  93. BeginTran();
  94. try
  95. {
  96. int id = 0;
  97. Grp_DecreasePayments grp_Decrease = _mapper.Map<Grp_DecreasePayments>(dto);
  98. if (dto.Status == 1)//添加
  99. {
  100. string selectSql = string.Format(@"select * from Grp_DecreasePayments where PriceName='{0}' and IsDel={1} and DiId={2}"
  101. , dto.PriceName, 0, dto.DiId);
  102. var DecreasePayments = await _sqlSugar.SqlQueryable<Grp_DecreasePayments>(selectSql).FirstAsync();//查询是否存在
  103. if (DecreasePayments != null)
  104. {
  105. return result = new Result() { Code = -1, Msg = "该客户已存在,请勿重复添加!" };
  106. }
  107. else//不存在,可添加
  108. {
  109. id = await AddAsyncReturnId(grp_Decrease);
  110. if (id != 0)
  111. {
  112. result = new Result() { Code = 0, Msg = "添加成功!" };
  113. }
  114. else
  115. {
  116. result = new Result() { Code = 0, Msg = "添加失败!" };
  117. }
  118. if (result.Code == 0)
  119. {
  120. //进行C表添加
  121. Grp_CreditCardPayment C = new Grp_CreditCardPayment();
  122. C.PayDId = dto.PayDId;
  123. C.ConsumptionPatterns = "";
  124. C.ConsumptionDate = new DateTime();
  125. C.CTDId = 0;
  126. C.BankNo = "";
  127. C.CardholderName = "";
  128. C.PayMoney = grp_Decrease.Price;
  129. C.PaymentCurrency = grp_Decrease.Currency;
  130. //当天汇率
  131. //if (!string.IsNullOrEmpty(hfRate.Value))
  132. // C.DayRate = hfRate.Value;
  133. //else
  134. //C.DayRate = "";
  135. C.CompanyBankNo = "";
  136. C.OtherBankName = "";
  137. C.OtherSideNo = "";
  138. C.OtherSideName = "";
  139. C.Remark = "";
  140. C.CreateUserId = grp_Decrease.CreateUserId;
  141. C.MFOperator = "";
  142. C.MFOperatorDate = new DateTime();
  143. C.IsAuditDM = 0;
  144. C.AuditDMOperate = 0;
  145. C.AuditDMDate = new DateTime();
  146. C.IsAuditMF = 0;
  147. C.AuditMFOperate = 0;
  148. C.AuditMFDate = new DateTime();
  149. C.IsAuditGM = 0;
  150. C.AuditGMOperate = 21;
  151. C.AuditGMDate = new DateTime();
  152. C.IsPay = 0;
  153. C.DIId = grp_Decrease.DiId;
  154. C.CId = id;
  155. C.CTable = 98;
  156. C.PayPercentage = 0;
  157. C.PayThenMoney = 0;
  158. C.PayPercentageOld = 0;
  159. C.PayThenMoneyOld = 0;
  160. C.UpdateDate = new DateTime();
  161. C.Payee = dto.Payee;
  162. C.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  163. C.ExceedBudget = 0;
  164. //C.RMBPrice = 0.00f;
  165. //设置该团组的汇率
  166. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == grp_Decrease.DiId && a.IsDel == 0 && a.CTable == 85);
  167. if (_TeamRate != null)
  168. {
  169. if (grp_Decrease.Currency == 49)
  170. {
  171. C.DayRate = _TeamRate.RateU;
  172. C.RMBPrice = C.PayMoney * Convert.ToDecimal(_TeamRate.RateU);
  173. //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateU);
  174. }
  175. else if (grp_Decrease.Currency == 51)
  176. {
  177. C.DayRate = _TeamRate.RateE;
  178. C.RMBPrice = C.PayMoney * Convert.ToDecimal(_TeamRate.RateE);
  179. //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateE);
  180. }
  181. else
  182. {
  183. C.DayRate = "1";
  184. C.RMBPrice = C.PayMoney;
  185. }
  186. }
  187. else
  188. {
  189. C.DayRate = "1";
  190. C.RMBPrice = C.PayMoney;
  191. }
  192. int cId = await _sqlSugar.Insertable(C).ExecuteReturnIdentityAsync();
  193. if (cId != 0)
  194. {
  195. result = new Result() { Code = 0, Msg = "添加成功!" };
  196. }
  197. else
  198. {
  199. RollbackTran();
  200. result = new Result() { Code = -1, Msg = "添加失败!" };
  201. }
  202. }
  203. else
  204. {
  205. result = 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.IsDel == 0);
  223. if (grp_CreditCardPayment != null)
  224. {
  225. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == grp_Decrease.DiId && a.IsDel == 0 && a.CTable == 85);
  226. if (_TeamRate != null)
  227. {
  228. if (grp_Decrease.Currency == 49)
  229. {
  230. grp_CreditCardPayment.DayRate = _TeamRate.RateU;
  231. grp_CreditCardPayment.RMBPrice = grp_Decrease.Price * Convert.ToDecimal(_TeamRate.RateU);
  232. //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateU);
  233. }
  234. else if (grp_Decrease.Currency == 51)
  235. {
  236. grp_CreditCardPayment.DayRate = _TeamRate.RateE;
  237. grp_CreditCardPayment.RMBPrice = grp_Decrease.Price * Convert.ToDecimal(_TeamRate.RateE);
  238. //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateE);
  239. }
  240. else
  241. {
  242. grp_CreditCardPayment.DayRate = "1";
  243. grp_CreditCardPayment.RMBPrice = grp_Decrease.Price;
  244. }
  245. }
  246. else
  247. {
  248. grp_CreditCardPayment.DayRate = "1";
  249. grp_CreditCardPayment.RMBPrice = grp_Decrease.Price;
  250. }
  251. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.Id == grp_CreditCardPayment.Id).SetColumns(a => new Grp_CreditCardPayment
  252. {
  253. PayDId = dto.PayDId,
  254. PayMoney = grp_Decrease.Price,
  255. PaymentCurrency = grp_Decrease.Currency,
  256. Payee = dto.Payee,
  257. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  258. DayRate = grp_CreditCardPayment.DayRate,
  259. RMBPrice = grp_CreditCardPayment.RMBPrice,
  260. }).ExecuteCommandAsync();
  261. if (CTable != 0)
  262. {
  263. result = new Result() { Code = 0, Msg = "修改成功!" };
  264. }
  265. else
  266. {
  267. result = new Result() { Code = -1, Msg = "修改失败!" };
  268. RollbackTran();
  269. }
  270. }
  271. else
  272. {
  273. RollbackTran();
  274. result = new Result() { Code = -1, Msg = "修改失败!" };
  275. }
  276. }
  277. else
  278. {
  279. result = new Result() { Code = -1, Msg = "修改失败!" };
  280. }
  281. }
  282. CommitTran();
  283. }
  284. catch (Exception ex)
  285. {
  286. RollbackTran();
  287. result = new Result() { Code = -2, Msg = "未知错误" };
  288. }
  289. return result;
  290. }
  291. /// <summary>
  292. /// 根据团组增减款项表Id查询数据
  293. /// </summary>
  294. /// <param name="dto"></param>
  295. /// <returns></returns>
  296. /// <exception cref="NotImplementedException"></exception>
  297. public async Task<Result> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
  298. {
  299. Result result = new Result() { Code = -2, Msg = "程序错误" };
  300. try
  301. {
  302. Grp_DecreasePayments grp_Decrease = _sqlSugar.Queryable<Grp_DecreasePayments>().First(a=>a.Id==dto.Id && a.IsDel==0);
  303. Grp_CreditCardPayment grp_CreditCard= _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0);
  304. var data = new
  305. {
  306. _Decrease = grp_Decrease,
  307. _CreditCard = grp_CreditCard,
  308. };
  309. result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  310. }
  311. catch (Exception)
  312. {
  313. result = new Result() { Code = -2, Msg = "程序错误" };
  314. throw;
  315. }
  316. return result;
  317. }
  318. }
  319. }