fix: 修复bug
This commit is contained in:
@@ -44,6 +44,7 @@ import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -51,6 +52,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -115,7 +117,7 @@ public class WxClerkController {
|
||||
* 店员获取个人业绩信息
|
||||
*/
|
||||
@ApiOperation(value = "查询店员业绩", notes = "店员获取个人业绩信息")
|
||||
@ApiResponses({ @ApiResponse(code = 200, message = "操作成功") })
|
||||
@ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
|
||||
@ClerkUserLogin
|
||||
@PostMapping("/user/queryPerformanceInfo")
|
||||
public R queryPerformanceInfo(
|
||||
@@ -134,7 +136,7 @@ public class WxClerkController {
|
||||
* 店员获取个人等级信息
|
||||
*/
|
||||
@ApiOperation(value = "查询店员等级", notes = "店员获取个人等级信息")
|
||||
@ApiResponses({ @ApiResponse(code = 200, message = "操作成功", response = PlayClerkLevelInfoReturnVo.class) })
|
||||
@ApiResponses({@ApiResponse(code = 200, message = "操作成功", response = PlayClerkLevelInfoReturnVo.class)})
|
||||
@ClerkUserLogin
|
||||
@GetMapping("/user/queryLevelInfo")
|
||||
public R queryLevelInfo() {
|
||||
@@ -159,8 +161,8 @@ public class WxClerkController {
|
||||
* 店员获取个人信息
|
||||
*/
|
||||
@ApiOperation(value = "查询店员信息", notes = "店员获取个人详细信息")
|
||||
@ApiResponses({ @ApiResponse(code = 200, message = "操作成功", response = PlayClerkUserInfoResultVo.class),
|
||||
@ApiResponse(code = 500, message = "用户不存在") })
|
||||
@ApiResponses({@ApiResponse(code = 200, message = "操作成功", response = PlayClerkUserInfoResultVo.class),
|
||||
@ApiResponse(code = 500, message = "用户不存在")})
|
||||
@ClerkUserLogin
|
||||
@GetMapping("/user/queryById")
|
||||
public R queryById() {
|
||||
@@ -173,7 +175,7 @@ public class WxClerkController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "发送验证码", notes = "店员绑定手机号发送验证码")
|
||||
@ApiResponses({ @ApiResponse(code = 200, message = "操作成功", response = String.class) })
|
||||
@ApiResponses({@ApiResponse(code = 200, message = "操作成功", response = String.class)})
|
||||
@ClerkUserLogin
|
||||
@PostMapping("/user/sendCode")
|
||||
public R sendCode(
|
||||
@@ -187,7 +189,7 @@ public class WxClerkController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "绑定手机号", notes = "店员绑定手机号")
|
||||
@ApiResponses({ @ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "验证码错误") })
|
||||
@ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "验证码错误")})
|
||||
@ClerkUserLogin
|
||||
@PostMapping("/user/bindCode")
|
||||
public R bindCode(
|
||||
@@ -211,17 +213,19 @@ public class WxClerkController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "店员申请", notes = "用户申请成为店员")
|
||||
@ApiResponses({ @ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "系统错误,用户不存在"),
|
||||
@ApiResponse(code = 500, message = "当前用户已经是店员"), @ApiResponse(code = 500, message = "已有申请未审核") })
|
||||
@ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "系统错误,用户不存在"),
|
||||
@ApiResponse(code = 500, message = "当前用户已经是店员"), @ApiResponse(code = 500, message = "已有申请未审核")})
|
||||
@ClerkUserLogin
|
||||
@PostMapping("/user/add")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public R userAdd(@ApiParam(value = "店员申请信息", required = true) @Validated @RequestBody PlayClerkUserByWxAddVo vo) {
|
||||
String clerkId = ThreadLocalRequestDetail.getClerkUserInfo().getId();
|
||||
|
||||
PlayClerkUserInfoEntity userInfo = playClerkUserInfoService.selectById(clerkId);
|
||||
if (userInfo == null) {
|
||||
throw new CustomException("系统错误,用户不存在");
|
||||
}
|
||||
wxCustomMpService.checkSubscribeThrowsExp(userInfo.getOpenid(), userInfo.getTenantId());
|
||||
if ("1".equals(userInfo.getClerkState())) {
|
||||
throw new CustomException("当前用户已经是店员");
|
||||
}
|
||||
@@ -241,7 +245,7 @@ public class WxClerkController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "更新头像", notes = "店员更新头像")
|
||||
@ApiResponses({ @ApiResponse(code = 200, message = "操作成功") })
|
||||
@ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
|
||||
@ClerkUserLogin
|
||||
@PostMapping("/user/updateAvatar")
|
||||
public R updateAvatar(@ApiParam(value = "头像信息", required = true) @Validated @RequestBody PlayClerkUserAvatarVo vo) {
|
||||
@@ -340,8 +344,7 @@ public class WxClerkController {
|
||||
/**
|
||||
* 分页获取店员列表
|
||||
*
|
||||
* @param vo
|
||||
* PlayClerkUserInfoQueryVo
|
||||
* @param vo PlayClerkUserInfoQueryVo
|
||||
* @return 店员列表
|
||||
*/
|
||||
@PostMapping("/user/queryByPage")
|
||||
@@ -369,8 +372,7 @@ public class WxClerkController {
|
||||
/**
|
||||
* 获取店员礼物信息
|
||||
*
|
||||
* @param id
|
||||
* 店员ID
|
||||
* @param id 店员ID
|
||||
* @return 店员礼物
|
||||
*/
|
||||
|
||||
@@ -405,8 +407,7 @@ public class WxClerkController {
|
||||
/**
|
||||
* 获取店员价格
|
||||
*
|
||||
* @param id
|
||||
* 店员ID
|
||||
* @param id 店员ID
|
||||
* @return 店员价格
|
||||
*/
|
||||
@GetMapping("/user/queryPriceById")
|
||||
@@ -417,8 +418,7 @@ public class WxClerkController {
|
||||
/**
|
||||
* 店员分页查询本人订单列表
|
||||
*
|
||||
* @param vo
|
||||
* 订单列表分页查询对象
|
||||
* @param vo 订单列表分页查询对象
|
||||
* @return com.starry.common.result.R
|
||||
* @author admin
|
||||
* @since 2024/5/8 15:57
|
||||
@@ -434,8 +434,7 @@ public class WxClerkController {
|
||||
/**
|
||||
* 店员查询本人订单详情
|
||||
*
|
||||
* @param id
|
||||
* 订单ID
|
||||
* @param id 订单ID
|
||||
* @return com.starry.common.result.R
|
||||
* @author admin
|
||||
* @since 2024/5/8 15:57
|
||||
@@ -448,7 +447,7 @@ public class WxClerkController {
|
||||
if (StringUtils.isNotEmpty(vo.getAcceptBy()) && !vo.getAcceptBy().equals(ThreadLocalRequestDetail.getClerkUserInfo().getId())) {
|
||||
vo.setWeiChatCode("");
|
||||
}
|
||||
if(vo.getOrderStatus().equals("4")){
|
||||
if (vo.getOrderStatus().equals("4")) {
|
||||
vo.setWeiChatCode("");
|
||||
}
|
||||
return R.ok(vo);
|
||||
@@ -457,8 +456,7 @@ public class WxClerkController {
|
||||
/**
|
||||
* 店员-接单
|
||||
*
|
||||
* @param id
|
||||
* 订单ID
|
||||
* @param id 订单ID
|
||||
* @return com.starry.common.result.R
|
||||
* @author admin
|
||||
* @since 2024/5/8 15:57
|
||||
@@ -466,16 +464,27 @@ public class WxClerkController {
|
||||
@ClerkUserLogin
|
||||
@GetMapping("/order/accept")
|
||||
public R acceptOrder(@RequestParam("id") String id) {
|
||||
playOrderInfoService.updateStateTo1("1", ThreadLocalRequestDetail.getClerkUserInfo().getId(),
|
||||
ThreadLocalRequestDetail.getClerkUserInfo().getId(), id);
|
||||
PlayClerkUserInfoEntity clerkUserInfo = ThreadLocalRequestDetail.getClerkUserInfo();
|
||||
wxCustomMpService.checkSubscribeThrowsExp(clerkUserInfo.getOpenid(), clerkUserInfo.getTenantId());
|
||||
playOrderInfoService.updateStateTo1("1", clerkUserInfo.getId(),
|
||||
clerkUserInfo.getId(), id);
|
||||
return R.ok("成功");
|
||||
}
|
||||
|
||||
@GetMapping("/checkSubscribe")
|
||||
@ClerkUserLogin
|
||||
public R checkSubscribe() {
|
||||
String openid = ThreadLocalRequestDetail.getClerkUserInfo().getOpenid();
|
||||
String tenantId = SecurityUtils.getTenantId();
|
||||
wxCustomMpService.checkSubscribe(openid, tenantId);
|
||||
return R.ok(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 店员-开始订单
|
||||
*
|
||||
* @param id
|
||||
* 订单ID
|
||||
* @param id 订单ID
|
||||
* @return com.starry.common.result.R
|
||||
* @author admin
|
||||
* @since 2024/5/8 15:57
|
||||
@@ -490,8 +499,7 @@ public class WxClerkController {
|
||||
/**
|
||||
* 店员-取消订单
|
||||
*
|
||||
* @param vo
|
||||
* 取消订单传参
|
||||
* @param vo 取消订单传参
|
||||
* @return com.starry.common.result.R
|
||||
* @author admin
|
||||
* @since 2024/5/8 15:57
|
||||
@@ -507,8 +515,7 @@ public class WxClerkController {
|
||||
/**
|
||||
* 分页获取店员评价(订单评价)
|
||||
*
|
||||
* @param vo
|
||||
* 店员评价查询对象
|
||||
* @param vo 店员评价查询对象
|
||||
* @return 店员评价
|
||||
*/
|
||||
@PostMapping("/user/queryEvaluateByPage")
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.starry.admin.modules.weichat.entity.WxUserQueryAddressVo;
|
||||
import com.starry.admin.modules.weichat.service.WxCustomMpService;
|
||||
import com.starry.admin.modules.weichat.service.WxOauthService;
|
||||
import com.starry.admin.modules.weichat.service.WxTokenService;
|
||||
import com.starry.admin.utils.SecurityUtils;
|
||||
import com.starry.common.redis.RedisCache;
|
||||
import com.starry.common.result.R;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -26,8 +27,10 @@ import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
|
||||
import java.util.Date;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
@@ -193,6 +196,15 @@ public class WxOauthController {
|
||||
return R.ok(url);
|
||||
}
|
||||
|
||||
@GetMapping("/checkSubscribe")
|
||||
@CustomUserLogin
|
||||
public R checkSubscribe() {
|
||||
String openid = ThreadLocalRequestDetail.getCustomUserInfo().getOpenid();
|
||||
String tenantId = SecurityUtils.getTenantId();
|
||||
wxCustomMpService.checkSubscribe(openid, tenantId);
|
||||
return R.ok(true);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "顾客登录回调", notes = "微信顾客授权登录回调处理")
|
||||
@ApiImplicitParam(name = "code", value = "授权码", required = true, dataType = "String", paramType = "query")
|
||||
@GetMapping("/customLoginCallback")
|
||||
|
||||
@@ -33,6 +33,7 @@ import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
@@ -42,6 +43,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
@@ -82,8 +84,7 @@ public class WxPlayController {
|
||||
@ApiResponses({@ApiResponse(code = 200, message = "成功")})
|
||||
@RequestMapping("/jsCallback")
|
||||
public String wxPayNotify(HttpServletRequest request) {
|
||||
try (InputStream inStream = request.getInputStream();
|
||||
ByteArrayOutputStream outSteam = new ByteArrayOutputStream()) {
|
||||
try (InputStream inStream = request.getInputStream(); ByteArrayOutputStream outSteam = new ByteArrayOutputStream()) {
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
while ((len = inStream.read(buffer)) != -1) {
|
||||
@@ -123,15 +124,13 @@ public class WxPlayController {
|
||||
orderInfoEntity.setPayState("1");
|
||||
orderInfoService.updateById(orderInfoEntity);
|
||||
// 修改账户余额
|
||||
customUserInfoService.customAccountBalanceRecharge(orderInfoEntity.getOrderMoney(),
|
||||
orderInfoEntity.getPurchaserBy(), orderInfoEntity.getId());
|
||||
customUserInfoService.customAccountBalanceRecharge(orderInfoEntity.getOrderMoney(), orderInfoEntity.getPurchaserBy(), orderInfoEntity.getId());
|
||||
log.info("*********支付处理完成");
|
||||
// 推送通知
|
||||
mpService.sendBalanceMessage(orderInfoEntity);
|
||||
// 请求分账
|
||||
WxPayService wxPayService = mpService.getWxPay();
|
||||
this.profitSharing(wxPayService, orderMap, orderInfoEntity,
|
||||
tenantService.selectSysTenantByTenantId(orderInfoEntity.getTenantId()));
|
||||
this.profitSharing(wxPayService, orderMap, orderInfoEntity, tenantService.selectSysTenantByTenantId(orderInfoEntity.getTenantId()));
|
||||
} catch (Exception e) {
|
||||
log.error("订单回调业务处理异常,xmlData={}", xmlData);
|
||||
}
|
||||
@@ -155,15 +154,13 @@ public class WxPlayController {
|
||||
if (StringUtils.isEmpty(money)) {
|
||||
throw new CustomException("请求参数错误,money不能为空");
|
||||
}
|
||||
BigDecimal paymentAmount = customUserInfoService.getCustomPaymentAmount(new BigDecimal(money),
|
||||
ThreadLocalRequestDetail.getCustomUserInfo().getId());
|
||||
BigDecimal paymentAmount = customUserInfoService.getCustomPaymentAmount(new BigDecimal(money), ThreadLocalRequestDetail.getCustomUserInfo().getId());
|
||||
return R.ok(paymentAmount);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "创建充值订单", notes = "创建微信支付充值订单")
|
||||
@ApiImplicitParam(name = "money", value = "充值金额", required = true, dataType = "String", paramType = "query")
|
||||
@ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "请求参数错误,money不能为空"),
|
||||
@ApiResponse(code = 500, message = "充值金额不能小于10元"), @ApiResponse(code = 500, message = "系统错误,租户ID获取失败")})
|
||||
@ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "请求参数错误,money不能为空"), @ApiResponse(code = 500, message = "充值金额不能小于10元"), @ApiResponse(code = 500, message = "系统错误,租户ID获取失败")})
|
||||
@CustomUserLogin
|
||||
@GetMapping("/custom/createOrder")
|
||||
public R createOrder(@RequestParam("money") String money) {
|
||||
@@ -178,17 +175,16 @@ public class WxPlayController {
|
||||
throw new CustomException("系统错误,租户ID获取失败");
|
||||
}
|
||||
// 用户信息
|
||||
PlayCustomUserInfoEntity customUserInfo = customUserInfoService
|
||||
.selectById(ThreadLocalRequestDetail.getCustomUserInfo().getId());
|
||||
PlayCustomUserInfoEntity customUserInfo = customUserInfoService.selectById(ThreadLocalRequestDetail.getCustomUserInfo().getId());
|
||||
// 租户信息
|
||||
SysTenantEntity tenant = tenantService.selectSysTenantByTenantId(tenantId);
|
||||
mpService.checkSubscribeThrowsExp(customUserInfo.getOpenid(), tenant.getTenantId());
|
||||
Boolean profitSharing = tenant.getProfitsharingRate() > 0;
|
||||
// 订单总金额,单位为分
|
||||
long totalFee = getTotalFee(money);
|
||||
// 创建订单信息
|
||||
String orderNo = playOrderInfoService.getOrderNo();
|
||||
orderInfoService.createRechargeOrder(orderNo, new BigDecimal(totalFee * 1.0 / 100),
|
||||
new BigDecimal(totalFee * 1.0 / 100), customUserInfo.getId());
|
||||
orderInfoService.createRechargeOrder(orderNo, new BigDecimal(totalFee * 1.0 / 100), new BigDecimal(totalFee * 1.0 / 100), customUserInfo.getId());
|
||||
|
||||
WxPayService wxPayService = mpService.getWxPay();
|
||||
WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest();
|
||||
@@ -229,10 +225,7 @@ public class WxPlayController {
|
||||
String paySign = SignUtils.createSign(paySignInfo, "MD5", wxPayService.getConfig().getMchKey(), signInfo);
|
||||
|
||||
// 组合支付参数
|
||||
JSONObject jsonObject = new JSONObject().fluentPut("appId", wxPayService.getConfig().getAppId())
|
||||
.fluentPut("timeStamp", timeStamp).fluentPut("nonceStr", nonceStr)
|
||||
.fluentPut("package", "prepay_id=" + prepayId).fluentPut("signType", "MD5")
|
||||
.fluentPut("paySign", paySign);
|
||||
JSONObject jsonObject = new JSONObject().fluentPut("appId", wxPayService.getConfig().getAppId()).fluentPut("timeStamp", timeStamp).fluentPut("nonceStr", nonceStr).fluentPut("package", "prepay_id=" + prepayId).fluentPut("signType", "MD5").fluentPut("paySign", paySign);
|
||||
return R.ok(jsonObject);
|
||||
}
|
||||
|
||||
@@ -243,9 +236,7 @@ public class WxPlayController {
|
||||
String nonceStr = "dalfhh241lnandnsklajax";
|
||||
request.setNonceStr(nonceStr);
|
||||
request.setSignType("HMAC-SHA256");
|
||||
request.setReceiver(new JSONObject().fluentPut("type", "MERCHANT_ID").fluentPut("account", "1681470208")
|
||||
.fluentPut("name", "合肥经济技术开发区陪陪信息技术服务部(个体工商户)").fluentPut("relation_type", "SERVICE_PROVIDER")
|
||||
.toString());
|
||||
request.setReceiver(new JSONObject().fluentPut("type", "MERCHANT_ID").fluentPut("account", "1681470208").fluentPut("name", "合肥经济技术开发区陪陪信息技术服务部(个体工商户)").fluentPut("relation_type", "SERVICE_PROVIDER").toString());
|
||||
try {
|
||||
ProfitSharingReceiverResult result = wxPayService.getProfitSharingService().addReceiver(request);
|
||||
log.info("请求添加分账结果:" + JSONObject.toJSONString(result));
|
||||
@@ -256,8 +247,7 @@ public class WxPlayController {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param money
|
||||
* 金额,单位-元
|
||||
* @param money 金额,单位-元
|
||||
* @return 金额, 单位-分
|
||||
*/
|
||||
public long getTotalFee(String money) {
|
||||
@@ -289,16 +279,14 @@ public class WxPlayController {
|
||||
return map;
|
||||
}
|
||||
|
||||
private void profitSharing(WxPayService wxPayService, Map<String, String> orderMap,
|
||||
PlayOrderInfoEntity orderInfoEntity, SysTenantEntity tenant) throws WxPayException {
|
||||
private void profitSharing(WxPayService wxPayService, Map<String, String> orderMap, PlayOrderInfoEntity orderInfoEntity, SysTenantEntity tenant) throws WxPayException {
|
||||
Boolean profitSharing = tenant.getProfitsharingRate() > 0;
|
||||
if (!profitSharing) {
|
||||
return;
|
||||
}
|
||||
log.info("开始进行分账。。。。。。。。。。。。。。。");
|
||||
long totalFee = getTotalFee(orderInfoEntity.getOrderMoney().toString());
|
||||
int amount = new BigDecimal(totalFee).multiply(BigDecimal.valueOf((double) tenant.getProfitsharingRate() / 100))
|
||||
.intValue();
|
||||
int amount = new BigDecimal(totalFee).multiply(BigDecimal.valueOf((double) tenant.getProfitsharingRate() / 100)).intValue();
|
||||
if (amount == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -307,17 +295,12 @@ public class WxPlayController {
|
||||
request.setTransactionId(orderMap.get("transaction_id"));
|
||||
request.setOutOrderNo("ps" + orderMap.get("out_trade_no"));
|
||||
|
||||
request.setReceivers(new JSONArray().fluentAdd(
|
||||
new JSONObject().fluentPut("type", "MERCHANT_ID").fluentPut("name", "合肥经济技术开发区陪陪信息技术服务部(个体工商户)")
|
||||
.fluentPut("account", "1681470208").fluentPut("amount", amount))
|
||||
.toString());
|
||||
request.setReceivers(new JSONArray().fluentAdd(new JSONObject().fluentPut("type", "MERCHANT_ID").fluentPut("name", "合肥经济技术开发区陪陪信息技术服务部(个体工商户)").fluentPut("account", "1681470208").fluentPut("amount", amount)).toString());
|
||||
ProfitSharingResult result = wxPayService.getProfitSharingService().profitSharing(request);
|
||||
log.info("分账结果:" + JSONObject.toJSONString(result));
|
||||
// 保存分账金额
|
||||
BigDecimal profitSharingAmount = new BigDecimal(amount).divide(new BigDecimal(100));
|
||||
orderInfoService.update(null,
|
||||
Wrappers.lambdaUpdate(PlayOrderInfoEntity.class).eq(PlayOrderInfoEntity::getId, orderInfoEntity.getId())
|
||||
.set(PlayOrderInfoEntity::getProfitSharingAmount, profitSharingAmount));
|
||||
orderInfoService.update(null, Wrappers.lambdaUpdate(PlayOrderInfoEntity.class).eq(PlayOrderInfoEntity::getId, orderInfoEntity.getId()).set(PlayOrderInfoEntity::getProfitSharingAmount, profitSharingAmount));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,12 +2,14 @@ package com.starry.admin.modules.weichat.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
||||
import com.starry.admin.common.exception.CustomException;
|
||||
import com.starry.admin.common.exception.ServiceException;
|
||||
import com.starry.admin.modules.clerk.module.entity.PlayClerkUserInfoEntity;
|
||||
import com.starry.admin.modules.clerk.module.entity.PlayClerkUserReviewInfoEntity;
|
||||
import com.starry.admin.modules.clerk.service.IPlayClerkUserInfoService;
|
||||
@@ -20,14 +22,17 @@ import com.starry.admin.modules.personnel.service.IPlayPersonnelAdminInfoService
|
||||
import com.starry.admin.modules.system.module.entity.SysTenantEntity;
|
||||
import com.starry.admin.modules.system.service.impl.SysTenantServiceImpl;
|
||||
import com.starry.admin.utils.SecurityUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
||||
import me.chanjar.weixin.mp.config.impl.WxMpMapConfigImpl;
|
||||
@@ -76,6 +81,7 @@ public class WxCustomMpService {
|
||||
wxMpService.addConfigStorage(entity.getAppId(), config);
|
||||
return wxMpService.switchoverTo(entity.getAppId());
|
||||
}
|
||||
|
||||
public WxMpService proxyWxMpService(String tenantId) {
|
||||
if (StrUtil.isBlankIfStr(tenantId)) {
|
||||
throw new CustomException("系统错误,租户ID不能为空");
|
||||
@@ -329,23 +335,46 @@ public class WxCustomMpService {
|
||||
if (order.getPlaceType().equals("1") || order.getPlaceType().equals("2")) {
|
||||
SysTenantEntity tenant = tenantService.selectSysTenantByTenantId(order.getTenantId());
|
||||
PlayCustomUserInfoEntity customUserInfo = customUserInfoService.selectById(order.getPurchaserBy());
|
||||
WxMpTemplateMessage templateMessage = getWxMpTemplateMessage(tenant.getDingdanwanchengtongzhiTemplateId(),
|
||||
customUserInfo.getOpenid(),
|
||||
"https://" + tenant.getTenantKey() + ".julyharbor.com/user/#/orderDetail/" + order.getId());
|
||||
List<WxMpTemplateData> data = new ArrayList<>();
|
||||
data.add(new WxMpTemplateData("time18", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")));
|
||||
data.add(new WxMpTemplateData("character_string8", order.getOrderNo()));
|
||||
data.add(new WxMpTemplateData("thing13", order.getCommodityName()));
|
||||
templateMessage.setData(data);
|
||||
try {
|
||||
proxyWxMpService(tenant.getTenantId()).getTemplateMsgService().sendTemplateMsg(templateMessage);
|
||||
} catch (WxErrorException e) {
|
||||
log.error("订单完成发送消息异常", e);
|
||||
}
|
||||
PlayClerkUserInfoEntity clerkUserInfo = clerkUserInfoService.selectById(order.getAcceptBy());
|
||||
this.sendUserOrderFinishMessage(order, customUserInfo, tenant);
|
||||
this.sendClerkOrderFinishMessage(order, clerkUserInfo, tenant);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void sendClerkOrderFinishMessage(PlayOrderInfoEntity order, PlayClerkUserInfoEntity clerkUserInfo, SysTenantEntity tenant) {
|
||||
WxMpTemplateMessage templateMessage = getWxMpTemplateMessage(tenant.getDingdanwanchengtongzhiTemplateId(),
|
||||
clerkUserInfo.getOpenid(),
|
||||
"https://" + tenant.getTenantKey() + ".julyharbor.com/clerk/#/orderDetail/" + order.getId());
|
||||
List<WxMpTemplateData> data = new ArrayList<>();
|
||||
data.add(new WxMpTemplateData("time18", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")));
|
||||
data.add(new WxMpTemplateData("character_string8", order.getOrderNo()));
|
||||
data.add(new WxMpTemplateData("thing13", order.getCommodityName()));
|
||||
templateMessage.setData(data);
|
||||
try {
|
||||
proxyWxMpService(tenant.getTenantId()).getTemplateMsgService().sendTemplateMsg(templateMessage);
|
||||
} catch (WxErrorException e) {
|
||||
log.error("订单完成发送消息异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendUserOrderFinishMessage(PlayOrderInfoEntity order, PlayCustomUserInfoEntity customUserInfo, SysTenantEntity tenant) {
|
||||
WxMpTemplateMessage templateMessage = getWxMpTemplateMessage(tenant.getDingdanwanchengtongzhiTemplateId(),
|
||||
customUserInfo.getOpenid(),
|
||||
"https://" + tenant.getTenantKey() + ".julyharbor.com/user/#/orderDetail/" + order.getId());
|
||||
List<WxMpTemplateData> data = new ArrayList<>();
|
||||
data.add(new WxMpTemplateData("time18", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")));
|
||||
data.add(new WxMpTemplateData("character_string8", order.getOrderNo()));
|
||||
data.add(new WxMpTemplateData("thing13", order.getCommodityName()));
|
||||
templateMessage.setData(data);
|
||||
try {
|
||||
proxyWxMpService(tenant.getTenantId()).getTemplateMsgService().sendTemplateMsg(templateMessage);
|
||||
} catch (WxErrorException e) {
|
||||
log.error("订单完成发送消息异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendOrderCancelMessage(PlayOrderInfoEntity orderInfo, String refundReason) {
|
||||
SysTenantEntity tenant = tenantService.selectSysTenantByTenantId(orderInfo.getTenantId());
|
||||
|
||||
@@ -380,5 +409,31 @@ public class WxCustomMpService {
|
||||
|
||||
}
|
||||
|
||||
public void checkSubscribeThrowsExp(String openId, String tenantId) {
|
||||
if (StrUtil.isBlankIfStr(openId)) {
|
||||
throw new ServiceException("openId不能为空");
|
||||
}
|
||||
try {
|
||||
WxMpUser wxMpUser = proxyWxMpService(tenantId).getUserService().userInfo(openId);
|
||||
if (!wxMpUser.getSubscribe()) {
|
||||
log.info("检测到用户未关注公众号:" + JSONObject.toJSONString(wxMpUser));
|
||||
throw new ServiceException("请先关注公众号然后再来使用系统~");
|
||||
}
|
||||
} catch (WxErrorException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean checkSubscribe(String openId, String tenantId) {
|
||||
if (StrUtil.isBlankIfStr(openId)) {
|
||||
throw new ServiceException("openId不能为空");
|
||||
}
|
||||
try {
|
||||
WxMpUser wxMpUser = proxyWxMpService(tenantId).getUserService().userInfo(openId);
|
||||
return wxMpUser.getSubscribe();
|
||||
} catch (WxErrorException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
package com.starry.admin.modules.weichat.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.starry.admin.common.exception.ServiceException;
|
||||
import com.starry.admin.common.oss.service.IOssFileService;
|
||||
import com.starry.admin.modules.clerk.module.entity.PlayClerkUserInfoEntity;
|
||||
import com.starry.admin.modules.clerk.service.IPlayClerkLevelInfoService;
|
||||
import com.starry.admin.modules.clerk.service.IPlayClerkUserInfoService;
|
||||
import com.starry.admin.modules.custom.module.entity.PlayCustomUserInfoEntity;
|
||||
import com.starry.admin.modules.custom.service.IPlayCustomLevelInfoService;
|
||||
import com.starry.admin.modules.custom.service.IPlayCustomUserInfoService;
|
||||
import com.starry.admin.utils.SecurityUtils;
|
||||
import com.starry.common.utils.ConvertUtil;
|
||||
import com.starry.common.utils.IdUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
|
||||
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -42,12 +49,13 @@ public class WxOauthService {
|
||||
|
||||
@Resource
|
||||
private IPlayCustomLevelInfoService playCustomLevelInfoService;
|
||||
@Resource
|
||||
IOssFileService ossFileService;
|
||||
|
||||
/**
|
||||
* 微信用户登录 如果用户不存在,初始化用户并登录
|
||||
*
|
||||
* @param code
|
||||
* 微信授权code
|
||||
* @param code 微信授权code
|
||||
* @return String 用户ID
|
||||
* @author admin
|
||||
* @since 2024/4/15 11:01
|
||||
@@ -61,22 +69,24 @@ public class WxOauthService {
|
||||
PlayClerkUserInfoEntity item = clerkUserInfoService.selectByOpenid(openId);
|
||||
if (item == null) {
|
||||
PlayClerkUserInfoEntity entity = ConvertUtil.entityToVo(userInfo, PlayClerkUserInfoEntity.class);
|
||||
entity.setAvatar(userInfo.getHeadImgUrl());
|
||||
entity.setWeiChatAvatar(userInfo.getHeadImgUrl());
|
||||
entity.setAvatar(generateAvatar(userInfo.getHeadImgUrl()));
|
||||
entity.setWeiChatAvatar(generateAvatar(userInfo.getHeadImgUrl()));
|
||||
entity.setId(IdUtils.getUuid());
|
||||
entity.setLevelId(playClerkLevelInfoService.getDefaultLevel().getId());
|
||||
clerkUserInfoService.create(entity);
|
||||
return entity.getId();
|
||||
} else {
|
||||
PlayClerkUserInfoEntity entity = new PlayClerkUserInfoEntity();
|
||||
entity.setId(item.getId());
|
||||
entity.setAvatar(userInfo.getHeadImgUrl());
|
||||
entity.setWeiChatAvatar(userInfo.getHeadImgUrl());
|
||||
clerkUserInfoService.updateById(entity);
|
||||
return item.getId();
|
||||
}
|
||||
}
|
||||
|
||||
private String generateAvatar(String imageUrl) {
|
||||
InputStream inputStream = HttpRequest.get(imageUrl).execute().bodyStream();
|
||||
String fileAddress = ossFileService.upload(inputStream, SecurityUtils.getTenantId(),
|
||||
"image");
|
||||
return fileAddress;
|
||||
}
|
||||
|
||||
public void clerkUserLogout(PlayClerkUserInfoEntity entity) {
|
||||
entity.setToken("empty");
|
||||
clerkUserInfoService.update(entity);
|
||||
@@ -110,8 +120,7 @@ public class WxOauthService {
|
||||
/**
|
||||
* 获取微信授权Token
|
||||
*
|
||||
* @param code
|
||||
* code
|
||||
* @param code code
|
||||
* @return WxOAuth2AccessToken
|
||||
* @author admin
|
||||
* @since 2024/4/8 14:47
|
||||
@@ -132,8 +141,7 @@ public class WxOauthService {
|
||||
/**
|
||||
* 获取微信用户ID
|
||||
*
|
||||
* @param token
|
||||
* code
|
||||
* @param token code
|
||||
* @return WxOAuth2AccessToken
|
||||
* @author admin
|
||||
* @since 2024/4/8 14:47
|
||||
@@ -152,8 +160,7 @@ public class WxOauthService {
|
||||
/**
|
||||
* 获取微信用户ID
|
||||
*
|
||||
* @param token
|
||||
* WxOAuth2AccessToken
|
||||
* @param token WxOAuth2AccessToken
|
||||
* @return WxOAuth2UserInfo
|
||||
* @author admin
|
||||
* @since 2024/4/8 14:47
|
||||
|
||||
Reference in New Issue
Block a user