|
|
|
@@ -3,9 +3,7 @@ package com.iformall.service.impl; |
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil; |
|
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams; |
|
|
|
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; |
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService; |
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaTemplateData; |
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
@@ -16,6 +14,9 @@ import com.iformall.common.Result; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.dto.WxSharingOrderDto; |
|
|
|
import com.iformall.domain.po.*; |
|
|
|
import com.iformall.domain.po.msg.AppUniformMsg; |
|
|
|
import com.iformall.domain.po.msg.MpAppMsg; |
|
|
|
import com.iformall.domain.po.msg.SmartAppMsg; |
|
|
|
import com.iformall.domain.vo.*; |
|
|
|
import com.iformall.enums.*; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
@@ -24,8 +25,7 @@ import com.iformall.mq.MqBaseProducer; |
|
|
|
import com.iformall.service.*; |
|
|
|
import com.iformall.utils.Constant; |
|
|
|
import com.iformall.utils.DateUtils; |
|
|
|
import com.iformall.utils.MaUtil; |
|
|
|
import me.chanjar.weixin.common.error.WxErrorException; |
|
|
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
import org.slf4j.Logger; |
|
|
|
@@ -106,6 +106,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
@Autowired |
|
|
|
MqBaseProducer mqBaseProducer; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxAuthorizerInfoMapper authorizerInfoMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageInfo<WxCouponOrder> listAsPage(WxCouponOrder record, Integer pageIndex, Integer pageSize) { |
|
|
|
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponOrderMapper.findList(record)); |
|
|
|
@@ -590,15 +593,97 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
couponDetail = "满" + coupon.getUsePriceStr() + "减" + coupon.getPriceStr(); |
|
|
|
} |
|
|
|
|
|
|
|
SmartAppMsg smartAppMsg; |
|
|
|
boolean bUsed = false; |
|
|
|
String gotopage = "pages/index/index"; |
|
|
|
String notes = ""; |
|
|
|
if (couponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) { |
|
|
|
String gotopage = "pages/index/index"; |
|
|
|
String notes = ""; |
|
|
|
if (hadSentCoupon) { |
|
|
|
gotopage = "pages/couponorder/index/index"; |
|
|
|
notes = "您有新的券"; |
|
|
|
} |
|
|
|
bUsed = true; |
|
|
|
} |
|
|
|
|
|
|
|
// 7. 公众号消息 |
|
|
|
if(StringUtils.isNotBlank(user.getMpAppId()) && StringUtils.isNotBlank(user.getMpOpenId())) { |
|
|
|
/** |
|
|
|
* 卡券核销通知 |
|
|
|
* {{first.DATA}} |
|
|
|
* 卡券类型:{{keyword1.DATA}} |
|
|
|
* 卡券号码:{{keyword2.DATA}} |
|
|
|
* 核销时间:{{keyword3.DATA}} |
|
|
|
* {{remark.DATA}} |
|
|
|
*/ |
|
|
|
MpAppMsg mpAppMsg = new MpAppMsg(); |
|
|
|
mpAppMsg.setMsgType(EnumMsgRecordType.PUBLIC.getCode()); |
|
|
|
mpAppMsg.setAppId(user.getMpAppId()); |
|
|
|
mpAppMsg.setTo(user.getMpOpenId()); |
|
|
|
mpAppMsg.setMiniAppId(user.getAppId()); |
|
|
|
mpAppMsg.setMiniPagePath(gotopage); |
|
|
|
mpAppMsg.setTenantId(couponOrder.getTenantId()); |
|
|
|
mpAppMsg.setTemplateType(EnumTemplateType.VERIFY_RESULT.getCode()); |
|
|
|
mpAppMsg.setTemplateDataList(Lists.newArrayList( |
|
|
|
new WxMpTemplateData("first", "商家"+merchant.getName()+"的券被核销", "#173177"), |
|
|
|
new WxMpTemplateData("keyword1", EnumCouponType.getEnum(coupon.getType()).getMessage(), "#173177"), |
|
|
|
new WxMpTemplateData("keyword2", couponOrder.getId().toString(), "#173177"), |
|
|
|
new WxMpTemplateData("keyword3", dateFormat.format(new Date()), "#173177"), |
|
|
|
new WxMpTemplateData("remark", "更多优惠等您来!", "#173177") |
|
|
|
)); |
|
|
|
|
|
|
|
try { |
|
|
|
mqBaseProducer.sendMessage(mpAppMsg, EnumMsgMqTopic.DEFAULT.getCode(),EnumMsgMqTag.DEFAULT.getCode(),EnumMsgMqKey.DEFAULT.getCode()); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("核销-公众号-模板消息发送失败: " + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.MP_TEMPLATE_SEND_FAILED); |
|
|
|
} |
|
|
|
return; |
|
|
|
} else { |
|
|
|
// 8. 微信小程序-统一消息 |
|
|
|
// 获取小程序关联的服务号 |
|
|
|
WxWeappInfo weappInfoQ = new WxWeappInfo(); |
|
|
|
weappInfoQ.setAuthorizerAppid(user.getAppId()); |
|
|
|
weappInfoQ.setTenantId(user.getTenantId()); |
|
|
|
WxWeappInfo weappInfo = authorizerInfoMapper.findMp(weappInfoQ); |
|
|
|
if(weappInfo != null) { |
|
|
|
AppUniformMsg appUniformMsg = new AppUniformMsg(); |
|
|
|
appUniformMsg.setMsgType(EnumMsgRecordType.SMART_APP_UNIFORM.getCode()); |
|
|
|
appUniformMsg.setAppId(user.getAppId()); |
|
|
|
appUniformMsg.setTo(user.getOpenId()); |
|
|
|
appUniformMsg.setTemplateType(EnumTemplateType.VERIFY_RESULT.getCode()); |
|
|
|
appUniformMsg.setPagePath(gotopage); |
|
|
|
appUniformMsg.setUrl("http://iformall.com"); |
|
|
|
appUniformMsg.setMpAppId(weappInfo.getAuthorizerAppid()); |
|
|
|
appUniformMsg.setTemplateDataList(Lists.newArrayList( |
|
|
|
new WxMaTemplateData("first", "商家"+merchant.getName()+"的券被核销", "#173177"), |
|
|
|
new WxMaTemplateData("keyword1", EnumCouponType.getEnum(coupon.getType()).getMessage(), "#173177"), |
|
|
|
new WxMaTemplateData("keyword2", couponOrder.getId().toString(), "#173177"), |
|
|
|
new WxMaTemplateData("keyword3", dateFormat.format(new Date()), "#173177"), |
|
|
|
new WxMaTemplateData("remark", "更多优惠等您来!", "#173177") |
|
|
|
)); |
|
|
|
try { |
|
|
|
mqBaseProducer.sendMessage(appUniformMsg, EnumMsgMqTopic.DEFAULT.getCode(),EnumMsgMqTag.DEFAULT.getCode(),EnumMsgMqKey.DEFAULT.getCode()); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("核销-公众号-模板消息发送失败: " + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.UNIFORM_SEND_FAILED); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 9. 微信小程序-模板消息 |
|
|
|
SmartAppMsg smartAppMsg; |
|
|
|
if (bUsed) { |
|
|
|
//mq发送小程序消息 - 核销成功消息 |
|
|
|
/** |
|
|
|
* 核销成功消息 |
|
|
|
* 核销金额 {{keyword1.DATA}} |
|
|
|
* 商家名称 {{keyword2.DATA}} |
|
|
|
* 商品 {{keyword3.DATA}} |
|
|
|
* 商品描述 {{keyword4.DATA}} |
|
|
|
* 订单金额 {{keyword5.DATA}} |
|
|
|
* 核销时间 {{keyword6.DATA}} |
|
|
|
* 温馨提示 {{keyword7.DATA}} |
|
|
|
*/ |
|
|
|
smartAppMsg = new SmartAppMsg(); |
|
|
|
smartAppMsg.setMsgType(EnumMsgRecordType.SMART_APP.getCode()); |
|
|
|
smartAppMsg.setAppId(user.getAppId()); |
|
|
|
@@ -617,13 +702,20 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
|
new WxMaTemplateData("keyword7", notes, "#173177"))); |
|
|
|
smartAppMsg.setEmphasisKeyword("keyword1.DATA"); |
|
|
|
} else { |
|
|
|
//mq发送小程序消息 - 核销失败消息 |
|
|
|
// mq发送小程序消息 - 核销失败消息 |
|
|
|
/** |
|
|
|
* 核销失败消息 |
|
|
|
* 商品名称 {{keyword1.DATA}} |
|
|
|
* 核销时间 {{keyword2.DATA}} |
|
|
|
* 失败原因 {{keyword3.DATA}} |
|
|
|
* 备注 {{keyword4.DATA}} |
|
|
|
*/ |
|
|
|
smartAppMsg = new SmartAppMsg(); |
|
|
|
smartAppMsg.setMsgType(EnumMsgRecordType.SMART_APP.getCode()); |
|
|
|
smartAppMsg.setAppId(user.getAppId()); |
|
|
|
smartAppMsg.setTenantId(couponOrder.getTenantId()); |
|
|
|
smartAppMsg.setTemplateType(EnumTemplateType.VERIFY_FAIL.getCode()); |
|
|
|
smartAppMsg.setGotopage("pages/index/index"); |
|
|
|
smartAppMsg.setGotopage(gotopage); |
|
|
|
smartAppMsg.setTo(user.getOpenId()); |
|
|
|
smartAppMsg.setReceiver(user.getOpenId()); |
|
|
|
smartAppMsg.setFormId(formId); |
|
|
|
|