ソースを参照

新增管理端确认提现接口

codingliang 1 年間 前
コミット
3882b13bf8

+ 3 - 1
src/main/java/com/sqx/modules/app/service/impl/UserMoneyServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -320,7 +321,8 @@ public class UserMoneyServiceImpl extends ServiceImpl<UserMoneyDao, UserMoney> i
                 .build();
         UserMoneyDetails userMoneyDetails = updateUserMoney(updateMoneyBO);
 
-        String traceNo = newPayService.wechatSplitBill(mchId, amount);
+        String traceNo = IdWorker.getTimeId();
+        newPayService.wechatSplitBill(traceNo, mchId, amount);
 
         userMoneyDetails.setRemark(traceNo);
         userMoneyDetailsService.updateById(userMoneyDetails);

+ 1 - 0
src/main/java/com/sqx/modules/goods/dao/GoodsShopDao.java

@@ -107,4 +107,5 @@ public interface GoodsShopDao extends BaseMapper<GoodsShop> {
 
     IPage<GoodsShop> selectSupplierShop(Page<GoodsShop> pages, Integer screen, Integer shopTypeId, Double lng, Double lat, String city, String impotr,Long activityId);
 
+    GoodsShop getByAdminUserId(@Param("adminUserId") Long adminUserId);
 }

+ 7 - 0
src/main/java/com/sqx/modules/goods/service/GoodsShopService.java

@@ -50,4 +50,11 @@ public interface GoodsShopService extends IService<GoodsShop> {
      * @param remark 备注
      */
     void updateCashDeposit(Double money, Long shopId, String remark);
+
+    /**
+     * 根据管理员id查询店铺
+     * @param adminUserId 管理员id
+     * @return 店铺信息
+     */
+    GoodsShop getByAdminUserId(Long adminUserId);
 }

+ 5 - 0
src/main/java/com/sqx/modules/goods/service/impl/GoodsShopServiceImpl.java

@@ -554,4 +554,9 @@ public class GoodsShopServiceImpl extends ServiceImpl<GoodsShopDao, GoodsShop> i
         userMoneyDetails.setCreateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
         userMoneyDetailsService.save(userMoneyDetails);
     }
+
+    @Override
+    public GoodsShop getByAdminUserId(Long adminUserId) {
+        return baseMapper.getByAdminUserId(adminUserId);
+    }
 }

+ 8 - 147
src/main/java/com/sqx/modules/pay/controller/CashController.java

