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.

599 lines
28 KiB

2 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
2 months ago
  1. package com.example.demo.serviceImpl.cash;
  2. import com.example.demo.Util.JWTUtil;
  3. import com.example.demo.Util.LanguageTranslationUtil;
  4. import com.example.demo.config.RabbitMQConfig;
  5. import com.example.demo.domain.DTO.PerformanceDTO;
  6. import com.example.demo.domain.entity.*;
  7. import com.example.demo.domain.vo.cash.CashCollection;
  8. import com.example.demo.domain.vo.cash.CashCollectionMessage;
  9. import com.example.demo.domain.vo.cash.PerformanceVO;
  10. import com.example.demo.domain.vo.coin.GoldUser;
  11. import com.example.demo.domain.vo.coin.Messages;
  12. import com.example.demo.domain.vo.coin.Result;
  13. import com.example.demo.mapper.cash.CashCollectionMapper;
  14. import com.example.demo.mapper.coin.MarketMapper;
  15. import com.example.demo.mapper.coin.UserMapper;
  16. import com.example.demo.service.cash.CashCollectionService;
  17. import com.github.pagehelper.PageHelper;
  18. import com.github.pagehelper.PageInfo;
  19. import jakarta.servlet.http.HttpServletRequest;
  20. import lombok.extern.slf4j.Slf4j;
  21. import org.springframework.amqp.rabbit.core.RabbitTemplate;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Service;
  24. import org.springframework.transaction.annotation.Transactional;
  25. import org.springframework.util.CollectionUtils;
  26. import org.springframework.web.bind.annotation.RequestHeader;
  27. import org.springframework.web.context.request.RequestContextHolder;
  28. import org.springframework.web.context.request.ServletRequestAttributes;
  29. import java.math.BigDecimal;
  30. import java.time.LocalDateTime;
  31. import java.time.ZoneOffset;
  32. import java.util.Arrays;
  33. import java.util.List;
  34. import java.util.Objects;
  35. import java.util.UUID;
  36. import java.util.stream.Collectors;
  37. /**
  38. * @program: gold-java
  39. * @ClassName cashCollectionServiceImpl
  40. * @description: 处理收款相关业务逻辑
  41. * @author: Ethan
  42. * @create: 202509-26 11:23
  43. * @Version 1.0
  44. **/
  45. @Service
  46. @Slf4j
  47. public class CashCollectionServiceImpl implements CashCollectionService {
  48. @Autowired
  49. private CashCollectionMapper cashCollectionMapper;
  50. @Autowired
  51. private UserMapper userMapper;
  52. @Autowired
  53. private MarketMapper marketMapper;
  54. @Autowired
  55. private RabbitTemplate rabbitTemplate;
  56. @Autowired
  57. private LanguageTranslationUtil languageTranslationUtil;
  58. //新增收款订单
  59. @Override
  60. public String add(CashCollection cashCollection,@RequestHeader(defaultValue = "zh_CN") String lang) {
  61. if (cashCollection.getJwcode() == null) {
  62. throw new IllegalArgumentException("精网号不能为空");
  63. }
  64. if (cashCollection.getJwcode() < 10000000 || cashCollection.getJwcode() > 99999999) {
  65. throw new IllegalArgumentException("精网号必须为8位");
  66. }
  67. if (cashCollection.getName() == null || cashCollection.getName().isEmpty()){
  68. throw new IllegalArgumentException("客户姓名不能为空");
  69. }
  70. if (cashCollection.getActivity() == null || cashCollection.getActivity().isEmpty()) {
  71. throw new IllegalArgumentException("活动不能为空");
  72. }
  73. if (cashCollection.getGoodsName() == null|| cashCollection.getGoodsName().isEmpty()) {
  74. throw new IllegalArgumentException("产品名称不能为空");
  75. }
  76. if (cashCollection.getGoodsName().equals("金币充值")) {
  77. if (cashCollection.getPermanentGold() == 0 && cashCollection.getFreeGold() == 0) {
  78. throw new IllegalArgumentException("金币数量不能为空");
  79. }
  80. }
  81. if (!cashCollection.getGoodsName().equals("金币充值")) {
  82. if (cashCollection.getGoodNum() == 0) {
  83. throw new IllegalArgumentException("产品数量不能为空");
  84. }
  85. if (cashCollection.getNumUnit() == null|| cashCollection.getNumUnit().isEmpty()) {
  86. throw new IllegalArgumentException("数量单位不能为空");
  87. }
  88. }
  89. if (cashCollection.getPaymentCurrency() == null || cashCollection.getPaymentCurrency().isEmpty()) {
  90. throw new IllegalArgumentException("支付币种不能为空");
  91. }
  92. if (cashCollection.getPaymentAmount() == null || cashCollection.getPaymentAmount().compareTo(BigDecimal.ZERO) == 0) {
  93. throw new IllegalArgumentException("支付金额不能为空");
  94. }
  95. if (cashCollection.getPayType() == null|| cashCollection.getPayType().isEmpty()) {
  96. throw new IllegalArgumentException("支付方式不能为空");
  97. }
  98. if (cashCollection.getReceivedMarket() == null||cashCollection.getReceivedMarket().isEmpty()) {
  99. throw new IllegalArgumentException("到账地区不能为空");
  100. }
  101. if (cashCollection.getPayTime() == null) {
  102. throw new IllegalArgumentException("付款时间不能为空");
  103. }
  104. //生成订单号后半部分
  105. String orderNumber = UUID.randomUUID().toString().replaceAll("-", "");
  106. CashRecord cashRecord = new CashRecord();
  107. //构建订单信息
  108. cashRecord.setOrderCode("XJ_" + orderNumber); //订单号
  109. cashRecord.setJwcode(cashCollection.getJwcode()); //精网号
  110. cashRecord.setName(cashCollection.getName()); //客户姓名
  111. cashRecord.setActivity(cashCollection.getActivity()); // 活动
  112. cashRecord.setGoodsName(cashCollection.getGoodsName()); //商品名称
  113. cashRecord.setGoodNum(cashCollection.getGoodNum()); //商品数量
  114. cashRecord.setNumUnit(cashCollection.getNumUnit()); //数量单位
  115. cashRecord.setPermanentGold(cashCollection.getPermanentGold()); //永久金币
  116. cashRecord.setFreeGold(cashCollection.getFreeGold()); //免费金币
  117. cashRecord.setPaymentCurrency(cashCollection.getPaymentCurrency()); //付款币种
  118. cashRecord.setPaymentAmount(cashCollection.getPaymentAmount()); //付款金额
  119. cashRecord.setReceivedMarket(cashCollection.getReceivedMarket()); //到账地区
  120. cashRecord.setPayType(cashCollection.getPayType()); //支付方式
  121. cashRecord.setPayTime(cashCollection.getPayTime()); //付款时间
  122. cashRecord.setVoucher(cashCollection.getVoucher()); //转账凭证
  123. cashRecord.setRemark(cashCollection.getRemark()); //备注
  124. cashRecord.setStatus(0); //订单状态:付款线下财务待审核
  125. cashRecord.setSubmitterId(cashCollection.getSubmitterId()); //提交人ID
  126. cashRecord.setSubmitterMarket(cashCollection.getSubmitterMarket());
  127. cashRecord.setOrderType(1); //订单类型:1-收款
  128. cashRecord.setMarket(cashCollection.getMarket());
  129. //地区,根据jwcode插入
  130. //cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
  131. //插入新收款订单
  132. cashCollectionMapper.add(cashRecord);
  133. // 发送收款创建消息
  134. Messages message = new Messages();
  135. message.setJwcode(cashRecord.getJwcode());
  136. message.setName(cashRecord.getName());
  137. message.setStatus(cashRecord.getStatus());
  138. message.setDesc("的现金收款申请待审核,前往审核");
  139. message.setTitle("现金管理--收款处理");
  140. message.setType(0);
  141. message.setTypeId(cashRecord.getId());
  142. message.setMarket(Integer.valueOf(cashRecord.getMarket()));
  143. String marketName = marketMapper.getMarketNameById(String.valueOf(message.getMarket()));
  144. message.setMarketName(marketName);
  145. message.setQueryId(67);
  146. rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_COLLECTION_EXCHANGE, "cash.collection.save", message);
  147. return "添加成功";
  148. }
  149. @Override
  150. public String addFreeCoin(CashCollection cashCollection,@RequestHeader(defaultValue = "zh_CN") String lang) {
  151. if (cashCollection.getJwcode() == null) {
  152. throw new IllegalArgumentException("精网号不能为空");
  153. }
  154. if (cashCollection.getJwcode() < 10000000 || cashCollection.getJwcode() > 99999999) {
  155. throw new IllegalArgumentException("精网号必须为8位");
  156. }
  157. if (cashCollection.getName() == null || cashCollection.getName().isEmpty()){
  158. throw new IllegalArgumentException("客户姓名不能为空");
  159. }
  160. if (cashCollection.getActivity() == null || cashCollection.getActivity().isEmpty()) {
  161. throw new IllegalArgumentException("活动不能为空");
  162. }
  163. if (cashCollection.getFreeGold() == 0) {
  164. throw new IllegalArgumentException("免费金币数量不能为空");
  165. }
  166. //生成订单号后半部分
  167. String orderNumber = UUID.randomUUID().toString().replaceAll("-", "");
  168. CashRecord cashRecord = new CashRecord();
  169. //构建订单信息
  170. cashRecord.setOrderCode("XJ_" + orderNumber); //订单号
  171. cashRecord.setJwcode(cashCollection.getJwcode()); //精网号
  172. cashRecord.setName(cashCollection.getName()); //客户姓名
  173. cashRecord.setActivity(cashCollection.getActivity()); // 活动
  174. cashRecord.setGoodsName("免费金币赠送"); //商品名称
  175. cashRecord.setFreeGold(cashCollection.getFreeGold()); //免费金币
  176. cashRecord.setRemark(cashCollection.getRemark()); //备注
  177. cashRecord.setStatus(0); //订单状态:付款线下财务待审核
  178. cashRecord.setSubmitterId(cashCollection.getSubmitterId()); //提交人ID
  179. cashRecord.setSubmitterMarket(cashCollection.getSubmitterMarket());
  180. cashRecord.setOrderType(1); //订单类型:1-收款
  181. cashRecord.setMarket(cashCollection.getMarket());
  182. //地区,根据jwcode插入
  183. //cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
  184. //插入新收款订单
  185. cashCollectionMapper.add(cashRecord);
  186. // 发送收款创建消息
  187. Messages message = new Messages();
  188. message.setJwcode(cashRecord.getJwcode());
  189. message.setName(cashRecord.getName());
  190. message.setStatus(cashRecord.getStatus());
  191. message.setDesc("的现金收款申请待审核,请前往审核");
  192. message.setTitle("现金收款--现金收款");
  193. message.setType(1);
  194. message.setTypeId(cashRecord.getId());
  195. message.setMarket(Integer.valueOf(cashRecord.getMarket()));
  196. String marketName = marketMapper.getMarketNameById(String.valueOf(message.getMarket()));
  197. message.setMarketName(marketName);
  198. message.setQueryId(67);
  199. rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_COLLECTION_EXCHANGE, "cash.collection.save", message);
  200. return "添加成功";
  201. }
  202. //撤回未审核的订单
  203. @Override
  204. public String cancel(String orderCode) {
  205. // 查询订单是否存在
  206. CashRecord cashRecord = cashCollectionMapper.selectByOrderCode(orderCode);
  207. if (cashRecord == null) {
  208. throw new IllegalArgumentException("订单不存在");
  209. }
  210. if (cashRecord.getStatus() != 0) {
  211. throw new IllegalArgumentException("订单状态不符合条件");
  212. }
  213. // 更新订单状态为撤回状态(5)
  214. int rows = cashCollectionMapper.updateStatus(orderCode, 5);
  215. // 更新与该订单关联的消息记录的 flag 字段为 1
  216. try {
  217. // 根据订单ID查找关联的消息记录
  218. Messages message = new Messages();
  219. message.setTypeId(cashRecord.getId()); // 订单ID作为消息的 typeId
  220. message.setType(0); // 消息类型为收款
  221. // 更新消息的 flag 字段为 1
  222. int messageRows = cashCollectionMapper.updateMessageFlagByTypeIdAndType(
  223. message.getTypeId(), message.getType(), 1);
  224. if (messageRows <= 0) {
  225. log.warn("未找到与订单 {} 关联的消息记录", orderCode);
  226. }
  227. } catch (Exception e) {
  228. log.error("更新消息状态失败,订单号:{}", orderCode, e);
  229. // 可选择抛出异常或记录日志后继续执行
  230. }
  231. return rows > 0 ? "撤回成功" : "撤回失败";
  232. }
  233. //编辑并重新提交收款订单
  234. @Override
  235. public String reSubmit(CashRecord cashRecord,@RequestHeader(defaultValue = "zh_CN") String lang) {
  236. if (cashRecord.getJwcode() == null) {
  237. throw new IllegalArgumentException("精网号不能为空");
  238. }
  239. if (cashRecord.getJwcode() < 10000000 || cashRecord.getJwcode() > 99999999) {
  240. throw new IllegalArgumentException("精网号必须为8位");
  241. }
  242. if (cashRecord.getName() == null) {
  243. throw new IllegalArgumentException("客户姓名不能为空");
  244. }
  245. if (cashRecord.getActivity() == null) {
  246. throw new IllegalArgumentException("活动不能为空");
  247. }
  248. if (cashRecord.getGoodsName() == null) {
  249. throw new IllegalArgumentException("商品名不能为空");
  250. }
  251. if (cashRecord.getGoodsName().equals("金币充值")) {
  252. if (cashRecord.getPermanentGold() == 0 && cashRecord.getFreeGold() == 0) {
  253. throw new IllegalArgumentException("金币数量不能为空");
  254. }if (cashRecord.getPermanentGold() == 0){
  255. throw new IllegalArgumentException("永久金币数量不能为空");
  256. }
  257. }
  258. if (!cashRecord.getGoodsName().equals("金币充值")) {
  259. if (cashRecord.getGoodNum() == 0) {
  260. throw new IllegalArgumentException("产品数量不能为空");
  261. }
  262. if (cashRecord.getNumUnit() == null) {
  263. throw new IllegalArgumentException("数量单位不能为空");
  264. }
  265. }
  266. if (cashRecord.getPaymentCurrency() == null) {
  267. throw new IllegalArgumentException("支付币种不能为空");
  268. }
  269. if (cashRecord.getPaymentAmount() == null || cashRecord.getPaymentAmount().compareTo(BigDecimal.ZERO) == 0) {
  270. throw new IllegalArgumentException("支付金额不能为空");
  271. }
  272. if (cashRecord.getPayType() == null) {
  273. throw new IllegalArgumentException("支付方式不能为空");
  274. }
  275. if (cashRecord.getReceivedMarket() == null) {
  276. throw new IllegalArgumentException("到账地区不能为空");
  277. }
  278. if (cashRecord.getPayTime() == null) {
  279. throw new IllegalArgumentException("付款时间不能为空");
  280. }
  281. CashRecord status = cashCollectionMapper.selectByOrderCode(cashRecord.getOrderCode());
  282. if (!status.getStatus().equals(5)) {
  283. throw new IllegalArgumentException("只允许编辑已撤回订单");
  284. }
  285. //地区,根据jwcode插入(弃用,插入前调用接口获取地区和姓名,之后前端传入)
  286. //cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
  287. int rows = cashCollectionMapper.updateByOrderCode(cashRecord);
  288. if (rows > 0) {
  289. // 发送收款创建消息
  290. Messages message = new Messages();
  291. message.setJwcode(cashRecord.getJwcode());
  292. message.setName(cashRecord.getName());
  293. message.setStatus(cashRecord.getStatus());
  294. message.setDesc("的现金收款申请待审核,前往审核");
  295. message.setTitle("现金管理--收款处理");
  296. message.setType(0);
  297. message.setTypeId(cashRecord.getId());
  298. message.setMarket(Integer.valueOf(cashRecord.getMarket()));
  299. String marketName = marketMapper.getMarketNameById(String.valueOf(message.getMarket()));
  300. message.setMarketName(marketName);
  301. message.setQueryId(67);
  302. rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_COLLECTION_EXCHANGE, "cash.collection.save", message);
  303. }
  304. return rows > 0 ? "重新提交成功" : "重新提交失败";
  305. }
  306. //多条件查询收款订单列表
  307. @Override
  308. public PageInfo<CashCollection> selectCollection(Integer pageNum, Integer pageSize, CashCollection cashCollection) {
  309. /* //将操作人的地区列表改为id
  310. List<String> markets = marketMapper.getMarketIds(cashCollection.getMarkets());
  311. if (markets.contains("9") || markets.contains("9999")) {
  312. markets = null;
  313. }*/
  314. // cashCollection.setReceivedMarket(marketMapper.getMarketId(cashCollection.getReceivedMarket()));
  315. if (cashCollection.getCashRoleId() == 2) {
  316. //角色是总部时,若不特地传状态,传1346,sql处理为(1,3,4,6)筛选,
  317. if (cashCollection.getStatus() == null) {
  318. cashCollection.setStatus(1346);
  319. }
  320. cashCollection.setSubmitterId(null);
  321. cashCollection.setReceivedMarket(null);
  322. cashCollection.setSubmitterMarket(null);
  323. }
  324. if (cashCollection.getCashRoleId() == 1) {
  325. //角色是地方财务,提交人置空不设筛选条件,仅按收款地区、提交人地区筛选()
  326. if (cashCollection.getStatus() == null) {
  327. cashCollection.setStatus(123460);
  328. }
  329. //状态为待审核和已驳回时按照提交人地区筛选
  330. if (cashCollection.getStatus() == 0 || cashCollection.getStatus() == 2) {
  331. cashCollection.setReceivedMarket(null);
  332. }
  333. //状态为已通过和Link通过时,满足收款地区或提交人地区即可
  334. /* if (cashCollection.getStatus() == 13) {
  335. cashCollection.setSubmitterId(null);
  336. }*/
  337. //状态为13 或46,已通过或已完成和已退款,满足收款地区或提交人地区即可,
  338. cashCollection.setSubmitterId(null);
  339. }
  340. if (cashCollection.getCashRoleId() == 0) {
  341. //角色是地方财务,提交人置空不设筛选条件---仅当角色是0 地方客服时,按提交人筛选
  342. if (cashCollection.getStatus() == null) {
  343. cashCollection.setStatus(1234560);
  344. }
  345. cashCollection.setSubmitterId(cashCollection.getSubmitterId());
  346. cashCollection.setReceivedMarket(null);
  347. }
  348. // cashCollection.setMarkets(markets);
  349. PageHelper.startPage(pageNum, pageSize); //必须要直接跟mapper
  350. List<CashCollection> cashCollections = cashCollectionMapper.selectCollection1(pageNum, pageSize, cashCollection);
  351. return new PageInfo<>(cashCollections);
  352. }
  353. //补全手续费等内容
  354. @Override
  355. public String complete(CashRecord cashRecord) {
  356. if (!Objects.equals(cashRecord.getPaymentCurrency(), cashRecord.getReceivedCurrency())
  357. && ("Stripe".equals(cashRecord.getPayType()) || "Paypal".equals(cashRecord.getPayType()))) {
  358. return "支付币种与收款币种不一致";
  359. }
  360. int rows = cashCollectionMapper.complete(cashRecord);
  361. String goodsName = cashCollectionMapper.selectGoodsNameByCode(cashRecord.getOrderCode());
  362. if (goodsName .equals("金币充值")) {
  363. cashRecord.setOrderCode(cashRecord.getOrderCode().replace("XJ_", "XJCZ_"));
  364. //修改金币订单
  365. cashCollectionMapper.updateGoldOrder(cashRecord);
  366. }
  367. return rows > 0 ? "编辑成功" : "编辑失败";
  368. }
  369. //根据精网号查询姓名和地区
  370. @Override
  371. public Result getNameAndMarket(Integer jwcode,@RequestHeader(defaultValue = "zh_CN") String lang) {
  372. try {
  373. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  374. String token = request.getHeader("token");
  375. Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class);
  376. if (admin != null) {
  377. List<String> list = Arrays.asList(admin.getMarkets().split(","));
  378. List<String> markets = marketMapper.getMarketIds(list);
  379. // 检查用户是否存在
  380. int userCount = cashCollectionMapper.checkUserExists(jwcode);
  381. if (userCount == 0) {
  382. String message = languageTranslationUtil.translate("精网号有误!请检查", lang);
  383. return Result.error(message);
  384. }
  385. if (markets.contains("9") || markets.contains("9999")) {
  386. // 有特殊权限,可访问所有用户
  387. User user = new User();
  388. user.setMarket(cashCollectionMapper.getMarketByJwcode(jwcode));
  389. user.setName(cashCollectionMapper.getNameByJwcode(jwcode));
  390. user.setMarketName(cashCollectionMapper.getMarketNameByJwcode(jwcode));
  391. return Result.success(user);
  392. } else {
  393. // 检查用户所在市场是否在管理员权限范围内
  394. String userMarket = cashCollectionMapper.getMarketByJwcode(jwcode);
  395. if (userMarket != null && markets.contains(userMarket)) {
  396. // 有权限访问,返回用户信息
  397. User user = new User();
  398. user.setMarket(userMarket);
  399. user.setName(cashCollectionMapper.getNameByJwcode(jwcode));
  400. user.setMarketName(cashCollectionMapper.getMarketNameByJwcode(jwcode));
  401. return Result.success(user);
  402. } else {
  403. // 无权限,返回用户所属地区
  404. String userMarketName = cashCollectionMapper.getMarketNameByJwcode(jwcode);
  405. String translatedMarketName = languageTranslationUtil.translate(userMarketName, lang);
  406. String message = languageTranslationUtil.translate("无权限访问", lang);
  407. return Result.errorWithData(message, java.util.Map.of("market", translatedMarketName));
  408. }
  409. }
  410. } else {
  411. // admin 为 null,即权限验证失败
  412. String userMarketName = cashCollectionMapper.getMarketNameByJwcode(jwcode);
  413. String translatedMarketName = languageTranslationUtil.translate(userMarketName, lang);
  414. String message = languageTranslationUtil.translate("无权限访问", lang);
  415. return Result.errorWithData(message, java.util.Map.of("market", translatedMarketName));
  416. }
  417. } catch (Exception e) {
  418. e.printStackTrace();
  419. String errorMessage = languageTranslationUtil.translate("精网号有误!请检查", lang);
  420. return Result.error(errorMessage);
  421. }
  422. }
  423. //获取收款活动列表
  424. @Override
  425. public List<RechargeActivity> getActivityList() {
  426. LocalDateTime now = LocalDateTime.now();
  427. return cashCollectionMapper.getActivityList(now);
  428. }
  429. //同步g_order订单到cash_record表
  430. @Override
  431. public Object syncToCashRecord() {
  432. int total = 0;
  433. while (true) {
  434. List<GOrder> gOrders = cashCollectionMapper.getUnSync(50);
  435. if (CollectionUtils.isEmpty(gOrders)) {
  436. break;
  437. }
  438. try {
  439. // 每批独立事务
  440. processBatch(gOrders);
  441. total += gOrders.size();
  442. log.info("✅ 同步完成一批,数量: {}, 累计: {}", gOrders.size(), total);
  443. } catch (Exception e) {
  444. List<Integer> failedIds = gOrders.stream().map(GOrder::getId).collect(Collectors.toList());
  445. log.error("失败订单ID: {}", failedIds);
  446. // 可存入 error_log 表,供人工处理
  447. // 这里选择继续下一批(容忍部分失败)
  448. }
  449. if (gOrders.size() < 50) {
  450. break; // 最后一批
  451. }
  452. }
  453. return "同步完毕,成功处理 " + total + " 条";
  454. }
  455. @Override
  456. @Transactional(rollbackFor = Exception.class)
  457. public void processBatch(List<GOrder> gOrders) {
  458. for (GOrder gOrder : gOrders) {
  459. CashRecord cashRecord = new CashRecord();
  460. //构建基础信息
  461. cashRecord.setOrderType(1);
  462. cashRecord.setJwcode(gOrder.getJwcode());
  463. String name=cashCollectionMapper.getNameByJwcode(gOrder.getJwcode());
  464. if (name!=null){
  465. cashRecord.setName(name);
  466. }else cashRecord.setName("未知");
  467. cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(gOrder.getJwcode()));
  468. if (gOrder.getType().equals("gold")){ //充金豆
  469. cashRecord.setActivity("99");
  470. cashRecord.setGoodsName("Link充值金豆");
  471. cashRecord.setRemark("Link充值金豆");
  472. cashRecord.setNumUnit("个");
  473. cashRecord.setPermanentGold(0);
  474. cashRecord.setGoodNum(gOrder.getCount());
  475. }
  476. if (gOrder.getType().equals("gold_coin")){//充金币
  477. cashRecord.setActivity("98");
  478. cashRecord.setGoodsName("Link充值金币");
  479. cashRecord.setRemark("Link充值金币");
  480. cashRecord.setPermanentGold(gOrder.getCount()*100);
  481. cashRecord.setGoodNum(0);
  482. }
  483. cashRecord.setOrderCode(gOrder.getOrderNo());
  484. if (gOrder != null) {
  485. switch (gOrder.getPayStyle()) {
  486. case 3:
  487. cashRecord.setPayType("IOS内购");
  488. cashRecord.setBankCode(gOrder.getIosTransactionId());
  489. cashRecord.setReceivedMarket("4");
  490. cashRecord.setPayload("IOS");
  491. break;
  492. case 5:
  493. cashRecord.setPayType("Stripe");
  494. cashRecord.setReceivedMarket("13");
  495. cashRecord.setPayload("Stripe");
  496. break;
  497. case 6:
  498. cashRecord.setPayType("PaymentAsia");
  499. cashRecord.setReceivedMarket("13");
  500. cashRecord.setPayload("PaymentAsia");
  501. break;
  502. case 7:
  503. cashRecord.setPayType("Ipay88");
  504. cashRecord.setReceivedMarket("5");
  505. cashRecord.setPayload("Ipay88");
  506. break;
  507. case 9:
  508. cashRecord.setPayType("FirstData");
  509. cashRecord.setReceivedMarket("4");
  510. cashRecord.setBankCode(gOrder.getFirstdataIpgTransactionId());
  511. cashRecord.setPayload("FirstData");
  512. break;
  513. case 10:
  514. cashRecord.setPayType("PaySolutions");
  515. cashRecord.setReceivedMarket("24018");
  516. cashRecord.setPayload("PaySolutions");
  517. break;
  518. case 15:
  519. cashRecord.setPayType("Stripe2");
  520. cashRecord.setReceivedMarket("4");
  521. cashRecord.setPayload("Stripe2");
  522. default:
  523. break;
  524. }
  525. }
  526. cashRecord.setFreeGold(0);
  527. cashRecord.setPaymentCurrency("");
  528. cashRecord.setPaymentAmount(BigDecimal.valueOf(0));
  529. //转换时间戳,加上时区偏移
  530. cashRecord.setPayTime(LocalDateTime.ofEpochSecond(gOrder.getSuccessTime(), 0, ZoneOffset.of("+08:00")));
  531. cashRecord.setAuditTime(LocalDateTime.ofEpochSecond(gOrder.getSuccessTime(), 0, ZoneOffset.of("+08:00")));
  532. cashRecord.setStatus(3);
  533. cashRecord.setSubmitterId(99999);
  534. //存入现金库
  535. cashCollectionMapper.add(cashRecord);
  536. cashCollectionMapper.markSynced(gOrder.getId());
  537. }
  538. }
  539. @Override
  540. public CashCollection selectById(CashCollection cashCollection) {
  541. return cashCollectionMapper.selectById(cashCollection.getId());
  542. }
  543. //根据goldcoin订单号查询收款订单
  544. @Override
  545. public CashCollection selectByGoldCoinOrderCode(String orderNo) {
  546. return cashCollectionMapper.selectByGoldCoinOrderCode(orderNo);
  547. }
  548. //多条件查询收款订单列表
  549. @Override
  550. public PageInfo<PerformanceVO> performanceSelect(Integer pageNum, Integer pageSize, PerformanceDTO performanceDTO) {
  551. PageHelper.startPage(pageNum, pageSize); //必须要直接跟mapper
  552. List<PerformanceVO> performanceVOs = cashCollectionMapper.performanceSelect(performanceDTO);
  553. return new PageInfo<>(performanceVOs);
  554. }
  555. }