| @@ -7,6 +7,7 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCouponOrder; | |||
| import com.iformall.domain.po.WxMerchantBUser; | |||
| import com.iformall.domain.vo.WxCouponOrderCVo; | |||
| import com.iformall.enums.EnumCouponVerifyType; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxCouponOrderService; | |||
| import com.iformall.service.WxMerchantBUserService; | |||
| @@ -163,7 +164,7 @@ public class WxCouponOrderController extends BaseController { | |||
| } | |||
| if(couponOrder != null) { | |||
| wxCouponOrderService.sendInsideCouponVerifyMsg(couponOrder.getTenantId(), couponOrderId, wxMerchantBUser.getId()); | |||
| wxCouponOrderService.sendInsideCouponVerifyMsg(couponOrder.getTenantId(), couponOrderId, wxMerchantBUser.getId(), EnumCouponVerifyType.VERIFY_B.getCode()); | |||
| } | |||
| return new ResultData(couponOrder); | |||
| @@ -1,5 +1,7 @@ | |||
| package com.iformall.controller; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.annotation.SystemControllerLog; | |||
| import com.iformall.common.ErrorCode; | |||
| @@ -282,7 +284,12 @@ public class PosController extends BaseController { | |||
| WxPayConstant.RET_FAIL, | |||
| 500, e.getMessage()); | |||
| } | |||
| doActionAfterVerify(params, retMap, EnumCouponVerifyType.VERIFY_POS_INDEPENDENT); | |||
| return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", | |||
| WxPayConstant.RET_SUCCESS, null); | |||
| } | |||
| private void doActionAfterVerify(@RequestBody Map<String, String> params, Map<String, String> retMap, EnumCouponVerifyType verifyType) { | |||
| String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID | |||
| String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID | |||
| String couponOrderIdStr = params.get(WxPayConstant.COUPON_ORDER_ID); // 券ID | |||
| @@ -298,11 +305,8 @@ public class PosController extends BaseController { | |||
| String errCode = retMap.get(WxPayConstant.ERR_CODE); | |||
| if(StringUtils.isBlank(errCode)) { | |||
| // 无异常信息,核销成功 | |||
| couponOrderService.sendInsideCouponVerifyMsg(tenantId, couponOrderId, buUserId); | |||
| couponOrderService.sendInsideCouponVerifyMsg(tenantId, couponOrderId, buUserId, verifyType.getCode()); | |||
| } | |||
| return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", | |||
| WxPayConstant.RET_SUCCESS, null); | |||
| } | |||
| @ApiOperation(value = "券交易核销-单个优惠券接口", notes = "{" + | |||
| @@ -329,8 +333,6 @@ public class PosController extends BaseController { | |||
| try { | |||
| retMap = posService.couponOrderVerifyDo(params, EnumVerifyActionType.VERIFY_PAY); | |||
| return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", | |||
| WxPayConstant.RET_SUCCESS, null); | |||
| } catch (MallinkException e) { | |||
| return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", | |||
| WxPayConstant.RET_FAIL, | |||
| @@ -340,6 +342,10 @@ public class PosController extends BaseController { | |||
| WxPayConstant.RET_FAIL, | |||
| 500, e.getMessage()); | |||
| } | |||
| doActionAfterVerify(params, retMap, EnumCouponVerifyType.VERIFY_POS_PAY); | |||
| return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", | |||
| WxPayConstant.RET_SUCCESS, null); | |||
| } | |||
| @ApiOperation(value = "券交易核销-优惠券列表接口", notes = "{" + | |||
| @@ -367,8 +373,6 @@ public class PosController extends BaseController { | |||
| try { | |||
| retMap = posService.couponOrderVerifyListDo(params, EnumVerifyActionType.VERIFY_PAY); | |||
| return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", | |||
| WxPayConstant.RET_SUCCESS, null); | |||
| } catch (MallinkException e) { | |||
| return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", | |||
| WxPayConstant.RET_FAIL, | |||
| @@ -378,6 +382,41 @@ public class PosController extends BaseController { | |||
| WxPayConstant.RET_FAIL, | |||
| 500, e.getMessage()); | |||
| } | |||
| String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID | |||
| String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID | |||
| String arrString = retMap.get(WxPayConstant.RET); | |||
| Long buUserId; | |||
| try { | |||
| buUserId = Long.valueOf(buUserIdStr); | |||
| } catch (NumberFormatException e) { | |||
| logger.error(e.getMessage()); | |||
| return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", | |||
| WxPayConstant.RET_FAIL, | |||
| ErrorCode.SYS_PARAMETER_CAST_ERROR); | |||
| } | |||
| JSONArray couponArr = JSON.parseArray(arrString); | |||
| for (int i = 0;i < couponArr.size(); i++) { | |||
| String id = retMap.get(WxPayConstant.ID); | |||
| Long couponOrderId; | |||
| try { | |||
| couponOrderId = Long.valueOf(id); | |||
| } catch (NumberFormatException e) { | |||
| logger.error(e.getMessage()); | |||
| return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", | |||
| WxPayConstant.RET_FAIL, | |||
| ErrorCode.SYS_PARAMETER_CAST_ERROR); | |||
| } | |||
| String errCode = retMap.get(WxPayConstant.VERIFY); | |||
| if(errCode.equalsIgnoreCase("true")) { | |||
| // 核销成功 | |||
| couponOrderService.sendInsideCouponVerifyMsg(tenantId, couponOrderId, buUserId, EnumCouponVerifyType.VERIFY_POS_PAY.getCode()); | |||
| } | |||
| } | |||
| return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", | |||
| WxPayConstant.RET_SUCCESS, null); | |||
| } | |||
| @ApiOperation(value = "券核销取消", notes = "{" + | |||
| @@ -1032,6 +1032,8 @@ public class PosServiceImpl implements PosService { | |||
| throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), "updatete num " + num); | |||
| } | |||
| // TODO 成长值,必须等POS数据入库后才能继续 | |||
| // 3. 成长值 | |||
| try { | |||
| WxOrder order = orderMapper.selectByPrimaryKey(couponOrderCVo.getOrderId()); | |||
| @@ -16,4 +16,6 @@ public class FmInsideCouponVerifyMsg extends BaseMsg{ | |||
| private Long couponOrderId; | |||
| @io.swagger.annotations.ApiModelProperty(value = "B端用户ID", name = "bUserId") | |||
| private Long bUserId; | |||
| @io.swagger.annotations.ApiModelProperty(value = "核销类型()", name = "verifyType") | |||
| private Integer verifyType; | |||
| } | |||
| @@ -3,14 +3,16 @@ package com.iformall.enums; | |||
| /** | |||
| * Created by Stormeye on 2018/08/09. | |||
| */ | |||
| public enum EnumVerifyType { | |||
| public enum EnumCouponVerifyType { | |||
| YES(1, "是"), | |||
| NO(0, "否") | |||
| // 0: 微信B端核销 1:POS独立核销 2:POS交易核销 | |||
| VERIFY_B(0,"微信B端核销"), | |||
| VERIFY_POS_INDEPENDENT(1, "POS独立核销"), | |||
| VERIFY_POS_PAY(2, "POS交易核销"), | |||
| ; | |||
| public static EnumVerifyType getEnum(Integer code) { | |||
| for (EnumVerifyType value : values()) { | |||
| public static EnumCouponVerifyType getEnum(Integer code) { | |||
| for (EnumCouponVerifyType value : values()) { | |||
| if (value.getCode().equals(code)) { | |||
| return value; | |||
| } | |||
| @@ -21,7 +23,7 @@ public enum EnumVerifyType { | |||
| private Integer code; | |||
| private String message; | |||
| EnumVerifyType(Integer code, String message) { | |||
| EnumCouponVerifyType(Integer code, String message) { | |||
| this.code = code; | |||
| this.message = message; | |||
| } | |||
| @@ -57,7 +57,7 @@ public interface WxCouponOrderService { | |||
| /** | |||
| * 核销后发送消息 | |||
| */ | |||
| void sendInsideCouponVerifyMsg(String tenantId, Long couponOrderId, Long buUserId); | |||
| void sendInsideCouponVerifyMsg(String tenantId, Long couponOrderId, Long buUserId, Integer verifyType); | |||
| /** | |||
| * 核销后处理 | |||
| @@ -65,7 +65,7 @@ public interface WxCouponOrderService { | |||
| * @param couponOrder | |||
| * @param bUser 核销人(登录用户) | |||
| */ | |||
| void actionAfterVerify(WxCouponOrder couponOrder, WxMerchantBUser bUser); | |||
| void actionAfterVerify(WxCouponOrder couponOrder, WxMerchantBUser bUser, Integer verifyType); | |||
| /** | |||
| * 核销发券 | |||
| @@ -387,17 +387,18 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| } | |||
| @Override | |||
| public void sendInsideCouponVerifyMsg(String tenantId, Long couponOrderId, Long buUserId) { | |||
| public void sendInsideCouponVerifyMsg(String tenantId, Long couponOrderId, Long buUserId, Integer verifyType) { | |||
| FmInsideCouponVerifyMsg verifyMsg = new FmInsideCouponVerifyMsg(); | |||
| verifyMsg.setMsgType(EnumMsgRecordType.INSIDE_COUPON_VERIFY.getCode()); | |||
| verifyMsg.setTenantId(tenantId); | |||
| verifyMsg.setCouponOrderId(couponOrderId); | |||
| verifyMsg.setBUserId(buUserId); | |||
| verifyMsg.setVerifyType(verifyType); | |||
| mqBaseProducer.sendMessage(verifyMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| } | |||
| @Override | |||
| public void actionAfterVerify(WxCouponOrder couponOrder, WxMerchantBUser bUser) { | |||
| public void actionAfterVerify(WxCouponOrder couponOrder, WxMerchantBUser bUser, Integer verifyType) { | |||
| try { | |||
| // 核销分账 | |||
| shareAfterVerify(couponOrder, bUser.getMerchantId()); | |||
| @@ -415,10 +416,14 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| boolean bSentCoupon = false; | |||
| // 核销发券 | |||
| try { | |||
| bSentCoupon = sendCouponAfterVerify(couponOrder, bUser); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| // POS交易核销暂不发券 | |||
| if (verifyType.equals(EnumCouponVerifyType.VERIFY_B.getCode()) || | |||
| verifyType.equals(EnumCouponVerifyType.VERIFY_POS_INDEPENDENT.getCode())) { | |||
| try { | |||
| bSentCoupon = sendCouponAfterVerify(couponOrder, bUser); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| } | |||
| // 核销发模板消息 | |||
| @@ -5,6 +5,7 @@ import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.msg.BaseMsg; | |||
| import com.iformall.domain.po.msg.FmInsideCouponVerifyMsg; | |||
| import com.iformall.domain.po.msg.FmInsideOrderSuccessMsg; | |||
| import com.iformall.enums.EnumCouponVerifyType; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.*; | |||
| import com.iformall.service.msg.MsgSendService; | |||
| @@ -43,6 +44,11 @@ public class FmInsideCouponVerifyMsgServiceImpl implements MsgSendService { | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), "用户未找到" + msg.getBUserId()); | |||
| } | |||
| couponOrderService.actionAfterVerify(couponOrder, user); | |||
| Integer verifyType = msg.getVerifyType(); | |||
| if (verifyType == null) { | |||
| verifyType = EnumCouponVerifyType.VERIFY_B.getCode(); | |||
| } | |||
| couponOrderService.actionAfterVerify(couponOrder, user, verifyType); | |||
| } | |||
| } | |||