|
@@ -0,0 +1,263 @@
|
|
|
+package com.szwl.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.szwl.feign.SzwlFeign;
|
|
|
+import com.szwl.mapper.TOrderMapper;
|
|
|
+import com.szwl.model.bo.R;
|
|
|
+import com.szwl.model.entity.TAdmin;
|
|
|
+import com.szwl.model.entity.TEquipment;
|
|
|
+import com.szwl.model.entity.TOrder;
|
|
|
+import com.szwl.model.entity.TShandeMch;
|
|
|
+import com.szwl.mapper.TShandeMchMapper;
|
|
|
+import com.szwl.service.TShandeMchService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 杉德支付收款信息 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author wuhs
|
|
|
+ * @since 2022-07-14
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class TShandeMchServiceImpl extends ServiceImpl<TShandeMchMapper, TShandeMch> implements TShandeMchService {
|
|
|
+ @Autowired
|
|
|
+ TOrderMapper orderMapper;
|
|
|
+ @Autowired
|
|
|
+ SzwlFeign szwlFeign;
|
|
|
+
|
|
|
+ //24点更新结算表
|
|
|
+ @Override
|
|
|
+ public void jiesuan() {
|
|
|
+ //1,查出杉德金额表中今日交易金额大于0的人
|
|
|
+// TShandeMchExample example = new TShandeMchExample();
|
|
|
+// TShandeMchExample.Criteria criteria = example.createCriteria();
|
|
|
+// criteria.andTodayBalanceGreaterThan(0.00f);
|
|
|
+// List<TShandeMch> tShandeMches = tShandeMchMapper.selectByExample(example);
|
|
|
+ //2,并把这些人的adminId整合到一个list中
|
|
|
+// List<Long> list = new ArrayList<>();
|
|
|
+// if(tShandeMches.size()>0){
|
|
|
+// for(TShandeMch shandeMch : tShandeMches){
|
|
|
+// list.add(shandeMch.getAdminId());
|
|
|
+// }
|
|
|
+// }
|
|
|
+ Set<Long> set = new HashSet<>();
|
|
|
+ //昨天起始时间 因为是第二天才去查的
|
|
|
+ Date startDate = getStartTime();
|
|
|
+ Date endDate = getEndTime();
|
|
|
+ //1,找出今天用杉德支付的订单
|
|
|
+ LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
|
|
|
+ query.eq(TOrder::getPayPlatform,"1");
|
|
|
+ query.eq(TOrder::getStatus,1);
|
|
|
+ query.gt(TOrder::getPayDate,startDate);
|
|
|
+ query.lt(TOrder::getPayDate,endDate);
|
|
|
+ List<TOrder> orderList = orderMapper.selectList(query);
|
|
|
+ if(orderList.size()>0){
|
|
|
+ for(TOrder order:orderList){
|
|
|
+ set.add(order.getAdminId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //3,根据adminId去order表里查今日的支付,退款的订单
|
|
|
+ //昨天起始时间 因为是第二天才去查的
|
|
|
+// Date startDate = getStartTime();
|
|
|
+// Date endDate = getEndTime();
|
|
|
+ if(set.size()>0){
|
|
|
+ for(Long adminId : set){
|
|
|
+ //支付订单
|
|
|
+ List<TOrder> orderPayList = getOrderlist(startDate,endDate,adminId,1);
|
|
|
+ //退款订单---主要查不是今天支付的退款订单,隔天退款
|
|
|
+ List<TOrder> orderRefuseList = getOrderlist(startDate,endDate,adminId,3);
|
|
|
+ //根据订单表去更新金额表
|
|
|
+ if(orderPayList.size()>0){
|
|
|
+ updateShandeMchList(orderPayList,1);
|
|
|
+ }
|
|
|
+ if(orderRefuseList.size()>0){
|
|
|
+ updateShandeMchList(orderRefuseList,3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //根据订单表去更新金额表
|
|
|
+ private void updateShandeMchList(List<TOrder> orderList, int type) {
|
|
|
+ BigDecimal agencyTotal = new BigDecimal(0.00);
|
|
|
+ BigDecimal merchantTotal = new BigDecimal(0.00);
|
|
|
+ BigDecimal personageTotal = new BigDecimal(0.00);
|
|
|
+ TOrder tOrder = orderList.get(0);
|
|
|
+ TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(tOrder.getAdminId())));
|
|
|
+ Integer orderType = tOrder.getType();
|
|
|
+ switch (orderType) {
|
|
|
+ case 1:
|
|
|
+ for(TOrder order:orderList){
|
|
|
+ BigDecimal agencyProportion = order.getAgencyProportion();
|
|
|
+ BigDecimal price = order.getPrice();
|
|
|
+ // 代理分销获得利润
|
|
|
+ BigDecimal agencyPrice = price.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ agencyTotal = agencyTotal.add(agencyPrice);
|
|
|
+ }
|
|
|
+ //修改金额表的今日金额
|
|
|
+ TShandeMch shandeMch = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(tOrder.getAdminId())));
|
|
|
+ BigDecimal settleableBalance = shandeMch.getSettleableBalance();
|
|
|
+ if(type==1){
|
|
|
+ settleableBalance = settleableBalance.add(agencyTotal).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ }
|
|
|
+ if(type == 3){
|
|
|
+ settleableBalance = settleableBalance.subtract(agencyTotal).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ }
|
|
|
+ shandeMch.setSettleableBalance(settleableBalance);
|
|
|
+ shandeMch.setTodayBalance(BigDecimal.valueOf(0));
|
|
|
+ shandeMch.setModifyDate(new Date());
|
|
|
+ szwlFeign.updateShandeMch(shandeMch);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ for(TOrder order:orderList){
|
|
|
+ BigDecimal agencyProportion = order.getAgencyProportion();
|
|
|
+ BigDecimal merchantProportion = order.getMerchantProportion();
|
|
|
+ BigDecimal price = order.getPrice();
|
|
|
+ // 代理分销获得利润
|
|
|
+ BigDecimal agencyPrice = price.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ // 经销商分销获得利润
|
|
|
+ BigDecimal merchantAmount = price.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ agencyTotal = agencyTotal.add(agencyPrice);
|
|
|
+ merchantTotal = merchantTotal.add(merchantAmount);
|
|
|
+ }
|
|
|
+ //修改金额表的今日金额
|
|
|
+ //省级
|
|
|
+ TShandeMch shandeMch1 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(admin.getParentId())));
|
|
|
+ BigDecimal settleableBalance1 = shandeMch1.getSettleableBalance();
|
|
|
+ if(type==1){
|
|
|
+ settleableBalance1 = settleableBalance1.add(agencyTotal).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ }
|
|
|
+ if(type == 3){
|
|
|
+ settleableBalance1 = settleableBalance1.subtract(agencyTotal).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ }
|
|
|
+ shandeMch1.setSettleableBalance(settleableBalance1);
|
|
|
+ shandeMch1.setTodayBalance(BigDecimal.valueOf(0));
|
|
|
+ shandeMch1.setModifyDate(new Date());
|
|
|
+ szwlFeign.updateShandeMch(shandeMch1);
|
|
|
+ //市级
|
|
|
+ TShandeMch shandeMch2 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(admin.getId())));
|
|
|
+ BigDecimal settleableBalance2 = shandeMch2.getSettleableBalance();
|
|
|
+ if(type==1){
|
|
|
+ settleableBalance2 = settleableBalance2.add(merchantTotal).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ }
|
|
|
+ if(type == 3){
|
|
|
+ settleableBalance2 = settleableBalance2.subtract(merchantTotal).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ }
|
|
|
+ shandeMch2.setSettleableBalance(settleableBalance2);
|
|
|
+ shandeMch2.setTodayBalance(BigDecimal.valueOf(0));
|
|
|
+ shandeMch2.setModifyDate(new Date());
|
|
|
+ szwlFeign.updateShandeMch(shandeMch2);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ for(TOrder order:orderList){
|
|
|
+ BigDecimal agencyProportion = order.getAgencyProportion();
|
|
|
+ BigDecimal merchantProportion = order.getMerchantProportion();
|
|
|
+ BigDecimal personageProportion = order.getPersonageProportion();
|
|
|
+ BigDecimal price = order.getPrice();
|
|
|
+ // 代理分销获得利润
|
|
|
+ BigDecimal agencyPrice = price.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ // 经销商分销获得利润
|
|
|
+ BigDecimal merchantAmount = price.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ // 经销商分销获得利润
|
|
|
+ BigDecimal personageAmount = price.multiply(personageProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+
|
|
|
+ agencyTotal = agencyTotal.add(agencyPrice);
|
|
|
+ merchantTotal = merchantTotal.add(merchantAmount);
|
|
|
+ personageTotal = personageTotal.add(personageAmount);
|
|
|
+ }
|
|
|
+ //修改金额表的今日金额
|
|
|
+ //省级
|
|
|
+
|
|
|
+ TShandeMch shandeMch3 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(admin.getAgencyId())));
|
|
|
+
|
|
|
+ BigDecimal settleableBalance3 = shandeMch3.getSettleableBalance();
|
|
|
+ if(type==1){
|
|
|
+ settleableBalance3 = settleableBalance3.add(agencyTotal).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ }
|
|
|
+ if(type == 3){
|
|
|
+ settleableBalance3 = settleableBalance3.subtract(agencyTotal).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ }
|
|
|
+ shandeMch3.setSettleableBalance(settleableBalance3);
|
|
|
+ shandeMch3.setTodayBalance(BigDecimal.valueOf(0));
|
|
|
+ shandeMch3.setModifyDate(new Date());
|
|
|
+ szwlFeign.updateShandeMch(shandeMch3);
|
|
|
+ //市级
|
|
|
+;
|
|
|
+ TShandeMch shandeMch4 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(admin.getMerchantId())));
|
|
|
+ BigDecimal settleableBalance4 =shandeMch4.getSettleableBalance();
|
|
|
+ if(type==1){
|
|
|
+ settleableBalance4 = settleableBalance4.add(merchantTotal).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ }
|
|
|
+ if(type == 3){
|
|
|
+ settleableBalance4 = settleableBalance4.subtract(merchantTotal).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ }
|
|
|
+ shandeMch4.setSettleableBalance(settleableBalance4);
|
|
|
+ shandeMch4.setTodayBalance(BigDecimal.valueOf(0));
|
|
|
+ shandeMch4.setModifyDate(new Date());
|
|
|
+ szwlFeign.updateShandeMch(shandeMch4);
|
|
|
+ //终端
|
|
|
+ TShandeMch shandeMch5 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(admin.getId())));
|
|
|
+ BigDecimal settleableBalance5 =shandeMch5.getSettleableBalance();
|
|
|
+ if(type==1){
|
|
|
+ settleableBalance5 = settleableBalance5.add(personageTotal).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ }
|
|
|
+ if(type == 3){
|
|
|
+ settleableBalance5 = settleableBalance5.subtract(personageTotal).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ }
|
|
|
+ shandeMch5.setSettleableBalance(settleableBalance5);
|
|
|
+ shandeMch5.setTodayBalance(BigDecimal.valueOf(0));
|
|
|
+ shandeMch5.setModifyDate(new Date());
|
|
|
+ szwlFeign.updateShandeMch(shandeMch5);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //查询订单列表
|
|
|
+ private List<TOrder> getOrderlist(Date startDate, Date endDate, Long adminId, int type) {
|
|
|
+ LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
|
|
|
+ query.eq(TOrder::getAdminId,adminId);
|
|
|
+ if(type==1){
|
|
|
+ query.gt(TOrder::getPayDate,startDate);
|
|
|
+ query.lt(TOrder::getPayDate,endDate);
|
|
|
+ }
|
|
|
+ if(type == 3){
|
|
|
+
|
|
|
+ query.gt(TOrder::getRefundDate,startDate);
|
|
|
+ query.lt(TOrder::getRefundDate,endDate);
|
|
|
+ query.lt(TOrder::getPayDate,startDate);
|
|
|
+
|
|
|
+ }
|
|
|
+ query.eq(TOrder::getStatus,type);
|
|
|
+ query.eq(TOrder::getPayPlatform,"1");
|
|
|
+ List<TOrder> orderList = orderMapper.selectList(query);
|
|
|
+ return orderList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Date getStartTime() {
|
|
|
+ Calendar todayStart = Calendar.getInstance();
|
|
|
+ todayStart.add(Calendar.DATE, -1);
|
|
|
+ todayStart.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ todayStart.set(Calendar.MINUTE, 0);
|
|
|
+ todayStart.set(Calendar.SECOND, 0);
|
|
|
+ todayStart.set(Calendar.MILLISECOND, 0);
|
|
|
+ return todayStart.getTime();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Date getEndTime() {
|
|
|
+ Calendar todayEnd = Calendar.getInstance();
|
|
|
+ todayEnd.add(Calendar.DATE, -1);
|
|
|
+ todayEnd.set(Calendar.HOUR_OF_DAY, 23);
|
|
|
+ todayEnd.set(Calendar.MINUTE, 59);
|
|
|
+ todayEnd.set(Calendar.SECOND, 59);
|
|
|
+ todayEnd.set(Calendar.MILLISECOND, 999);
|
|
|
+ return todayEnd.getTime();
|
|
|
+ }
|
|
|
+}
|