修改订单支付及退款消息通知
This commit is contained in:
@@ -244,7 +244,7 @@ dubbo:
|
|||||||
bxg:
|
bxg:
|
||||||
shop:
|
shop:
|
||||||
# API_URL: http://192.168.10.113:48080/bxgApp
|
# API_URL: http://192.168.10.113:48080/bxgApp
|
||||||
API_URL: https://912e-27-19-79-51.jp.ngrok.io
|
API_URL: https://d305-27-19-79-51.jp.ngrok.io
|
||||||
SITE_URL: http://192.168.10.113:48080/bxgApp
|
SITE_URL: http://192.168.10.113:48080/bxgApp
|
||||||
UNI_SITE_URL: http://192.168.10.113:48080/bxgApp
|
UNI_SITE_URL: http://192.168.10.113:48080/bxgApp
|
||||||
ADMIN_API_URL: http://192.168.10.113:48080/bxg
|
ADMIN_API_URL: http://192.168.10.113:48080/bxg
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import co.yixiang.app.modules.services.OrderSupplyService;
|
|||||||
import cn.iocoder.yudao.framework.security.core.annotations.AuthCheck;
|
import cn.iocoder.yudao.framework.security.core.annotations.AuthCheck;
|
||||||
import co.yixiang.enums.*;
|
import co.yixiang.enums.*;
|
||||||
import co.yixiang.logging.aop.log.AppLog;
|
import co.yixiang.logging.aop.log.AppLog;
|
||||||
import co.yixiang.modules.inform.SendMsgService;
|
|
||||||
import co.yixiang.modules.mp.domain.YxWechatTemplate;
|
import co.yixiang.modules.mp.domain.YxWechatTemplate;
|
||||||
import co.yixiang.modules.mp.service.WeixinPayService;
|
import co.yixiang.modules.mp.service.WeixinPayService;
|
||||||
import co.yixiang.modules.mp.service.YxWechatTemplateService;
|
import co.yixiang.modules.mp.service.YxWechatTemplateService;
|
||||||
@@ -84,7 +83,6 @@ public class AppStoreOrderController {
|
|||||||
private final YxStoreOrderCartInfoService storeOrderCartInfoService;
|
private final YxStoreOrderCartInfoService storeOrderCartInfoService;
|
||||||
private final WeixinPayService weixinPayService;
|
private final WeixinPayService weixinPayService;
|
||||||
|
|
||||||
private final SendMsgService sendMsgService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单确认
|
* 订单确认
|
||||||
|
|||||||
@@ -1,130 +0,0 @@
|
|||||||
package co.yixiang.modules.inform;
|
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import cn.hutool.json.JSONUtil;
|
|
||||||
import cn.iocoder.yudao.framework.common.exception.YshopException;
|
|
||||||
import co.yixiang.constant.SystemConfigConstants;
|
|
||||||
import co.yixiang.modules.inform.domin.*;
|
|
||||||
import co.yixiang.modules.order.service.YxStoreOrderService;
|
|
||||||
import co.yixiang.modules.order.service.dto.YxStoreOrderDto;
|
|
||||||
import co.yixiang.modules.shop.service.YxSystemConfigService;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import org.apache.http.HttpStatus;
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
|
||||||
import org.apache.http.entity.StringEntity;
|
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClients;
|
|
||||||
import org.apache.http.util.EntityUtils;
|
|
||||||
import org.jsoup.nodes.Element;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
|
||||||
import org.jsoup.nodes.Document;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class SendMsgService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private YxStoreOrderService yxStoreOrderService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private YxSystemConfigService systemConfigService;
|
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
public String inform(long orderId, int type) {
|
|
||||||
CloseableHttpClient httpClient = HttpClients.createDefault();//实例化对象
|
|
||||||
// String webhook_url="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a2f0f8c9-e406-4f6b-86e4-d6ac9e4df88e";
|
|
||||||
String webhook_url = systemConfigService.getData(SystemConfigConstants.ROBOT_URL);
|
|
||||||
if (StrUtil.isBlank(webhook_url)) {
|
|
||||||
throw new YshopException("未配置企业微信群机器人");
|
|
||||||
}
|
|
||||||
HttpPost httpPost = new HttpPost(webhook_url);
|
|
||||||
httpPost.addHeader("Content-Type", "application/json; charset=utf-8");
|
|
||||||
TemplateCard templateCard = this.creatTemplatecard(orderId, type);
|
|
||||||
Map<String, Object> param = new HashMap<>();
|
|
||||||
param.put("msgtype", "template_card");
|
|
||||||
param.put("template_card", JSONObject.parseObject(JSONUtil.toJsonStr(templateCard)));
|
|
||||||
String jsonParam = JSONObject.toJSONString(param);
|
|
||||||
|
|
||||||
StringEntity stringEntity = new StringEntity(jsonParam, "utf-8");
|
|
||||||
httpPost.setEntity(stringEntity);
|
|
||||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
||||||
// 发送成功接收返回值
|
|
||||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
|
||||||
String result = EntityUtils.toString(response.getEntity(), "utf-8");
|
|
||||||
System.out.println("发送微信机器人消息成功 " + result);
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
System.out.println("发送微信机器人消息失败");
|
|
||||||
}
|
|
||||||
// 关闭
|
|
||||||
httpClient.close();
|
|
||||||
response.close();
|
|
||||||
return "发送微信机器人消息失败";
|
|
||||||
}
|
|
||||||
|
|
||||||
//创建订单消息
|
|
||||||
public TemplateCard creatTemplatecard(long orderId, int type) {
|
|
||||||
YxStoreOrderDto yxStoreOrderDto = yxStoreOrderService.getOrderDetailByOrderId(orderId);
|
|
||||||
String mainTitle;
|
|
||||||
ArrayList<HorizontalContent> arrayList = new ArrayList<>();
|
|
||||||
arrayList.add(new HorizontalContent().setKeyname("会员名称").setValue(yxStoreOrderDto.getRealName()));
|
|
||||||
arrayList.add(new HorizontalContent().setKeyname("会员手机号").setValue(yxStoreOrderDto.getUserPhone()));
|
|
||||||
if (type == 0) {//支付时候
|
|
||||||
mainTitle = "有新的在线订单来啦";
|
|
||||||
arrayList.add(new HorizontalContent().setKeyname("下单地址").setValue(yxStoreOrderDto.getUserAddress()));
|
|
||||||
arrayList.add(new HorizontalContent().setKeyname("下单时间").setValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(yxStoreOrderDto.getCreateTime())));
|
|
||||||
} else {
|
|
||||||
mainTitle = "有新的退款申请";
|
|
||||||
//获取Document模型
|
|
||||||
Document docDesc = Jsoup.parse(yxStoreOrderDto.getStatusName());
|
|
||||||
//获取span节点
|
|
||||||
ArrayList<Element> list = docDesc.getElementsByTag("span");
|
|
||||||
//获取文本内容,并且截取只需要标题后面的
|
|
||||||
arrayList.add(new HorizontalContent().setKeyname("退款原因").setValue(list.get(0).text().substring(5)));
|
|
||||||
arrayList.add(new HorizontalContent().setKeyname("备注说明").setValue(list.get(1).text().substring(5).length() == 0 ? list.get(1).text().substring(5) : "本次退款无备注"));
|
|
||||||
arrayList.add(new HorizontalContent().setKeyname("申请时间").setValue(list.get(2).text().substring(5)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// templateCard.setHorizontal_content_list(arrayList);
|
|
||||||
// templateCard.setCard_type("text_notice");
|
|
||||||
// templateCard.setSource(new Souce().setDesc("眼界甄选").setIcon_url("https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0").setDesc_color(0));
|
|
||||||
// templateCard.setMain_title(new MainTitle().setTitle(mainTitle).setDesc("订单号:"+orderId));
|
|
||||||
// templateCard.setEmphasis_content(new EmphasisContent().setTitle(yxStoreOrderDto.getPayPrice().toString()).setDesc("订单总金额"));
|
|
||||||
//// templateCard.setQuote_area(new QuoteArea().setType(0).setUrl("").setAppid("APPID").setTitle("订单详情").setQuote_text("眼镜*1 0.01"));
|
|
||||||
// templateCard.setSub_title_text("订单类型:"+yxStoreOrderDto.getPinkName());//订单类型
|
|
||||||
// templateCard.setJump_list(arrayList1);
|
|
||||||
// templateCard.setCard_action(new CardAction().setType(1).setUrl(cardActionUrl));
|
|
||||||
ArrayList<Jump> arrayList1 = new ArrayList<>();
|
|
||||||
//机器人消息跳转地址
|
|
||||||
String cardActionUrl = systemConfigService.getData(SystemConfigConstants.CARD_ACTION_URL);
|
|
||||||
if (StrUtil.isBlank(cardActionUrl)) {
|
|
||||||
// throw new YshopException("未配置企业微信群机器人跳转地址");
|
|
||||||
cardActionUrl = "未配置跳转网址";
|
|
||||||
}
|
|
||||||
arrayList1.add(new Jump().setType(1).setUrl(cardActionUrl).setTitle("前去处理订单"));
|
|
||||||
|
|
||||||
return TemplateCard.builder()
|
|
||||||
.horizontalContentList(arrayList).card_type("text_notice")
|
|
||||||
.source(Souce.builder()
|
|
||||||
.desc("眼界甄选")
|
|
||||||
.icon_url("https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0")
|
|
||||||
.desc_color(0)
|
|
||||||
.build())
|
|
||||||
.main_title(MainTitle.builder().title(mainTitle).desc("订单号:" + orderId).build())
|
|
||||||
.emphasis_content(EmphasisContent.builder().title(yxStoreOrderDto.getPayPrice().toString()).desc("订单总金额").build())
|
|
||||||
.sub_title_text("订单类型:" + yxStoreOrderDto.getPinkName())
|
|
||||||
.jump_list(arrayList1)
|
|
||||||
.card_action(CardAction.builder().type(1).url(cardActionUrl).build())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -29,6 +29,7 @@ import co.yixiang.modules.user.domain.YxUser;
|
|||||||
import co.yixiang.modules.user.service.YxUserBillService;
|
import co.yixiang.modules.user.service.YxUserBillService;
|
||||||
import co.yixiang.modules.user.service.YxUserService;
|
import co.yixiang.modules.user.service.YxUserService;
|
||||||
import co.yixiang.modules.user.service.dto.WechatUserDto;
|
import co.yixiang.modules.user.service.dto.WechatUserDto;
|
||||||
|
import co.yixiang.utils.WxbotMsgUtil;
|
||||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -37,6 +38,7 @@ import org.springframework.context.event.SmartApplicationListener;
|
|||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -67,6 +69,8 @@ public class TemplateListener implements SmartApplicationListener {
|
|||||||
private YxStoreCustomerService yxStoreCustomerService;
|
private YxStoreCustomerService yxStoreCustomerService;
|
||||||
//@Autowired
|
//@Autowired
|
||||||
//private MqProducer mqProducer;
|
//private MqProducer mqProducer;
|
||||||
|
@Autowired
|
||||||
|
private WxbotMsgUtil wxbotMsgUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsEventType(Class<? extends ApplicationEvent> aClass) {
|
public boolean supportsEventType(Class<? extends ApplicationEvent> aClass) {
|
||||||
@@ -83,10 +87,17 @@ public class TemplateListener implements SmartApplicationListener {
|
|||||||
log.info("模板事件类型:{}", templateBean.getTemplateType());
|
log.info("模板事件类型:{}", templateBean.getTemplateType());
|
||||||
switch (TemplateListenEnum.toType(templateBean.getTemplateType())) {
|
switch (TemplateListenEnum.toType(templateBean.getTemplateType())) {
|
||||||
case TYPE_1:
|
case TYPE_1:
|
||||||
|
try {
|
||||||
|
wxbotMsgUtil.inform(Long.parseLong(templateBean.getOrderId()),0);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("机器人发送失败,{}",e);
|
||||||
|
// throw new RuntimeException(e);
|
||||||
|
}
|
||||||
weixinTemplateService.paySuccessNotice(templateBean.getOrderId()
|
weixinTemplateService.paySuccessNotice(templateBean.getOrderId()
|
||||||
, templateBean.getPrice(), templateBean.getUid());
|
, templateBean.getPrice(), templateBean.getUid());
|
||||||
weiXinSubscribeService.paySuccessNotice(templateBean.getOrderId()
|
weiXinSubscribeService.paySuccessNotice(templateBean.getOrderId()
|
||||||
, templateBean.getPrice(), templateBean.getUid());
|
, templateBean.getPrice(), templateBean.getUid());
|
||||||
|
|
||||||
/**************给客服发送消息**************/
|
/**************给客服发送消息**************/
|
||||||
try {
|
try {
|
||||||
List<YxStoreCustomer> yxStoreCustomers = yxStoreCustomerService.lambdaQuery().eq(YxStoreCustomer::getIsEnable, ShopConstants.ZSW_ONE_NUM).list();
|
List<YxStoreCustomer> yxStoreCustomers = yxStoreCustomerService.lambdaQuery().eq(YxStoreCustomer::getIsEnable, ShopConstants.ZSW_ONE_NUM).list();
|
||||||
@@ -164,6 +175,11 @@ public class TemplateListener implements SmartApplicationListener {
|
|||||||
case TYPE_9:
|
case TYPE_9:
|
||||||
weixinTemplateService.refundSuccessNotice("您的订单退款申请已提交,等待审核。",templateBean.getOrderId(), templateBean.getPrice(),
|
weixinTemplateService.refundSuccessNotice("您的订单退款申请已提交,等待审核。",templateBean.getOrderId(), templateBean.getPrice(),
|
||||||
templateBean.getUid(), templateBean.getTime());
|
templateBean.getUid(), templateBean.getTime());
|
||||||
|
try {
|
||||||
|
wxbotMsgUtil.inform(Long.parseLong(templateBean.getOrderId()),1);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
/**************给客服发送消息**************/
|
/**************给客服发送消息**************/
|
||||||
try {
|
try {
|
||||||
List<YxStoreCustomer> yxStoreCustomers = yxStoreCustomerService.lambdaQuery().eq(YxStoreCustomer::getIsEnable, ShopConstants.ZSW_ONE_NUM).list();
|
List<YxStoreCustomer> yxStoreCustomers = yxStoreCustomerService.lambdaQuery().eq(YxStoreCustomer::getIsEnable, ShopConstants.ZSW_ONE_NUM).list();
|
||||||
|
|||||||
@@ -112,6 +112,9 @@ public class YxStoreOrderDto implements Serializable {
|
|||||||
// 退款用户说明
|
// 退款用户说明
|
||||||
private String refundReasonWapExplain;
|
private String refundReasonWapExplain;
|
||||||
|
|
||||||
|
// 申请退款时间
|
||||||
|
private String refundTime;
|
||||||
|
|
||||||
/** 退款联系人 */
|
/** 退款联系人 */
|
||||||
private String refundName;
|
private String refundName;
|
||||||
|
|
||||||
|
|||||||
+7
-8
@@ -40,7 +40,6 @@ import co.yixiang.modules.cart.domain.YxStoreCart;
|
|||||||
import co.yixiang.modules.cart.service.YxStoreCartService;
|
import co.yixiang.modules.cart.service.YxStoreCartService;
|
||||||
import co.yixiang.modules.cart.service.mapper.StoreCartMapper;
|
import co.yixiang.modules.cart.service.mapper.StoreCartMapper;
|
||||||
import co.yixiang.modules.cart.vo.YxStoreCartQueryVo;
|
import co.yixiang.modules.cart.vo.YxStoreCartQueryVo;
|
||||||
import co.yixiang.modules.inform.SendMsgService;
|
|
||||||
import co.yixiang.modules.order.domain.YxExpress;
|
import co.yixiang.modules.order.domain.YxExpress;
|
||||||
import co.yixiang.modules.order.domain.YxStoreOrder;
|
import co.yixiang.modules.order.domain.YxStoreOrder;
|
||||||
import co.yixiang.modules.order.domain.YxStoreOrderCartInfo;
|
import co.yixiang.modules.order.domain.YxStoreOrderCartInfo;
|
||||||
@@ -191,8 +190,7 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationEventPublisher publisher;
|
private ApplicationEventPublisher publisher;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SendMsgService sendMsgService;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private StoreAfterSalesService storeAfterSalesService;
|
private StoreAfterSalesService storeAfterSalesService;
|
||||||
|
|
||||||
@@ -1566,14 +1564,13 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
|
|||||||
BillDetailEnum.TYPE_3.getValue(),
|
BillDetailEnum.TYPE_3.getValue(),
|
||||||
orderInfo.getPayPrice().doubleValue(), userInfo.getNowMoney().doubleValue(),
|
orderInfo.getPayPrice().doubleValue(), userInfo.getNowMoney().doubleValue(),
|
||||||
payTypeMsg + orderInfo.getPayPrice() + "元购买商品");
|
payTypeMsg + orderInfo.getPayPrice() + "元购买商品");
|
||||||
//支付成功企业微信
|
|
||||||
sendMsgService.inform(Long.valueOf(orderId),0);
|
|
||||||
//模板消息支付成功发布事件
|
//模板消息支付成功发布事件
|
||||||
TemplateBean templateBean = TemplateBean.builder()
|
TemplateBean templateBean = TemplateBean.builder()
|
||||||
.orderId(orderInfo.getOrderId())
|
.orderId(orderInfo.getOrderId())
|
||||||
.price(orderInfo.getPayPrice().toString())
|
.price(orderInfo.getPayPrice().toString())
|
||||||
.uid(orderInfo.getUid())
|
.uid(orderInfo.getUid())
|
||||||
.templateType(TemplateListenEnum.TYPE_1.getValue())
|
.templateType(TemplateListenEnum.TYPE_1.getValue())
|
||||||
|
.time(DateUtil.formatTime(new Date()))
|
||||||
.build();
|
.build();
|
||||||
publisher.publishEvent(new TemplateEvent(this, templateBean));
|
publisher.publishEvent(new TemplateEvent(this, templateBean));
|
||||||
|
|
||||||
@@ -2427,10 +2424,10 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
|
|||||||
String orderStatusStr = OrderUtil.orderStatusStr(yxStoreOrder.getPaid()
|
String orderStatusStr = OrderUtil.orderStatusStr(yxStoreOrder.getPaid()
|
||||||
, yxStoreOrder.getStatus(), yxStoreOrder.getShippingType()
|
, yxStoreOrder.getStatus(), yxStoreOrder.getShippingType()
|
||||||
, yxStoreOrder.getRefundStatus());
|
, yxStoreOrder.getRefundStatus());
|
||||||
|
String refundTime="";
|
||||||
if (_status == 3) {
|
if (_status == 3) {
|
||||||
|
|
||||||
String refundTime = DateUtil.formatDateTime(yxStoreOrder.getRefundReasonTime());
|
refundTime = DateUtil.formatDateTime(yxStoreOrder.getRefundReasonTime());
|
||||||
String str = "<b style='color:#f124c7'>申请退款</b>" +
|
String str = "<b style='color:#f124c7'>申请退款</b>" +
|
||||||
"<span>退款原因:" + yxStoreOrder.getRefundReasonWap() + "</span>" +
|
"<span>退款原因:" + yxStoreOrder.getRefundReasonWap() + "</span>" +
|
||||||
"<span>备注说明:" + yxStoreOrder.getRefundReasonWapExplain() + "</span>" +
|
"<span>备注说明:" + yxStoreOrder.getRefundReasonWapExplain() + "</span>" +
|
||||||
@@ -2438,7 +2435,9 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
|
|||||||
orderStatusStr = str;
|
orderStatusStr = str;
|
||||||
}
|
}
|
||||||
yxStoreOrderDto.setStatusName(orderStatusStr);
|
yxStoreOrderDto.setStatusName(orderStatusStr);
|
||||||
|
yxStoreOrderDto.setRefundReasonWap(yxStoreOrder.getRefundReasonWap());
|
||||||
|
yxStoreOrderDto.setRefundReasonWapExplain(yxStoreOrder.getRefundReasonWapExplain());
|
||||||
|
yxStoreOrderDto.setRefundTime(refundTime);
|
||||||
yxStoreOrderDto.set_status(_status);
|
yxStoreOrderDto.set_status(_status);
|
||||||
|
|
||||||
String payTypeName = OrderUtil.payTypeName(yxStoreOrder.getPayType()
|
String payTypeName = OrderUtil.payTypeName(yxStoreOrder.getPayType()
|
||||||
|
|||||||
+16
-5
@@ -1,5 +1,6 @@
|
|||||||
package co.yixiang.modules.sales.service.impl;
|
package co.yixiang.modules.sales.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.NumberUtil;
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import cn.iocoder.yudao.framework.common.exception.YshopException;
|
import cn.iocoder.yudao.framework.common.exception.YshopException;
|
||||||
import co.yixiang.common.service.impl.BaseServiceImpl;
|
import co.yixiang.common.service.impl.BaseServiceImpl;
|
||||||
@@ -8,9 +9,11 @@ import co.yixiang.dozer.service.IGenerator;
|
|||||||
import co.yixiang.enums.AfterSalesStatusEnum;
|
import co.yixiang.enums.AfterSalesStatusEnum;
|
||||||
import co.yixiang.enums.OrderInfoEnum;
|
import co.yixiang.enums.OrderInfoEnum;
|
||||||
import co.yixiang.enums.ShopCommonEnum;
|
import co.yixiang.enums.ShopCommonEnum;
|
||||||
|
import co.yixiang.event.TemplateBean;
|
||||||
|
import co.yixiang.event.TemplateEvent;
|
||||||
|
import co.yixiang.event.TemplateListenEnum;
|
||||||
import co.yixiang.exception.ErrorRequestException;
|
import co.yixiang.exception.ErrorRequestException;
|
||||||
import co.yixiang.modules.cart.vo.YxStoreCartQueryVo;
|
import co.yixiang.modules.cart.vo.YxStoreCartQueryVo;
|
||||||
import co.yixiang.modules.inform.SendMsgService;
|
|
||||||
import co.yixiang.modules.order.domain.YxStoreOrder;
|
import co.yixiang.modules.order.domain.YxStoreOrder;
|
||||||
import co.yixiang.modules.order.domain.YxStoreOrderCartInfo;
|
import co.yixiang.modules.order.domain.YxStoreOrderCartInfo;
|
||||||
import co.yixiang.modules.order.service.mapper.StoreOrderCartInfoMapper;
|
import co.yixiang.modules.order.service.mapper.StoreOrderCartInfoMapper;
|
||||||
@@ -39,6 +42,7 @@ import org.apache.commons.collections.CollectionUtils;
|
|||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
@@ -65,9 +69,9 @@ public class StoreAfterSalesServiceImpl extends BaseServiceImpl<StoreAfterSalesM
|
|||||||
private final StoreAfterSalesItemMapper storeAfterSalesItemMapper;
|
private final StoreAfterSalesItemMapper storeAfterSalesItemMapper;
|
||||||
private final StoreAfterSalesStatusMapper storeAfterSalesStatusMapper;
|
private final StoreAfterSalesStatusMapper storeAfterSalesStatusMapper;
|
||||||
private final IGenerator generator;
|
private final IGenerator generator;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SendMsgService sendMsgService;
|
private ApplicationEventPublisher publisher;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyForAfterSales(Long userId, String nickname, StoreAfterSalesParam storeAfterSalesParam) {
|
public void applyForAfterSales(Long userId, String nickname, StoreAfterSalesParam storeAfterSalesParam) {
|
||||||
|
|
||||||
@@ -127,8 +131,6 @@ public class StoreAfterSalesServiceImpl extends BaseServiceImpl<StoreAfterSalesM
|
|||||||
storeAfterSalesItemMapper.insert(storeAfterSalesItem);
|
storeAfterSalesItemMapper.insert(storeAfterSalesItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
//申请退款企业微信
|
|
||||||
sendMsgService.inform(Long.valueOf(yxStoreOrder.getOrderId()),1);
|
|
||||||
//操作记录
|
//操作记录
|
||||||
StoreAfterSalesStatus storeAfterSalesStatus = new StoreAfterSalesStatus();
|
StoreAfterSalesStatus storeAfterSalesStatus = new StoreAfterSalesStatus();
|
||||||
storeAfterSalesStatus.setStoreAfterSalesId(storeAfterSales.getId());
|
storeAfterSalesStatus.setStoreAfterSalesId(storeAfterSales.getId());
|
||||||
@@ -137,6 +139,15 @@ public class StoreAfterSalesServiceImpl extends BaseServiceImpl<StoreAfterSalesM
|
|||||||
storeAfterSalesStatus.setChangeTime(Timestamp.valueOf(LocalDateTime.now()));
|
storeAfterSalesStatus.setChangeTime(Timestamp.valueOf(LocalDateTime.now()));
|
||||||
storeAfterSalesStatus.setOperator(nickname);
|
storeAfterSalesStatus.setOperator(nickname);
|
||||||
storeAfterSalesStatusMapper.insert(storeAfterSalesStatus);
|
storeAfterSalesStatusMapper.insert(storeAfterSalesStatus);
|
||||||
|
//模板消息发布事件
|
||||||
|
TemplateBean templateBean = TemplateBean.builder()
|
||||||
|
.orderId(yxStoreOrder.getOrderId())
|
||||||
|
.price(yxStoreOrder.getPayPrice().toString())
|
||||||
|
.uid(yxStoreOrder.getUid())
|
||||||
|
.templateType(TemplateListenEnum.TYPE_9.getValue())
|
||||||
|
.time(DateUtil.formatTime(new Date()))
|
||||||
|
.build();
|
||||||
|
publisher.publishEvent(new TemplateEvent(this, templateBean));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+19
-9
@@ -1,5 +1,7 @@
|
|||||||
package co.yixiang.modules.inform.domin;
|
package co.yixiang.utils.WxTemplate;
|
||||||
|
|
||||||
|
import co.yixiang.utils.WxTemplate.dto.*;
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -9,17 +11,20 @@ import java.util.ArrayList;
|
|||||||
public class TemplateCard {
|
public class TemplateCard {
|
||||||
|
|
||||||
/** 模板卡片的模板类型*/
|
/** 模板卡片的模板类型*/
|
||||||
private String card_type;
|
@JSONField(name = "card_type")
|
||||||
|
private String cardType;
|
||||||
|
|
||||||
/**卡片来源信息模板 icon_url:来源图片url、desc:描述、desc_color:颜色 0(默认) 灰色,1 黑色,2 红色,3 绿色 */
|
/**卡片来源信息模板 icon_url:来源图片url、desc:描述、desc_color:颜色 0(默认) 灰色,1 黑色,2 红色,3 绿色 */
|
||||||
private Souce source;
|
private Souce source;
|
||||||
|
|
||||||
/** 模版卡片的主要内容 title:一级标题、desc:标题辅助信息*/
|
/** 模版卡片的主要内容 title:一级标题、desc:标题辅助信息*/
|
||||||
private MainTitle main_title;
|
@JSONField(name = "main_title")
|
||||||
|
private MainTitle mainTitle;
|
||||||
|
|
||||||
/** 关键数据样式 "title":"100",
|
/** 关键数据样式 "title":"100",
|
||||||
"desc":"数据含义"*/
|
"desc":"数据含义"*/
|
||||||
private EmphasisContent emphasis_content;
|
@JSONField(name = "emphasis_content")
|
||||||
|
private EmphasisContent emphasisContent;
|
||||||
|
|
||||||
/** 引用文献样式
|
/** 引用文献样式
|
||||||
* "type":1,
|
* "type":1,
|
||||||
@@ -28,14 +33,16 @@ public class TemplateCard {
|
|||||||
"pagepath":"PAGEPATH",
|
"pagepath":"PAGEPATH",
|
||||||
"title":"引用文本标题",
|
"title":"引用文本标题",
|
||||||
"quote_text":"Jack:企业微信真的很好用~\nBalian:超级好的一款软件!"*/
|
"quote_text":"Jack:企业微信真的很好用~\nBalian:超级好的一款软件!"*/
|
||||||
private QuoteArea quote_area;
|
@JSONField(name = "quote_area")
|
||||||
|
private QuoteArea quoteArea;
|
||||||
|
|
||||||
|
@JSONField(name = "sub_title_text")
|
||||||
private String sub_title_text;
|
private String subTitleText;
|
||||||
|
|
||||||
/** 二级标题+文本列表 type:0或不填代表是普通文本,1 代表跳转url,2 代表下载附件,3 代表@员工
|
/** 二级标题+文本列表 type:0或不填代表是普通文本,1 代表跳转url,2 代表下载附件,3 代表@员工
|
||||||
keyname:二级标题、value:内容、url:链接
|
keyname:二级标题、value:内容、url:链接
|
||||||
* */
|
* */
|
||||||
|
@JSONField(name = "horizontal_content_list")
|
||||||
private ArrayList<HorizontalContent> horizontalContentList;
|
private ArrayList<HorizontalContent> horizontalContentList;
|
||||||
|
|
||||||
/** {
|
/** {
|
||||||
@@ -49,11 +56,14 @@ public class TemplateCard {
|
|||||||
"pagepath":"PAGEPATH",
|
"pagepath":"PAGEPATH",
|
||||||
"title":"跳转小程序"
|
"title":"跳转小程序"
|
||||||
}*/
|
}*/
|
||||||
private ArrayList<Jump> jump_list;
|
@JSONField(name = "jump_list")
|
||||||
|
private ArrayList<Jump> jumpList;
|
||||||
|
|
||||||
/** 0 = 未购买 1 = 已购买 "type":1,
|
/** 0 = 未购买 1 = 已购买 "type":1,
|
||||||
"url":"https://work.weixin.qq.com/?from=openApi",
|
"url":"https://work.weixin.qq.com/?from=openApi",
|
||||||
"appid":"APPID",
|
"appid":"APPID",
|
||||||
"pagepath":"PAGEPATH"*/
|
"pagepath":"PAGEPATH"*/
|
||||||
private CardAction card_action;
|
@JSONField(name = "card_action")
|
||||||
|
private CardAction cardAction;
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package co.yixiang.modules.inform.domin;
|
package co.yixiang.utils.WxTemplate.dto;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package co.yixiang.modules.inform.domin;
|
package co.yixiang.utils.WxTemplate.dto;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
+5
-2
@@ -1,4 +1,4 @@
|
|||||||
package co.yixiang.modules.inform.domin;
|
package co.yixiang.utils.WxTemplate.dto;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -14,5 +14,8 @@ public class HorizontalContent {
|
|||||||
private String url;
|
private String url;
|
||||||
private String media_id;
|
private String media_id;
|
||||||
|
|
||||||
|
public HorizontalContent(String keyname, String value) {
|
||||||
|
this.keyname = keyname;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
package co.yixiang.modules.inform.domin;
|
package co.yixiang.utils.WxTemplate.dto;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package co.yixiang.modules.inform.domin;
|
package co.yixiang.utils.WxTemplate.dto;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package co.yixiang.modules.inform.domin;
|
package co.yixiang.utils.WxTemplate.dto;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
package co.yixiang.modules.inform.domin;
|
package co.yixiang.utils.WxTemplate.dto;
|
||||||
|
|
||||||
import io.swagger.models.auth.In;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package co.yixiang.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import co.yixiang.constant.SystemConfigConstants;
|
||||||
|
import co.yixiang.modules.order.service.YxStoreOrderService;
|
||||||
|
import co.yixiang.modules.order.service.dto.YxStoreOrderDto;
|
||||||
|
import co.yixiang.modules.shop.service.YxSystemConfigService;
|
||||||
|
import co.yixiang.utils.WxTemplate.TemplateCard;
|
||||||
|
import co.yixiang.utils.WxTemplate.dto.*;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.http.HttpStatus;
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class WxbotMsgUtil {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private YxStoreOrderService yxStoreOrderService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private YxSystemConfigService systemConfigService;
|
||||||
|
public void inform(long orderId, int type) throws IOException {
|
||||||
|
CloseableHttpClient httpClient = HttpClients.createDefault();//实例化对象
|
||||||
|
// String webhook_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a08fa2aa-e299-4946-8cba-c99bacac6c33";
|
||||||
|
String webhook_url=systemConfigService.getData(SystemConfigConstants.ROBOT_URL);
|
||||||
|
HttpPost httpPost = new HttpPost(webhook_url);
|
||||||
|
httpPost.addHeader("Content-Type", "application/json; charset=utf-8");
|
||||||
|
TemplateCard templateCard = this.creatTemplatecard(orderId, type);
|
||||||
|
Map<String, Object> param = new HashMap<>();
|
||||||
|
param.put("msgtype", "template_card");
|
||||||
|
param.put("template_card", templateCard);
|
||||||
|
|
||||||
|
String jsonParam = JSON.toJSONString(param);
|
||||||
|
|
||||||
|
StringEntity stringEntity = new StringEntity(jsonParam, "utf-8");
|
||||||
|
|
||||||
|
httpPost.setEntity(stringEntity);
|
||||||
|
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||||
|
|
||||||
|
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||||
|
String result = EntityUtils.toString(response.getEntity(), "utf-8");
|
||||||
|
log.info("result:{}", result);
|
||||||
|
} else {
|
||||||
|
log.error("发送微信机器人消息失败");
|
||||||
|
}
|
||||||
|
// 关闭
|
||||||
|
httpClient.close();
|
||||||
|
response.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
//创建订单消息
|
||||||
|
private TemplateCard creatTemplatecard(long orderId, int type) {
|
||||||
|
YxStoreOrderDto yxStoreOrderDto = yxStoreOrderService.getOrderDetailByOrderId(orderId);
|
||||||
|
String mainTitle;
|
||||||
|
ArrayList<HorizontalContent> arrayList = new ArrayList<>();
|
||||||
|
|
||||||
|
arrayList.add(new HorizontalContent("会员名称", yxStoreOrderDto.getRealName()));
|
||||||
|
arrayList.add(new HorizontalContent("会员手机号", yxStoreOrderDto.getUserPhone()));
|
||||||
|
if (type == 0) {//支付时候
|
||||||
|
mainTitle = StrUtil.format("您有{}条新订单需要处理", 1);
|
||||||
|
arrayList.add(new HorizontalContent("下单地址", yxStoreOrderDto.getUserAddress()));
|
||||||
|
arrayList.add(new HorizontalContent("下单时间", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(yxStoreOrderDto.getCreateTime())));
|
||||||
|
} else {
|
||||||
|
mainTitle = StrUtil.format("您有{}条退款需要处理", 1);
|
||||||
|
//获取文本内容,并且截取只需要标题后面的
|
||||||
|
arrayList.add(new HorizontalContent("退款原因", yxStoreOrderDto.getRefundReasonWap()));
|
||||||
|
arrayList.add(new HorizontalContent("备注说明", StringUtils.isNotBlank(yxStoreOrderDto.getRefundReasonWapExplain())?yxStoreOrderDto.getRefundReasonWapExplain():"本次退款无备注" ));
|
||||||
|
arrayList.add(new HorizontalContent("申请时间", yxStoreOrderDto.getRefundTime()));
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<Jump> arrayList1 = new ArrayList<>();
|
||||||
|
//机器人消息跳转地址
|
||||||
|
String cardActionUrl = systemConfigService.getData(SystemConfigConstants.CARD_ACTION_URL);
|
||||||
|
if (StrUtil.isBlank(cardActionUrl)) {
|
||||||
|
// throw new YshopException("未配置企业微信群机器人跳转地址");
|
||||||
|
cardActionUrl = "未配置跳转网址";
|
||||||
|
}
|
||||||
|
arrayList1.add(new Jump().setType(1).setUrl(cardActionUrl).setTitle("前去处理订单"));
|
||||||
|
return TemplateCard.builder()
|
||||||
|
.horizontalContentList(arrayList)
|
||||||
|
.cardType("text_notice")
|
||||||
|
.source(Souce.builder()
|
||||||
|
.desc("眼界甄选")
|
||||||
|
.icon_url("https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0")
|
||||||
|
.desc_color(0)
|
||||||
|
.build())
|
||||||
|
.mainTitle(MainTitle.builder().title(mainTitle).desc("订单号:" + orderId).build())
|
||||||
|
.emphasisContent(EmphasisContent.builder().title(yxStoreOrderDto.getPayPrice().toString()).desc("订单总金额").build())
|
||||||
|
.subTitleText("订单类型:" + yxStoreOrderDto.getPinkName())
|
||||||
|
.jumpList(arrayList1)
|
||||||
|
.cardAction(CardAction.builder().type(1).url(cardActionUrl).build())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user