You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
10 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. package com.example.demo.serviceImpl.cash;
  2. import com.example.demo.domain.entity.CashRecord;
  3. import com.example.demo.domain.entity.User;
  4. import com.example.demo.domain.vo.cash.CashCollection;
  5. import com.example.demo.domain.vo.coin.Result;
  6. import com.example.demo.mapper.cash.CashCollectionMapper;
  7. import com.example.demo.mapper.coin.MarketMapper;
  8. import com.example.demo.service.cash.CashCollectionService;
  9. import com.github.pagehelper.PageHelper;
  10. import com.github.pagehelper.PageInfo;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Service;
  13. import java.util.List;
  14. import java.util.UUID;
  15. /**
  16. * @program: gold-java
  17. * @ClassName cashCollectionServiceImpl
  18. * @description:
  19. * @author: Ethan
  20. * @create: 202509-26 11:23
  21. * @Version 1.0
  22. **/
  23. @Service
  24. public class CashCollectionServiceImpl implements CashCollectionService {
  25. @Autowired
  26. private CashCollectionMapper cashCollectionMapper;
  27. @Autowired
  28. private MarketMapper marketMapper;
  29. //新增收款订单
  30. @Override
  31. public String add(CashCollection cashCollection) {
  32. if (cashCollection.getJwcode()==null){
  33. throw new IllegalArgumentException("精网号不能为空");
  34. }
  35. if(cashCollection.getJwcode()<10000000||cashCollection.getJwcode()>99999999){
  36. throw new IllegalArgumentException("精网号必须为8位");
  37. }
  38. if(cashCollection.getName()== null){
  39. throw new IllegalArgumentException("客户姓名不能为空");
  40. }
  41. if(cashCollection.getActivity()== null){
  42. throw new IllegalArgumentException("活动不能为空");
  43. }
  44. if(cashCollection.getGoodsName()== null){
  45. throw new IllegalArgumentException("商品名不能为空");
  46. }
  47. if(cashCollection.getGoodNum()== null && cashCollection.getPermanentGold()== null && cashCollection.getFreeGold()== null){
  48. throw new IllegalArgumentException("商品数量或金币数量不能为空");
  49. }
  50. if(cashCollection.getPaymentCurrency()== null){
  51. throw new IllegalArgumentException("支付币种不能为空");
  52. }
  53. if(cashCollection.getPaymentAmount()== null){
  54. throw new IllegalArgumentException("支付金额不能为空");
  55. }
  56. if (cashCollection.getPayType()== null){
  57. throw new IllegalArgumentException("支付方式不能为空");
  58. }
  59. if (cashCollection.getReceivedMarket()== null){
  60. throw new IllegalArgumentException("到账地区不能为空");
  61. }
  62. if(cashCollection.getPayTime()== null){
  63. throw new IllegalArgumentException("付款时间不能为空");
  64. }
  65. if (cashCollection.getVoucher()== null){
  66. throw new IllegalArgumentException("转账凭证不能为空");
  67. }
  68. if (cashCollection.getRemark()==null){
  69. throw new IllegalArgumentException("备注不能为空");
  70. }
  71. //生成订单号后半部分
  72. String orderNumber = UUID.randomUUID().toString().replaceAll("-", "");
  73. CashRecord cashRecord = new CashRecord();
  74. //构建订单信息
  75. cashRecord.setOrderCode("XJ_" + orderNumber); //订单号
  76. cashRecord.setJwcode(cashCollection.getJwcode()); //精网号
  77. cashRecord.setName(cashCollection.getName()); //客户姓名
  78. cashRecord.setActivity(cashCollection.getActivity()); // 活动
  79. cashRecord.setGoodsName(cashCollection.getGoodsName()); //商品名称
  80. cashRecord.setGoodNum(cashCollection.getGoodNum()); //商品数量
  81. cashRecord.setPermanentGold(cashCollection.getPermanentGold()); //永久金币
  82. cashRecord.setFreeGold(cashCollection.getFreeGold()); //免费金币
  83. cashRecord.setPaymentCurrency(cashCollection.getPaymentCurrency()); //付款币种
  84. cashRecord.setPaymentAmount(cashCollection.getPaymentAmount()); //付款金额
  85. cashRecord.setReceivedMarket(cashCollection.getReceivedMarket()); //到账地区
  86. cashRecord.setPayType(cashCollection.getPayType()); //支付方式
  87. cashRecord.setPayTime(cashCollection.getPayTime()); //付款时间
  88. cashRecord.setVoucher(cashCollection.getVoucher()); //转账凭证
  89. cashRecord.setRemark(cashCollection.getRemark()); //备注
  90. cashRecord.setStatus(0); //订单状态:付款线下财务待审核
  91. cashRecord.setSubmitterId(cashCollection.getSubmitterId()); //提交人ID
  92. cashRecord.setOrderType(1); //订单类型:1-收款
  93. cashRecord.setMarket(cashCollection.getMarket());
  94. //地区,根据jwcode插入
  95. //cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
  96. //插入新收款订单
  97. cashCollectionMapper.add(cashRecord);
  98. return "添加成功";
  99. }
  100. //撤回未审核的订单
  101. @Override
  102. public String cancel(String orderCode) {
  103. CashRecord cashRecord = cashCollectionMapper.selectByOrderCode(orderCode);
  104. if (cashRecord == null) {
  105. throw new IllegalArgumentException("订单不存在");
  106. }
  107. if (cashRecord.getStatus() != 0){
  108. throw new IllegalArgumentException("订单状态不符合条件");
  109. }
  110. //修改订单状态
  111. int rows = cashCollectionMapper.updateStatus(orderCode, 5);
  112. return rows > 0 ? "撤回成功" : "撤回失败";
  113. }
  114. //编辑并重新提交收款订单
  115. @Override
  116. public String reSubmit(CashRecord cashRecord) {
  117. if (cashRecord.getJwcode()==null){
  118. throw new IllegalArgumentException("精网号不能为空");
  119. }
  120. if(cashRecord.getJwcode()<10000000||cashRecord.getJwcode()>99999999){
  121. throw new IllegalArgumentException("精网号必须为8位");
  122. }
  123. if(cashRecord.getName()== null){
  124. throw new IllegalArgumentException("客户姓名不能为空");
  125. }
  126. if(cashRecord.getActivity()== null){
  127. throw new IllegalArgumentException("活动不能为空");
  128. }
  129. if(cashRecord.getGoodsName()== null){
  130. throw new IllegalArgumentException("商品名不能为空");
  131. }
  132. if(cashRecord.getGoodNum()== null){
  133. throw new IllegalArgumentException("商品数量不能为空");
  134. }
  135. if(cashRecord.getPaymentCurrency()== null){
  136. throw new IllegalArgumentException("支付币种不能为空");
  137. }
  138. if(cashRecord.getPaymentAmount()== null){
  139. throw new IllegalArgumentException("支付金额不能为空");
  140. }
  141. if (cashRecord.getPayType()== null){
  142. throw new IllegalArgumentException("支付方式不能为空");
  143. }
  144. if (cashRecord.getReceivedMarket()== null){
  145. throw new IllegalArgumentException("到账地区不能为空");
  146. }
  147. if(cashRecord.getPayTime()== null){
  148. throw new IllegalArgumentException("付款时间不能为空");
  149. }
  150. if (cashRecord.getVoucher()== null){
  151. throw new IllegalArgumentException("转账凭证不能为空");
  152. }
  153. if (cashRecord.getRemark()==null){
  154. throw new IllegalArgumentException("备注不能为空");
  155. }
  156. CashRecord status=cashCollectionMapper.selectByOrderCode(cashRecord.getOrderCode());
  157. if (!status.getStatus().equals(5)){
  158. throw new IllegalArgumentException("只允许编辑已撤回订单");
  159. }
  160. //地区,根据jwcode插入(弃用,插入前调用接口获取地区和姓名,之后前端传入)
  161. //cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
  162. int rows = cashCollectionMapper.updateByOrderCode(cashRecord);
  163. return rows > 0 ? "重新提交成功" : "重新提交失败";
  164. }
  165. //多条件查询收款订单列表
  166. @Override
  167. public PageInfo<CashCollection> selectCollection(Integer pageNum, Integer pageSize, CashCollection cashCollection) {
  168. //将操作人的地区列表改为id
  169. List<String> markets = marketMapper.getMarketIds(cashCollection.getMarkets());
  170. if (markets.contains("9") || markets.contains("9999")){
  171. markets=null;
  172. }
  173. cashCollection.setReceivedMarket(marketMapper.getMarketId(cashCollection.getReceivedMarket()));
  174. if (cashCollection.getCashRoleId()==2) {
  175. //角色是总部时,传1346,sql处理为(1,3,4,6)筛选,
  176. cashCollection.setStatus(1346);
  177. cashCollection.setSubmitterId(null);
  178. cashCollection.setReceivedMarket(null);
  179. }if (cashCollection.getCashRoleId()==1){
  180. //角色是地方财务,提交人置空不设筛选条件,仅按地区筛选,查看
  181. if(cashCollection.getStatus()==null){
  182. cashCollection.setStatus(123460);
  183. }
  184. cashCollection.setSubmitterId(null);
  185. }if (cashCollection.getCashRoleId()==0){
  186. //角色是地方财务,提交人置空不设筛选条件---仅当角色是0 地方客服时,按提交人筛选
  187. cashCollection.setStatus(null);
  188. cashCollection.setSubmitterId(cashCollection.getSubmitterId());
  189. cashCollection.setReceivedMarket(null);
  190. }
  191. cashCollection.setMarkets(markets);
  192. PageHelper.startPage(pageNum, pageSize);
  193. List<CashCollection> cashCollections = cashCollectionMapper.selectCollection1(pageNum, pageSize, cashCollection);
  194. return new PageInfo<>(cashCollections);
  195. }
  196. //补全手续费等内容
  197. @Override
  198. public String complete(CashRecord cashRecord) {
  199. int rows = cashCollectionMapper.complete(cashRecord);
  200. return rows > 0 ? "编辑成功" : "编辑失败";
  201. }
  202. //根据精网号查询姓名和地区
  203. @Override
  204. public User getNameAndMarket(Integer jwcode) {
  205. User user = new User();
  206. user.setMarket(cashCollectionMapper.getMarketByJwcode(jwcode));
  207. user.setName(cashCollectionMapper.getNameByJwcode(jwcode));
  208. user.setMarketName(cashCollectionMapper.getMarketNameByJwcode(jwcode));
  209. return user;
  210. }
  211. //获取收款活动列表
  212. @Override
  213. public List<String> getActivityList() {
  214. return cashCollectionMapper.getActivityList();
  215. }
  216. }