he2802 2 年 前
コミット
d056d351eb

+ 16 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/common/CommonController.java

@@ -4,9 +4,11 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.zhongzheng.common.annotation.Log;
 import com.zhongzheng.common.config.RuoYiConfig;
 import com.zhongzheng.common.constant.Constants;
 import com.zhongzheng.common.core.domain.AjaxResult;
+import com.zhongzheng.common.enums.BusinessType;
 import com.zhongzheng.common.type.EncryptHandler;
 import com.zhongzheng.common.utils.ServletUtils;
 import com.zhongzheng.common.utils.ToolsUtils;
@@ -16,6 +18,9 @@ import com.zhongzheng.common.utils.poi.ExcelUtil;
 import com.zhongzheng.framework.config.ServerConfig;
 import com.zhongzheng.framework.web.service.WxLoginService;
 import com.zhongzheng.modules.base.bo.ConfigQueryBo;
+import com.zhongzheng.modules.distribution.bo.DistributionCashWithdrawalPayBo;
+import com.zhongzheng.modules.distribution.bo.DistributionCheckQueryBo;
+import com.zhongzheng.modules.distribution.service.IDistributionCashWithdrawalService;
 import com.zhongzheng.modules.goods.bo.GoodsQueryBo;
 import com.zhongzheng.modules.goods.bo.GoodsStudyUrlBo;
 import com.zhongzheng.modules.goods.bo.UserGoodsListBo;
@@ -46,6 +51,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -100,6 +106,8 @@ public class CommonController
     private  ISysWebService webService;
     @Autowired
     private ISysConfigService configService;
+    @Autowired
+    private IDistributionCashWithdrawalService iDistributionCashWithdrawalService;
     /**
      * 通用下载请求
      *
@@ -388,4 +396,12 @@ public class CommonController
 
         return AjaxResult.success("成功", EncryptHandler.decrypt(key));
     }
+
+    @ApiOperation("分销打款结果回调")
+    @PreAuthorize("@ss.hasPermi('system:withdrawal:add')")
+    @Log(title = "打款", businessType = BusinessType.INSERT)
+    @PostMapping("/common/free/payCashCallBack")
+    public AjaxResult payCashCallBack(@RequestBody DistributionCashWithdrawalPayBo bo) {
+        return AjaxResult.success("成功", iDistributionCashWithdrawalService.payCashCallBack(bo) ? 1 : 0);
+    }
 }

+ 18 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/distribution/DistributionCashWithdrawalController.java

@@ -9,7 +9,9 @@ import com.zhongzheng.common.enums.BusinessType;
 import com.zhongzheng.common.utils.ServletUtils;
 import com.zhongzheng.framework.web.service.TokenService;
 import com.zhongzheng.modules.distribution.bo.DistributionCashWithdrawalAddBo;
+import com.zhongzheng.modules.distribution.bo.DistributionCashWithdrawalEditBo;
 import com.zhongzheng.modules.distribution.bo.DistributionCashWithdrawalQueryBo;
+import com.zhongzheng.modules.distribution.bo.DistributionCheckQueryBo;
 import com.zhongzheng.modules.distribution.service.IDistributionCashWithdrawalService;
 import com.zhongzheng.modules.distribution.vo.DistributionCashWithdrawalVo;
 import io.swagger.annotations.Api;
@@ -76,6 +78,22 @@ public class DistributionCashWithdrawalController extends BaseController {
         return toAjax(iDistributionCashWithdrawalService.insertByAddBo(bo) ? 1 : 0);
     }
 
+    @ApiOperation("打款")
+    @PreAuthorize("@ss.hasPermi('system:withdrawal:add')")
+    @Log(title = "打款", businessType = BusinessType.INSERT)
+    @PostMapping("/payCash")
+    public AjaxResult<Void> payCash(@RequestBody DistributionCheckQueryBo bo) {
+        return toAjax(iDistributionCashWithdrawalService.payCash(bo) ? 1 : 0);
+    }
 
 
+    @ApiOperation("取消打款申请")
+    @PreAuthorize("@ss.hasPermi('system:withdrawal:add')")
+    @Log(title = "取消打款申请", businessType = BusinessType.INSERT)
+    @PostMapping("/cancelApply")
+    public AjaxResult<Void> cancelApply(@RequestBody DistributionCashWithdrawalEditBo bo) {
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        bo.setSellerId(loginUser.getUser().getSellerId());
+        return toAjax(iDistributionCashWithdrawalService.cancelApply(bo) ? 1 : 0);
+    }
 }

+ 4 - 0
zhongzheng-admin/src/main/resources/application-dev.yml

@@ -172,3 +172,7 @@ officialPush:
     periodPath: http://jypt-dev.gdcic.net/organjxjy/XueshiShenqing
     infoAccount: peixunjigou
     token: 0ca175b9c0f726a831d895e26933246
+
+
+distributionOldPay:
+    host: http://gdxypx.xy.com/System/BussinessApi/AddRedPackData

+ 3 - 0
zhongzheng-admin/src/main/resources/application-pre.yml

@@ -147,3 +147,6 @@ officialPush:
     periodPath: http://jypt-dev.gdcic.net/organjxjy/XueshiShenqing
     infoAccount: peixunjigou
     token: 0ca175b9c0f726a831d895e26933246
+
+distributionOldPay:
+    host: http://test.jqbao.net/System/BussinessApi/AddRedPackData

+ 3 - 0
zhongzheng-admin/src/main/resources/application-prod.yml

@@ -147,3 +147,6 @@ officialPush:
     periodPath: http://jypt.gdcic.net/organjxjy/XueshiShenqing
     infoAccount: GDSXY
     token: 01b5d9833987efdff54483cdc9720da6
+
+distributionOldPay:
+    host: https://www.xyyxt.net/System/BussinessApi/AddRedPackData

+ 37 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/bo/DistributionCashWithdrawalPayBo.java

@@ -0,0 +1,37 @@
+package com.zhongzheng.modules.distribution.bo;
+
+import com.zhongzheng.common.core.domain.BaseEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.validation.constraints.NotBlank;
+import java.math.BigDecimal;
+
+/**
+ * 分销业务员提现申请分页查询对象 distribution_cash_withdrawal
+ *
+ * @author ruoyi
+ * @date 2023-03-25
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ApiModel("分销业务员提现申请分页查询对象")
+public class DistributionCashWithdrawalPayBo extends BaseEntity {
+
+	@ApiModelProperty("当前时间戳")
+	@NotBlank(message = "当前时间戳不能为空")
+	private Long stamp;
+
+	@ApiModelProperty("签名")
+	@NotBlank(message = "签名不能为空")
+	private String sign;
+
+	/** 提现申请编号 */
+	@ApiModelProperty("申请编号")
+	private String cwSn;
+
+	@ApiModelProperty("打款结果状态 1成功 0失败")
+	private Integer status;
+}

