| @@ -520,7 +520,7 @@ public class PosServiceImpl implements PosService { | |||
| * @param couponSelected | |||
| * @return | |||
| */ | |||
| private JSONObject oneCouponPay(PromotionCalc promotionCalc, WxCouponOrderCVo couponOrderCVo, boolean couponSelected) { | |||
| private JSONObject oneCouponPay(PromotionCalc promotionCalc, WxCouponOrderCVo couponOrderCVo, Long merchantId, Long buUserId, Long posOrderId, boolean couponSelected) { | |||
| JSONObject retObj = new JSONObject(); | |||
| Date now = new Date(); | |||
| @@ -534,7 +534,7 @@ public class PosServiceImpl implements PosService { | |||
| } | |||
| // 3. 满减券检查使用金额 | |||
| if (couponType.equals(EnumCouponType.COUPON_MANJIAN)) { | |||
| if (couponType.equals(EnumCouponType.COUPON_MANJIAN) && couponSelected) { | |||
| if (promotionCalc.getOrderAmount() < couponOrderCVo.getUsePrice()) { | |||
| logger.error(ErrorCode.VERIFY_MANJIAN_USER_PRICE_NOT_TOUCH.getMessage()); | |||
| throw new MallinkException(ErrorCode.VERIFY_MANJIAN_USER_PRICE_NOT_TOUCH); | |||
| @@ -561,6 +561,21 @@ public class PosServiceImpl implements PosService { | |||
| retObj.put(WxPayConstant.COUPON_DES, des); | |||
| } | |||
| if (couponSelected) { | |||
| // 5. get coupon | |||
| WxCoupon wxCoupon = couponMapper.selectByPrimaryKey(couponOrderCVo.getCouponId()); | |||
| if (wxCoupon == null) { | |||
| logger.error("券: coupon-" + wxCoupon.getId() + "不存在" + "couponOrder-" + couponOrderCVo.getId()); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| } | |||
| try { | |||
| doVerify(retObj, EnumPosActionType.VERIFY_PAY, couponOrderCVo, wxCoupon, merchantId, buUserId, posOrderId); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(e.getErrorCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(500, e.getMessage()); | |||
| } | |||
| retObj.put(WxPayConstant.IS_SELECTED, String.valueOf(EnumPosSelect.SELECTED.getCode())); | |||
| Integer remainAmount = promotionCalc.getAmountLeftAfterPay() - couponOrderCVo.getPrice(); | |||
| if (remainAmount < 0) { | |||
| @@ -883,7 +898,7 @@ public class PosServiceImpl implements PosService { | |||
| WxCouponOrderCVo couponOrderCVo = avaCoList.get(i); | |||
| boolean selCoupon = isSelCoupon(selCoArr, couponOrderCVo.getId()); | |||
| try { | |||
| JSONObject couponObj = oneCouponPay(promotionCalc, couponOrderCVo, selCoupon); | |||
| JSONObject couponObj = oneCouponPay(promotionCalc, couponOrderCVo, merchantId, buUserId, posOrderId, selCoupon); | |||
| couponList.add(couponObj); | |||
| } catch (MallinkException e) { | |||
| throw new MallinkException(e.getErrorCode(), e.getMessage()); | |||
| @@ -896,7 +911,7 @@ public class PosServiceImpl implements PosService { | |||
| WxCouponOrderCVo couponOrderCVo = avaCoList.get(i); | |||
| boolean selCoupon = isSelCoupon(selCoArr, couponOrderCVo.getId()); | |||
| try { | |||
| JSONObject couponObj = calcOneCouponPay(promotionCalc, couponOrderCVo, selCoupon); | |||
| JSONObject couponObj = oneCouponPay(promotionCalc, couponOrderCVo, merchantId, buUserId, posOrderId, selCoupon); | |||
| couponList.add(couponObj); | |||
| } catch (MallinkException e) { | |||
| throw new MallinkException(e.getErrorCode(), e.getMessage()); | |||
| @@ -1569,18 +1584,16 @@ public class PosServiceImpl implements PosService { | |||
| WxCouponOrder couponOrder = new WxCouponOrder(); | |||
| couponOrder.setId(couponOrderCVo.getId()); | |||
| couponOrder.setTenantId(couponOrderCVo.getTenantId()); | |||
| couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); //1核销 | |||
| if (actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) { | |||
| couponOrder.setVerifyType(EnumCouponVerifyType.VERIFY_POS_INDEPENDENT.getCode()); | |||
| couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); | |||
| } else { | |||
| couponOrder.setVerifyType(EnumCouponVerifyType.VERIFY_POS_PAY.getCode()); | |||
| couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode()); | |||
| } | |||
| if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode()) && | |||
| actionType.equals(EnumPosActionType.VERIFY_PAY)) { | |||
| couponOrder.setBUserId(buUserId); | |||
| } | |||
| couponOrder.setBUserId(buUserId); | |||
| couponOrder.setUpdateDate(curDate); | |||
| if (couponOrder.getBUserId() == null) { | |||
| if (couponOrderCVo.getBUserId() == null) { | |||
| num = couponOrderMapper.updateVerifyCouponOrder(couponOrder); | |||
| } else { | |||
| num = couponOrderMapper.updateVerifyCouponOrderStatus(couponOrder); | |||
| @@ -2317,7 +2330,10 @@ public class PosServiceImpl implements PosService { | |||
| Long couponOrderId = Long.valueOf(posPayOrderNo); | |||
| // 2. 预核销->核销 | |||
| if (sceneType.equals(EnumPosSceneType.PAY.getCode())) { | |||
| // TODO | |||
| WxCouponOrder updateCO = new WxCouponOrder(); | |||
| updateCO.setId(couponOrderId); | |||
| updateCO.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); | |||
| couponOrderMapper.updateByPrimaryKeySelective(updateCO); | |||
| } | |||
| // 3. 核销后处理 | |||
| couponOrderService.sendInsideCouponVerifyMsg(merchantBUser.getTenantId(), couponOrderId, merchantBUser.getId()); | |||
| @@ -330,6 +330,83 @@ public class PosAppTest { | |||
| Assert.assertEquals(resSigned, true); | |||
| } | |||
| @Test | |||
| public void payVerifyTest() throws Exception { | |||
| String memId = "321178010928119808"; | |||
| String memPhone = "13910154397"; | |||
| String posOrderId = "2"; | |||
| String orderAmount = "1000"; | |||
| String selCoList = "[\"321878223800205312\"]"; | |||
| String sceneType = String.valueOf(EnumPosSceneType.PAY.getCode()); | |||
| Map<String, String> reqObj = new HashMap<>(); | |||
| reqObj.put(WxPayConstant.NONCE_STR, "1"); | |||
| reqObj.put(WxPayConstant.DEV_ID, devId); | |||
| reqObj.put(WxPayConstant.TENANT_ID, tenantId); | |||
| reqObj.put(WxPayConstant.MERCHANT_ID, merchantId); | |||
| reqObj.put(WxPayConstant.BUSER_ID, buUserId); | |||
| reqObj.put(WxPayConstant.MEM_ID, memId); | |||
| reqObj.put(WxPayConstant.MEM_PHONE, memPhone); | |||
| reqObj.put(WxPayConstant.SCENE_TYPE, sceneType); | |||
| reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); | |||
| reqObj.put(WxPayConstant.ORDER_AMOUNT, orderAmount); | |||
| reqObj.put(WxPayConstant.ORDER_AMOUNT_LEFT, orderAmount); | |||
| reqObj.put(WxPayConstant.ORDER_CREATE_SN, posSN); | |||
| reqObj.put(WxPayConstant.COUPON_ORDER_LIST, selCoList); | |||
| boolean resSigned = sendAndRes("/couponOrderVerify", reqObj); | |||
| Assert.assertEquals(resSigned, true); | |||
| } | |||
| @Test | |||
| public void payVerifySyncTest() throws Exception { | |||
| String memId = "321178010928119808"; | |||
| String memPhone = "13910154397"; | |||
| String sceneType = "1"; // 支付 | |||
| String posOrderId = "2"; | |||
| String orderAmount = "1000"; | |||
| String posPayOrderId = "2"; | |||
| String posPaymentType = "4"; | |||
| String posPaymentTypeDes = "优惠券"; | |||
| String posPaymentStatus = "0"; | |||
| String couponOrderId = "321878223800205312"; | |||
| Date curDate = new Date(); | |||
| Map<String, String> payDetailOne = new HashMap<>(); | |||
| payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_ID, posPayOrderId); | |||
| payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_TIME, neuDateFormat.format(curDate)); | |||
| payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_TYPE, posPaymentType); | |||
| payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_TYPE_DES, posPaymentTypeDes); | |||
| payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_PARAM, "{}"); | |||
| payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_STATUS, posPaymentStatus); | |||
| payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_OUT_NO, couponOrderId); | |||
| payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_AMOUNT, orderAmount); | |||
| payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_OUT_TIME, neuDateFormat.format(curDate)); | |||
| JSONArray payDetailList = new JSONArray(); | |||
| payDetailList.add(payDetailOne); | |||
| Map<String, String> reqObj = new HashMap<>(); | |||
| reqObj.put(WxPayConstant.NONCE_STR, "1"); | |||
| reqObj.put(WxPayConstant.DEV_ID, devId); | |||
| reqObj.put(WxPayConstant.NEU_TENANT_ID, tenantId); | |||
| reqObj.put(WxPayConstant.NEU_MERCHANT_ID, merchantId); | |||
| reqObj.put(WxPayConstant.NEU_BU_USER_ID, buUserId); | |||
| reqObj.put(WxPayConstant.NEU_MEM_ID, memId); | |||
| reqObj.put(WxPayConstant.NEU_MEM_PHONE, memPhone); | |||
| reqObj.put(WxPayConstant.NEU_ORDER_SCENE_TYPE, sceneType); | |||
| reqObj.put(WxPayConstant.NEU_ORDER_ID, posOrderId); | |||
| reqObj.put(WxPayConstant.NEU_ORDER_TIME, neuDateFormat.format(curDate)); | |||
| reqObj.put(WxPayConstant.NEU_ORDER_AMOUNT, orderAmount); | |||
| reqObj.put(WxPayConstant.NEU_ORDER_CREATE_SN, posSN); | |||
| reqObj.put(WxPayConstant.NEU_ORDER_STATUS, "0"); | |||
| JSONObject payDetail = new JSONObject(); | |||
| payDetail.put(WxPayConstant.NEU_PAY_DETAIL_LIST, JSON.toJSONString(payDetailList)); | |||
| reqObj.put(WxPayConstant.NEU_PAY_DETAIL, JSON.toJSONString(payDetail)); | |||
| boolean resSigned = sendAndRes("/posOrderSync", reqObj); | |||
| Assert.assertEquals(resSigned, true); | |||
| } | |||
| @Test | |||
| public void couponOrderPreVerifyTest() throws Exception { | |||
| String couponOrderId = "321877927162249216"; | |||
| @@ -792,7 +792,7 @@ | |||
| <sql id="allCUserCouponOrderListColumns"> | |||
| co.id,co.coupon_id,co.coupon_type,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price,co.verify_type, | |||
| co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price,co.verify_type, | |||
| c.cover_img,c.title,c.sub_title,c.sale_price,c.use_price,c.price,c.unit,c.valid_start_date,c.valid_end_date,c.auto_refund, | |||
| cal.channel_type as send_channel_type | |||
| </sql> | |||
| @@ -877,31 +877,29 @@ | |||
| </select> | |||
| <select id="findAvailCouponOrder" parameterType="java.util.Map" resultMap="CVoResultMap"> | |||
| select <include refid="allCUserCouponOrderListColumns" /> | |||
| select <include refid="allCUserCouponOrderDetailColumns" /> | |||
| from wx_coupon_order co | |||
| left join wx_coupon_merchant cm on cm.product_id = co.coupon_id | |||
| left join wx_coupon c on c.id = co.coupon_id | |||
| left join wx_coupon_action_log cal on cal.coupon_order_id = co.id | |||
| inner join wx_coupon c on c.id = co.coupon_id | |||
| inner join wx_coupon_merchant cm on cm.product_id = co.coupon_id | |||
| where co.tenant_id = #{tenantId} and co.c_user_id = #{cUserId} | |||
| and co.coupon_order_status = 0 | |||
| and cm.merchant_id = #{merchantId} | |||
| and co.expired_time > now() | |||
| and c.type in (1, 2, 6) | |||
| union | |||
| select <include refid="allCUserCouponOrderListColumns" /> | |||
| select <include refid="allCUserCouponOrderDetailColumns" /> | |||
| from wx_coupon_order co | |||
| left join wx_coupon_merchant cm on cm.product_id = co.coupon_id | |||
| left join wx_coupon c on c.id = co.coupon_id | |||
| left join wx_coupon_action_log cal on cal.coupon_order_id = co.id | |||
| left join pos_coupon_order_verify pco on pco.coupon_order_id = co.id | |||
| inner join wx_coupon c on c.id = co.coupon_id | |||
| inner join wx_coupon_merchant cm on cm.product_id = co.coupon_id | |||
| inner join pos_coupon_order_verify pco on pco.coupon_order_id = co.id | |||
| where co.tenant_id = #{tenantId} and co.c_user_id = #{cUserId} | |||
| and co.coupon_order_status = 100 | |||
| and cm.merchant_id = #{merchantId} | |||
| and co.expired_time > now() | |||
| and c.type in (1, 2, 6) | |||
| <if test="posOrderId != null"> | |||
| and pco.pos_order_id = #{posOrderId} | |||
| </if> | |||
| and c.type in (1, 2, 6) | |||
| </select> | |||
| <sql id="allCUserCouponOrderCarListColumns"> | |||