公众号支付配置重构,增加枚举,增加积分抵扣限制

This commit is contained in:
hupeng
2020-03-01 17:52:30 +08:00
parent b2754e5560
commit a2e56fe072
44 changed files with 467 additions and 247 deletions

View File

@ -67,7 +67,7 @@ import java.util.concurrent.locks.ReentrantLock;
@Slf4j
@RestController
@RequestMapping
@Api(value = "砍价商品", tags = "砍价商品", description = "砍价商品")
@Api(value = "砍价商品", tags = "营销:砍价商品", description = "砍价商品")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@SuppressWarnings("unchecked")
public class StoreBargainController extends BaseController {

View File

@ -58,7 +58,7 @@ import java.util.Map;
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "拼团", tags = "拼团", description = "拼团")
@Api(value = "拼团", tags = "营销:拼团", description = "拼团")
public class StoreCombinationController extends BaseController {
private final YxStoreCombinationService storeCombinationService;

View File

@ -49,7 +49,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@Slf4j
@RestController
@RequestMapping
@Api(value = "商品秒杀", tags = "商品秒杀", description = "商品秒杀")
@Api(value = "商品秒杀", tags = "营销:商品秒杀", description = "商品秒杀")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class StoreSeckillController extends BaseController {

View File

@ -42,7 +42,7 @@ import java.util.Map;
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "商家管理", tags = "商家管理", description = "商家管理")
@Api(value = "商家管理", tags = "城:商家管理", description = "商家管理")
public class ShoperController extends BaseController {
private final YxStoreOrderService storeOrderService;

View File

@ -0,0 +1,121 @@
package co.yixiang.modules.order.service;
import cn.hutool.core.util.StrUtil;
import co.yixiang.exception.ErrorRequestException;
import co.yixiang.modules.shop.service.YxSystemConfigService;
import co.yixiang.mp.config.WxPayConfiguration;
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
import com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult;
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
/**
* @ClassName YxPayService
* @Author hupeng <610796224@qq.com>
* @Date 2020/3/1
**/
@Service
public class YxPayService {
@Autowired
private YxSystemConfigService systemConfigService;
/**
* 微信公众号支付/小程序支付
*
* @param orderId
* @param openId 公众号/小程序openid
* @param body
* @param totalFee
* @return
* @throws WxPayException
*/
public WxPayMpOrderResult wxPay(String orderId, String openId, String body,
Integer totalFee) throws WxPayException {
String apiUrl = systemConfigService.getData("api_url");
if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
WxPayService wxPayService = WxPayConfiguration.getPayService();
WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
orderRequest.setTradeType("JSAPI");
orderRequest.setOpenid(openId);
orderRequest.setBody(body);
orderRequest.setOutTradeNo(orderId);
orderRequest.setTotalFee(totalFee);
orderRequest.setSpbillCreateIp("127.0.0.1");
orderRequest.setNotifyUrl(apiUrl + "/api/wechat/notify");
WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
return orderResult;
}
;
/**
* 微信H5支付
*
* @param orderId
* @param body
* @param totalFee
* @return
* @throws WxPayException
*/
public WxPayMwebOrderResult wxH5Pay(String orderId, String body,
Integer totalFee) throws WxPayException {
String apiUrl = systemConfigService.getData("api_url");
if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
WxPayService wxPayService = WxPayConfiguration.getPayService();
WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
orderRequest.setTradeType("MWEB");
orderRequest.setBody(body);
orderRequest.setOutTradeNo(orderId);
orderRequest.setTotalFee(totalFee);
orderRequest.setSpbillCreateIp("127.0.0.1");
orderRequest.setNotifyUrl(apiUrl + "/api/wechat/notify");
WxPayMwebOrderResult orderResult = wxPayService.createOrder(orderRequest);
return orderResult;
}
/**
* 退款
* @param orderId
* @param totalFee
* @throws WxPayException
*/
public void refundOrder(String orderId, Integer totalFee) throws WxPayException {
String apiUrl = systemConfigService.getData("api_url");
if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
WxPayService wxPayService = WxPayConfiguration.getPayService();
WxPayRefundRequest wxPayRefundRequest = new WxPayRefundRequest();
wxPayRefundRequest.setTotalFee(totalFee);//订单总金额
wxPayRefundRequest.setOutTradeNo(orderId);
wxPayRefundRequest.setOutRefundNo(orderId);
wxPayRefundRequest.setRefundFee(totalFee);//退款金额
wxPayRefundRequest.setNotifyUrl(apiUrl + "/api/notify/refund");
wxPayService.refund(wxPayRefundRequest);
}
}

View File

@ -19,6 +19,8 @@ import co.yixiang.common.service.impl.BaseServiceImpl;
import co.yixiang.common.web.vo.Paging;
import co.yixiang.domain.AlipayConfig;
import co.yixiang.domain.vo.TradeVo;
import co.yixiang.enums.BillEnum;
import co.yixiang.enums.OrderInfoEnum;
import co.yixiang.exception.ErrorRequestException;
import co.yixiang.modules.activity.service.*;
import co.yixiang.modules.manage.service.YxExpressService;
@ -34,6 +36,7 @@ import co.yixiang.modules.order.entity.YxStoreOrder;
import co.yixiang.modules.order.entity.YxStoreOrderCartInfo;
import co.yixiang.modules.order.mapper.YxStoreOrderMapper;
import co.yixiang.modules.order.mapping.OrderMap;
import co.yixiang.modules.order.service.YxPayService;
import co.yixiang.modules.order.service.YxStoreOrderCartInfoService;
import co.yixiang.modules.order.service.YxStoreOrderService;
import co.yixiang.modules.order.service.YxStoreOrderStatusService;
@ -63,6 +66,7 @@ import co.yixiang.modules.user.web.vo.YxUserQueryVo;
import co.yixiang.modules.user.web.vo.YxWechatUserQueryVo;
import co.yixiang.modules.wechat.entity.YxWechatTemplate;
import co.yixiang.modules.wechat.service.YxWechatTemplateService;
import co.yixiang.mp.config.WxPayConfiguration;
import co.yixiang.mp.service.WxMpTemplateMessageService;
import co.yixiang.service.AlipayService;
import co.yixiang.utils.OrderUtil;
@ -127,8 +131,8 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
private YxUserBillService billService;
@Autowired
private YxStoreProductReplyService storeProductReplyService;
@Autowired
private WxPayService wxPayService;
// @Autowired
//private WxPayService wxPayService;
@Autowired
private YxWechatUserService wechatUserService;
@Autowired
@ -165,6 +169,9 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Autowired
private YxPayService payService;
@ -188,14 +195,14 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
storeOrder.setId(orderQueryVo.getId());
if(param.getType() == 2){
storeOrder.setRefundStatus(0);
storeOrder.setRefundStatus(OrderInfoEnum.REFUND_STATUS_0.getValue());
yxStoreOrderMapper.updateById(storeOrder);
return;
}
//根据支付类型不同退款不同
if(orderQueryVo.getPayType().equals("yue")){
storeOrder.setRefundStatus(2);
storeOrder.setRefundStatus(OrderInfoEnum.REFUND_STATUS_2.getValue());
storeOrder.setRefundPrice(BigDecimal.valueOf(param.getPrice()));
yxStoreOrderMapper.updateById(storeOrder);
//退款到余额
@ -205,7 +212,7 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
YxUserBill userBill = new YxUserBill();
userBill.setUid(orderQueryVo.getUid());
userBill.setLinkId(orderQueryVo.getId().toString());
userBill.setPm(1);
userBill.setPm(BillEnum.PM_1.getValue());
userBill.setTitle("商品退款");
userBill.setCategory("now_money");
userBill.setType("pay_product_refund");
@ -213,43 +220,16 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
userBill.setBalance(NumberUtil.add(param.getPrice(),userQueryVo.getNowMoney()));
userBill.setMark("订单退款到余额");
userBill.setAddTime(OrderUtil.getSecondTimestampTwo());
userBill.setStatus(1);
userBill.setStatus(BillEnum.STATUS_1.getValue());
billService.save(userBill);
orderStatusService.create(orderQueryVo.getId(),"order_edit","退款给用户:"+param.getPrice() +"");
}else{
String apiUrl = RedisUtil.get("api_url");
if(StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
//读取redis配置
String appId = RedisUtil.get("wxpay_appId");
String mchId = RedisUtil.get("wxpay_mchId");
String mchKey = RedisUtil.get("wxpay_mchKey");
String keyPath = RedisUtil.get("wxpay_keyPath");
if(StrUtil.isBlank(appId) || StrUtil.isBlank(mchId) || StrUtil.isBlank(mchKey)){
throw new ErrorRequestException("请配置微信支付");
}
if(StrUtil.isBlank(keyPath)){
throw new ErrorRequestException("请配置微信支付证书");
}
WxPayRefundRequest wxPayRefundRequest = new WxPayRefundRequest();
BigDecimal bigDecimal = new BigDecimal("100");
wxPayRefundRequest.setTotalFee(bigDecimal.multiply(orderQueryVo.getPayPrice()).intValue());//订单总金额
wxPayRefundRequest.setOutTradeNo(param.getOrderId());
wxPayRefundRequest.setOutRefundNo(param.getOrderId());
wxPayRefundRequest.setRefundFee(bigDecimal.multiply(orderQueryVo.getPayPrice()).intValue());//退款金额
wxPayRefundRequest.setOpUserId(mchId); //操作人默认商户号当前
wxPayRefundRequest.setNotifyUrl(apiUrl+"/api/notify/refund");
WxPayConfig wxPayConfig = new WxPayConfig();
wxPayConfig.setAppId(appId);
wxPayConfig.setMchId(mchId);
wxPayConfig.setMchKey(mchKey);
wxPayConfig.setKeyPath(keyPath);
wxPayService.setConfig(wxPayConfig);
try {
wxPayService.refund(wxPayRefundRequest);
payService.refundOrder(param.getOrderId(),
bigDecimal.multiply(orderQueryVo.getPayPrice()).intValue());
} catch (WxPayException e) {
log.info("refund-error:{}",e.getMessage());
}
@ -1053,49 +1033,26 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
*/
@Override
public WxPayMwebOrderResult wxH5Pay(String orderId) throws WxPayException {
String apiUrl = systemConfigService.getData("api_url");
if(StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
//读取redis配置
String appId = RedisUtil.get("wxpay_appId");
String mchId = RedisUtil.get("wxpay_mchId");
String mchKey = RedisUtil.get("wxpay_mchKey");
if(StrUtil.isBlank(appId) || StrUtil.isBlank(mchId) || StrUtil.isBlank(mchKey)){
throw new ErrorRequestException("请配置微信支付与公众号appId");
}
WxPayConfig wxPayConfig = new WxPayConfig();
wxPayConfig.setAppId(appId);
wxPayConfig.setMchId(mchId);
wxPayConfig.setMchKey(mchKey);
wxPayService.setConfig(wxPayConfig);
YxStoreOrderQueryVo orderInfo = getOrderInfo(orderId,0);
if(ObjectUtil.isNull(orderInfo)) throw new ErrorRequestException("订单不存在");
if(orderInfo.getPaid() == 1) throw new ErrorRequestException("该订单已支付");
if(orderInfo.getPayPrice().doubleValue() <= 0) throw new ErrorRequestException("该支付无需支付");
WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
YxUser wechatUser = userService.getById(orderInfo.getUid());
if(ObjectUtil.isNull(wechatUser)) throw new ErrorRequestException("用户错误");
orderRequest.setTradeType("MWEB");
orderRequest.setBody("商品购买");
if(StrUtil.isNotEmpty(orderInfo.getExtendOrderId())){
orderId = orderInfo.getExtendOrderId();
}
orderRequest.setOutTradeNo(orderId);
BigDecimal bigDecimal = new BigDecimal(100);
orderRequest.setTotalFee(bigDecimal.multiply(orderInfo.getPayPrice()).intValue());//元转成分
orderRequest.setSpbillCreateIp("127.0.0.1");
orderRequest.setNotifyUrl(apiUrl+"/api/wechat/notify");
WxPayMwebOrderResult orderResult = wxPayService.createOrder(orderRequest);
return orderResult;
return payService.wxH5Pay(orderId,"H5商品购买",
bigDecimal.multiply(orderInfo.getPayPrice()).intValue());
}
/**
* 小程序支付
* @param orderId
@ -1104,99 +1061,52 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
*/
@Override
public WxPayMpOrderResult wxAppPay(String orderId) throws WxPayException {
String apiUrl = systemConfigService.getData("api_url");
if(StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
//读取redis配置
String appId = RedisUtil.get("wxapp_appId");
String mchId = RedisUtil.get("wxpay_mchId");
String mchKey = RedisUtil.get("wxpay_mchKey");
if(StrUtil.isBlank(appId) || StrUtil.isBlank(mchId) || StrUtil.isBlank(mchKey)){
throw new ErrorRequestException("请配置微信支付与小程序appId");
}
WxPayConfig wxPayConfig = new WxPayConfig();
wxPayConfig.setAppId(appId);
wxPayConfig.setMchId(mchId);
wxPayConfig.setMchKey(mchKey);
wxPayService.setConfig(wxPayConfig);
YxStoreOrderQueryVo orderInfo = getOrderInfo(orderId,0);
if(ObjectUtil.isNull(orderInfo)) throw new ErrorRequestException("订单不存在");
if(orderInfo.getPaid() == 1) throw new ErrorRequestException("该订单已支付");
if(orderInfo.getPayPrice().doubleValue() <= 0) throw new ErrorRequestException("该支付无需支付");
WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
YxWechatUser wechatUser = wechatUserService.getById(orderInfo.getUid());
if(ObjectUtil.isNull(wechatUser)) throw new ErrorRequestException("用户错误");
orderRequest.setTradeType("JSAPI");
orderRequest.setOpenid(wechatUser.getRoutineOpenid());
orderRequest.setBody("商品购买");
if(StrUtil.isNotEmpty(orderInfo.getExtendOrderId())){
orderId = orderInfo.getExtendOrderId();
}
orderRequest.setOutTradeNo(orderId);
BigDecimal bigDecimal = new BigDecimal(100);
orderRequest.setTotalFee(bigDecimal.multiply(orderInfo.getPayPrice()).intValue());//元转成分
orderRequest.setSpbillCreateIp("127.0.0.1");
orderRequest.setNotifyUrl(apiUrl+"/api/wechat/notify");
WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
return orderResult;
return payService.wxPay(orderId,wechatUser.getRoutineOpenid(),"小程序商品购买",
bigDecimal.multiply(orderInfo.getPayPrice()).intValue());
}
/**
* 微信支付
* @param orderId
*/
@Override
public WxPayMpOrderResult wxPay(String orderId) throws WxPayException {
String apiUrl = systemConfigService.getData("api_url");
if(StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");
//读取redis配置
String appId = RedisUtil.get("wxpay_appId");
String mchId = RedisUtil.get("wxpay_mchId");
String mchKey = RedisUtil.get("wxpay_mchKey");
if(StrUtil.isBlank(appId) || StrUtil.isBlank(mchId) || StrUtil.isBlank(mchKey)){
throw new ErrorRequestException("请配置微信支付与公众号appId");
}
WxPayConfig wxPayConfig = new WxPayConfig();
wxPayConfig.setAppId(appId);
wxPayConfig.setMchId(mchId);
wxPayConfig.setMchKey(mchKey);
wxPayService.setConfig(wxPayConfig);
YxStoreOrderQueryVo orderInfo = getOrderInfo(orderId,0);
if(ObjectUtil.isNull(orderInfo)) throw new ErrorRequestException("订单不存在");
if(orderInfo.getPaid() == 1) throw new ErrorRequestException("该订单已支付");
if(orderInfo.getPayPrice().doubleValue() <= 0) throw new ErrorRequestException("该支付无需支付");
WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
YxWechatUser wechatUser = wechatUserService.getById(orderInfo.getUid());
if(ObjectUtil.isNull(wechatUser)) throw new ErrorRequestException("用户错误");
orderRequest.setTradeType("JSAPI");
orderRequest.setOpenid(wechatUser.getOpenid());
orderRequest.setBody("商品购买");
if(StrUtil.isNotEmpty(orderInfo.getExtendOrderId())){
orderId = orderInfo.getExtendOrderId();
}
orderRequest.setOutTradeNo(orderId);
BigDecimal bigDecimal = new BigDecimal(100);
orderRequest.setTotalFee(bigDecimal.multiply(orderInfo.getPayPrice()).intValue());//元转成分
orderRequest.setSpbillCreateIp("127.0.0.1");
orderRequest.setNotifyUrl(apiUrl+"/api/wechat/notify");
WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
return orderResult;
return payService.wxPay(orderId,wechatUser.getOpenid(),"公众号商品购买",
bigDecimal.multiply(orderInfo.getPayPrice()).intValue());
}
/**
* 余额支付
* @param orderId 订单号
@ -1331,39 +1241,42 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
// 积分抵扣
double deductionPrice = 0; //抵扣金额
double usedIntegral = 0; //使用的积分
if(useIntegral > 0 && userInfo.getIntegral().doubleValue() > 0){
deductionPrice = NumberUtil.mul(userInfo.getIntegral(),
Double.valueOf(cacheDTO.getOther().getIntegralRatio())).doubleValue();
if(deductionPrice < payPrice){
payPrice = NumberUtil.sub(payPrice.doubleValue(),deductionPrice);
usedIntegral = userInfo.getIntegral().doubleValue();
YxUser yxUser = new YxUser();
yxUser.setIntegral(BigDecimal.ZERO);
yxUser.setUid(uid);
userService.updateById(yxUser);
}else{
deductionPrice = payPrice;
usedIntegral = NumberUtil.div(payPrice,
Double.valueOf(cacheDTO.getOther().getIntegralRatio()));
userService.decIntegral(uid,usedIntegral);
payPrice = 0d;
//积分抵扣开始
if(useIntegral > 0 && userInfo.getIntegral().doubleValue() > 0){
Double integralMax = Double.valueOf(cacheDTO.getOther().getIntegralMax());
Double integralFull = Double.valueOf(cacheDTO.getOther().getIntegralFull());
Double integralRatio = Double.valueOf(cacheDTO.getOther().getIntegralRatio());
if(totalPrice >= integralFull){
Double userIntegral = userInfo.getIntegral().doubleValue();
if(userIntegral >= integralMax) userIntegral = integralMax;
deductionPrice = NumberUtil.mul(userIntegral, integralRatio);
if(deductionPrice < payPrice){
payPrice = NumberUtil.sub(payPrice.doubleValue(),deductionPrice);
usedIntegral = userIntegral;
}else{
deductionPrice = payPrice;
usedIntegral = NumberUtil.div(payPrice,
Double.valueOf(cacheDTO.getOther().getIntegralRatio()));
payPrice = 0d;
}
userService.decIntegral(uid,usedIntegral);
//积分流水
YxUserBill userBill = new YxUserBill();
userBill.setUid(uid);
userBill.setTitle("积分抵扣");
userBill.setLinkId(key);
userBill.setCategory("integral");
userBill.setType("deduction");
userBill.setNumber(BigDecimal.valueOf(usedIntegral));
userBill.setBalance(userInfo.getIntegral());
userBill.setMark("购买商品使用");
userBill.setStatus(1);
userBill.setPm(0);
userBill.setAddTime(OrderUtil.getSecondTimestampTwo());
billService.save(userBill);
}
//积分流水
YxUserBill userBill = new YxUserBill();
userBill.setUid(uid);
userBill.setTitle("积分抵扣");
userBill.setLinkId(key);
userBill.setCategory("integral");
userBill.setType("deduction");
userBill.setNumber(BigDecimal.valueOf(usedIntegral));
userBill.setBalance(userInfo.getIntegral());
userBill.setMark("购买商品使用");
userBill.setStatus(1);
userBill.setPm(0);
userBill.setAddTime(OrderUtil.getSecondTimestampTwo());
billService.save(userBill);
}
@ -1480,13 +1393,15 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
boolean deduction = false;//拼团秒杀砍价等
int combinationId = 0;
int seckillId = 0;
int bargainId = 0;
List<YxStoreCartQueryVo> cartInfo = cacheDTO.getCartInfo();
for (YxStoreCartQueryVo cart : cartInfo) {
combinationId = cart.getCombinationId();
seckillId = cart.getSeckillId();
bargainId = cart.getBargainId();
}
//拼团等不参与抵扣
if(combinationId > 0 || seckillId > 0) deduction = true;
if(combinationId > 0 || seckillId > 0 || bargainId > 0) deduction = true;
if(deduction){
@ -1510,15 +1425,20 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
// 积分抵扣
double deductionPrice = 0;
if(useIntegral > 0 && userInfo.getIntegral().doubleValue() > 0){
deductionPrice = NumberUtil.mul(userInfo.getIntegral(),
Double.valueOf(cacheDTO.getOther().getIntegralRatio())).doubleValue();
if(deductionPrice < payPrice){
payPrice = NumberUtil.sub(payPrice.doubleValue(),deductionPrice);
}else{
deductionPrice = payPrice;
payPrice = 0d;
Double integralMax = Double.valueOf(cacheDTO.getOther().getIntegralMax());
Double integralFull = Double.valueOf(cacheDTO.getOther().getIntegralFull());
Double integralRatio = Double.valueOf(cacheDTO.getOther().getIntegralRatio());
if(computeDTO.getTotalPrice() >= integralFull){
Double userIntegral = userInfo.getIntegral().doubleValue();
if(userIntegral >= integralMax) userIntegral = integralMax;
deductionPrice = NumberUtil.mul(userIntegral, integralRatio);
if(deductionPrice < payPrice){
payPrice = NumberUtil.sub(payPrice.doubleValue(),deductionPrice);
}else{
deductionPrice = payPrice;
payPrice = 0d;
}
}
}
if(payPrice <= 0) payPrice = 0d;

View File

@ -13,6 +13,7 @@ import cn.hutool.core.util.StrUtil;
import co.yixiang.aop.log.Log;
import co.yixiang.common.api.ApiResult;
import co.yixiang.common.web.controller.BaseController;
import co.yixiang.enums.OrderInfoEnum;
import co.yixiang.exception.ErrorRequestException;
import co.yixiang.express.ExpressService;
import co.yixiang.express.dao.ExpressInfo;
@ -65,7 +66,7 @@ import java.util.concurrent.locks.ReentrantLock;
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "订单模块", tags = "订单模块", description = "订单模块")
@Api(value = "订单模块", tags = "商城:订单模块", description = "订单模块")
public class StoreOrderController extends BaseController {
private final YxStoreOrderService storeOrderService;
@ -113,6 +114,8 @@ public class StoreOrderController extends BaseController {
//积分抵扣
OtherDTO other = new OtherDTO();
other.setIntegralRatio(systemConfigService.getData("integral_ratio"));
other.setIntegralFull(systemConfigService.getData("integral_full"));
other.setIntegralMax(systemConfigService.getData("integral_max"));
//todo 拼团 砍价 秒杀
int combinationId = 0;
@ -139,6 +142,12 @@ public class StoreOrderController extends BaseController {
//拼团砍价秒杀类产品不参与抵扣
if(combinationId > 0 || secKillId > 0 || bargainId > 0) confirmOrderDTO.setDeduction(true);
//判断积分是否满足订单额度
if(priceGroup.getTotalPrice() < Double.valueOf(other.getIntegralFull())) confirmOrderDTO.setEnableIntegral(false);
confirmOrderDTO.setEnableIntegralNum(Double.valueOf(other.getIntegralMax()));
confirmOrderDTO.setAddressInfo(addressService.getUserDefaultAddress(uid));
confirmOrderDTO.setCartInfo(cartInfo);
@ -179,7 +188,7 @@ public class StoreOrderController extends BaseController {
YxStoreBargainUser storeBargainUser = storeBargainUserService.
getBargainUserInfo(param.getBargainId(),uid);
if(ObjectUtil.isNull(storeBargainUser)) return ApiResult.fail("砍价失败");
if(storeBargainUser.getStatus() == 3) return ApiResult.fail("砍价已支付");
if(storeBargainUser.getStatus().equals(OrderInfoEnum.BARGAIN_STATUS_3.getValue())) return ApiResult.fail("砍价已支付");
storeBargainUserService.setBargainUserStatus(param.getBargainId(),uid);
@ -311,7 +320,7 @@ public class StoreOrderController extends BaseController {
.getOrderInfo(param.getUni(),uid);
if(ObjectUtil.isNull(storeOrder)) return ApiResult.fail("订单不存在");
if(storeOrder.getPaid() == 1) return ApiResult.fail("该订单已支付");
if(storeOrder.getPaid().equals(OrderInfoEnum.REFUND_STATUS_1.getValue())) return ApiResult.fail("该订单已支付");
String orderId = storeOrder.getOrderId();

View File

@ -29,6 +29,10 @@ public class ConfirmOrderDTO implements Serializable {
//优惠券减
private Boolean deduction = false;
private Boolean enableIntegral = true;
private Double enableIntegralNum = 0d;
//积分抵扣
private Integer integralRatio = 0;

View File

@ -15,4 +15,11 @@ public class OtherDTO implements Serializable {
private String offlinePostage;
//积分抵扣
private String integralRatio;
//最大
private String integralMax;
//满多少
private String integralFull;
}

View File

@ -78,7 +78,7 @@ import java.util.Map;
*/
@Slf4j
@RestController
@Api(tags = "用户授权中心")
@Api(tags = "授权:用户授权中心")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AuthController {
@ -150,11 +150,7 @@ public class AuthController {
HttpServletRequest request) {
try {
String appId = RedisUtil.get("wechat_appid");
if(StrUtil.isBlank(appId)) {
return ApiResult.fail("请配置公众号");
}
WxMpService wxService = WxMpConfiguration.getWxMpService(appId);
WxMpService wxService = WxMpConfiguration.getWxMpService();
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxService.oauth2getAccessToken(code);
WxMpUser wxMpUser = wxService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
String openid = wxMpUser.getOpenId();

View File

@ -42,10 +42,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
@ -145,7 +142,7 @@ public class YxStoreCartServiceImpl extends BaseServiceImpl<YxStoreCartMapper, Y
wrapper.eq("uid",uid).eq("type","product").eq("is_pay",0)
.eq("is_del",0).orderByDesc("add_time");
if(status == 0) wrapper.eq("is_new",0);
if(StrUtil.isNotEmpty(cartIds)) wrapper.in("id",cartIds.split(","));
if(StrUtil.isNotEmpty(cartIds)) wrapper.in("id", Arrays.asList(cartIds.split(",")));
List<YxStoreCart> carts = yxStoreCartMapper.selectList(wrapper);
List<YxStoreCartQueryVo> valid = new ArrayList<>();
@ -306,7 +303,7 @@ public class YxStoreCartServiceImpl extends BaseServiceImpl<YxStoreCartMapper, Y
.eq("product_id",productId)
.eq("is_new",isNew).eq("product_attr_unique",productAttrUnique)
.eq("combination_id",combinationId).eq("bargain_id",bargainId)
.eq("seckill_id",seckillId);
.eq("seckill_id",seckillId).orderByDesc("id").last("limit 1");
YxStoreCart cart =yxStoreCartMapper.selectOne(wrapper);
YxStoreCart storeCart = new YxStoreCart();
@ -327,6 +324,7 @@ public class YxStoreCartServiceImpl extends BaseServiceImpl<YxStoreCartMapper, Y
storeCart.setId(cart.getId());
yxStoreCartMapper.updateById(storeCart);
}else{
//判断是否已经添加过
storeCart.setAddTime(OrderUtil.getSecondTimestampTwo());
yxStoreCartMapper.insert(storeCart);
}

View File

@ -39,6 +39,8 @@ public class YxSystemConfigServiceImpl extends BaseServiceImpl<YxSystemConfigMap
public String getData(String name) {
QueryWrapper<YxSystemConfig> wrapper = new QueryWrapper<>();
wrapper.eq("menu_name",name);
return yxSystemConfigMapper.selectOne(wrapper).getValue();
YxSystemConfig systemConfig = yxSystemConfigMapper.selectOne(wrapper);
if(systemConfig == null) return "";
return systemConfig.getValue();
}
}

View File

@ -34,7 +34,7 @@ import org.springframework.web.bind.annotation.*;
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/article")
@Api(value = "文章模块", tags = "文章模块", description = "文章模块")
@Api(value = "文章模块", tags = "商城:文章模块", description = "文章模块")
public class ArticleController extends BaseController {
private final ArticleService articleService;

View File

@ -38,7 +38,7 @@ import java.util.List;
*/
@Slf4j
@RestController
@Api(value = "优惠券", tags = "优惠券", description = "优惠券")
@Api(value = "优惠券", tags = "营销:优惠券", description = "优惠券")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CouponController extends BaseController {

View File

@ -39,7 +39,7 @@ import java.util.Map;
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "首页模块", tags = "首页模块", description = "首页模块")
@Api(value = "首页模块", tags = "商城:首页模块", description = "首页模块")
public class IndexController {
private final YxSystemGroupDataService systemGroupDataService;

View File

@ -39,7 +39,7 @@ import java.util.Map;
*/
@Slf4j
@RestController
@Api(value = "购物车", tags = "购物车", description = "购物车")
@Api(value = "购物车", tags = "商城:购物车", description = "购物车")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class StoreCartController extends BaseController {

View File

@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.RestController;
*/
@Slf4j
@RestController
@Api(value = "商品分类", tags = "商品分类", description = "商品分类")
@Api(value = "商品分类", tags = "城:商品分类", description = "商品分类")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class StoreCategoryController extends BaseController {

View File

@ -54,7 +54,7 @@ import java.util.Map;
*/
@Slf4j
@RestController
@Api(value = "产品模块", tags = "产品模块", description = "产品模块")
@Api(value = "产品模块", tags = "商城:产品模块", description = "产品模块")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class StoreProductController extends BaseController {

View File

@ -115,7 +115,9 @@ public class YxUserServiceImpl extends BaseServiceImpl<YxUserMapper, YxUser> imp
*/
@Override
public boolean backOrderBrokerage(YxStoreOrderQueryVo order) {
//todo 拼团等
//如果分销没开启直接返回
String open = systemConfigService.getData("store_brokerage_open");
if(StrUtil.isEmpty(open) || open.equals("2")) return false;
//支付金额减掉邮费
double payPrice = 0d;
payPrice = NumberUtil.sub(order.getPayPrice(),order.getPayPostage()).doubleValue();
@ -366,6 +368,9 @@ public class YxUserServiceImpl extends BaseServiceImpl<YxUserMapper, YxUser> imp
*/
@Override
public boolean setSpread(int spread, int uid) {
//如果分销没开启直接返回
String open = systemConfigService.getData("store_brokerage_open");
if(StrUtil.isEmpty(open) || open.equals("2")) return false;
//当前用户信息
YxUserQueryVo userInfo = getYxUserById(uid);
if(ObjectUtil.isNull(userInfo)) return true;

View File

@ -44,7 +44,7 @@ import java.util.Map;
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "用户地址", tags = "用户地址", description = "用户地址")
@Api(value = "用户地址", tags = "用户:用户地址", description = "用户地址")
public class UserAddressController extends BaseController {
private final YxUserAddressService userAddressService;

View File

@ -54,7 +54,7 @@ import java.util.Map;
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "用户分销", tags = "用户分销", description = "用户分销")
@Api(value = "用户分销", tags = "用户:用户分销", description = "用户分销")
public class UserBillController extends BaseController {
private final YxUserBillService userBillService;

View File

@ -51,7 +51,7 @@ import java.util.concurrent.locks.ReentrantLock;
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "用户中心", tags = "用户中心", description = "用户中心")
@Api(value = "用户中心", tags = "用户:用户中心", description = "用户中心")
public class UserController extends BaseController {
private final YxUserService yxUserService;

View File

@ -44,7 +44,7 @@ import java.util.Map;
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "用户提现", tags = "用户提现", description = "用户提现")
@Api(value = "用户提现", tags = "用户:用户提现", description = "用户提现")
public class UserExtractController extends BaseController {
private final YxUserExtractService userExtractService;

View File

@ -35,7 +35,7 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "用户等级", tags = "用户等级", description = "用户等级")
@Api(value = "用户等级", tags = "用户:用户等级", description = "用户等级")
public class UserLevelController extends BaseController {
private final YxUserLevelService userLevelService;

View File

@ -32,21 +32,21 @@ import java.util.Map;
* </p>
*
* @author hupeng
* @since 2019-12-08
* @since 2019-03-01
*/
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "用户充值", tags = "用户充值", description = "用户充值")
@Api(value = "用户充值", tags = "用户:用户充值", description = "用户充值")
public class UserRechargeController extends BaseController {
private final YxUserRechargeService userRechargeService;
/**
* 公众号充值
* 公众号充值/H5充值
*/
@PostMapping("/recharge/wechat")
@ApiOperation(value = "公众号充值",notes = "公众号充值",response = ApiResult.class)
@ApiOperation(value = "公众号充值/H5充值",notes = "公众号充值/H5充值",response = ApiResult.class)
public ApiResult<Map<String,Object>> add(@Valid @RequestBody RechargeParam param){
int uid = SecurityUtils.getUserId().intValue();

View File

@ -50,7 +50,7 @@ import java.util.Map;
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "微信模块", tags = "微信模块", description = "微信模块")
@Api(value = "微信模块", tags = "微信:微信模块", description = "微信模块")
public class WechatController extends BaseController {
private final WxPayService wxPayService;
@ -81,9 +81,7 @@ public class WechatController extends BaseController {
@GetMapping("/wechat/config")
@ApiOperation(value = "jssdk配置",notes = "jssdk配置")
public ApiResult<Object> jsConfig(@RequestParam(value = "url") String url) throws WxErrorException {
String appId = RedisUtil.get("wechat_appid");
if(StrUtil.isBlank(appId)) return ApiResult.fail("请配置公众号");
WxMpService wxService = WxMpConfiguration.getWxMpService(appId);
WxMpService wxService = WxMpConfiguration.getWxMpService();
return ApiResult.ok(wxService.createJsapiSignature(url));
}
@ -157,12 +155,9 @@ public class WechatController extends BaseController {
@RequestParam(name = "nonce", required = false) String nonce,
@RequestParam(name = "echostr", required = false) String echostr){
String appId = RedisUtil.get("wechat_appid");
if(StrUtil.isBlank(appId)) return "请配置公众号";
final WxMpService wxService = WxMpConfiguration.getWxMpService(appId);
final WxMpService wxService = WxMpConfiguration.getWxMpService();
if (wxService == null) {
throw new IllegalArgumentException(String.format("未找到对应appid=[%d]的配置,请核实!", appId));
throw new IllegalArgumentException("未找到对应配置的服务,请核实!");
}
if (wxService.checkSignature(timestamp, nonce, signature)) {
@ -186,12 +181,7 @@ public class WechatController extends BaseController {
HttpServletRequest request,
HttpServletResponse response) throws IOException {
String appId = RedisUtil.get("wechat_appid");
if(StrUtil.isBlank(appId)) {
log.error("请配置公众号!");
return;
}
WxMpService wxService = WxMpConfiguration.getWxMpService(appId);
WxMpService wxService = WxMpConfiguration.getWxMpService();
if (!wxService.checkSignature(timestamp, nonce, signature)) {
throw new IllegalArgumentException("非法请求,可能属于伪造的请求!");
@ -201,14 +191,14 @@ public class WechatController extends BaseController {
if (encType == null) {
// 明文传输的消息
WxMpXmlMessage inMessage = WxMpXmlMessage.fromXml(requestBody);
WxMpXmlOutMessage outMessage = this.route(inMessage,appId);
WxMpXmlOutMessage outMessage = this.route(inMessage);
if(outMessage == null) return;
out = outMessage.toXml();;
} else if ("aes".equalsIgnoreCase(encType)) {
// aes加密的消息
WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(requestBody, wxService.getWxMpConfigStorage(),
timestamp, nonce, msgSignature);
WxMpXmlOutMessage outMessage = this.route(inMessage,appId);
WxMpXmlOutMessage outMessage = this.route(inMessage);
if(outMessage == null) return;
out = outMessage.toEncryptedXml(wxService.getWxMpConfigStorage());
@ -220,9 +210,9 @@ public class WechatController extends BaseController {
writer.close();
}
private WxMpXmlOutMessage route(WxMpXmlMessage message,String appId) {
private WxMpXmlOutMessage route(WxMpXmlMessage message) {
try {
return WxMpConfiguration.getWxMpMessageRouter(appId).route(message);
return WxMpConfiguration.getWxMpMessageRouter().route(message);
} catch (Exception e) {
log.error("路由消息时出现异常!", e);
}

View File

@ -54,7 +54,7 @@ import java.util.Map;
*/
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "微信其他", tags = "微信其他", description = "微信其他")
@Api(value = "微信其他", tags = "微信:微信其他", description = "微信其他")
public class WxMaUserController {
private final WxMaService wxMaService;

View File

@ -71,7 +71,7 @@ swagger:
enabled: true
title: yshop商城移动端API
serverUrl: http://localhost:8009
version: 1.8
version: 2.0
# 文件存储路径
file:

View File

@ -81,7 +81,7 @@ swagger:
enabled: true
title: yshop商城移动端API
serverUrl: http://localhost:8009
version: 1.9
version: 2.0
# 文件存储路径
file:

View File

@ -24,4 +24,16 @@ public interface ShopConstants {
*/
String REDIS_ORDER_OUTTIME_UNCONFIRM = "order:unconfirm:";
/**
* 微信支付service
*/
String YSHOP_WEIXIN_PAY_SERVICE = "yshop_weixin_pay_service";
/**
* 微信公众号service
*/
String YSHOP_WEIXIN_MP_SERVICE = "yshop_weixin_mp_service";
}

View File

@ -0,0 +1,23 @@
package co.yixiang.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 应用来源相关枚举
*/
@Getter
@AllArgsConstructor
public enum AppFromEnum {
WEIXIN_H5("weixinh5","weixinh5"),
H5("h5","H5"),
WECHAT("wechat","公众号"),
ROUNTINE("routine","小程序");
private String value;
private String desc;
}

View File

@ -0,0 +1,25 @@
package co.yixiang.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 账单相关枚举
*/
@Getter
@AllArgsConstructor
public enum BillEnum {
PM_0(0,"支出"),
PM_1(1,"获得"),
STATUS_0(0,"默认"),
STATUS_1(1,"有效"),
STATUS_2(2,"无效");
private Integer value;
private String desc;
}

View File

@ -0,0 +1,35 @@
package co.yixiang.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import javax.persistence.criteria.CriteriaBuilder;
/**
* 订单相关枚举
*/
@Getter
@AllArgsConstructor
public enum OrderInfoEnum {
STATUS_0(0,"默认"),
STATUS_1(1,"待收货"),
STATUS_2(2,"已收货"),
STATUS_3(3,"已完成"),
PAY_STATUS_0(0,"未支付"),
PAY_STATUS_1(1,"已支付"),
REFUND_STATUS_0(0,"未支付"),
REFUND_STATUS_1(1,"退款中"),
REFUND_STATUS_2(2,"已退款"),
BARGAIN_STATUS_1(1,"参与中"),
BARGAIN_STATUS_2(2,"参与失败"),
BARGAIN_STATUS_3(3,"参与成功");
private Integer value;
private String desc;
}

View File

@ -0,0 +1,21 @@
package co.yixiang.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 支付相关枚举
*/
@Getter
@AllArgsConstructor
public enum PayTypeEnum {
WEIXIN("weixin","微信支付"),
YUE("yue","余额支付");
private String value;
private String desc;
}

View File

@ -49,7 +49,6 @@ public class GlobalExceptionHandler {
*/
@ExceptionHandler(value = BadRequestException.class)
public ResponseEntity<ApiError> badRequestException(BadRequestException e) {
System.out.println("88888");
// 打印堆栈信息
log.error(ThrowableUtil.getStackTrace(e));
return buildResponseEntity(ApiError.error(e.getStatus(),e.getMessage()));

View File

@ -24,7 +24,7 @@
</dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>wx-java-pay-spring-boot-starter</artifactId>
<artifactId>weixin-java-pay</artifactId>
<version>${weixin-java.version}</version>
</dependency>
<dependency>

View File

@ -1,5 +1,6 @@
package co.yixiang.mp.config;
import co.yixiang.constant.ShopConstants;
import co.yixiang.mp.handler.*;
import com.google.common.collect.Maps;
import me.chanjar.weixin.common.api.WxConsts;
@ -61,9 +62,9 @@ public class WxMpConfiguration {
* 获取WxMpService
* @return
*/
public static WxMpService getWxMpService(String appId) {
public static WxMpService getWxMpService() {
WxMpService wxMpService = mpServices.get(appId);
WxMpService wxMpService = mpServices.get(ShopConstants.YSHOP_WEIXIN_MP_SERVICE);
if(wxMpService == null) {
WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
configStorage.setAppId(redisHandler.getVal("wechat_appid"));
@ -72,27 +73,25 @@ public class WxMpConfiguration {
configStorage.setAesKey(redisHandler.getVal("wechat_encodingaeskey"));
wxMpService = new WxMpServiceImpl();
wxMpService.setWxMpConfigStorage(configStorage);
mpServices.put(appId, wxMpService);
routers.put(appId, newRouter(wxMpService));
mpServices.put(ShopConstants.YSHOP_WEIXIN_MP_SERVICE, wxMpService);
routers.put(ShopConstants.YSHOP_WEIXIN_MP_SERVICE, newRouter(wxMpService));
}
return wxMpService;
}
/**
* 移除WxMpService
* @param appId
*/
public static void removeWxMpService(String appId){
mpServices.remove(appId);
routers.remove(appId);
public static void removeWxMpService(){
mpServices.remove(ShopConstants.YSHOP_WEIXIN_MP_SERVICE);
routers.remove(ShopConstants.YSHOP_WEIXIN_MP_SERVICE);
}
/**
* 获取WxMpMessageRouter
* @param appId
*/
public static WxMpMessageRouter getWxMpMessageRouter(String appId) {
WxMpMessageRouter wxMpMessageRouter = routers.get(appId);
public static WxMpMessageRouter getWxMpMessageRouter() {
WxMpMessageRouter wxMpMessageRouter = routers.get(ShopConstants.YSHOP_WEIXIN_MP_SERVICE);
return wxMpMessageRouter;
}

View File

@ -0,0 +1,62 @@
package co.yixiang.mp.config;
import co.yixiang.constant.ShopConstants;
import co.yixiang.mp.handler.RedisHandler;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import java.util.Map;
/**
* 支付配置
* @author hupeng
* @date 2020/03/01
*/
@Slf4j
@Configuration
public class WxPayConfiguration {
private static Map<String, WxPayService> payServices = Maps.newHashMap();
private static RedisHandler redisHandler;
@Autowired
public WxPayConfiguration(RedisHandler redisHandler) {
this.redisHandler = redisHandler;
}
/**
* 获取WxPayService
* @return
*/
public static WxPayService getPayService() {
WxPayService wxPayService = payServices.get(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE);
if(wxPayService == null) {
WxPayConfig payConfig = new WxPayConfig();
payConfig.setAppId(redisHandler.getVal("wxpay_appId"));
payConfig.setMchId(redisHandler.getVal("wxpay_mchId"));
payConfig.setMchKey(redisHandler.getVal("wxpay_mchKey"));
payConfig.setKeyPath(redisHandler.getVal("wxpay_keyPath"));
// 可以指定是否使用沙箱环境
payConfig.setUseSandboxEnv(false);
wxPayService = new WxPayServiceImpl();
wxPayService.setConfig(payConfig);
payServices.put(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE, wxPayService);
}
return wxPayService;
}
/**
* 移除WxPayService
*/
public static void removeWxPayService(){
payServices.remove(ShopConstants.YSHOP_WEIXIN_PAY_SERVICE);
}
}

View File

@ -55,11 +55,7 @@ public class WechatMenuController {
Boolean isExist = yxCacheService.isExist("wechat_menus");
WxMenu menu = JSONObject.parseObject(jsonStr,WxMenu.class);
String appId = RedisUtil.get("wechat_appid");
if(StrUtil.isBlank(appId)) {
throw new BadRequestException("请配置公众号");
}
WxMpService wxService = WxMpConfiguration.getWxMpService(appId);
WxMpService wxService = WxMpConfiguration.getWxMpService();
if(isExist){
yxCache.setKey("wechat_menus");
yxCache.setResult(jsonButton);

View File

@ -25,11 +25,7 @@ public class WxMpTemplateMessageServiceImpl implements WxMpTemplateMessageServic
.build();
map.forEach( (k,v)-> { templateMessage.addData(new WxMpTemplateData(k, v, "#000000"));} );
String msgId = null;
String appId = RedisUtil.get("wechat_appid");
if(StrUtil.isBlank(appId)) {
return "请配置公众号";
}
WxMpService wxService = WxMpConfiguration.getWxMpService(appId);
WxMpService wxService = WxMpConfiguration.getWxMpService();
try {
msgId = wxService.getTemplateMsgService().sendTemplateMsg(templateMessage);
} catch (WxErrorException e) {

View File

@ -106,11 +106,7 @@ public class YxArticleServiceImpl implements YxArticleService {
@Override
public void uploadNews(YxArticleDTO wxNewsArticleItem) throws Exception {
String appId = RedisUtil.get("wechat_appid");
if(StrUtil.isBlank(appId)) {
throw new BadRequestException("请配置公众号");
}
WxMpService wxMpService = WxMpConfiguration.getWxMpService(appId);
WxMpService wxMpService = WxMpConfiguration.getWxMpService();
WxMpMaterialNews wxMpMaterialNews = new WxMpMaterialNews();

View File

@ -6,6 +6,7 @@ import co.yixiang.modules.shop.domain.YxSystemConfig;
import co.yixiang.modules.shop.service.YxSystemConfigService;
import co.yixiang.modules.shop.service.dto.YxSystemConfigQueryCriteria;
import co.yixiang.mp.config.WxMpConfiguration;
import co.yixiang.mp.config.WxPayConfiguration;
import co.yixiang.utils.RedisUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@ -55,7 +56,10 @@ public class SystemConfigController {
yxSystemConfigModel.setValue(value.toString());
//重新配置微信相关
if(key.equals("wechat_appid")){
WxMpConfiguration.removeWxMpService(value.toString());
WxMpConfiguration.removeWxMpService();
}
if(key.equals("wxpay_appId")){
WxPayConfiguration.removeWxPayService();
}
RedisUtil.set(key,value.toString(),0);
if(ObjectUtil.isNull(yxSystemConfig)){

View File

@ -76,7 +76,7 @@ swagger:
enabled: true
title: yshop商城管理后台API
serverUrl: http://localhost:8000
version: 1.8
version: 2.0
# 文件存储路径
file:

View File

@ -81,7 +81,7 @@ swagger:
enabled: true
title: yshop商城管理后台API
serverUrl: http://localhost:8000
version: 1.9
version: 2.0
# 文件存储路径
file: