DecreasePaymentsRepository.cs 16 KB

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