AfterSalesFlow.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package com.fjhx.sale.flow;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.fjhx.account.entity.account.enums.PaymentStatusEnum;
  5. import com.fjhx.account.entity.account.po.AccountPayment;
  6. import com.fjhx.account.service.account.AccountPaymentService;
  7. import com.fjhx.common.enums.CodingRuleEnum;
  8. import com.fjhx.common.enums.FlowStatusEnum1;
  9. import com.fjhx.common.service.coding.CodingRuleService;
  10. import com.fjhx.common.utils.Assert;
  11. import com.fjhx.flow.core.FlowDelegate;
  12. import com.fjhx.sale.entity.after.dto.AfterSalesDto;
  13. import com.fjhx.sale.entity.after.po.AfterSales;
  14. import com.fjhx.sale.entity.contract.po.Contract;
  15. import com.fjhx.sale.entity.contract.po.ContractProduct;
  16. import com.fjhx.sale.service.after.AfterSalesService;
  17. import com.fjhx.sale.service.contract.ContractProductService;
  18. import com.fjhx.sale.service.contract.ContractService;
  19. import com.ruoyi.common.core.domain.entity.SysUser;
  20. import com.ruoyi.common.utils.SecurityUtils;
  21. import com.ruoyi.system.service.ISysUserService;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Component;
  24. import java.math.BigDecimal;
  25. import java.util.Date;
  26. @Component
  27. public class AfterSalesFlow extends FlowDelegate {
  28. private final AfterSalesService afterSalesService;
  29. private final CodingRuleService codingRuleService;
  30. private final ContractProductService contractProductService;
  31. private final ISysUserService userService;
  32. private final AccountPaymentService accountPaymentService;
  33. private final ContractService contractService;
  34. @Autowired
  35. public AfterSalesFlow(AfterSalesService afterSalesService, CodingRuleService codingRuleService, ContractProductService contractProductService, ISysUserService userService, AccountPaymentService accountPaymentService, ContractService contractService) {
  36. this.afterSalesService = afterSalesService;
  37. this.codingRuleService = codingRuleService;
  38. this.contractProductService = contractProductService;
  39. this.userService = userService;
  40. this.accountPaymentService = accountPaymentService;
  41. this.contractService = contractService;
  42. }
  43. @Override
  44. public String getFlowKey() {
  45. return "after_sales_flow";
  46. }
  47. @Override
  48. public Long start(Long flowId, JSONObject submitData) {
  49. AfterSalesDto afterSalesDto = submitData.toJavaObject(AfterSalesDto.class);
  50. afterSalesDto.setFlowId(flowId);
  51. Long contractProductId = afterSalesDto.getContractProductId();
  52. ContractProduct contractProduct = contractProductService.getById(contractProductId);
  53. Assert.notEmpty(contractProduct, "查询不到订单产品信息!");
  54. afterSalesDto.setCode(codingRuleService.createCode(CodingRuleEnum.AFTER_SALES.getKey(), null));
  55. //赋值信息
  56. afterSalesDto.setContractId(contractProduct.getContractId());
  57. afterSalesDto.setProductId(contractProduct.getProductId());
  58. afterSalesDto.setCompanyId(SecurityUtils.getCompanyId());
  59. afterSalesService.save(afterSalesDto);
  60. //回填数据
  61. submitData.put("code", afterSalesDto.getCode());
  62. return afterSalesDto.getId();
  63. }
  64. @Override
  65. public void end(Long flowId, Long businessId, JSONObject submitData) {
  66. AfterSales afterSales = afterSalesService.getById(businessId);
  67. afterSales.setStatus(FlowStatusEnum1.PASS.getKey());
  68. afterSalesService.updateById(afterSales);
  69. Long contractProductId = afterSales.getContractProductId();
  70. ContractProduct contractProduct = contractProductService.getById(contractProductId);
  71. Assert.notEmpty(contractProduct, "查询不到合同产品明细信息!");
  72. //计算售后价格
  73. BigDecimal multiply = contractProduct.getPrice().multiply(afterSales.getQuantity());
  74. //如果售后类型=仅退款30/退货退款40。审批通过后生成打款数据
  75. if (ObjectUtil.equals(afterSales, 30) || ObjectUtil.equals(afterSales, 40)) {
  76. // 添加一条付款流水
  77. AccountPayment accountPayment = new AccountPayment();
  78. SysUser sysUser = userService.getById(afterSales.getUserId());
  79. if (ObjectUtil.isNotEmpty(sysUser)) {
  80. accountPayment.setDepartmentId(sysUser.getDeptId());
  81. }
  82. accountPayment.setBusinessId(afterSales.getId());
  83. accountPayment.setPaymentTime(new Date());
  84. accountPayment.setCurrency("CNY");
  85. accountPayment.setStatus(PaymentStatusEnum.UNDER_REVIEW.getKey());
  86. accountPayment.setType(40);//售后
  87. accountPayment.setPaymentRemark(afterSales.getRemark());
  88. accountPayment.setIncomeAmount(multiply);
  89. accountPayment.setName(afterSales.getAccountName());
  90. accountPayment.setOpeningBank(afterSales.getOpeningBank());
  91. accountPayment.setAccountOpening(afterSales.getAccountOpening());
  92. accountPayment.setDataUser(afterSales.getUserId());
  93. accountPayment.setAmount(BigDecimal.ZERO);
  94. accountPayment.setCompanyId(afterSales.getCompanyId());
  95. accountPaymentService.save(accountPayment);
  96. }
  97. //如果售后类型=补发10/换货20。审批通过后,生成一条销售订单,与原销售订单信息基本一致:商品清单只有这一条,数量=售后数量,价格=0。默认审批通过
  98. if (ObjectUtil.equals(afterSales, 30) || ObjectUtil.equals(afterSales, 40)) {
  99. Contract contract = contractService.getById(contractProduct.getContractId());
  100. Assert.notEmpty(contract, "查询不到合同信息!");
  101. contract.setId(null);
  102. contract.setAmount(BigDecimal.ZERO);
  103. contractService.save(contract);
  104. ContractProduct contractProduct1 = contractProductService.getById(contractProductId);
  105. contractProduct1.setId(null);
  106. contractProduct1.setContractId(contract.getId());
  107. contractProduct1.setPrice(BigDecimal.ZERO);
  108. contractProduct1.setQuantity(afterSales.getQuantity());
  109. contractProductService.save(contractProduct1);
  110. }
  111. }
  112. }