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.
|
|
package com.example.demo.serviceImpl.cash;
import com.example.demo.domain.entity.CashRecord;import com.example.demo.domain.entity.GOrder;import com.example.demo.domain.entity.User;import com.example.demo.domain.vo.cash.CashCollection;import com.example.demo.domain.vo.coin.Result;import com.example.demo.mapper.cash.CashCollectionMapper;import com.example.demo.mapper.coin.MarketMapper;import com.example.demo.service.cash.CashCollectionService;import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import lombok.extern.slf4j.Slf4j;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional;import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;import java.time.LocalDateTime;import java.time.ZoneOffset;import java.util.List;import java.util.UUID;
/** * @program: gold-java * @ClassName cashCollectionServiceImpl * @description: * @author: Ethan * @create: 2025−09-26 11:23 * @Version 1.0 **/@Service@Slf4jpublic class CashCollectionServiceImpl implements CashCollectionService {
@Autowired private CashCollectionMapper cashCollectionMapper; @Autowired private MarketMapper marketMapper;
//新增收款订单
@Override public String add(CashCollection cashCollection) { if (cashCollection.getJwcode()==null){ throw new IllegalArgumentException("精网号不能为空"); } if(cashCollection.getJwcode()<10000000||cashCollection.getJwcode()>99999999){ throw new IllegalArgumentException("精网号必须为8位"); } if(cashCollection.getName()== null){ throw new IllegalArgumentException("客户姓名不能为空"); } if(cashCollection.getActivity()== null){ throw new IllegalArgumentException("活动不能为空"); } if(cashCollection.getGoodsName()== null){ throw new IllegalArgumentException("商品名不能为空"); } if(cashCollection.getGoodNum()== null && cashCollection.getPermanentGold()== null && cashCollection.getFreeGold()== null){ throw new IllegalArgumentException("商品数量或金币数量不能为空"); } if(cashCollection.getPaymentCurrency()== null){ throw new IllegalArgumentException("支付币种不能为空"); } if(cashCollection.getPaymentAmount()== null){ throw new IllegalArgumentException("支付金额不能为空"); } if (cashCollection.getPayType()== null){ throw new IllegalArgumentException("支付方式不能为空"); } if (cashCollection.getReceivedMarket()== null){ throw new IllegalArgumentException("到账地区不能为空"); } if(cashCollection.getPayTime()== null){ throw new IllegalArgumentException("付款时间不能为空"); } if (cashCollection.getVoucher()== null){ throw new IllegalArgumentException("转账凭证不能为空"); } if (cashCollection.getRemark()==null){ throw new IllegalArgumentException("备注不能为空"); } //生成订单号后半部分
String orderNumber = UUID.randomUUID().toString().replaceAll("-", ""); CashRecord cashRecord = new CashRecord(); //构建订单信息
cashRecord.setOrderCode("XJ_" + orderNumber); //订单号
cashRecord.setJwcode(cashCollection.getJwcode()); //精网号
cashRecord.setName(cashCollection.getName()); //客户姓名
cashRecord.setActivity(cashCollection.getActivity()); // 活动
cashRecord.setGoodsName(cashCollection.getGoodsName()); //商品名称
cashRecord.setGoodNum(cashCollection.getGoodNum()); //商品数量
cashRecord.setPermanentGold(cashCollection.getPermanentGold()); //永久金币
cashRecord.setFreeGold(cashCollection.getFreeGold()); //免费金币
cashRecord.setPaymentCurrency(cashCollection.getPaymentCurrency()); //付款币种
cashRecord.setPaymentAmount(cashCollection.getPaymentAmount()); //付款金额
cashRecord.setReceivedMarket(cashCollection.getReceivedMarket()); //到账地区
cashRecord.setPayType(cashCollection.getPayType()); //支付方式
cashRecord.setPayTime(cashCollection.getPayTime()); //付款时间
cashRecord.setVoucher(cashCollection.getVoucher()); //转账凭证
cashRecord.setRemark(cashCollection.getRemark()); //备注
cashRecord.setStatus(0); //订单状态:付款线下财务待审核
cashRecord.setSubmitterId(cashCollection.getSubmitterId()); //提交人ID
cashRecord.setSubmitterMarket(cashCollection.getSubmitterMarket()); cashRecord.setOrderType(1); //订单类型:1-收款
cashRecord.setMarket(cashCollection.getMarket()); //地区,根据jwcode插入
//cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
//插入新收款订单
cashCollectionMapper.add(cashRecord);
return "添加成功"; } //撤回未审核的订单
@Override public String cancel(String orderCode) { CashRecord cashRecord = cashCollectionMapper.selectByOrderCode(orderCode); if (cashRecord == null) { throw new IllegalArgumentException("订单不存在"); } if (cashRecord.getStatus() != 0){ throw new IllegalArgumentException("订单状态不符合条件"); } //修改订单状态
int rows = cashCollectionMapper.updateStatus(orderCode, 5); return rows > 0 ? "撤回成功" : "撤回失败"; }
//编辑并重新提交收款订单
@Override public String reSubmit(CashRecord cashRecord) { if (cashRecord.getJwcode()==null){ throw new IllegalArgumentException("精网号不能为空"); } if(cashRecord.getJwcode()<10000000||cashRecord.getJwcode()>99999999){ throw new IllegalArgumentException("精网号必须为8位"); } if(cashRecord.getName()== null){ throw new IllegalArgumentException("客户姓名不能为空"); } if(cashRecord.getActivity()== null){ throw new IllegalArgumentException("活动不能为空"); } if(cashRecord.getGoodsName()== null){ throw new IllegalArgumentException("商品名不能为空"); } if(cashRecord.getGoodNum()== null){ throw new IllegalArgumentException("商品数量不能为空"); } if(cashRecord.getPaymentCurrency()== null){ throw new IllegalArgumentException("支付币种不能为空"); } if(cashRecord.getPaymentAmount()== null){ throw new IllegalArgumentException("支付金额不能为空"); } if (cashRecord.getPayType()== null){ throw new IllegalArgumentException("支付方式不能为空"); } if (cashRecord.getReceivedMarket()== null){ throw new IllegalArgumentException("到账地区不能为空"); } if(cashRecord.getPayTime()== null){ throw new IllegalArgumentException("付款时间不能为空"); } if (cashRecord.getVoucher()== null){ throw new IllegalArgumentException("转账凭证不能为空"); } if (cashRecord.getRemark()==null){ throw new IllegalArgumentException("备注不能为空"); } CashRecord status=cashCollectionMapper.selectByOrderCode(cashRecord.getOrderCode()); if (!status.getStatus().equals(5)){ throw new IllegalArgumentException("只允许编辑已撤回订单"); } //地区,根据jwcode插入(弃用,插入前调用接口获取地区和姓名,之后前端传入)
//cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
int rows = cashCollectionMapper.updateByOrderCode(cashRecord); return rows > 0 ? "重新提交成功" : "重新提交失败"; } //多条件查询收款订单列表
@Override public PageInfo<CashCollection> selectCollection(Integer pageNum, Integer pageSize, CashCollection cashCollection) { //将操作人的地区列表改为id
List<String> markets = marketMapper.getMarketIds(cashCollection.getMarkets()); if (markets.contains("9") || markets.contains("9999")){ markets=null; } // cashCollection.setReceivedMarket(marketMapper.getMarketId(cashCollection.getReceivedMarket()));
if (cashCollection.getCashRoleId()==2) { //角色是总部时,若不特地传状态,传1346,sql处理为(1,3,4,6)筛选,
if(cashCollection.getStatus()==null){ cashCollection.setStatus(1346);} cashCollection.setSubmitterId(null); cashCollection.setReceivedMarket(null); cashCollection.setSubmitterMarket(null); } if (cashCollection.getCashRoleId()==1){ //角色是地方财务,提交人置空不设筛选条件,仅按收款地区、提交人地区筛选()
if(cashCollection.getStatus()==null){ cashCollection.setStatus(123460);} //状态为待审核和已驳回时按照提交人地区筛选
if (cashCollection.getStatus()==0||cashCollection.getStatus()==2){ cashCollection.setReceivedMarket(null);} //状态为已通过和Link通过时,按收款地区筛选
if (cashCollection.getStatus()==13){ cashCollection.setSubmitterMarket(null);} cashCollection.setSubmitterId(null); //状态为46,已通过和已退款,满足收款地区或提交人地区即可,
} if (cashCollection.getCashRoleId()==0){ //角色是地方财务,提交人置空不设筛选条件---仅当角色是0 地方客服时,按提交人筛选
if(cashCollection.getStatus()==null){ cashCollection.setStatus(1234560);} cashCollection.setSubmitterId(cashCollection.getSubmitterId()); cashCollection.setReceivedMarket(null); } cashCollection.setMarkets(markets); PageHelper.startPage(pageNum, pageSize); List<CashCollection> cashCollections = cashCollectionMapper.selectCollection1(pageNum, pageSize, cashCollection); return new PageInfo<>(cashCollections); } //补全手续费等内容
@Override public String complete(CashRecord cashRecord) {
int rows = cashCollectionMapper.complete(cashRecord);
return rows > 0 ? "编辑成功" : "编辑失败"; } //根据精网号查询姓名和地区
@Override public User getNameAndMarket(Integer jwcode) { User user = new User(); user.setMarket(cashCollectionMapper.getMarketByJwcode(jwcode)); user.setName(cashCollectionMapper.getNameByJwcode(jwcode)); user.setMarketName(cashCollectionMapper.getMarketNameByJwcode(jwcode));
return user; } //获取收款活动列表
@Override public List<String> getActivityList() { return cashCollectionMapper.getActivityList(); } //同步g_order订单到cash_record表
@Override @Transactional(rollbackFor = Exception.class) public Object syncToCashRecord() { while (true) { List<GOrder> gOrders = cashCollectionMapper.getUnSync(100); if (CollectionUtils.isEmpty(gOrders)) { break; } for (GOrder gOrder : gOrders) { CashRecord cashRecord = new CashRecord(); cashRecord.setOrderType(1); cashRecord.setJwcode(gOrder.getJwcode()); cashRecord.setName(cashCollectionMapper.getNameByJwcode(gOrder.getJwcode())); cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(gOrder.getJwcode())); cashRecord.setActivity("Link日常充值"); cashRecord.setOrderCode(gOrder.getOrderNo()); if (gOrder != null) { switch (gOrder.getPayStyle()) { case 3: cashRecord.setPayType("IOS内购"); cashRecord.setBankCode(gOrder.getIosTransactionId()); cashRecord.setReceivedMarket("3"); break; case 5: cashRecord.setPayType("Stripe-链接收款"); cashRecord.setReceivedMarket("13"); break; case 6: cashRecord.setPayType("PaymentAsia-链接收款"); cashRecord.setReceivedMarket("13"); break; case 7: cashRecord.setPayType("Ipay88-链接收款"); cashRecord.setReceivedMarket("5"); break; case 9: cashRecord.setPayType("FistData"); cashRecord.setReceivedMarket("4"); break; default: break; } } cashRecord.setGoodsName("Link充值金币"); cashRecord.setGoodNum(0); cashRecord.setPermanentGold(gOrder.getCount()); cashRecord.setFreeGold(0); cashRecord.setPaymentCurrency(""); cashRecord.setPaymentAmount(BigDecimal.valueOf(0)); cashRecord.setPayTime(LocalDateTime.ofEpochSecond(gOrder.getSuccessTime(), 0, ZoneOffset.UTC)); cashRecord.setStatus(3); cashRecord.setSubmitterId(99999); cashRecord.setRemark("Link充值金币"); //存入现金库
cashCollectionMapper.add(cashRecord); cashCollectionMapper.markSynced(gOrder.getId()); }log.info("同步完成一批,数量 {}", gOrders.size()); if (gOrders.size() < 100) { break; // 最后一批
} }return "同步完毕"; }}
|