Переглянути джерело

Merge remote-tracking branch 'origin/master'

小么熊🐻 3 роки тому
батько
коміт
b88fb67972

+ 0 - 83
twzd-admin/src/main/java/com/miaxis/app/controller/wx/VipController.java

@@ -1,83 +0,0 @@
-package com.miaxis.app.controller.wx;
-
-import com.alibaba.fastjson.JSONObject;
-import com.miaxis.common.config.WxpayConfig;
-import com.miaxis.common.constant.Constants;
-import com.miaxis.common.core.controller.BaseController;
-import com.miaxis.common.core.domain.Response;
-import com.miaxis.system.service.ISysDictDataService;
-import com.miaxis.wx.dto.WxOrderDTO;
-import com.miaxis.wx.service.IWxOrderService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.http.client.HttpClient;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * 【小程序-微信支付】Controller
- *
- * @author miaxis
- * @date 2021-03-10
- */
-@RestController
-@RequiredArgsConstructor
-@RequestMapping(Constants.VIP_PREFIX+"/wx")
-@Api(tags = {"【VIP-接口】"})
-@Slf4j
-public class VipController extends BaseController {
-
-    @Autowired
-    private HttpClient httpClient;
-
-    @Autowired
-    private WxpayConfig wxpayConfig;
-
-    @Autowired
-    private IWxOrderService wxOrderService;
-
-
-    @Autowired
-    private ISysDictDataService dictDataService;
-
-    @Value("${app.appid}")
-    private String appid;
-    @Value("${wxpay.notifyUrl}")
-    private  String notifyUrl ;
-
-
-
-
-
-
-    /**
-     * 微信支付获取预订单id
-     */
-    @PostMapping(value = "/prepareOrder")
-    @ApiOperation("微信支付下单")
-    public Response<JSONObject> getPrepareOrder(@RequestBody WxOrderDTO wxOrderDTO) throws Exception{
-
-            return Response.success();
-
-
-    }
-
-
-
-
-
-
-
-
-
-
-
-
-
-}

+ 13 - 3
twzd-admin/src/main/java/com/miaxis/app/controller/wx/WxNotifyController.java

@@ -10,6 +10,7 @@ import com.miaxis.common.core.domain.model.LoginUser;
 import com.miaxis.common.exception.CustomException;
 import com.miaxis.common.utils.AesUtil;
 import com.miaxis.common.utils.SecurityUtils;
+import com.miaxis.extension.service.IWxExtensionIncomeService;
 import com.miaxis.framework.web.service.TokenService;
 import com.miaxis.user.service.IUserInfoService;
 import com.miaxis.wx.domain.RefundRecord;
@@ -67,6 +68,11 @@ public class WxNotifyController {
     @Autowired
     private TokenService tokenService;
 
+    @Autowired
+    private IWxExtensionIncomeService wxExtensionIncomeService;
+
+
+
 
     /**
      * 微信支付回调接口
@@ -75,9 +81,9 @@ public class WxNotifyController {
     @ApiOperation("微信支付回调")
     public WxNotifyReturnDTO wxpayNotify(@RequestBody WxpayNotifyDTO wxpayNotifyDTO, HttpServletRequest request) throws GeneralSecurityException, IOException {
         String bodyString = getBodyString(request);
-//        if (!validate(request,bodyString)){
-//            throw new CustomException("签名失败");
-//        }
+        if (!validate(request,bodyString)){
+            throw new CustomException("签名失败");
+        }
         String resourceString = getSourString(wxpayNotifyDTO);
         log.info("微信支付回调数据"+resourceString);
         JSONObject jsonObject = JSONObject.parseObject(resourceString);
@@ -241,6 +247,10 @@ public class WxNotifyController {
         //刷新缓存中的数据
         tokenService.refreshToken(loginUser);
 
+
+        // 分成
+        wxExtensionIncomeService.addExtensionIncomeBySourceId(wxOrder.getOutTradeNo(),wxOrder.getOpenid(),wxOrder.getTotal());
+
         return outTradeNo;
 
     }

+ 10 - 0
twzd-admin/src/main/java/com/miaxis/pc/controller/wx/WxMenuController.java

@@ -90,4 +90,14 @@ public class WxMenuController extends BaseController {
         return wxMenuService.removeMenuByIds(ids);
     }
 
+    /**
+     * 一键更新公众号菜单
+     */
+    @GetMapping("/sendMenu")
+    @ApiOperation("一键更新公众号菜单--手动修改数据库操作")
+    public Response sendMenu(){
+        return wxMenuService.sendMenuBySql();
+    }
+
+
 }

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

@@ -76,7 +76,7 @@ spring:
                 # #连接池最大阻塞等待时间(使用负值表示没有限制)
                 max-wait: -1ms
         # 指定库
-        database: 12
+        database: 13
 
 # 微信公众号
 app:
@@ -90,8 +90,8 @@ wxpay:
     merchantId: 1615410794
     serialNumber: 5F85D69504B3B33DAF5A7C5B86A3E93915D3D5B0
     v3key: 8604f2a6eb6338cfa64e7df4ec2c08b3
-    notifyUrl: http://jpcj-h5.zzxcx.net.zzxcx.net/prod-api/open-api/wx/notify/wxpay
-    notifyUrlRefund: http://jpcj-h5.zzxcx.net.zzxcx.net/prod-api/open-api/wx/notify/refund
+    notifyUrl: http://jpcj-h5.zzxcx.net/prod-api/open-api/wx/notify/wxpay
+    notifyUrlRefund: http://jpcj-h5.zzxcx.net/prod-api/open-api/wx/notify/refund
 
 
 # 腾讯cos

+ 7 - 7
twzd-service/src/main/java/com/miaxis/extension/domain/WxExtensionIncome.java

@@ -27,9 +27,9 @@ public class WxExtensionIncome extends BaseBusinessEntity {
     @ApiModelProperty(value = "主键")
     private Long id;
 
-    @TableField("source_id")
-    @ApiModelProperty(value = "收益来源订单id")
-    private Long sourceId;
+    @TableField("out_trade_no")
+    @ApiModelProperty(value = "商户订单号(根据wx_order订单表)")
+    private String outTradeNo;
 
     @TableField("beneficiary_openid")
     @ApiModelProperty(value = "受益人----用户唯一标识(微信)")
@@ -44,12 +44,12 @@ public class WxExtensionIncome extends BaseBusinessEntity {
     private String hierarchy;
 
     @TableField("percentage")
-    @ApiModelProperty(value = "分成百分比")
-    private BigDecimal percentage;
+    @ApiModelProperty(value = "分成百分比(%)")
+    private Integer percentage;
 
     @TableField("profit_price")
-    @ApiModelProperty(value = "收益金额-----根据层级分成百分比计算")
-    private BigDecimal profitPrice;
+    @ApiModelProperty(value = "收益金额(分)-----根据层级分成百分比计算")
+    private Integer profitPrice;
 
     @TableField("extract_status")
     @ApiModelProperty(value = "提现状态  0:未提现(默认)、1:已提现")

+ 4 - 4
twzd-service/src/main/java/com/miaxis/extension/service/IWxExtensionIncomeService.java

@@ -26,11 +26,11 @@ public interface IWxExtensionIncomeService extends IService<WxExtensionIncome> {
 
     /**
      * 新增收益信息
-     * @param sourceId  订单id
-     * @param sourceOpenid 用户openid
-     * @param sourcePrice 订单金额
+     * @param outTradeNo  商户订单号
+     * @param openid 用户openid
+     * @param total 订单金额
      * @return
      */
-    Response addExtensionIncomeBySourceId(Long sourceId, String sourceOpenid, BigDecimal sourcePrice);
+    void addExtensionIncomeBySourceId(String outTradeNo, String openid, Integer total);
 
 }

+ 14 - 21
twzd-service/src/main/java/com/miaxis/extension/service/impl/WxExtensionIncomeServiceImpl.java

@@ -2,7 +2,6 @@ package com.miaxis.extension.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.miaxis.common.core.domain.Response;
 import com.miaxis.common.core.domain.entity.SysDictData;
 import com.miaxis.extension.domain.WxExtensionIncome;
 import com.miaxis.extension.mapper.WxExtensionIncomeMapper;
@@ -15,7 +14,6 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
-import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -52,19 +50,18 @@ public class WxExtensionIncomeServiceImpl extends ServiceImpl<WxExtensionIncomeM
 
     /**
      * 新增收益信息
-     * @param sourceId  订单id
-     * @param sourceOpenid 用户openid
-     * @param sourcePrice 订单金额
+     * @param outTradeNo  商户订单号
+     * @param openid 用户openid
+     * @param total 订单金额
      * @return
      */
     @Override
-    public Response addExtensionIncomeBySourceId(Long sourceId, String sourceOpenid, BigDecimal sourcePrice) {
+    public void addExtensionIncomeBySourceId(String outTradeNo, String openid, Integer total) {
 
         //查找一二级绑定关系
-        WxSpreadRelation oneRelation = wxSpreadRelationService.getOne(new QueryWrapper<WxSpreadRelation>().eq("openid", sourceOpenid));
+        WxSpreadRelation oneRelation = wxSpreadRelationService.getOne(new QueryWrapper<WxSpreadRelation>().eq("openid", openid));
         if (oneRelation == null){
-            log.info(sourceOpenid+": 此用户不存在绑定关系");
-            return Response.success();
+            log.info(openid+": 此用户不存在绑定关系");
         }
 
         WxSpreadRelation twoRelation = wxSpreadRelationService.getOne(new QueryWrapper<WxSpreadRelation>().eq("openid", oneRelation.getParentOpenid()));
@@ -75,27 +72,25 @@ public class WxExtensionIncomeServiceImpl extends ServiceImpl<WxExtensionIncomeM
         List<WxExtensionIncome> extensionIncomes = new ArrayList<>();
         dictDatas.forEach(d -> {
             if ("一级".equals(d.getDictLabel())){
-                BigDecimal decimal = BigDecimal.valueOf(Double.parseDouble(d.getDictValue()));//百分比
                 WxExtensionIncome income = new WxExtensionIncome();
-                income.setSourceId(sourceId);
+                income.setOutTradeNo(outTradeNo);
                 income.setBeneficiaryOpenid(oneRelation.getParentOpenid());
-                income.setSourceOpenid(sourceOpenid);
+                income.setSourceOpenid(openid);
                 income.setHierarchy("1");
-                income.setPercentage(decimal);
-                income.setProfitPrice(sourcePrice.multiply(decimal));
+                income.setPercentage(Integer.parseInt(d.getDictValue()));
+                income.setProfitPrice((total*Integer.parseInt(d.getDictValue()))/100);
                 extensionIncomes.add(income);
             }
 
             if (twoRelation != null){
                 if ("二级".equals(d.getDictLabel())){
-                    BigDecimal decimal = BigDecimal.valueOf(Double.parseDouble(d.getDictValue()));//百分比
                     WxExtensionIncome income = new WxExtensionIncome();
-                    income.setSourceId(sourceId);
+                    income.setOutTradeNo(outTradeNo);
                     income.setBeneficiaryOpenid(twoRelation.getParentOpenid());
-                    income.setSourceOpenid(sourceOpenid);
+                    income.setSourceOpenid(openid);
                     income.setHierarchy("2");
-                    income.setPercentage(decimal);
-                    income.setProfitPrice(sourcePrice.multiply(decimal));
+                    income.setPercentage(Integer.parseInt(d.getDictValue()));
+                    income.setProfitPrice((total*Integer.parseInt(d.getDictValue()))/100);
                     extensionIncomes.add(income);
                 }
             }
@@ -103,8 +98,6 @@ public class WxExtensionIncomeServiceImpl extends ServiceImpl<WxExtensionIncomeM
 
         //保存分成收益信息
         this.saveBatch(extensionIncomes);
-
-        return Response.success();
     }
 
 }

+ 7 - 0
twzd-service/src/main/java/com/miaxis/wx/service/IWxMenuService.java

@@ -45,4 +45,11 @@ public interface IWxMenuService extends IService<WxMenu> {
      * @return
      */
     Response removeMenuByIds(Long[] ids);
+
+    /**
+     * 一键发送数据库菜单
+     * @return
+     */
+    Response sendMenuBySql();
+
 }

+ 19 - 1
twzd-service/src/main/java/com/miaxis/wx/service/impl/WxGzhServiceImpl.java

@@ -3,9 +3,11 @@ package com.miaxis.wx.service.impl;
 import cn.hutool.json.XML;
 import com.alibaba.fastjson.JSONObject;
 import com.miaxis.common.constant.Constants;
+import com.miaxis.common.core.domain.entity.UserInfo;
 import com.miaxis.common.utils.StringUtils;
 import com.miaxis.common.utils.wx.MessageUtil;
 import com.miaxis.feign.service.IWxSendService;
+import com.miaxis.system.service.ISysUserService;
 import com.miaxis.wx.mapper.WxMenuMapper;
 import com.miaxis.wx.service.IWxGzhService;
 import com.miaxis.wx.service.IWxMessageEvenService;
@@ -39,6 +41,8 @@ public class WxGzhServiceImpl implements IWxGzhService {
 
     private final COSClient cosClient;
 
+    private final ISysUserService userService;
+
     private final IWxMessageEvenService wxMessageEvenService;
 
     @Value("${app.appid}")
@@ -117,6 +121,20 @@ public class WxGzhServiceImpl implements IWxGzhService {
                 String event = jsonObjectData.getStr("Event");
                 if (MessageUtil.MESSAGE_SUBSCRIBE.equals(event)) { // 关注事件 或 扫描二维码关注事件
                     log.info("3.1...");
+
+                    //获取用户信息
+                    String userInfoResult = wxSendService.userInfo(this.getGzhToken(), fromUserName, "zh_CN");
+                    JSONObject jsonObj = JSONObject.parseObject(userInfoResult);
+                    UserInfo user = userService.getStudentByOpenId(fromUserName);
+                    if (user == null){
+                        //保存用户信息
+                        UserInfo userInfo = new UserInfo();
+                        userInfo.setHeadImage(jsonObj.getString("headimgurl"));
+                        userInfo.setNickName(jsonObj.getString("nickname"));
+                        userInfo.setOpenid(jsonObj.getString("openid"));
+                        userService.saveUserInfo(userInfo);
+                    }
+
                     //存在Ticket为扫码关注
                     if (org.apache.commons.lang3.StringUtils.isNotEmpty(jsonObjectData.getStr("Ticket"))){
                         log.info("3.1.2..");
@@ -125,7 +143,7 @@ public class WxGzhServiceImpl implements IWxGzhService {
                         return MessageUtil.initText(fromUserName,toUserName,subscribeEvent);
 
                     }else {
-                        return MessageUtil.initText(fromUserName, toUserName, "关注事件");
+                        return MessageUtil.initText(fromUserName, toUserName, jsonObj.getString("nickname")+":关注事件");
                     }
 
                 }  else if (MessageUtil.MESSAGE_UNSUBSCRIBE.equals(event)) { // 取消订阅事件

+ 10 - 0
twzd-service/src/main/java/com/miaxis/wx/service/impl/WxMenuServiceImpl.java

@@ -127,6 +127,16 @@ public class WxMenuServiceImpl extends ServiceImpl<WxMenuMapper, WxMenu> impleme
         }
     }
 
+    /**
+     * 一键发送数据库菜单
+     * @return
+     */
+    @Override
+    public Response sendMenuBySql() {
+        sendMenu();
+        return Response.success();
+    }
+
 
     /**
      * 发送菜单至微信

+ 29 - 14
twzd-service/src/main/java/com/miaxis/wx/service/impl/WxMessageEvenServiceImpl.java

@@ -135,32 +135,41 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
                 FileUtil.file(ticketPath+fromUserName+"_img.jpg"),
                 ImgUtil.read(FileUtil.file(ticketPath+fromUserName+".jpg")), //水印图片
                 0, //x坐标修正值。 默认在中间,偏移量相对于中间偏移
-                -360, //y坐标修正值。 默认在中间,偏移量相对于中间偏移
+                -340, //y坐标修正值。 默认在中间,偏移量相对于中间偏移
                 1.0f
         );
 
+        ImgUtil.pressText(
+                FileUtil.file(ticketPath+fromUserName+"_img.jpg"),
+                FileUtil.file(ticketPath+fromUserName+"_text1.jpg"),
+                userInfo.getString("nickname"), Color.black, //文字
+                new Font("黑体", Font.BOLD, 30), //字体
+                0, //x坐标修正值。 默认在中间,偏移量相对于中间偏移
+                -500, //y坐标修正值。 默认在中间,偏移量相对于中间偏移
+                1.0f//透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字
+        );
+
         DateTime date = DateUtil.date();
         Date newDate = DateUtil.offsetDay(date, 3);
         String dateStr = DateUtil.format(newDate, "yyyy-MM-dd");
         log.info(dateStr);
 
-        String text = userInfo.getString("nickname")+"  此二维码有效期至:"+dateStr;
         ImgUtil.pressText(
-                FileUtil.file(ticketPath+fromUserName+"_img.jpg"),
-                FileUtil.file(ticketPath+fromUserName+"_text.jpg"),
-                text, Color.red, //文字
-                new Font("黑体", Font.BOLD, 30), //字体
+                FileUtil.file(ticketPath+fromUserName+"_text1.jpg"),
+                FileUtil.file(ticketPath+fromUserName+"_text2.jpg"),
+                "二维码有效期至:"+dateStr, Color.black, //文字
+                new Font("黑体", Font.BOLD, 28), //字体
                 0, //x坐标修正值。 默认在中间,偏移量相对于中间偏移
-                400, //y坐标修正值。 默认在中间,偏移量相对于中间偏移
-                0.8f//透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字
+                -80, //y坐标修正值。 默认在中间,偏移量相对于中间偏移
+                1.0f//透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字
         );
 
 
         try {
-            File textFile = new File(ticketPath + fromUserName+"_text.jpg");
+            File textTwoFile = new File(ticketPath + fromUserName+"_text2.jpg");
             //上传素材
             String path = mediaUpload + token + "&type=image";
-            String result = HttpUtils.connectHttpsByPost(path,textFile);
+            String result = HttpUtils.connectHttpsByPost(path,textTwoFile);
             result = result.replaceAll("[\\\\]", "");
             JSONObject resultJSON = JSONObject.parseObject(result);
             log.info("------result:" + resultJSON);
@@ -171,7 +180,8 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
 
             //删除服务器文件
             File imgFile = new File(ticketPath + fromUserName+"_img.jpg");
-            if (ticketFile.exists() && imgFile.exists() && textFile.exists()) {
+            File textOneFile = new File(ticketPath + fromUserName+"_text1.jpg");
+            if (ticketFile.exists() && imgFile.exists() && textOneFile.exists() && textTwoFile.exists()) {
                 if (ticketFile.delete()) {
                     log.info("删除:" + ticketFile.getName() + "成功!");
                 } else {
@@ -182,10 +192,15 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
                 } else {
                     log.info("删除:" + imgFile.getName() + "失败!");
                 }
-                if (textFile.delete()) {
-                    log.info("删除:" + textFile.getName() + "成功!");
+                if (textOneFile.delete()) {
+                    log.info("删除:" + textOneFile.getName() + "成功!");
+                } else {
+                    log.info("删除:" + textOneFile.getName() + "失败!");
+                }
+                if (textTwoFile.delete()) {
+                    log.info("删除:" + textTwoFile.getName() + "成功!");
                 } else {
-                    log.info("删除:" + textFile.getName() + "失败!");
+                    log.info("删除:" + textTwoFile.getName() + "失败!");
                 }
             }
 

+ 1 - 1
twzd-service/src/main/resources/mapper/extension/WxExtensionIncomeMapper.xml

@@ -6,7 +6,7 @@
 
     <resultMap type="WxExtensionIncome" id="WxExtensionIncomeResult">
         <result property="id"    column="id"    />
-        <result property="sourceId"    column="source_id"    />
+        <result property="out_trade_no"    column="outTradeNo"    />
         <result property="beneficiaryOpenid"    column="beneficiary_openid"    />
         <result property="sourceOpenid"    column="source_openid"    />
         <result property="hierarchy"    column="hierarchy"    />