yshop1.6.3新增微信退款及其模板消息,后台新增支付证书配置,修复手机端管理端拒绝退款bug
This commit is contained in:
@ -141,8 +141,6 @@ public class ShoperController extends BaseController {
|
||||
@PostMapping("/admin/order/refund")
|
||||
@ApiOperation(value = "订单退款",notes = "订单退款")
|
||||
public ApiResult<Object> orderRefund(@Validated @RequestBody OrderRefundParam param){
|
||||
//if(ObjectUtil.isNotNull(param)) return ApiResult.fail("演示环境禁止操作");
|
||||
int uid = SecurityUtils.getUserId().intValue();
|
||||
|
||||
storeOrderService.orderRefund(param);
|
||||
|
||||
@ -157,7 +155,6 @@ public class ShoperController extends BaseController {
|
||||
@ApiOperation(value = "chart统计",notes = "chart统计")
|
||||
public ApiResult<Object> chartCount(@RequestParam(value = "cate",defaultValue = "1") int cate,
|
||||
@RequestParam(value = "type",defaultValue = "1") int type){
|
||||
int uid = SecurityUtils.getUserId().intValue();
|
||||
|
||||
return ApiResult.ok(storeOrderService.chartCount(cate,type));
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @ClassName OrderPriceParam
|
||||
* @ClassName OrderRefundParam
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2019/11/26
|
||||
**/
|
||||
|
@ -32,9 +32,6 @@ import java.util.Map;
|
||||
* @author hupeng
|
||||
* @since 2019-10-27
|
||||
*/
|
||||
//@WebService(serviceName = "YxStoreOrderService",
|
||||
// targetNamespace = "http://service.order.modules.yixiang.co"
|
||||
//)
|
||||
public interface YxStoreOrderService extends BaseService<YxStoreOrder> {
|
||||
|
||||
Map<String,Object> chartCount(int cate,int type);
|
||||
|
@ -57,6 +57,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
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.config.WxPayConfig;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
@ -168,8 +169,6 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
|
||||
private AlipayService alipayService;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 订单退款
|
||||
* @param param
|
||||
@ -188,30 +187,92 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<YxStoreOrderMapper,
|
||||
YxStoreOrder storeOrder = new YxStoreOrder();
|
||||
//修改状态
|
||||
storeOrder.setId(orderQueryVo.getId());
|
||||
storeOrder.setRefundStatus(2);
|
||||
storeOrder.setRefundPrice(BigDecimal.valueOf(param.getPrice()));
|
||||
yxStoreOrderMapper.updateById(storeOrder);
|
||||
|
||||
//退款到余额
|
||||
userService.incMoney(orderQueryVo.getUid(),param.getPrice());
|
||||
if(param.getType() == 2){
|
||||
storeOrder.setRefundStatus(0);
|
||||
yxStoreOrderMapper.updateById(storeOrder);
|
||||
return;
|
||||
}
|
||||
|
||||
//增加流水
|
||||
YxUserBill userBill = new YxUserBill();
|
||||
userBill.setUid(orderQueryVo.getUid());
|
||||
userBill.setLinkId(orderQueryVo.getId().toString());
|
||||
userBill.setPm(1);
|
||||
userBill.setTitle("商品退款");
|
||||
userBill.setCategory("now_money");
|
||||
userBill.setType("pay_product_refund");
|
||||
userBill.setNumber(BigDecimal.valueOf(param.getPrice()));
|
||||
userBill.setBalance(NumberUtil.add(param.getPrice(),userQueryVo.getNowMoney()));
|
||||
userBill.setMark("订单退款到余额");
|
||||
userBill.setAddTime(OrderUtil.getSecondTimestampTwo());
|
||||
userBill.setStatus(1);
|
||||
billService.save(userBill);
|
||||
//根据支付类型不同退款不同
|
||||
if(orderQueryVo.getPayType().equals("yue")){
|
||||
storeOrder.setRefundStatus(2);
|
||||
storeOrder.setRefundPrice(BigDecimal.valueOf(param.getPrice()));
|
||||
yxStoreOrderMapper.updateById(storeOrder);
|
||||
//退款到余额
|
||||
userService.incMoney(orderQueryVo.getUid(),param.getPrice());
|
||||
|
||||
//增加流水
|
||||
YxUserBill userBill = new YxUserBill();
|
||||
userBill.setUid(orderQueryVo.getUid());
|
||||
userBill.setLinkId(orderQueryVo.getId().toString());
|
||||
userBill.setPm(1);
|
||||
userBill.setTitle("商品退款");
|
||||
userBill.setCategory("now_money");
|
||||
userBill.setType("pay_product_refund");
|
||||
userBill.setNumber(BigDecimal.valueOf(param.getPrice()));
|
||||
userBill.setBalance(NumberUtil.add(param.getPrice(),userQueryVo.getNowMoney()));
|
||||
userBill.setMark("订单退款到余额");
|
||||
userBill.setAddTime(OrderUtil.getSecondTimestampTwo());
|
||||
userBill.setStatus(1);
|
||||
billService.save(userBill);
|
||||
|
||||
|
||||
orderStatusService.create(orderQueryVo.getId(),"order_edit","退款给用户:"+param.getPrice() +"元");
|
||||
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);
|
||||
} catch (WxPayException e) {
|
||||
log.info("refund-error:{}",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
//模板消息通知
|
||||
String siteUrl = RedisUtil.get("site_url");
|
||||
YxWechatUserQueryVo wechatUser = wechatUserService.getYxWechatUserById(orderQueryVo.getUid());
|
||||
if(ObjectUtil.isNotNull(wechatUser)){
|
||||
YxWechatTemplate WechatTemplate = yxWechatTemplateService.getOne(
|
||||
new QueryWrapper<YxWechatTemplate>().eq("tempkey","OPENTM410119152"));
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("first","您在yshop的订单退款申请被通过,钱款将很快还至您的支付账户。");
|
||||
map.put("keyword1",orderQueryVo.getOrderId());//订单号
|
||||
map.put("keyword2",orderQueryVo.getPayPrice().toString());
|
||||
map.put("keyword3",OrderUtil.stampToDate(orderQueryVo.getAddTime().toString()));
|
||||
map.put("remark","yshop电商系统为你服务!");
|
||||
templateMessageService.sendWxMpTemplateMessage( wechatUser.getOpenid()
|
||||
,WechatTemplate.getTempid(),
|
||||
siteUrl+"/order/detail/"+orderQueryVo.getOrderId(),map);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -113,6 +113,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.antMatchers("/wechat/auth").anonymous()
|
||||
.antMatchers("/share").anonymous()
|
||||
.antMatchers("/wechat/notify").anonymous()
|
||||
.antMatchers("/notify/refund").anonymous()
|
||||
.antMatchers("/wechat/serve").anonymous()
|
||||
.antMatchers("/logistics").anonymous()
|
||||
.antMatchers("/seckill/index").anonymous()
|
||||
|
@ -34,7 +34,9 @@ public class JobTimer {
|
||||
while (true) {
|
||||
try {
|
||||
Map<String,Object> job = blockingQueue.take();
|
||||
executorService.execute(new ExecutorTask(job));
|
||||
if(job != null){
|
||||
executorService.execute(new ExecutorTask(job));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
|
@ -6,6 +6,8 @@ import cn.hutool.core.util.StrUtil;
|
||||
import co.yixiang.common.api.ApiCode;
|
||||
import co.yixiang.common.api.ApiResult;
|
||||
import co.yixiang.common.web.controller.BaseController;
|
||||
import co.yixiang.modules.manage.web.param.OrderRefundParam;
|
||||
import co.yixiang.modules.order.entity.YxStoreOrder;
|
||||
import co.yixiang.modules.order.service.YxStoreOrderService;
|
||||
import co.yixiang.modules.order.web.vo.YxStoreOrderQueryVo;
|
||||
import co.yixiang.modules.security.security.JwtUser;
|
||||
@ -21,6 +23,7 @@ import co.yixiang.utils.EncryptUtils;
|
||||
import co.yixiang.utils.OrderUtil;
|
||||
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
|
||||
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
|
||||
import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.vdurmont.emoji.EmojiParser;
|
||||
@ -245,6 +248,36 @@ public class WechatController extends BaseController {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信退款回调
|
||||
* @param xmlData
|
||||
* @return
|
||||
* @throws WxPayException
|
||||
*/
|
||||
@ApiOperation(value = "退款回调通知处理",notes = "退款回调通知处理")
|
||||
@PostMapping("/notify/refund")
|
||||
public String parseRefundNotifyResult(@RequestBody String xmlData) {
|
||||
try {
|
||||
WxPayRefundNotifyResult result = wxPayService.parseRefundNotifyResult(xmlData);
|
||||
String orderId = result.getReqInfo().getOutTradeNo();
|
||||
Integer refundFee = result.getReqInfo().getRefundFee()/100;
|
||||
YxStoreOrderQueryVo orderInfo = orderService.getOrderInfo(orderId,0);
|
||||
if(orderInfo.getRefundStatus() == 2){
|
||||
return WxPayNotifyResponse.success("处理成功!");
|
||||
}
|
||||
YxStoreOrder storeOrder = new YxStoreOrder();
|
||||
//修改状态
|
||||
storeOrder.setId(orderInfo.getId());
|
||||
storeOrder.setRefundStatus(2);
|
||||
storeOrder.setRefundPrice(BigDecimal.valueOf(refundFee));
|
||||
orderService.updateById(storeOrder);
|
||||
return WxPayNotifyResponse.success("处理成功!");
|
||||
} catch (WxPayException e) {
|
||||
log.error(e.getMessage());
|
||||
return WxPayNotifyResponse.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 微信验证消息
|
||||
|
@ -36,7 +36,6 @@ spring:
|
||||
web-stat-filter:
|
||||
url-pattern: /*
|
||||
exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
|
||||
connection-init-sqls: set names utf8mb4
|
||||
|
||||
#配置 Jpa
|
||||
jpa:
|
||||
|
Reference in New Issue
Block a user