diff --git a/mallinkAdmin/src/main/resources/db/migration/V201909031540__POS_CARD_SPEND.sql b/mallinkAdmin/src/main/resources/db/migration/V201909031540__POS_CARD_SPEND.sql new file mode 100644 index 000000000..bd6fc778a --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V201909031540__POS_CARD_SPEND.sql @@ -0,0 +1,3 @@ +ALTER TABLE `wx_card_spend` +change `from` `pay_from` tinyint(6) NOT NULL DEFAULT '0' COMMENT '来源(0:C端小程序扫一扫, 1:POS)', +drop column `pos_refund_status`; \ No newline at end of file diff --git a/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java b/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java index bf200b8d9..91e412902 100644 --- a/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java +++ b/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java @@ -229,82 +229,6 @@ public class PosController extends BaseController { return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",null); } - /* - private Map couponOrderPayVerify(@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.VERIFY_PAY); - } 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()); - } - - doActionAfterVerify(params, retMap); - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null); - } - - private Map couponOrderPayVerifyList(@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.couponOrderVerifyListDo(params, EnumPosActionType.VERIFY_PAY); - } 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()); - } - - 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, "", 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, "", ErrorCode.SYS_PARAMETER_CAST_ERROR); - } - String errCode = retMap.get(WxPayConstant.VERIFY); - if(errCode.equalsIgnoreCase(WxPayConstant.TRUE)) { - // 核销成功 - couponOrderService.sendInsideCouponVerifyMsg(tenantId, couponOrderId, buUserId); - } - } - - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null); - } - @ApiOperation(value = "消费卡预支付", notes = "{" + "\"dev_id\":\"string(必填)\"," + "\"nonce_str\":\"string(必填)\"," + @@ -318,6 +242,7 @@ public class PosController extends BaseController { @SystemControllerLog(description = "消费卡预支付") public Map cardPayPre(@RequestBody Map params) { JSONObject payContent = new JSONObject(); + JSONObject retObj = new JSONObject(); // 1. check sign Map retMap = checkSign(params, payContent); @@ -329,12 +254,12 @@ public class PosController extends BaseController { logger.info(WxPayConstant.RES_KEY + ": " + resKey); try { - retMap = posService.cardPayPre(params); - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null); + retObj = posService.cardPayPre(params); + return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",null); } catch (MallinkException e) { - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", e.getErrorCode(), e.getMessage()); + return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", e.getErrorCode(), e.getMessage()); } catch (Exception e) { - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", 500, e.getMessage()); + return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", 500, e.getMessage()); } } @@ -352,52 +277,7 @@ public class PosController extends BaseController { @SystemControllerLog(description = "消费卡预支付取消") public Map cardPayPreCancel(@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.cardPayPreCancel(params); - 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()); - } - } - - private Map cardPay(@RequestBody Map params) { - JSONObject retObj = new JSONObject(); - 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 { - retObj = posService.cardPay(params); - return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", null); - } catch (MallinkException e) { - return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", e.getErrorCode(), e.getMessage()); - } catch (Exception e) { - return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", 500, e.getMessage()); - } - } - - private Map cardPayCancel(@RequestBody Map params) { JSONObject retObj = new JSONObject(); - JSONObject payContent = new JSONObject(); // 1. check sign Map retMap = checkSign(params, payContent); @@ -409,15 +289,14 @@ public class PosController extends BaseController { logger.info(WxPayConstant.RES_KEY + ": " + resKey); try { - retMap = posService.cardPayCancel(params); + retObj = posService.cardPayPreCancel(params); return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",null); } catch (MallinkException e) { return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", e.getErrorCode(), e.getMessage()); } catch (Exception e) { - return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", 500, e.getMessage()); + return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",500, e.getMessage()); } } - */ /** * 构造返回map,无签名, 有错误 diff --git a/mallinkPosApi/src/main/java/com/iformall/service/PosService.java b/mallinkPosApi/src/main/java/com/iformall/service/PosService.java index 787d9ebd5..65d640e5e 100644 --- a/mallinkPosApi/src/main/java/com/iformall/service/PosService.java +++ b/mallinkPosApi/src/main/java/com/iformall/service/PosService.java @@ -44,7 +44,7 @@ public interface PosService { * @return * @throws MallinkException */ - //Map cardPayPre(Map params) throws MallinkException; + JSONObject cardPayPre(Map params) throws MallinkException; /** * 消费卡POS预支付取消 @@ -52,7 +52,7 @@ public interface PosService { * @return * @throws MallinkException */ - //Map cardPayPreCancel(Map params) throws MallinkException; + JSONObject cardPayPreCancel(Map params) throws MallinkException; /** * 订单同步-Neusoft-支付或者退款成功后通知富茂 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 f141d8909..20c1d0c2f 100644 --- a/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java +++ b/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java @@ -348,18 +348,6 @@ public class PosServiceImpl implements PosService { return dataMap; } - private boolean isSelCoupon(JSONArray selCoArr, Long couponOrderId) { - boolean selCoupon = false; - for (int j=0;j cardPayPre(Map params) throws MallinkException { - Map retMap = new HashMap<>(); + public JSONObject cardPayPre(Map params) throws MallinkException { + JSONObject retMap = new JSONObject(); String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID - String posAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单总额(单位:分) + String posAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单总额(单位:分) String cardIdStr = params.get(WxPayConstant.CARD_ID); // 消费卡ID if (StringUtils.isBlank(tenantId)) { @@ -1798,7 +1786,7 @@ public class PosServiceImpl implements PosService { throw new MallinkException(ErrorCode.CARD_REMAIN_AMOUNT_IS_NOT_ENOUGH); } WxCardSpend record = new WxCardSpend(); - record.setFrom(EnumCardSpendFrom.POS.getCode()); + record.setPayFrom(EnumCardSpendFrom.POS.getCode()); record.setTenantId(merchant.getTenantId()); record.setCardId(cardId); record.setOwnerId(couponOrder.getOwnerId()); @@ -1825,10 +1813,10 @@ public class PosServiceImpl implements PosService { return retMap; } - //@Override + @Override @Transactional(rollbackFor = Exception.class) - public Map cardPayPreCancel(@RequestBody Map params) throws MallinkException { - Map retMap = new HashMap<>(); + public JSONObject cardPayPreCancel(@RequestBody Map params) throws MallinkException { + JSONObject retMap = new JSONObject(); String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID @@ -1934,129 +1922,6 @@ public class PosServiceImpl implements PosService { return retMap; } - //@Override - @Transactional(rollbackFor = Exception.class) - public Map cardPay(Map params) throws MallinkException { - return null; - } - - //@Override - @Transactional(rollbackFor = Exception.class) - public Map cardPayCancel(Map params) throws MallinkException { - Map retMap = new HashMap<>(); - - String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID - String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID - String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID - String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID - String posAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单总额(单位:分) - String cardIdStr = params.get(WxPayConstant.CARD_ID); // 消费卡ID - String cardSpendIdStr = params.get(WxPayConstant.CARD_SPEND_ID); // 消费卡花费ID - - if (StringUtils.isBlank(tenantId)) { - errParam(WxPayConstant.TENANT_ID); - } - PosMallConfig config = posMallConfigService.getByTenantId(tenantId); - if (config == null) { - logger.error(ErrorCode.POS_CONFIG_NOT_FOUND.getMessage()); - throw new MallinkException(ErrorCode.POS_CONFIG_NOT_FOUND); - } - if (!config.getCard().equals(EnumEnableType.Enable.getCode())) { - logger.error(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE.getMessage()); - throw new MallinkException(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE); - } - if (StringUtils.isBlank(merchantIdStr)) { - errParam(WxPayConstant.MERCHANT_ID); - } - if (StringUtils.isBlank(buUserIdStr)) { - errParam(WxPayConstant.BUSER_ID); - } - if (StringUtils.isBlank(posOrderIdStr)) { - errParam(WxPayConstant.POS_ORDER_ID); - } - if (StringUtils.isBlank(posAmountStr)) { - errParam(WxPayConstant.ORDER_AMOUNT); - } - if (StringUtils.isBlank(cardIdStr)) { - errParam(WxPayConstant.CARD_ID); - } - if (StringUtils.isBlank(cardSpendIdStr)) { - errParam(WxPayConstant.CARD_SPEND_ID); - } - - Long merchantId, buUserId, posOrderId, cardId, cardSpendId; - Integer posAmount = 0; - try { - merchantId = Long.valueOf(merchantIdStr); - buUserId = Long.valueOf(buUserIdStr); - posOrderId = Long.valueOf(posOrderIdStr); - posAmount = Integer.valueOf(posAmountStr); - cardId = Long.valueOf(cardIdStr); - cardSpendId = Long.valueOf(cardSpendIdStr); - } catch (NumberFormatException e) { - logger.error(e.getMessage()); - throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); - } - WxCardInfo cardInfo = cardInfoService.getById(cardId); - if(cardInfo == null) { - String errMessage = "卡不存在: " + cardIdStr; - logger.error(errMessage); - throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND.getCode(), errMessage); - } - WxCouponMerchant couponMerchant = cardSpendService.checkMerchantInCoupon(cardInfo, merchantId); - if(couponMerchant == null) { - String errMessage = "商户不支持此卡 " + cardIdStr; - logger.error(errMessage); - throw new MallinkException(ErrorCode.COUPON_ORDER_MERANT_IS_NULL.getCode(), errMessage); - } - // 2. check merchant - WxMerchant merchant = merchantService.getById(merchantId); - if (merchant == null) { - logger.error(ErrorCode.MERCHANT_INFO_NOT_FOUND.getMessage() + ": " + merchantIdStr); - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); - } - if (merchant.getIsDel().equals(EnumDelStatus.DEL.getCode()) || merchant.getStatus().equals(EnumMerchantStatus.NOT_VALID.getCode())) { - logger.error(ErrorCode.MERCHANT_INFO_NOT_VALID.getMessage() + ": " + merchantIdStr); - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID); - } - // 3. check buUser - WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId); - - WxCouponOrder couponOrder = couponOrderService.getById(cardId); - if(couponOrder == null) { - logger.error("卡不存在: " + cardIdStr); - throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); - } - - WxCardSpend record = cardSpendService.getById(cardSpendId); - if (record == null) { - logger.error(ErrorCode.CARD_SPEND_IS_NOT_FOUND.getMessage() + ": " + cardSpendIdStr); - throw new MallinkException(ErrorCode.CARD_SPEND_IS_NOT_FOUND); - } - if (!record.getPayStatus().equals(EnumCardSpendStatus.PREV_PAY.getCode())) { - logger.error(ErrorCode.POS_CAR_PAY_NOT_CANCEL.getMessage()); - throw new MallinkException(ErrorCode.POS_CAR_PAY_NOT_CANCEL); - } - - try { - WxCardInfo updateCardInfo = cardSpendService.cardSpendForPosPrePayCancel(cardInfo, record); - JSONObject retObj = new JSONObject(); - retObj.put(WxPayConstant.CARD_ID, cardId); - retObj.put(WxPayConstant.ORG_REMAIN_AMOUNT, cardInfo.getRemainingAmount()); - retObj.put(WxPayConstant.REMAIN_AMOUNT, updateCardInfo.getRemainingAmount()); - retObj.put(WxPayConstant.CANCEL, WxPayConstant.TRUE); - retMap.put(WxPayConstant.RET, JSON.toJSONString(retObj)); - } catch (MallinkException e) { - logger.error("card spend error, req 2: " + record.toString() + ", e:" + e.getMessage()); - throw new MallinkException(e.getErrorCode(), e.getMessage()); - } catch (Exception e) { - logger.error("card spend error, req 3: " + record.toString() + ", e:" + e.getMessage()); - throw new MallinkException(500, e.getMessage()); - } - - return retMap; - } - @Override @Transactional(rollbackFor = Exception.class) public JSONObject posOrderSync(Map params) throws MallinkException { @@ -2461,6 +2326,24 @@ public class PosServiceImpl implements PosService { return buUser; } + /** + * 券是否在选择列表中 + * @param selCoArr + * @param couponOrderId + * @return + */ + private boolean isSelCoupon(JSONArray selCoArr, Long couponOrderId) { + boolean selCoupon = false; + for (int j=0;j - - + - `id`,`tenant_id`,`card_id`,`owner_id`,`merchant_id`,`order_id`,`pos_order_id`,``deduction_amount`,`payment`,`real_payment`, - `card_remain_amount`,`card_before_amount`,`card_remain_real_amount`,`card_before_real_amount`, - `create_date`,`update_date`, `pay_status`, `from`, `pos_refund_status` + `id`,`tenant_id`,`card_id`,`owner_id`,`merchant_id`,`order_id`,`pos_order_id`, + `deduction_amount`,`payment`,`real_payment`, `card_remain_amount`, + `card_before_amount`,`card_remain_real_amount`,`card_before_real_amount`, + `create_date`, `update_date`, `pay_status`, `pay_from` @@ -82,11 +82,8 @@ and `pay_status` = #{payStatus} - - and `from` = #{from} - - - and `pos_refund_status` = #{posRefundStatus} + + and `pay_from` = #{payFrom} and `create_date` between #{startdate} and #{enddate}