+ 6 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/bo/DistributionCashWithdrawalQueryBo.java

@@ -64,4 +64,10 @@ public class DistributionCashWithdrawalQueryBo extends BaseEntity {
 	/** 申请时间 */
 	@ApiModelProperty("申请时间")
 	private Long applyTime;
+
+	@ApiModelProperty("申请开始时间")
+	private Long applyStartTime;
+
+	@ApiModelProperty("申请结束时间")
+	private Long applyEndTime;
 }

+ 6 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/service/IDistributionCashWithdrawalService.java

@@ -62,4 +62,10 @@ public interface IDistributionCashWithdrawalService extends IService<Distributio
     boolean checkHandle(DistributionCheckHandleBo bo);
 
     List<DistributionCheckDetailVo> checkDetail(Long id);
+
+	boolean payCash(DistributionCheckQueryBo bo);
+
+	boolean payCashCallBack(DistributionCashWithdrawalPayBo bo);
+
+	boolean cancelApply(DistributionCashWithdrawalEditBo bo);
 }

+ 125 - 4
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/service/impl/DistributionCashWithdrawalServiceImpl.java

@@ -3,6 +3,7 @@ package com.zhongzheng.modules.distribution.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
@@ -13,6 +14,8 @@ import com.zhongzheng.common.core.domain.entity.SysRole;
 import com.zhongzheng.common.core.domain.entity.SysUser;
 import com.zhongzheng.common.exception.CustomException;
 import com.zhongzheng.common.utils.DateUtils;
+import com.zhongzheng.common.utils.ToolsUtils;
+import com.zhongzheng.common.utils.http.HttpUtils;
 import com.zhongzheng.modules.distribution.bo.*;
 import com.zhongzheng.modules.distribution.domain.DistributionCashWithdrawal;
 import com.zhongzheng.modules.distribution.domain.DistributionCheck;
