From 2c7faf4040dbf0088b202d7bdf31e58fd8de6281 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Tue, 9 Apr 2019 15:28:20 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=B6=88=E6=81=AFformId][=E6=96=B0=E5=A2=9E]:=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E6=A8=A1=E6=9D=BF=E6=B6=88=E6=81=AFformId?= =?UTF-8?q?=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../V201904091440__ADD_FORMID_FOR_ORDER.sql | 2 + .../controller/WxOrderController.java | 10 ++-- .../java/com/iformall/domain/po/WxOrder.java | 37 ++++++------- .../com/iformall/domain/po/WxTemplateMsg.java | 10 +--- .../com/iformall/service/WxOrderService.java | 18 +++---- .../impl/WxCouponOrderServiceImpl.java | 54 ++++++++++--------- .../service/impl/WxOrderServiceImpl.java | 6 ++- .../main/resources/mapper/WxOrderMapper.xml | 7 ++- 8 files changed, 73 insertions(+), 71 deletions(-) create mode 100644 mallinkAdmin/src/main/resources/db/migration/V201904091440__ADD_FORMID_FOR_ORDER.sql diff --git a/mallinkAdmin/src/main/resources/db/migration/V201904091440__ADD_FORMID_FOR_ORDER.sql b/mallinkAdmin/src/main/resources/db/migration/V201904091440__ADD_FORMID_FOR_ORDER.sql new file mode 100644 index 000000000..0599a5d3d --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V201904091440__ADD_FORMID_FOR_ORDER.sql @@ -0,0 +1,2 @@ +ALTER TABLE `wx_order` +ADD COLUMN `form_id` VARCHAR(64) NULL COMMENT 'formId' AFTER `order_group_id`; \ No newline at end of file diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java index ff8e1bef5..9d7f211b0 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java @@ -39,13 +39,14 @@ public class WxOrderController extends BaseController { @Autowired private WxOrderService wxOrderService; - @ApiOperation(value = "免费领取", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\"}") + @ApiOperation(value = "免费领取", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"formId\":\"String\"}") @PostMapping("freeCoupon") public ResultData freeCoupon(@RequestBody Map paramMap) { //Assert.notNull(wxOrders.getName(), "角色名不能为空"); //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); String couponChannelIdStr = paramMap.get("couponChannelId"); String couponIdStr = paramMap.get("couponId"); + String formId = paramMap.get("formId"); if (StringUtils.isBlank(couponChannelIdStr)) { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId不能为空"); } @@ -72,7 +73,7 @@ public class WxOrderController extends BaseController { WxOrder order = null; try { - order = wxOrderService.saveFreeCouponOrder(getUserId(), couponChannelId, couponId); + order = wxOrderService.saveFreeCouponOrder(getUserId(), couponChannelId, couponId, formId); return new ResultData(order); } catch (MallinkException e) { logger.error(e.getMessage()); @@ -83,7 +84,7 @@ public class WxOrderController extends BaseController { } } - @ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"press\":\"String\",\"orderGroupId\":\"String\"}") + @ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"press\":\"String\",\"orderGroupId\":\"String\",\"formId\":\"String\"}") @PostMapping("save") public ResultData saveOrder(@RequestBody Map paramMap) { logger.info("OrderSave: " + paramMap.toString()); @@ -93,6 +94,7 @@ public class WxOrderController extends BaseController { String couponIdStr = paramMap.get("couponId"); String pressStr = paramMap.get("press"); String orderGroupIdStr = paramMap.get("orderGroupId"); + String formId = paramMap.get("formId"); if (StringUtils.isBlank(couponChannelIdStr)) { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId不能为空"); @@ -165,7 +167,7 @@ public class WxOrderController extends BaseController { WxCUser user = getUser(); try { - WxOrder order = wxOrderService.saveCouponOrder(user, couponChannelId, couponId, isPress, orderGroupId); + WxOrder order = wxOrderService.saveCouponOrder(user, couponChannelId, couponId, isPress, orderGroupId, formId); return new ResultData(order); } catch (MallinkException e) { logger.error(e.getMessage()); diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxOrder.java b/mallinkService/src/main/java/com/iformall/domain/po/WxOrder.java index 35f120bc3..6bf6c37a0 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxOrder.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxOrder.java @@ -48,65 +48,52 @@ public class WxOrder implements Serializable { @Transient private String phone; - /**订单码;正反向交易保持一致。**/ @io.swagger.annotations.ApiModelProperty(value="订单码;正反向交易保持一致。",name="orderNumber") private Long orderNumber; - /**租户ID**/ @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") private String tenantId; - /**c端用户id**/ @io.swagger.annotations.ApiModelProperty(value="c端用户id",name="cUserId") private Long cUserId; - /**渠道ID**/ @io.swagger.annotations.ApiModelProperty(value="渠道ID",name="couponChannelId") private Long couponChannelId; - /**产品ID,根据order type**/ @io.swagger.annotations.ApiModelProperty(value="产品ID(type-0:couponId, 1:buserId, 3:merchantId)",name="productId") private Long productId; - /**类型0:券,1:B刷卡支付,2:C扫码支付,3:储值卡**/ - @io.swagger.annotations.ApiModelProperty(value="类型",name="type") + @io.swagger.annotations.ApiModelProperty(value="类型(0:券,1:B刷卡支付,2:C扫码支付,3:储值卡)",name="type") private Integer type; - /**0: 付款 1: 退款**/ @io.swagger.annotations.ApiModelProperty(value="0: 付款 1: 退款",name="paymentType") private Integer paymentType; - /**支付金额(分):允许有负数,退款时为负值。**/ @io.swagger.annotations.ApiModelProperty(value="支付金额(分):允许有负数,退款时为负值。",name="payment") private Integer payment; - /**支付时间**/ @io.swagger.annotations.ApiModelProperty(value="支付时间",name="paymentTime") private Date paymentTime; - /**订单状态:-1全部;正向交易:0-已下单/待付款;1-已支付;2-已取消(限定时间内未付款)反向交易:3-待退款;4-已退款,5-退款失败; 砍价:6-砍价中,7-砍价完成,8-砍价失败**/ @io.swagger.annotations.ApiModelProperty(value="订单状态:-1全部;正向交易:0-已下单/待付款;1-已支付;2-已取消(限定时间内未付款)反向交易:3-已退款; 4-退款失败,5-退款失败; 砍价:6-砍价中,7-砍价完成,8-砍价失败",name="orderStatus") private Integer orderStatus; - /**创建时间/砍价开始时间**/ @io.swagger.annotations.ApiModelProperty(value="创建时间/砍价开始时间",name="createDate") private Date createDate; - /**更新时间**/ @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") private Date updateDate; - /**支付描述,订单支付时用**/ @io.swagger.annotations.ApiModelProperty(value="支付描述,订单支付时用",name="detail") private String detail; - /**砍价结束时间**/ @io.swagger.annotations.ApiModelProperty(value="砍价结束时间",name="pressEndDate") private Date pressEndDate; - - /**砍价人数**/ @io.swagger.annotations.ApiModelProperty(value="砍价人数",name="pressCurrentNum") private Integer pressCurrentNum; - /**已砍价格**/ @io.swagger.annotations.ApiModelProperty(value="已砍价格",name="pressCurrentValue") private Integer pressCurrentValue; + @io.swagger.annotations.ApiModelProperty(value = "拼团ID", name = "orderGroupId") + private Long orderGroupId; + + @io.swagger.annotations.ApiModelProperty(value = "formId", name = "formId") + private String formId; + @Transient protected List statusS; @Transient protected String statusStr; - @io.swagger.annotations.ApiModelProperty(value = "拼团ID", name = "orderGroupId") - private Long orderGroupId; public Long getOrderNumber() { return orderNumber; @@ -275,7 +262,15 @@ public class WxOrder implements Serializable { this.orderGroupId = orderGroupId; } - public static enum Field + public String getFormId() { + return formId; + } + + public void setFormId(String formId) { + this.formId = formId; + } + + public static enum Field { Id_ASC("`id` ASC"),Id_DESC("`id` DESC") ,OrderNumber_ASC("`order_number` ASC"),OrderNumber_DESC("`order_number` DESC") diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxTemplateMsg.java b/mallinkService/src/main/java/com/iformall/domain/po/WxTemplateMsg.java index db4fc6dfe..af437a000 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxTemplateMsg.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxTemplateMsg.java @@ -21,21 +21,15 @@ public class WxTemplateMsg implements Serializable { protected List ids; @Transient protected String sortColumns; - - - /**租户ID**/ + @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") private String tenantId; - /**模板ID**/ @io.swagger.annotations.ApiModelProperty(value="模板ID",name="templateId") private String templateId; - /**模板类型1:核销成功消息, 2:核销失败消息**/ - @io.swagger.annotations.ApiModelProperty(value="模板类型1:核销成功消息,2:核销失败消息",name="type") + @io.swagger.annotations.ApiModelProperty(value="模板类型1:核销成功消息,2:核销失败消息, 101:公众号审核结果消息, 102:公众号卡券核销消息",name="type") private Integer type; - /**创建时间**/ @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") private Date createDate; - /**更新时间**/ @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") private Date updateDate; diff --git a/mallinkService/src/main/java/com/iformall/service/WxOrderService.java b/mallinkService/src/main/java/com/iformall/service/WxOrderService.java index a3fdb80cd..2c8218f6c 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxOrderService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxOrderService.java @@ -33,6 +33,14 @@ public interface WxOrderService { ResultData microPayListOnDateAsPage(Long bUserId, Integer type, String date, Integer pageIndex, Integer pageSize); + /** + * 下免费券订单接口 + * @param userId + * @param couponId + * @return WxOrder + */ + WxOrder saveFreeCouponOrder(Long userId, Long couponChannelId, Long couponId, String formId); + /** * 提交订单 * @param user @@ -40,7 +48,7 @@ public interface WxOrderService { * @param orderGroupId * @return 订单id */ - WxOrder saveCouponOrder(WxCUser user, Long couponChannelId, Long couponId, boolean isPress, Long orderGroupId); + WxOrder saveCouponOrder(WxCUser user, Long couponChannelId, Long couponId, boolean isPress, Long orderGroupId, String formId); /** * 付款码支付 @@ -60,14 +68,6 @@ public interface WxOrderService { */ WxOrder saveCardPayOrder(WxMerchant merchant, Long cUserId, String totalFeeStr, Integer payment); - /** - * 免费券订单接口 - * @param userId - * @param couponId - * @return WxOrder - */ - WxOrder saveFreeCouponOrder(Long userId, Long couponChannelId, Long couponId); - /** * 免费券订单接口 * @param userId diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java index bfe638825..a19e70d3a 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java @@ -26,6 +26,7 @@ import com.iformall.utils.Constant; import com.iformall.utils.DateUtils; import com.iformall.utils.MaUtil; import me.chanjar.weixin.common.error.WxErrorException; +import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.usermodel.Workbook; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -535,16 +536,16 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { logger.error("找不到订单信息"); throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); } + String formId = null; + if(StringUtils.isNotBlank(order.getFormId())) { + formId = order.getFormId(); + } // 2. get coupon info WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(couponOrder.getCouponId()); if (coupon == null) { logger.error("找不到券信息"); throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); } - if(coupon.getSalePrice().equals(0)) { - logger.info("免费券不发模板消息!"); - return; - } // 3. merchant info WxMerchant merchant = wxMerchantMapper.selectByPrimaryKey(bUser.getMerchantId()); if (merchant == null) { @@ -562,26 +563,27 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { // WxAppinfo appInfo = wxAppinfoService.getByAppId(user.getAppId()); // 6. get payOrder info - WxPayOrder payOrder = null; - WxPayOrder payOrderQ = new WxPayOrder(); - payOrderQ.setTenantId(couponOrder.getTenantId()); - payOrderQ.setOrderId(order.getId()); - payOrderQ.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); - List payList = wxPayOrderMapper.select(payOrderQ); - if (payList.size() > 0) { - payOrder = payList.get(0); - } - if (payOrder == null) { - logger.error("找不到payOrder信息"); - throw new MallinkException(ErrorCode.PAY_ORDER_NOT_FOUND); - } - if (payOrder.getPrepayId() == null) { - logger.error("payOrder信息中,prepay_id为空"); - throw new MallinkException(ErrorCode.PREPAY_ID_IS_EMPTY); + if(StringUtils.isBlank(order.getFormId())) { + WxPayOrder payOrder = null; + WxPayOrder payOrderQ = new WxPayOrder(); + payOrderQ.setTenantId(couponOrder.getTenantId()); + payOrderQ.setOrderId(order.getId()); + payOrderQ.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); + List payList = wxPayOrderMapper.select(payOrderQ); + if (payList.size() > 0) { + payOrder = payList.get(0); + } + if (payOrder == null) { + logger.error("找不到payOrder信息"); + throw new MallinkException(ErrorCode.PAY_ORDER_NOT_FOUND); + } + if (payOrder.getPrepayId() == null) { + logger.error("payOrder信息中,prepay_id为空"); + throw new MallinkException(ErrorCode.PREPAY_ID_IS_EMPTY); + } + formId = payOrder.getPrepayId(); } -// WxMaService wxMaService = MaUtil.getWeappService(appInfo); - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); String couponDetail = ""; if (coupon.getType() == EnumCouponType.COUPON_MANJIAN.getCode()) { @@ -596,7 +598,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { gotopage = "pages/couponorder/index/index"; notes = "您有新的券"; } - //mq发送小程序消息 + //mq发送小程序消息 - 核销成功消息 smartAppMsg = new SmartAppMsg(); smartAppMsg.setMsgType(EnumMsgRecordType.SMART_APP.getCode()); smartAppMsg.setAppId(user.getAppId()); @@ -604,7 +606,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { smartAppMsg.setTemplateType(EnumTemplateType.VERIFY_SUCCESS.getCode()); smartAppMsg.setGotopage(gotopage); smartAppMsg.setTo(user.getOpenId()); - smartAppMsg.setFrom(payOrder.getPrepayId()); + smartAppMsg.setFormId(formId); smartAppMsg.setTemplateDataList(Lists.newArrayList( new WxMaTemplateData("keyword1", coupon.getPriceStr() + "元", "#173177"), new WxMaTemplateData("keyword2", merchant.getName(), "#173177"), @@ -615,7 +617,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { new WxMaTemplateData("keyword7", notes, "#173177"))); smartAppMsg.setEmphasisKeyword("keyword1.DATA"); } else { - //mq发送小程序消息 + //mq发送小程序消息 - 核销失败消息 smartAppMsg = new SmartAppMsg(); smartAppMsg.setMsgType(EnumMsgRecordType.SMART_APP.getCode()); smartAppMsg.setAppId(user.getAppId()); @@ -624,7 +626,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { smartAppMsg.setGotopage("pages/index/index"); smartAppMsg.setTo(user.getOpenId()); smartAppMsg.setReceiver(user.getOpenId()); - smartAppMsg.setFrom(payOrder.getPrepayId()); + smartAppMsg.setFormId(formId); smartAppMsg.setTemplateDataList(Lists.newArrayList( new WxMaTemplateData("keyword1", coupon.getTitle(), "#173177"), new WxMaTemplateData("keyword2", dateFormat.format(new Date()), "#173177"), diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java index 050578020..f02f79093 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java @@ -337,7 +337,7 @@ public class WxOrderServiceImpl implements WxOrderService { @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) - public WxOrder saveCouponOrder(WxCUser user, Long couponChannelId, Long couponId, boolean isPress, Long orderGroupId) { + public WxOrder saveCouponOrder(WxCUser user, Long couponChannelId, Long couponId, boolean isPress, Long orderGroupId, String formId) { // 检查用户 if (user == null) { logger.error("用户不存在"); @@ -428,6 +428,7 @@ public class WxOrderServiceImpl implements WxOrderService { record.setCreateDate(curr); record.setUpdateDate(curr); record.setOrderGroupId(orderGroupId); + record.setFormId(formId); if (isPress) { // 初始砍价信息 @@ -688,7 +689,7 @@ public class WxOrderServiceImpl implements WxOrderService { @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) - public WxOrder saveFreeCouponOrder(Long userId, Long couponChannelId, Long couponId) { + public WxOrder saveFreeCouponOrder(Long userId, Long couponChannelId, Long couponId, String formId) { // check 用户状态 WxCUser user = null; try { @@ -750,6 +751,7 @@ public class WxOrderServiceImpl implements WxOrderService { record.setDetail(bodyStr); record.setCreateDate(curr); record.setUpdateDate(curr); + record.setFormId(formId); // 保存订单 try { diff --git a/mallinkService/src/main/resources/mapper/WxOrderMapper.xml b/mallinkService/src/main/resources/mapper/WxOrderMapper.xml index bd91adeed..a92019815 100644 --- a/mallinkService/src/main/resources/mapper/WxOrderMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxOrderMapper.xml @@ -20,12 +20,13 @@ + `id`,`order_number`,`tenant_id`,`c_user_id`,`coupon_channel_id`,`product_id`,`type`,`payment_type`,`payment`,`payment_time`,`order_status`,`create_date`,`update_date`,`detail`, - `press_end_date`,`press_current_num`,`press_current_value`,`order_group_id` + `press_end_date`,`press_current_num`,`press_current_value`,`order_group_id`,`form_id` @@ -102,6 +103,10 @@ and `order_group_id` = #{orderGroupId} + + + and `form_id` = #{formId} + and `order_status` in