|
@@ -1,5 +1,8 @@
|
|
|
package com.ruoyi.web.work.service.impl;
|
|
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
@@ -12,10 +15,12 @@ import com.ruoyi.web.work.mapper.PayMapper;
|
|
|
import com.ruoyi.web.work.service.IPayService;
|
|
|
import com.ruoyi.web.work.service.IUserService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.env.Environment;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.rmi.ServerException;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -30,6 +35,9 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements IPayS
|
|
|
@Autowired
|
|
|
IUserService userService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private Environment env;
|
|
|
+
|
|
|
@Override
|
|
|
public List<Pay> selectList(Pay pay) {
|
|
|
return payMapper.selectList(pay);
|
|
@@ -73,7 +81,7 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements IPayS
|
|
|
@Override
|
|
|
public AjaxResult audit(PayAuditDto dto) throws ServerException {
|
|
|
Pay pay = getById(dto.getId());
|
|
|
- if (pay == null) {
|
|
|
+ if (pay == null || pay.getType() != 2) {
|
|
|
return AjaxResult.error("提现信息不存在");
|
|
|
}
|
|
|
if (pay.getState() == 1) {
|
|
@@ -86,12 +94,46 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements IPayS
|
|
|
}
|
|
|
//提现驳回需要退回到用户账户余额
|
|
|
if (dto.getState() == 2) {
|
|
|
- User user =userService.getById(pay.getUserId());
|
|
|
+ User user = userService.getById(pay.getUserId());
|
|
|
user.setMoney(user.getMoney().add(pay.getMoney()));
|
|
|
if (!userService.updateById(user)) {
|
|
|
throw new ServerException("更新用户账户余额失败,请联系平台");
|
|
|
}
|
|
|
}
|
|
|
+ sendMessage(pay);
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void sendMessage(Pay pay) {
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(HttpUtil.get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + env.getProperty("wx.appid") + "&secret=" + env.getProperty("wx.appSecret")));
|
|
|
+ JSONObject body = new JSONObject();
|
|
|
+ body.set("appid", env.getProperty("wx.appid"));
|
|
|
+ JSONObject content = new JSONObject();
|
|
|
+ //提现成功通知
|
|
|
+ if (pay.getState() == 1) {
|
|
|
+ User user = userService.getById(pay.getUserId());
|
|
|
+ body.set("touser", user.getOpenId());
|
|
|
+ body.set("template_id", "PtdKbqfzmpvGsJPx_YekDX4-cljbhOXcvoUB3XJaVLg");
|
|
|
+ body.set("page", "pages/user/money/index");
|
|
|
+ content.set("amount3", new JSONObject().set("value", pay.getMoney()));//提现金额
|
|
|
+ content.set("character_string4", new JSONObject().set("value", pay.getNums()));//交易单号
|
|
|
+ content.set("time2", new JSONObject().set("value", new Date())); //提现时间
|
|
|
+ }
|
|
|
+ //提现失败通知
|
|
|
+ if (pay.getState() == 2) {
|
|
|
+ User user = userService.getById(pay.getUserId());
|
|
|
+ body.set("touser", user.getOpenId());
|
|
|
+ body.set("template_id", "NIqSQq0j765o9Iz9gMiSelnuxMgPIPeCnk3lvEnWJlo");
|
|
|
+ body.set("page", "pages/user/money/index");
|
|
|
+ content.set("amount3", new JSONObject().set("value", pay.getMoney()));//提现金额
|
|
|
+ content.set("character_string4", new JSONObject().set("value", pay.getNums()));//交易单号
|
|
|
+ content.set("thing5", new JSONObject().set("value", pay.getMsg())); //失败原因
|
|
|
+ content.set("time2", new JSONObject().set("value", new Date())); //提现时间
|
|
|
+ }
|
|
|
+ body.set("data", content);
|
|
|
+ String result = HttpUtil.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + jsonObject.getStr("access_token"), body.toString());
|
|
|
+ System.out.println("body:" + body);
|
|
|
+ System.out.println("小程序订阅消息:" + result);
|
|
|
+ }
|
|
|
}
|