@@ -25,17 +28,24 @@ import com.zhongzheng.modules.distribution.service.IDistributionSellerService;
 import com.zhongzheng.modules.distribution.vo.DistributionCashWithdrawalVo;
 import com.zhongzheng.modules.distribution.vo.DistributionCheckDetailVo;
 import com.zhongzheng.modules.distribution.vo.DistributionCheckVo;
+import com.zhongzheng.modules.grade.domain.ClassGradeUser;
+import com.zhongzheng.modules.grade.service.impl.UserPeriodServiceImpl;
+import com.zhongzheng.modules.order.domain.OrderGoods;
 import com.zhongzheng.modules.system.domain.SysUserRole;
 import com.zhongzheng.modules.system.service.ISysRoleService;
 import com.zhongzheng.modules.system.service.ISysUserRoleService;
 import com.zhongzheng.modules.system.service.ISysUserService;
+import com.zhongzheng.modules.user.domain.UserVisitLog;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.io.IOException;
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -60,6 +70,11 @@ public class DistributionCashWithdrawalServiceImpl extends ServiceImpl<Distribut
     @Autowired
     public IDistributionCheckService iDistributionCheckService;
 
+    @Value("${distributionOldPay.host}")
+    private String OLD_PAY_HOST;
+
+    private static Logger log = LoggerFactory.getLogger(DistributionCashWithdrawalServiceImpl.class);
+
     @Override
     public DistributionCashWithdrawalVo queryById(Long id){
         DistributionCashWithdrawal db = this.baseMapper.selectById(id);
@@ -78,6 +93,7 @@ public class DistributionCashWithdrawalServiceImpl extends ServiceImpl<Distribut
         lqw.eq(StrUtil.isNotBlank(bo.getRefundResaon()), DistributionCashWithdrawal::getRefundResaon, bo.getRefundResaon());
         lqw.eq(bo.getCash() != null, DistributionCashWithdrawal::getCash, bo.getCash());
         lqw.eq(bo.getApplyTime() != null, DistributionCashWithdrawal::getApplyTime, bo.getApplyTime());
+        lqw.between(bo.getApplyStartTime()!= null, DistributionCashWithdrawal::getApplyTime,bo.getApplyStartTime(),bo.getApplyEndTime());
         return entity2Vo(this.list(lqw));
     }
 
@@ -255,13 +271,118 @@ public class DistributionCashWithdrawalServiceImpl extends ServiceImpl<Distribut
         return list.stream().map(item -> BeanUtil.toBean(item,DistributionCheckDetailVo.class)).collect(Collectors.toList());
     }
 