@@ -49,6 +49,7 @@ import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -289,7 +290,6 @@ public class CashController {
     @ApiOperation("管理平台确认提现")
     @ResponseBody
     public Result alipayPay(@PathVariable Long cashId) {
-
         CashOut one = cashOutService.selectById(cashId);
         if (one == null) {
             return Result.error("提现记录不存在!");
@@ -403,8 +403,6 @@ public class CashController {
         return Result.error("转账失败!");
     }
 
-
-
     private Result aliPay(CashOut one) {
         RLock lock = redissonClient.getLock(String.format(RedisKey.CASH_OUT_LOCK, one.getUserId()));
         try {
@@ -551,146 +549,6 @@ public class CashController {
         return Result.error("系统繁忙,请稍后再试!");
     }
 
-    /*@RequestMapping(value = "/alipay/{cashId}", method = RequestMethod.POST)
-    @ApiOperation("管理平台确认提现")
-    @ResponseBody
-    public Result alipayPay(@PathVariable Long cashId) {
-        reentrantReadWriteLock.writeLock().lock();
-        try {
-            //提现订单
-            CashOut one = cashOutService.selectById(cashId);
-            log.error("进来了!!!");
-            //订单记录不为空
-            if (one == null) {
-                return Result.error("提现记录不存在!");
-            }
-            //订单状态不是待转帐
-            if (one.getState()!=0) {
-                return Result.error(9999, one.getZhifubaoName() + "转账失败!原因是用户已转账");
-            }
-            //订单编号为空
-            if(StringUtils.isEmpty(one.getOrderNumber())){
-                one.setOrderNumber(String.valueOf(System.currentTimeMillis()));
-            }
-            //配置文件对象
-            CommonInfo commonInfo = commonInfoService.findOne(98);
-
-            CommonInfo name = commonInfoService.findOne(12);
-            if (commonInfo.getValue() != null && commonInfo.getValue().equals("1")) {
-
-                try {
-                    CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
-                    certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");  //gateway:支付宝网关(固定)https://openapi.alipay.com/gateway.do
-                    certAlipayRequest.setAppId(commonInfoService.findOne(63).getValue());  //APPID 即创建应用后生成,详情见创建应用并获取 APPID
-                    certAlipayRequest.setPrivateKey(commonInfoService.findOne(65).getValue());  //开发者应用私钥,由开发者自己生成
-                    certAlipayRequest.setFormat("json");  //参数返回格式,只支持 json 格式
-                    certAlipayRequest.setCharset(AliPayConstants.CHARSET);  //请求和签名使用的字符编码格式,支持 GBK和 UTF-8
-                    certAlipayRequest.setSignType(AliPayConstants.SIGNTYPE);  //商户生成签名字符串所使用的签名算法类型,目前支持 RSA2 和 RSA,推荐商家使用 RSA2。
-                    CommonInfo url = commonInfoService.findOne(200);
-                    certAlipayRequest.setCertPath(url.getValue()+"/appCertPublicKey.crt"); //应用公钥证书路径(app_cert_path 文件绝对路径)
-                    certAlipayRequest.setAlipayPublicCertPath(url.getValue()+"/alipayCertPublicKey_RSA2.crt"); //支付宝公钥证书文件路径(alipay_cert_path 文件绝对路径)
-                    certAlipayRequest.setRootCertPath(url.getValue()+"/alipayRootCert.crt");  //支付宝CA根证书文件路径(alipay_root_cert_path 文件绝对路径)
-                    AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);
-                    AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
-                    request.setBizContent("{" +
-                            "\"out_biz_no\":\""+one.getOrderNumber()+"\"," +             //订单编号
-                            "\"trans_amount\":"+new BigDecimal(one.getMoney())+"," +     //转账金额
-                            "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +
-                            "\"biz_scene\":\"DIRECT_TRANSFER\"," +
-                            "\"order_title\":\""+name.getValue() + "佣金结算"+"\"," +
-                            "\"payee_info\":{" +
-                            "\"identity\":\""+one.getZhifubao()+"\"," +                  //支付宝账号
-                            "\"identity_type\":\"ALIPAY_LOGON_ID\"," +
-                            "\"name\":\""+one.getZhifubaoName()+"\"," +                  //支付宝名称
-                            "}," +
-                            "\"remark\":\""+name.getValue() + "佣金结算"+"\"" +
-                            "}");
-                    AlipayFundTransUniTransferResponse response = null;
-                    response = alipayClient.certificateExecute(request);
-                    log.error("支付宝转账返回值:"+response.getBody());
-                    //如果转账成功
-                    if (AliPayConstants.SUCCESS_CODE.equalsIgnoreCase(response.getCode())) {
-                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-                        //修改状态为转账成功
-                        one.setState(1);
-                        //设置转账时间
-                        one.setOutAt(sdf.format(new Date()));
-                        //更新转账订单
-                        cashOutService.update(one);
-                        //查询用户
-                        UserEntity userInfo=userService.queryByUserId(one.getUserId());
-                        cashOutService.cashOutSuccess(userInfo, one.getOutAt(), one.getMoney(), one.getZhifubao(),  commonInfoService.findOne(19).getValue());
-
-                        return Result.success(one.getZhifubaoName() + "转账成功");
-                    } else {
-                        return Result.error(9999, one.getZhifubaoName() + "转账失败!" + response.getSubMsg());
-                    }
-                } catch (AlipayApiException e) {
-                    log.error("零钱提现异常原因:" + e.getMessage());
-                    e.printStackTrace();
-                    return Result.error(9999, one.getZhifubaoName() + "转账失败!" + e.getMessage());
-                }
-            }else if (commonInfo.getValue() != null && commonInfo.getValue().equals("2")) {
-                AlipayClient alipayClient = new DefaultAlipayClient(AliPayConstants.REQUEST_URL,
-                        commonInfoService.findOne(63).getValue(), commonInfoService.findOne(65).getValue(), AliPayConstants.FORMAT,
-                        AliPayConstants.CHARSET, commonInfoService.findOne(64).getValue(), AliPayConstants.SIGNTYPE);
-                val aliPayWithdrawModel = AliPayWithdrawModel.builder()
-                        .out_biz_no(one.getOrderNumber())
-                        .amount(new BigDecimal(one.getMoney()))
-                        .payee_account(one.getZhifubao())
-                        .payee_real_name(one.getZhifubaoName())
-                        .payee_type(AliPayConstants.PAY_TYPE)
-                        .remark(name.getValue())
-                        .build();
-                String json = JSON.toJSONString(aliPayWithdrawModel);
-                //实例化连接对象
-                AlipayFundTransToaccountTransferRequest withdrawRequest = new AlipayFundTransToaccountTransferRequest();
-                withdrawRequest.setBizContent(json);
-                try {
-                    AlipayFundTransToaccountTransferResponse response = alipayClient.execute(withdrawRequest);
-                    if (AliPayConstants.SUCCESS_CODE.equalsIgnoreCase(response.getCode())) {
-                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-                        //修改状态为转账成功
-                        one.setState(1);
-                        //设置转账时间
-                        one.setOutAt(sdf.format(new Date()));
-                        //更新转账订单
-                        cashOutService.update(one);
-                        //查询用户
-                        UserEntity userInfo=userService.queryByUserId(one.getUserId());
-                        cashOutService.cashOutSuccess(userInfo, one.getOutAt(), one.getMoney(), one.getZhifubao(),  commonInfoService.findOne(19).getValue());
-                        return Result.success(one.getZhifubaoName() + "转账成功");
-                    } else {
-                        return Result.error(9999, one.getZhifubaoName() + "转账失败!" + response.getSubMsg());
-                    }
-                } catch (AlipayApiException e) {
-                    log.error("零钱提现异常原因:" + e.getMessage());
-                    e.printStackTrace();
-                    return Result.error(9999, one.getZhifubaoName() + "转账失败!" + e.getMessage());
-
-                }
-            }else{
-                //人工转账后改变状态的
-                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-                Date now = new Date();
-                one.setState(1);
-                one.setOutAt(sdf.format(now));
-                cashOutService.update(one);
-                UserEntity userInfo=userService.queryByUserId(one.getUserId());
-                cashOutService.cashOutSuccess(userInfo, one.getOutAt(), one.getMoney(), one.getZhifubao(),commonInfoService.findOne(19).getValue());
-                return Result.success(one.getZhifubaoName() + "转账成功");
-            }
-        }catch (Exception e){
-            e.printStackTrace();
-            log.error("转账异常"+e.getMessage());
-        }finally {
-            reentrantReadWriteLock.writeLock().unlock();
-        }
-        return Result.error("系统繁忙,请稍后再试!");
-    }
-*/
-
-
     @RequestMapping(value = "/refund", method = RequestMethod.POST)
     @ApiOperation("管理平台退款")
     @ResponseBody
@@ -737,8 +595,11 @@ public class CashController {
         return Result.success();
     }
 
-
-
-
-
+    @PostMapping(value = "confirm-cash/{cashId}")
+    @ApiOperation("确认提现")
+    @ResponseBody
+    public Result confirmCash(@PathVariable Long cashId) {
+        cashOutService.confirmCash(cashId);
+        return Result.success();
+    }
 }

+ 1 - 1
src/main/java/com/sqx/modules/pay/entity/CashOut.java

@@ -99,7 +99,7 @@ public class CashOut implements Serializable {
     private Integer type;
 
     /**
-     * 1 支付宝  2 小程序  3公众号  4 微信app 5 银行卡
+     * 1 支付宝  2 小程序  3公众号  4 微信app 5 银行卡 6rht分账
      */
     private Integer classify;
 

+ 6 - 0
src/main/java/com/sqx/modules/pay/service/CashOutService.java

@@ -56,4 +56,10 @@ public interface CashOutService extends IService<CashOut> {
      * @return
      */
     Double selectCommissionTotal(CashOutQueryDTO queryDTO);
+
+    /**
+     * 确认提现
+     * @param cashId 提现申请id
+     */
+    void confirmCash(Long cashId);
 }

+ 2 - 1
src/main/java/com/sqx/modules/pay/service/NewPayService.java

@@ -23,11 +23,12 @@ public interface NewPayService {
 
     /**
      * 微信分账
+     * @param traceNo 交易号
      * @param inMchId 入账商户号
      * @param amount 入账金额
      * @return 分账编号
      */
-    String wechatSplitBill(String inMchId, BigDecimal amount);
+    void wechatSplitBill(String traceNo, String inMchId, BigDecimal amount);
 
     /**
      * 微信支付回调

+ 73 - 0
src/main/java/com/sqx/modules/pay/service/impl/CashOutServiceImpl.java

@@ -1,11 +1,13 @@
 package com.sqx.modules.pay.service.impl;
 
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.sqx.common.constant.MyConstant;
 import com.sqx.common.constant.RedisKey;
 import com.sqx.common.exception.SqxException;
 import com.sqx.common.utils.PageUtils;
@@ -28,12 +30,15 @@ import com.sqx.modules.errand.dao.ErrandComplaintDao;
 import com.sqx.modules.errand.dao.TbIndentDao;
 import com.sqx.modules.errand.entity.ErrandComplaint;
 import com.sqx.modules.errand.entity.TbIndent;
+import com.sqx.modules.goods.entity.GoodsShop;
+import com.sqx.modules.goods.service.GoodsShopService;
 import com.sqx.modules.message.dao.MessageInfoDao;
 import com.sqx.modules.message.entity.MessageInfo;
 import com.sqx.modules.pay.controller.query.CashOutQueryDTO;
 import com.sqx.modules.pay.dao.CashOutDao;
 import com.sqx.modules.pay.entity.CashOut;
 import com.sqx.modules.pay.service.CashOutService;
+import com.sqx.modules.pay.service.NewPayService;
 import com.sqx.modules.pay.vo.CashOutVO;
 import com.sqx.modules.shop.entity.ShopBankCardInfo;
 import com.sqx.modules.shop.service.ShopBankCardInfoService;
@@ -104,6 +109,10 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
     @Autowired
     private ShopBankCardInfoService shopBankCardInfoService;
     @Autowired
+    private NewPayService newPayService;
+    @Autowired
+    private GoodsShopService goodsShopService;
+    @Autowired
     private RedissonClient redissonClient;
     @Autowired
     private RiderBankCardInfoService riderBankCardInfoService;
@@ -599,6 +608,70 @@ public class CashOutServiceImpl extends ServiceImpl<CashOutDao, CashOut> impleme
         return this.baseMapper.selectCommissionTotal(queryDTO);
     }
 
+    @Override
+    public void confirmCash(Long cashId) {
+        RLock lock = redissonClient.getLock(String.format(RedisKey.CASH_OUT_LOCK, cashId));
+        lock.lock();
+        try {
+            CashOut cashOut = getById(cashId);
+            // 前置准备
+            String mchId = prepareBeforeConfirmCashOut(cashOut);
+
+            // 1 支付宝  2 小程序  3公众号  4 微信app 5银行卡 6rht分账
+            Integer classify = cashOut.getClassify();
+            if (classify == 5) {
+                // 银行卡为手动转账,不需要做任何事情
+            } else if (classify == 6) {
+                if (StrUtil.isBlank(mchId)) {
+                    throw new SqxException("当前用户/店铺未设置商户号");
+                }
+                newPayService.wechatSplitBill(cashOut.getOrderNumber(), mchId, new BigDecimal(cashOut.getMoney()));
+            } else {
+                throw new SqxException("不支持的提现方式");
+            }
+
+            cashOut.setState(1);
+            cashOut.setOutAt(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+
+            updateById(cashOut);
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    private String prepareBeforeConfirmCashOut(CashOut cashOut) {
+        if (ObjectUtil.isNull(cashOut)) {
+            throw new SqxException("无效的提现申请id");
+        }
+
+        // 提现申请状态判断 0表示待转账状态
+        if (cashOut.getState() != 0) {
+            throw new SqxException("当前提现申请状态异常");
+        }
+
+        UserEntity userEntity = userService.getById(cashOut.getUserId());
+        if (ObjectUtil.isNull(userEntity)) {
+            throw new SqxException("无效的用户id");
+        }
+
+        // 1用户提现  2商户提现  3骑手提现
+        Integer cashOutType = cashOut.getType();
+
+        String mchId = null;
+        if (cashOutType == 2) {
+            // TODO 骑手商户号
+        } else if (cashOutType == 3) {
+            // 店铺商户号
+            Long adminUserId = userEntity.getAdminUserId();
+            GoodsShop goodsShop = goodsShopService.getByAdminUserId(adminUserId);
+            mchId = goodsShop.getMchId();
+        } else {
+            throw new SqxException("暂不支持用户提现");
+        }
+
+        return mchId;
+    }
+
     /**
      * CashOutVO转换成row
      * @param cashOutVO vo

+ 1 - 4
src/main/java/com/sqx/modules/pay/service/impl/NewPayServiceImpl.java

@@ -144,11 +144,10 @@ public class NewPayServiceImpl implements NewPayService {
     }
 
     @Override
-    public String wechatSplitBill(String inMchId, BigDecimal amount) {
+    public void wechatSplitBill(String traceNo, String inMchId, BigDecimal amount) {
         WechatPayConfig wechatMchConfig = getWechatMchConfig();
         RhtSplitApi splitApi = new RhtSplitApi(wechatMchConfig.getMchId(), wechatMchConfig.getMchKey(), RHT_PAY_BASE_URL);
 
-        String traceNo = IdWorker.getTimeId();
         String outAmount = amount.toString();
 
         SplitPayRequestBean request = new SplitPayRequestBean();
@@ -168,8 +167,6 @@ public class NewPayServiceImpl implements NewPayService {
             if (splitPayResponse.getStatus() != 1) {
                 throw new SqxException("分账支付失败," + splitPayResponse.getMessage());
             }
-
-            return traceNo;
         } catch (Exception e) {
             e.printStackTrace();
             throw new SqxException("分账," + e.getMessage());

+ 9 - 0
src/main/resources/mapper/goods/GoodsShopMapper.xml

@@ -528,6 +528,15 @@
         where distribution_distance >= distance
     </select>
 
+    <select id="getByAdminUserId" resultType="com.sqx.modules.goods.entity.GoodsShop">
+        select
+               gs.*
+        from
+             goods_shop gs
+             left join sys_user_shop sus on sus.shop_id = gs.shop_id
+        where sus.user_id = #{adminUserId}
+    </select>
+
 
     <insert id="insertGoodsShop" useGeneratedKeys="true" keyProperty="shopId"
             parameterType="com.sqx.modules.goods.entity.GoodsShop">

+ 1 - 1
src/main/resources/mapper/pay/CashDao.xml

@@ -267,7 +267,7 @@
             <if test="params.phone != null and params.phone != '' and params.phone != 'null'">
                 and co.phone like concat('%',#{params.phone},'%')
             </if>
-            <if test="params.classify == 1 || params.classify == 5">
+            <if test="params.classify == 1 || params.classify == 5 || params.classify == 6">
                 and co.classify = #{params.classify}
             </if>
             <if test="params.classify == 2">