|
|
|
@@ -19,6 +19,7 @@ import com.iformall.domain.vo.*; |
|
|
|
import com.iformall.enums.*; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.mapper.*; |
|
|
|
import com.iformall.mq.MqBaseProducer; |
|
|
|
import com.iformall.service.*; |
|
|
|
import com.iformall.utils.Constant; |
|
|
|
import com.iformall.utils.DateUtils; |
|
|
|
@@ -100,6 +101,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
@Autowired |
|
|
|
WxCouponChannelMapper wxCouponChannelMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
MqBaseProducer mqBaseProducer; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageInfo<WxCouponOrder> listAsPage(WxCouponOrder record, Integer pageIndex, Integer pageSize) { |
|
|
|
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponOrderMapper.findList(record)); |
|
|
|
@@ -287,11 +291,8 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void downFile(String filePath, String filename, HttpServletResponse response, |
|
|
|
HttpServletRequest req) throws IOException { |
|
|
|
try { |
|
|
|
@@ -547,7 +548,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
} |
|
|
|
|
|
|
|
// 5. get app info |
|
|
|
WxAppinfo appInfo = wxAppinfoService.getByAppId(user.getAppId()); |
|
|
|
// WxAppinfo appInfo = wxAppinfoService.getByAppId(user.getAppId()); |
|
|
|
|
|
|
|
// 6. get payOrder info |
|
|
|
WxPayOrder payOrder = null; |
|
|
|
@@ -568,7 +569,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
throw new MallinkException(ErrorCode.PREPAY_ID_IS_EMPTY); |
|
|
|
} |
|
|
|
|
|
|
|
WxMaService wxMaService = MaUtil.getWeappService(appInfo); |
|
|
|
// WxMaService wxMaService = MaUtil.getWeappService(appInfo); |
|
|
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); |
|
|
|
String couponDetail = ""; |
|
|
|
@@ -576,91 +577,51 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
couponDetail = "满" + coupon.getUsePriceStr() + "减" + coupon.getPriceStr(); |
|
|
|
} |
|
|
|
|
|
|
|
WxTemplateMsg msg = null; |
|
|
|
WxMaTemplateMessage templateMessage = null; |
|
|
|
SmartAppMsg smartAppMsg; |
|
|
|
if (couponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) { |
|
|
|
WxTemplateMsg msgQ = new WxTemplateMsg(); |
|
|
|
msgQ.setTenantId(couponOrder.getTenantId()); |
|
|
|
msgQ.setType(EnumTemplateType.VERIFY_SUCCESS.getCode()); |
|
|
|
List<WxTemplateMsg> list = wxTemplateMsgMapper.select(msgQ); |
|
|
|
if (list.size() > 0) { |
|
|
|
msg = list.get(0); |
|
|
|
} |
|
|
|
if (msg == null) { |
|
|
|
logger.error("找不到模板Id"); |
|
|
|
throw new MallinkException(ErrorCode.TEMPLATE_NOT_FOUND); |
|
|
|
} |
|
|
|
String gotopage = "pages/index/index"; |
|
|
|
String notes = ""; |
|
|
|
if (hadSentCoupon) { |
|
|
|
gotopage = "pages/couponorder/index/index"; |
|
|
|
notes = "您有新的券"; |
|
|
|
} |
|
|
|
/** |
|
|
|
* 核销成功 |
|
|
|
* 核销金额 {{keyword1.DATA}} |
|
|
|
* 商家名称 {{keyword2.DATA}} |
|
|
|
* 商品 {{keyword3.DATA}} |
|
|
|
* 商品描述 {{keyword4.DATA}} |
|
|
|
* 订单金额 {{keyword5.DATA}} |
|
|
|
* 核销时间 {{keyword6.DATA}} |
|
|
|
* 温馨提示 {{keyword7.DATA}} |
|
|
|
* |
|
|
|
*/ |
|
|
|
templateMessage = WxMaTemplateMessage.builder() |
|
|
|
.toUser(user.getOpenId()) |
|
|
|
.formId(payOrder.getPrepayId()) // 微信支付的formId是prepayId |
|
|
|
.page(gotopage) |
|
|
|
.data(Lists.newArrayList( |
|
|
|
new WxMaTemplateData("keyword1", coupon.getPriceStr() + "元", "#173177"), |
|
|
|
new WxMaTemplateData("keyword2", merchant.getName(), "#173177"), |
|
|
|
new WxMaTemplateData("keyword3", coupon.getTitle(), "#173177"), |
|
|
|
new WxMaTemplateData("keyword4", couponDetail, "#173177"), |
|
|
|
new WxMaTemplateData("keyword5", coupon.getSalePriceStr() + "元", "#173177"), |
|
|
|
new WxMaTemplateData("keyword6", dateFormat.format(new Date()), "#173177"), |
|
|
|
new WxMaTemplateData("keyword7", notes, "#173177")) |
|
|
|
) |
|
|
|
.templateId(msg.getTemplateId()) |
|
|
|
.emphasisKeyword("keyword1.DATA") |
|
|
|
.build(); |
|
|
|
//mq发送小程序消息 |
|
|
|
smartAppMsg = new SmartAppMsg(); |
|
|
|
smartAppMsg.setAppId(user.getAppId()); |
|
|
|
smartAppMsg.setTenantId(couponOrder.getTenantId()); |
|
|
|
smartAppMsg.setTemplateType(EnumTemplateType.VERIFY_SUCCESS.getCode()); |
|
|
|
smartAppMsg.setGotopage(gotopage); |
|
|
|
smartAppMsg.setTo(user.getOpenId()); |
|
|
|
smartAppMsg.setFrom(payOrder.getPrepayId()); |
|
|
|
smartAppMsg.setTemplateDataList(Lists.newArrayList( |
|
|
|
new WxMaTemplateData("keyword1", coupon.getPriceStr() + "元", "#173177"), |
|
|
|
new WxMaTemplateData("keyword2", merchant.getName(), "#173177"), |
|
|
|
new WxMaTemplateData("keyword3", coupon.getTitle(), "#173177"), |
|
|
|
new WxMaTemplateData("keyword4", couponDetail, "#173177"), |
|
|
|
new WxMaTemplateData("keyword5", coupon.getSalePriceStr() + "元", "#173177"), |
|
|
|
new WxMaTemplateData("keyword6", dateFormat.format(new Date()), "#173177"), |
|
|
|
new WxMaTemplateData("keyword7", notes, "#173177"))); |
|
|
|
smartAppMsg.setEmphasisKeyword("keyword1.DATA"); |
|
|
|
} else { |
|
|
|
WxTemplateMsg msgQ = new WxTemplateMsg(); |
|
|
|
msgQ.setTenantId(couponOrder.getTenantId()); |
|
|
|
msgQ.setType(EnumTemplateType.VERIFY_FAIL.getCode()); |
|
|
|
List<WxTemplateMsg> list = wxTemplateMsgMapper.select(msgQ); |
|
|
|
if (list.size() > 0) { |
|
|
|
msg = list.get(0); |
|
|
|
} |
|
|
|
if (msg == null) { |
|
|
|
logger.error("找不到模板Id"); |
|
|
|
throw new MallinkException(ErrorCode.TEMPLATE_NOT_FOUND); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 核销失败 |
|
|
|
* 商品名称 {{keyword1.DATA}} |
|
|
|
* 核销时间 {{keyword2.DATA}} |
|
|
|
* 失败原因 {{keyword3.DATA}} |
|
|
|
* 备注 {{keyword4.DATA}} |
|
|
|
*/ |
|
|
|
templateMessage = WxMaTemplateMessage.builder() |
|
|
|
.toUser(user.getOpenId()) |
|
|
|
.formId(payOrder.getPrepayId()) // 微信支付的formId是prepayId |
|
|
|
.page("pages/index/index") |
|
|
|
.data(Lists.newArrayList( |
|
|
|
new WxMaTemplateData("keyword1", coupon.getTitle(), "#173177"), |
|
|
|
new WxMaTemplateData("keyword2", dateFormat.format(new Date()), "#173177"), |
|
|
|
new WxMaTemplateData("keyword3", "未知"), |
|
|
|
new WxMaTemplateData("keyword4", couponDetail)) |
|
|
|
) |
|
|
|
.templateId(msg.getTemplateId()) |
|
|
|
.emphasisKeyword("keyword1.DATA") |
|
|
|
.build(); |
|
|
|
} |
|
|
|
|
|
|
|
//templateMessage.addData( new WxMaTemplateMessage.Data("keyword1", "339208499", "#173177")); |
|
|
|
//mq发送小程序消息 |
|
|
|
smartAppMsg = new SmartAppMsg(); |
|
|
|
smartAppMsg.setAppId(user.getAppId()); |
|
|
|
smartAppMsg.setTenantId(couponOrder.getTenantId()); |
|
|
|
smartAppMsg.setTemplateType(EnumTemplateType.VERIFY_FAIL.getCode()); |
|
|
|
smartAppMsg.setGotopage("pages/index/index"); |
|
|
|
smartAppMsg.setTo(user.getOpenId()); |
|
|
|
smartAppMsg.setFrom(payOrder.getPrepayId()); |
|
|
|
smartAppMsg.setTemplateDataList(Lists.newArrayList( |
|
|
|
new WxMaTemplateData("keyword1", coupon.getTitle(), "#173177"), |
|
|
|
new WxMaTemplateData("keyword2", dateFormat.format(new Date()), "#173177"), |
|
|
|
new WxMaTemplateData("keyword3", "未知"), |
|
|
|
new WxMaTemplateData("keyword4", couponDetail))); |
|
|
|
smartAppMsg.setEmphasisKeyword("keyword1.DATA"); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
wxMaService.getMsgService().sendTemplateMsg(templateMessage); |
|
|
|
} catch (WxErrorException e) { |
|
|
|
mqBaseProducer.sendMessage(smartAppMsg, EnumMsgMqTopic.DEFAULT.getCode(),EnumMsgMqTag.DEFAULT.getCode(),EnumMsgMqKey.DEFAULT.getCode()); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("支付通知发送失败: " + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.TEMPLATE_SEND_FAILED); |
|
|
|
} |
|
|
|
|