From 6abc407b510f3fa09e891cc76f679852d54cd903 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Tue, 3 Sep 2019 15:13:18 +0800 Subject: [PATCH] =?UTF-8?q?[POS][=E4=BF=AE=E6=94=B9]:=E5=88=B8=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E6=A0=B8=E9=94=80=E5=90=8E=E7=BB=99=E6=88=90=E9=95=BF?= =?UTF-8?q?=E5=80=BC=E7=A7=AF=E5=88=86=E7=A7=BB=E5=88=B0=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iformall/controller/PosController.java | 79 ++----------------- .../iformall/service/impl/PosServiceImpl.java | 65 +++++++-------- 2 files changed, 33 insertions(+), 111 deletions(-) diff --git a/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java b/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java index 8c946dcb3..bf200b8d9 100644 --- a/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java +++ b/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java @@ -167,15 +167,15 @@ public class PosController extends BaseController { "\"mem_phone_number\":\"string(选填)\"," + "\"business_type\":\"string(0:核销1支付(必填)\"," + "\"order_number_of_platform\":\"string(必填)\"," + - "\"order_amount\":\"string单位(分)(必填)\"," + - "\"order_amount_left\":\"string单位(分)(必填)\"," + + "\"order_amount\":\"string单位(分)(选填)\"," + + "\"order_amount_left\":\"string单位(分)(选填)\"," + "\"order_create_sn\":\"string单位(分)(必填)\"," + "\"payment_info\":{" + "\"coupon_id\":\"string(必填)\"," + - "\"order_amount\":\"string单位(分)(必填)\"," + - "\"amount_left\":\"string单位(分)(必填)\"," + - "\"promotion_amount\":\"string单位(分)(必填)\"," + - "\"amount_left_after_pay\":\"string单位(分)(必填)\"" + + "\"order_amount\":\"string单位(分)(选填)\"," + + "\"amount_left\":\"string单位(分)(选填)\"," + + "\"promotion_amount\":\"string单位(分)(选填)\"," + + "\"amount_left_after_pay\":\"string单位(分)(选填)\"" + "}}") @PostMapping("/couponOrderVerifyCancel") @SystemControllerLog(description = "券核销取消") @@ -201,73 +201,6 @@ public class PosController extends BaseController { return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",500, e.getMessage()); } } - /* - @ApiOperation(value = "POS支付-券", notes = "{" + - "\"dev_id\":\"string(必填)\"," + - "\"nonce_str\":\"string(必填)\"," + - "\"tenant_id\":\"string(必填)\"," + - "\"merchant_id\":\"string(必填)\"," + - "\"bu_user_id\":\"string(必填)\"," + - "\"sel_co_list\":\"json array[券包ID list](必填),例[\"1\",\"2\",\"3\"]\"" + - "\"pos_order_id\":\"string(必填)\"," + - "\"pos_amount\":\"string(必填)\"}") - @PostMapping("/couponOrderPay") - @SystemControllerLog(description = "POS支付-券") - public Map couponOrderPay(@RequestBody Map params) { - JSONObject payContent = new JSONObject(); - - // 1. check sign - Map retMap = checkSign(params, payContent); - if (retMap != null) { - // 签名相关异常返回 - return retMap; - } - String resKey = payContent.getString(WxPayConstant.RES_KEY); - logger.info(WxPayConstant.RES_KEY + ": " + resKey); - - try { - //retMap = posService.couponOrderVerifyDo(params, EnumPosActionType.PAY_VERIFY_PRE); - //return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null); - } catch (MallinkException e) { - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", e.getErrorCode(), e.getMessage()); - } catch (Exception e) { - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",500, e.getMessage()); - } - return null; - } - - @ApiOperation(value = "POS支付取消-券", notes = "{" + - "\"dev_id\":\"string(必填)\"," + - "\"tenant_id\":\"string(必填)\"," + - "\"merchant_id\":\"string(必填)\"," + - "\"bu_user_id\":\"string(必填)\"," + - "\"coupon_order_id\":\"string(必填)\" +" + - "\"nonce_str\":\"string(必填)\" +" + - "\"pos_order_id\":\"string(必填)\" }") - @PostMapping("/couponOrderPayCancel") - @SystemControllerLog(description = "POS支付取消-券") - public Map couponOrderPayCancel(@RequestBody Map params) { - JSONObject payContent = new JSONObject(); - - // 1. check sign - Map retMap = checkSign(params, payContent); - if (retMap != null) { - // 签名相关异常返回 - return retMap; - } - String resKey = payContent.getString(WxPayConstant.RES_KEY); - logger.info(WxPayConstant.RES_KEY + ": " + resKey); - - try { - retMap = posService.couponOrderVerifyCancel(params, EnumPosActionType.PAY_VERIFY_PRE_CANCEL); - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null); - } catch (MallinkException e) { - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", e.getErrorCode(), e.getMessage()); - } catch (Exception e) { - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",500, e.getMessage()); - } - } - */ @ApiOperation(value = "POS订单同步", notes = "支付成功/支付取消后订单同步") @PostMapping("/posOrderSync") diff --git a/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java b/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java index 97e90ef82..f141d8909 100644 --- a/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java +++ b/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java @@ -21,7 +21,6 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RequestBody; -import springfox.documentation.spring.web.json.Json; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -894,19 +893,9 @@ public class PosServiceImpl implements PosService { logger.error(errMessage); throw new MallinkException(ErrorCode.POS_COUPON_PAY_ERROR.getCode(), errMessage); } - for (int i = 0; i < avaCoList.size(); i++) { - WxCouponOrderCVo couponOrderCVo = avaCoList.get(i); - boolean selCoupon = isSelCoupon(selCoArr, couponOrderCVo.getId()); - try { - JSONObject couponObj = oneCouponPay(promotionCalc, couponOrderCVo, merchantId, buUserId, posOrderId, selCoupon); - couponList.add(couponObj); - } catch (MallinkException e) { - throw new MallinkException(e.getErrorCode(), e.getMessage()); - } catch (Exception e) { - throw new MallinkException(500, e.getMessage()); - } - } - } else if (config.getCoupon().equals(EnumPosCouponEnableType.MultiEnable.getCode())) { + } + if (config.getCoupon().equals(EnumPosCouponEnableType.SingleEnable.getCode()) || + config.getCoupon().equals(EnumPosCouponEnableType.MultiEnable.getCode())) { for (int i = 0; i < avaCoList.size(); i++) { WxCouponOrderCVo couponOrderCVo = avaCoList.get(i); boolean selCoupon = isSelCoupon(selCoArr, couponOrderCVo.getId()); @@ -1520,13 +1509,7 @@ public class PosServiceImpl implements PosService { posCouponOrderVerify = posCouponOrderVerifyList.get(0); if(posCouponOrderVerify != null) { try { - PosCouponOrderVerify updateCouponOrderVerify = new PosCouponOrderVerify(); - updateCouponOrderVerify.setId(posCouponOrderVerify.getId()); - updateCouponOrderVerify.setTenantId(posCouponOrderVerify.getTenantId()); - updateCouponOrderVerify.setState(EnumEnableType.Disable.getCode()); - updateCouponOrderVerify.setUpdateDate(new Date()); - posCouponOrderVerifyService.saveOrUpdate(updateCouponOrderVerify); - // posCouponOrderVerifyService.deleteById(posCouponOrderVerify.getId()); + posCouponOrderVerifyService.deleteById(posCouponOrderVerify.getId()); } catch (Exception e) { logger.error("db failed: couponOrder-" + couponOrderCVo.getId() + ", e:" + e.getMessage()); throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); @@ -1606,23 +1589,6 @@ public class PosServiceImpl implements PosService { logger.error("核销异常:update num " + num); throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), "updatete num " + num); } - - // 3. 成长值 - try { - WxOrder order = orderMapper.selectByPrimaryKey(couponOrderCVo.getOrderId()); - int point = scoreRulesService.addScore2(EnumScoreType.CONSUMPTION, order, couponOrderCVo.getBusinessId()); - retMap.put(WxPayConstant.POINT, point); - } catch (Exception e) { - logger.error("核销成长值异常:" + e.getMessage()); - } - - // 4. 积分 - int credit = posAddCredit(couponOrderCVo, coupon, merchantId, buUserId); - if (credit > 0) { - retMap.put(WxPayConstant.CREDIT, credit); - } else { - retMap.put(WxPayConstant.CREDIT, 0); - } logger.info("核销已完成: " + couponOrderCVo.getId()); } @@ -2335,6 +2301,29 @@ public class PosServiceImpl implements PosService { updateCO.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); couponOrderMapper.updateByPrimaryKeySelective(updateCO); } + WxCouponOrderCVo couponOrderCVo = couponOrderService.detailCUserVo(posPayOrderNo); + if (couponOrderCVo != null) { + // 3. 成长值 + try { + WxOrder scoreOrder = orderMapper.selectByPrimaryKey(couponOrderCVo.getOrderId()); + int point = scoreRulesService.addScore2(EnumScoreType.CONSUMPTION, scoreOrder, couponOrderCVo.getBusinessId()); + } catch (Exception e) { + logger.error("交易核销成长值异常:" + e.getMessage()); + } + + 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); + } + + // 4. 积分 + try { + int credit = posAddCredit(couponOrderCVo, wxCoupon, merchantBUser.getMerchantId(), merchantBUser.getId()); + } catch (Exception e) { + logger.error("交易核销积分异常:" + e.getMessage()); + } + } // 3. 核销后处理 couponOrderService.sendInsideCouponVerifyMsg(merchantBUser.getTenantId(), couponOrderId, merchantBUser.getId()); return payOrder;