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.

300 lines
14 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.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.setOrderType(1); //订单类型:1-收款
  101. cashRecord.setMarket(cashCollection.getMarket());
  102. //地区,根据jwcode插入
  103. //cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
  104. //插入新收款订单
  105. cashCollectionMapper.add(cashRecord);
  106. return "添加成功";
  107. }
  108. //撤回未审核的订单
  109. @Override
  110. public String cancel(String orderCode) {
  111. CashRecord cashRecord = cashCollectionMapper.selectByOrderCode(orderCode);
  112. if (cashRecord == null) {
  113. throw new IllegalArgumentException("订单不存在");
  114. }
  115. if (cashRecord.getStatus() != 0){
  116. throw new IllegalArgumentException("订单状态不符合条件");
  117. }
  118. //修改订单状态
  119. int rows = cashCollectionMapper.updateStatus(orderCode, 5);
  120. return rows > 0 ? "撤回成功" : "撤回失败";
  121. }
  122. //编辑并重新提交收款订单
  123. @Override
  124. public String reSubmit(CashRecord cashRecord) {
  125. if (cashRecord.getJwcode()==null){
  126. throw new IllegalArgumentException("精网号不能为空");
  127. }
  128. if(cashRecord.getJwcode()<10000000||cashRecord.getJwcode()>99999999){
  129. throw new IllegalArgumentException("精网号必须为8位");
  130. }
  131. if(cashRecord.getName()== null){
  132. throw new IllegalArgumentException("客户姓名不能为空");
  133. }
  134. if(cashRecord.getActivity()== null){
  135. throw new IllegalArgumentException("活动不能为空");
  136. }
  137. if(cashRecord.getGoodsName()== null){
  138. throw new IllegalArgumentException("商品名不能为空");
  139. }
  140. if(cashRecord.getGoodNum()== null){
  141. throw new IllegalArgumentException("商品数量不能为空");
  142. }
  143. if(cashRecord.getPaymentCurrency()== null){
  144. throw new IllegalArgumentException("支付币种不能为空");
  145. }
  146. if(cashRecord.getPaymentAmount()== null){
  147. throw new IllegalArgumentException("支付金额不能为空");
  148. }
  149. if (cashRecord.getPayType()== null){
  150. throw new IllegalArgumentException("支付方式不能为空");
  151. }
  152. if (cashRecord.getReceivedMarket()== null){
  153. throw new IllegalArgumentException("到账地区不能为空");
  154. }
  155. if(cashRecord.getPayTime()== null){
  156. throw new IllegalArgumentException("付款时间不能为空");
  157. }
  158. if (cashRecord.getVoucher()== null){
  159. throw new IllegalArgumentException("转账凭证不能为空");
  160. }
  161. if (cashRecord.getRemark()==null){
  162. throw new IllegalArgumentException("备注不能为空");
  163. }
  164. CashRecord status=cashCollectionMapper.selectByOrderCode(cashRecord.getOrderCode());
  165. if (!status.getStatus().equals(5)){
  166. throw new IllegalArgumentException("只允许编辑已撤回订单");
  167. }
  168. //地区,根据jwcode插入(弃用,插入前调用接口获取地区和姓名,之后前端传入)
  169. //cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
  170. int rows = cashCollectionMapper.updateByOrderCode(cashRecord);
  171. return rows > 0 ? "重新提交成功" : "重新提交失败";
  172. }
  173. //多条件查询收款订单列表
  174. @Override
  175. public PageInfo<CashCollection> selectCollection(Integer pageNum, Integer pageSize, CashCollection cashCollection) {
  176. //将操作人的地区列表改为id
  177. List<String> markets = marketMapper.getMarketIds(cashCollection.getMarkets());
  178. if (markets.contains("9") || markets.contains("9999")){
  179. markets=null;
  180. }
  181. cashCollection.setReceivedMarket(marketMapper.getMarketId(cashCollection.getReceivedMarket()));
  182. if (cashCollection.getCashRoleId()==2) {
  183. //角色是总部时,传1346,sql处理为(1,3,4,6)筛选,
  184. cashCollection.setStatus(1346);
  185. cashCollection.setSubmitterId(null);
  186. cashCollection.setReceivedMarket(null);
  187. }if (cashCollection.getCashRoleId()==1){
  188. //角色是地方财务,提交人置空不设筛选条件,仅按地区筛选,查看
  189. if(cashCollection.getStatus()==null){
  190. cashCollection.setStatus(123460);
  191. }
  192. cashCollection.setSubmitterId(null);
  193. }if (cashCollection.getCashRoleId()==0){
  194. //角色是地方财务,提交人置空不设筛选条件---仅当角色是0 地方客服时,按提交人筛选
  195. if(cashCollection.getStatus()==null){
  196. cashCollection.setStatus(1234560);
  197. }
  198. cashCollection.setSubmitterId(cashCollection.getSubmitterId());
  199. cashCollection.setReceivedMarket(null);
  200. }
  201. cashCollection.setMarkets(markets);
  202. PageHelper.startPage(pageNum, pageSize);
  203. List<CashCollection> cashCollections = cashCollectionMapper.selectCollection1(pageNum, pageSize, cashCollection);
  204. return new PageInfo<>(cashCollections);
  205. }
  206. //补全手续费等内容
  207. @Override
  208. public String complete(CashRecord cashRecord) {
  209. int rows = cashCollectionMapper.complete(cashRecord);
  210. return rows > 0 ? "编辑成功" : "编辑失败";
  211. }
  212. //根据精网号查询姓名和地区
  213. @Override
  214. public User getNameAndMarket(Integer jwcode) {
  215. User user = new User();
  216. user.setMarket(cashCollectionMapper.getMarketByJwcode(jwcode));
  217. user.setName(cashCollectionMapper.getNameByJwcode(jwcode));
  218. user.setMarketName(cashCollectionMapper.getMarketNameByJwcode(jwcode));
  219. return user;
  220. }
  221. //获取收款活动列表
  222. @Override
  223. public List<String> getActivityList() {
  224. return cashCollectionMapper.getActivityList();
  225. }
  226. //同步g_order订单到cash_record表
  227. @Override
  228. @Transactional(rollbackFor = Exception.class)
  229. public Object syncToCashRecord() {
  230. while (true) {
  231. List<GOrder> gOrders = cashCollectionMapper.getUnSync(100);
  232. if (CollectionUtils.isEmpty(gOrders)) {
  233. break;
  234. }
  235. for (GOrder gOrder : gOrders) {
  236. CashRecord cashRecord = new CashRecord();
  237. cashRecord.setOrderType(1);
  238. cashRecord.setJwcode(gOrder.getJwcode());
  239. cashRecord.setName(cashCollectionMapper.getNameByJwcode(gOrder.getJwcode()));
  240. cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(gOrder.getJwcode()));
  241. cashRecord.setActivity("Link日常充值");
  242. cashRecord.setOrderCode(gOrder.getOrderNo());
  243. if (gOrder != null) {
  244. switch (gOrder.getPayStyle()) {
  245. case 3:
  246. cashRecord.setPayType("IOS内购");
  247. cashRecord.setBankCode(gOrder.getIosTransactionId());
  248. cashRecord.setReceivedMarket("3");
  249. break;
  250. case 5:
  251. cashRecord.setPayType("Stripe-链接收款");
  252. cashRecord.setReceivedMarket("13");
  253. break;
  254. case 6:
  255. cashRecord.setPayType("PaymentAsia-链接收款");
  256. cashRecord.setReceivedMarket("13");
  257. break;
  258. case 7:
  259. cashRecord.setPayType("Ipay88-链接收款");
  260. cashRecord.setReceivedMarket("5");
  261. break;
  262. case 9:
  263. cashRecord.setPayType("FistData");
  264. cashRecord.setReceivedMarket("4");
  265. break;
  266. default:
  267. break;
  268. }
  269. }
  270. cashRecord.setGoodsName("Link充值金币");
  271. cashRecord.setGoodNum(0);
  272. cashRecord.setPermanentGold(gOrder.getCount());
  273. cashRecord.setFreeGold(0);
  274. cashRecord.setPaymentCurrency("");
  275. cashRecord.setPaymentAmount(BigDecimal.valueOf(0));
  276. cashRecord.setPayTime(LocalDateTime.ofEpochSecond(gOrder.getSuccessTime(), 0, ZoneOffset.UTC));
  277. cashRecord.setStatus(3);
  278. cashRecord.setSubmitterId(99999);
  279. cashRecord.setRemark("Link充值金币");
  280. //存入现金库
  281. cashCollectionMapper.add(cashRecord);
  282. cashCollectionMapper.markSynced(gOrder.getId());
  283. }log.info("同步完成一批,数量 {}", gOrders.size());
  284. if (gOrders.size() < 100) {
  285. break; // 最后一批
  286. }
  287. }return "同步完毕";
  288. }}