+    @Override
+    public boolean payCash(DistributionCheckQueryBo bo) {
+        DistributionCashWithdrawal withdrawal = getOne(new LambdaQueryWrapper<DistributionCashWithdrawal>()
+                .eq(DistributionCashWithdrawal::getCwSn, "CW23032517295715731864"));
+        if(withdrawal.getStatus()!=3){
+            throw new CustomException("非法操作");
+        }
+        DistributionSeller seller = iDistributionSellerService.getOne(new LambdaQueryWrapper<DistributionSeller>()
+                .eq(DistributionSeller::getSellerId, withdrawal.getSellerId()).last("limit 1"));
+        if(Validator.isEmpty(seller)||Validator.isEmpty(seller.getGzhOpenId())){
+            throw new CustomException("非法业务员或不存在openID");
+        }
+
+        Map<String, String> params = new HashMap<>();
+        Long nowTime = DateUtils.getNowTime();
+        String sign = ToolsUtils.EncoderByMd5(withdrawal.getCwSn()+nowTime.toString()+"pubilc2022");
+        params.put("stamp", nowTime.toString());
+        params.put("sign", sign);
+        params.put("OpenId", seller.getGzhOpenId());
+        params.put("MchBillno", withdrawal.getCwSn());
+        params.put("Money", withdrawal.getCash().toString());
+        String respone = "";
+        try {
+            respone = HttpUtils.postFormBody(OLD_PAY_HOST, params);
+            log.info("分享红包打款结果"+respone,"");
+            if (!respone.contains("\"Status\":true")) {
+                throw new CustomException("打款请求错误"+respone);
+            }
+        } catch (IOException e) {
+            throw new CustomException("打款请求错误"+e.getMessage());
+        }
+        withdrawal.setUpdateTime(DateUtils.getNowTime());
+        withdrawal.setCwStatus(5);
+        updateById(withdrawal);
+        return true;
+    }
+
+    @Override
+    public boolean payCashCallBack(DistributionCashWithdrawalPayBo bo) {
+        DistributionCashWithdrawal withdrawal = getOne(new LambdaQueryWrapper<DistributionCashWithdrawal>()
+                .eq(DistributionCashWithdrawal::getCwSn, bo.getCwSn()));
+        if(Validator.isEmpty(withdrawal)||withdrawal.getStatus()!=5){
+            throw new CustomException("非法操作");
+        }
+        if(bo.getStatus()==1){
+            withdrawal.setCwStatus(4);
+        }
+        else{
+            withdrawal.setCwStatus(6);
+        }
+        withdrawal.setPayTime(DateUtils.getNowTime());
+        withdrawal.setUpdateTime(DateUtils.getNowTime());
+        updateById(withdrawal);
+        return true;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean cancelApply(DistributionCashWithdrawalEditBo bo) {
+        DistributionCashWithdrawal withdrawal = getOne(new LambdaQueryWrapper<DistributionCashWithdrawal>()
+                .eq(DistributionCashWithdrawal::getCwSn, bo.getCwSn())
+                .eq(DistributionCashWithdrawal::getSellerId, bo.getSellerId()));
+        if(Validator.isEmpty(withdrawal)){
+            throw new CustomException("数据错误");
+        }
+        if(withdrawal.getCwStatus()!=0){
+            throw new CustomException("非法操作");
+        }
+        withdrawal.setCwStatus(-2);
+        withdrawal.setUpdateTime(DateUtils.getNowTime());
+        updateById(withdrawal);
+
+        DistributionSeller seller = iDistributionSellerService.getOne(new LambdaQueryWrapper<DistributionSeller>()
+                .eq(DistributionSeller::getSellerId, withdrawal.getSellerId()).last("limit 1"));
+        BigDecimal oldCash = seller.getCash();
+        BigDecimal newCash = seller.getCash().add(withdrawal.getCash());
+        //可提现日志
+        DistributionCashLogAddBo cashLogAddBo = new DistributionCashLogAddBo();
+        cashLogAddBo.setSellerId(withdrawal.getSellerId());
+        cashLogAddBo.setOldNum(oldCash);
+        cashLogAddBo.setNewNum(newCash);
+        cashLogAddBo.setDiffNum(withdrawal.getCash());
+        cashLogAddBo.setRelatedSn(withdrawal.getCwSn());
+        cashLogAddBo.setType(2L);
+        cashLogAddBo.setRemark("用户取消申请");
+        iDistributionCashLogService.insertByAddBo(cashLogAddBo);
+        //已提现日志
+        BigDecimal oldUsedCash = seller.getUsedCash();
+        BigDecimal newUsedCash = seller.getUsedCash().subtract(withdrawal.getCash());
+        DistributionCashLogAddBo usedCashLogAddBo = new DistributionCashLogAddBo();
+        usedCashLogAddBo.setSellerId(withdrawal.getSellerId());
+        usedCashLogAddBo.setOldNum(oldUsedCash);
+        usedCashLogAddBo.setNewNum(newUsedCash);
+        usedCashLogAddBo.setDiffNum(withdrawal.getCash().negate());
+        usedCashLogAddBo.setRelatedSn(withdrawal.getCwSn());
+        usedCashLogAddBo.setType(3L);
+        usedCashLogAddBo.setRemark("用户取消申请");
+        iDistributionCashLogService.insertByAddBo(usedCashLogAddBo);
+
+        seller.setCash(newCash);
+        seller.setUsedCash(newUsedCash);
+        seller.setUpdateTime(DateUtils.getNowTime());
+        iDistributionSellerService.updateById(seller);
+        return true;
+    }
+
     private void addNextAuditor(DistributionCheck check,Integer nextStatus,String nextKey){
         check.setNextStatus(nextStatus);//初审
         List<String> userNames = iSysUserService.getUserNameByRoleKey(nextKey);
         if (CollectionUtils.isNotEmpty(userNames)){
             check.setNextAuditor(userNames.stream().collect(Collectors.joining()));
         }
-
     }
 
     private void validPermission(DistributionCheckHandleBo bo,String roleKey) {