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.

311 lines
14 KiB

2 months ago
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.GOrder;
  4. import com.example.demo.domain.entity.User;
  5. import com.example.demo.domain.vo.cash.CashCollection;
  6. import com.example.demo.domain.vo.coin.Result;
  7. import com.example.demo.mapper.cash.CashCollectionMapper;
  8. import com.example.demo.mapper.coin.MarketMapper;
  9. import com.example.demo.service.cash.CashCollectionService;
  10. import com.github.pagehelper.PageHelper;
  11. import com.github.pagehelper.PageInfo;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import org.springframework.util.CollectionUtils;
  17. import java.math.BigDecimal;
  18. import java.time.LocalDateTime;
  19. import java.time.ZoneOffset;
  20. import java.util.List;
  21. import java.util.UUID;
  22. /**
  23. * @program: gold-java
  24. * @ClassName cashCollectionServiceImpl
  25. * @description:
  26. * @author: Ethan
  27. * @create: 202509-26 11:23
  28. * @Version 1.0
  29. **/
  30. @Service
  31. @Slf4j
  32. public class CashCollectionServiceImpl implements CashCollectionService {
  33. @Autowired
  34. private CashCollectionMapper cashCollectionMapper;
  35. @Autowired
  36. private MarketMapper marketMapper;
  37. //新增收款订单
  38. @Override
  39. public String add(CashCollection cashCollection) {
  40. if (cashCollection.getJwcode()==null){
  41. throw new IllegalArgumentException("精网号不能为空");
  42. }
  43. if(cashCollection.getJwcode()<10000000||cashCollection.getJwcode()>99999999){
  44. throw new IllegalArgumentException("精网号必须为8位");
  45. }
  46. if(cashCollection.getName()== null){
  47. throw new IllegalArgumentException("客户姓名不能为空");
  48. }
  49. if(cashCollection.getActivity()== null){
  50. throw new IllegalArgumentException("活动不能为空");
  51. }
  52. if(cashCollection.getGoodsName()== null){
  53. throw new IllegalArgumentException("商品名不能为空");
  54. }
  55. if(cashCollection.getGoodNum()== null && cashCollection.getPermanentGold()== null && cashCollection.getFreeGold()== null){
  56. throw new IllegalArgumentException("商品数量或金币数量不能为空");
  57. }
  58. if(cashCollection.getPaymentCurrency()== null){
  59. throw new IllegalArgumentException("支付币种不能为空");
  60. }
  61. if(cashCollection.getPaymentAmount()== null){
  62. throw new IllegalArgumentException("支付金额不能为空");
  63. }
  64. if (cashCollection.getPayType()== null){
  65. throw new IllegalArgumentException("支付方式不能为空");
  66. }
  67. if (cashCollection.getReceivedMarket()== null){
  68. throw new IllegalArgumentException("到账地区不能为空");
  69. }
  70. if(cashCollection.getPayTime()== null){
  71. throw new IllegalArgumentException("付款时间不能为空");
  72. }
  73. if (cashCollection.getVoucher()== null){
  74. throw new IllegalArgumentException("转账凭证不能为空");
  75. }
  76. if (cashCollection.getRemark()==null){
  77. throw new IllegalArgumentException("备注不能为空");
  78. }
  79. //生成订单号后半部分
  80. String orderNumber = UUID.randomUUID().toString().replaceAll("-", "");
  81. CashRecord cashRecord = new CashRecord();
  82. //构建订单信息
  83. cashRecord.setOrderCode("XJ_" + orderNumber); //订单号
  84. cashRecord.setJwcode(cashCollection.getJwcode()); //精网号
  85. cashRecord.setName(cashCollection.getName()); //客户姓名
  86. cashRecord.setActivity(cashCollection.getActivity()); // 活动
  87. cashRecord.setGoodsName(cashCollection.getGoodsName()); //商品名称
  88. cashRecord.setGoodNum(cashCollection.getGoodNum()); //商品数量
  89. cashRecord.setPermanentGold(cashCollection.getPermanentGold()); //永久金币
  90. cashRecord.setFreeGold(cashCollection.getFreeGold()); //免费金币
  91. cashRecord.setPaymentCurrency(cashCollection.getPaymentCurrency()); //付款币种
  92. cashRecord.setPaymentAmount(cashCollection.getPaymentAmount()); //付款金额
  93. cashRecord.setReceivedMarket(cashCollection.getReceivedMarket()); //到账地区
  94. cashRecord.setPayType(cashCollection.getPayType()); //支付方式
  95. cashRecord.setPayTime(cashCollection.getPayTime()); //付款时间
  96. cashRecord.setVoucher(cashCollection.getVoucher()); //转账凭证
  97. cashRecord.setRemark(cashCollection.getRemark()); //备注
  98. cashRecord.setStatus(0); //订单状态:付款线下财务待审核
  99. cashRecord.setSubmitterId(cashCollection.getSubmitterId()); //提交人ID
  100. cashRecord.setSubmitterMarket(cashCollection.getSubmitterMarket());
  101. cashRecord.setOrderType(1); //订单类型:1-收款
  102. cashRecord.setMarket(cashCollection.getMarket());
  103. //地区,根据jwcode插入
  104. //cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
  105. //插入新收款订单
  106. cashCollectionMapper.add(cashRecord);
  107. return "添加成功";
  108. }
  109. //撤回未审核的订单
  110. @Override
  111. public String cancel(String orderCode) {
  112. CashRecord cashRecord = cashCollectionMapper.selectByOrderCode(orderCode);
  113. if (cashRecord == null) {
  114. throw new IllegalArgumentException("订单不存在");
  115. }
  116. if (cashRecord.getStatus() != 0){
  117. throw new IllegalArgumentException("订单状态不符合条件");
  118. }
  119. //修改订单状态
  120. int rows = cashCollectionMapper.updateStatus(orderCode, 5);
  121. return rows > 0 ? "撤回成功" : "撤回失败";
  122. }
  123. //编辑并重新提交收款订单
  124. @Override
  125. public String reSubmit(CashRecord cashRecord) {
  126. if (cashRecord.getJwcode()==null){
  127. throw new IllegalArgumentException("精网号不能为空");
  128. }
  129. if(cashRecord.getJwcode()<10000000||cashRecord.getJwcode()>99999999){
  130. throw new IllegalArgumentException("精网号必须为8位");
  131. }
  132. if(cashRecord.getName()== null){
  133. throw new IllegalArgumentException("客户姓名不能为空");
  134. }
  135. if(cashRecord.getActivity()== null){
  136. throw new IllegalArgumentException("活动不能为空");
  137. }
  138. if(cashRecord.getGoodsName()== null){
  139. throw new IllegalArgumentException("商品名不能为空");
  140. }
  141. if(cashRecord.getGoodNum()== null){
  142. throw new IllegalArgumentException("商品数量不能为空");
  143. }
  144. if(cashRecord.getPaymentCurrency()== null){
  145. throw new IllegalArgumentException("支付币种不能为空");
  146. }
  147. if(cashRecord.getPaymentAmount()== null){
  148. throw new IllegalArgumentException("支付金额不能为空");
  149. }
  150. if (cashRecord.getPayType()== null){
  151. throw new IllegalArgumentException("支付方式不能为空");
  152. }
  153. if (cashRecord.getReceivedMarket()== null){
  154. throw new IllegalArgumentException("到账地区不能为空");
  155. }
  156. if(cashRecord.getPayTime()== null){
  157. throw new IllegalArgumentException("付款时间不能为空");
  158. }
  159. if (cashRecord.getVoucher()== null){
  160. throw new IllegalArgumentException("转账凭证不能为空");
  161. }
  162. if (cashRecord.getRemark()==null){
  163. throw new IllegalArgumentException("备注不能为空");
  164. }
  165. CashRecord status=cashCollectionMapper.selectByOrderCode(cashRecord.getOrderCode());
  166. if (!status.getStatus().equals(5)){
  167. throw new IllegalArgumentException("只允许编辑已撤回订单");
  168. }
  169. //地区,根据jwcode插入(弃用,插入前调用接口获取地区和姓名,之后前端传入)
  170. //cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
  171. int rows = cashCollectionMapper.updateByOrderCode(cashRecord);
  172. return rows > 0 ? "重新提交成功" : "重新提交失败";
  173. }
  174. //多条件查询收款订单列表
  175. @Override
  176. public PageInfo<CashCollection> selectCollection(Integer pageNum, Integer pageSize, CashCollection cashCollection) {
  177. //将操作人的地区列表改为id
  178. List<String> markets = marketMapper.getMarketIds(cashCollection.getMarkets());
  179. if (markets.contains("9") || markets.contains("9999")){
  180. markets=null;
  181. }
  182. // cashCollection.setReceivedMarket(marketMapper.getMarketId(cashCollection.getReceivedMarket()));
  183. if (cashCollection.getCashRoleId()==2) {
  184. //角色是总部时,若不特地传状态,传1346,sql处理为(1,3,4,6)筛选,
  185. if(cashCollection.getStatus()==null){
  186. cashCollection.setStatus(1346);}
  187. cashCollection.setSubmitterId(null);
  188. cashCollection.setReceivedMarket(null);
  189. cashCollection.setSubmitterMarket(null);
  190. }
  191. if (cashCollection.getCashRoleId()==1){
  192. //角色是地方财务,提交人置空不设筛选条件,仅按收款地区、提交人地区筛选()
  193. if(cashCollection.getStatus()==null){
  194. cashCollection.setStatus(123460);}
  195. //状态为待审核和已驳回时按照提交人地区筛选
  196. if (cashCollection.getStatus()==0||cashCollection.getStatus()==2){
  197. cashCollection.setReceivedMarket(null);}
  198. //状态为已通过和Link通过时,按收款地区筛选
  199. if (cashCollection.getStatus()==13){
  200. cashCollection.setSubmitterMarket(null);}
  201. cashCollection.setSubmitterId(null);
  202. //状态为46,已通过和已退款,满足收款地区或提交人地区即可,
  203. }
  204. if (cashCollection.getCashRoleId()==0){
  205. //角色是地方财务,提交人置空不设筛选条件---仅当角色是0 地方客服时,按提交人筛选
  206. if(cashCollection.getStatus()==null){
  207. cashCollection.setStatus(1234560);}
  208. cashCollection.setSubmitterId(cashCollection.getSubmitterId());
  209. cashCollection.setReceivedMarket(null);
  210. }
  211. cashCollection.setMarkets(markets);
  212. PageHelper.startPage(pageNum, pageSize);
  213. List<CashCollection> cashCollections = cashCollectionMapper.selectCollection1(pageNum, pageSize, cashCollection);
  214. return new PageInfo<>(cashCollections);
  215. }
  216. //补全手续费等内容
  217. @Override
  218. public String complete(CashRecord cashRecord) {
  219. int rows = cashCollectionMapper.complete(cashRecord);
  220. return rows > 0 ? "编辑成功" : "编辑失败";
  221. }
  222. //根据精网号查询姓名和地区
  223. @Override
  224. public User getNameAndMarket(Integer jwcode) {
  225. User user = new User();
  226. user.setMarket(cashCollectionMapper.getMarketByJwcode(jwcode));
  227. user.setName(cashCollectionMapper.getNameByJwcode(jwcode));
  228. user.setMarketName(cashCollectionMapper.getMarketNameByJwcode(jwcode));
  229. return user;
  230. }
  231. //获取收款活动列表
  232. @Override
  233. public List<String> getActivityList() {
  234. return cashCollectionMapper.getActivityList();
  235. }
  236. //同步g_order订单到cash_record表
  237. @Override
  238. @Transactional(rollbackFor = Exception.class)
  239. public Object syncToCashRecord() {
  240. while (true) {
  241. List<GOrder> gOrders = cashCollectionMapper.getUnSync(100);
  242. if (CollectionUtils.isEmpty(gOrders)) {
  243. break;
  244. }
  245. for (GOrder gOrder : gOrders) {
  246. CashRecord cashRecord = new CashRecord();
  247. cashRecord.setOrderType(1);
  248. cashRecord.setJwcode(gOrder.getJwcode());
  249. cashRecord.setName(cashCollectionMapper.getNameByJwcode(gOrder.getJwcode()));
  250. cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(gOrder.getJwcode()));
  251. cashRecord.setActivity("Link日常充值");
  252. cashRecord.setOrderCode(gOrder.getOrderNo());
  253. if (gOrder != null) {
  254. switch (gOrder.getPayStyle()) {
  255. case 3:
  256. cashRecord.setPayType("IOS内购");
  257. cashRecord.setBankCode(gOrder.getIosTransactionId());
  258. cashRecord.setReceivedMarket("3");
  259. break;
  260. case 5:
  261. cashRecord.setPayType("Stripe-链接收款");
  262. cashRecord.setReceivedMarket("13");
  263. break;
  264. case 6:
  265. cashRecord.setPayType("PaymentAsia-链接收款");
  266. cashRecord.setReceivedMarket("13");
  267. break;
  268. case 7:
  269. cashRecord.setPayType("Ipay88-链接收款");
  270. cashRecord.setReceivedMarket("5");
  271. break;
  272. case 9:
  273. cashRecord.setPayType("FistData");
  274. cashRecord.setReceivedMarket("4");
  275. break;
  276. default:
  277. break;
  278. }
  279. }
  280. cashRecord.setGoodsName("Link充值金币");
  281. cashRecord.setGoodNum(0);
  282. cashRecord.setPermanentGold(gOrder.getCount());
  283. cashRecord.setFreeGold(0);
  284. cashRecord.setPaymentCurrency("");
  285. cashRecord.setPaymentAmount(BigDecimal.valueOf(0));
  286. cashRecord.setPayTime(LocalDateTime.ofEpochSecond(gOrder.getSuccessTime(), 0, ZoneOffset.UTC));
  287. cashRecord.setStatus(3);
  288. cashRecord.setSubmitterId(99999);
  289. cashRecord.setRemark("Link充值金币");
  290. //存入现金库
  291. cashCollectionMapper.add(cashRecord);
  292. cashCollectionMapper.markSynced(gOrder.getId());
  293. }log.info("同步完成一批,数量 {}", gOrders.size());
  294. if (gOrders.size() < 100) {
  295. break; // 最后一批
  296. }
  297. }return "同步完毕";
  298. }}