Просмотр исходного кода

[POS][修改]:券核销及券核销撤销接口调试

release_toaliyun_real
Stormeye Wu 6 лет назад
Родитель
Сommit
3d4b8043d8
5 измененных файлов: 157 добавлений и 93 удалений
  1. +28
    -15
      mallinkPosApi/src/main/java/com/iformall/controller/PosController.java
  2. +4
    -15
      mallinkPosApi/src/main/java/com/iformall/service/PosService.java
  3. +94
    -51
      mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java
  4. +23
    -12
      mallinkPosApi/src/test/java/com/iformall/pos/test/PosAppTest.java
  5. +8
    -0
      mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java

+ 28
- 15
mallinkPosApi/src/main/java/com/iformall/controller/PosController.java Просмотреть файл

@@ -1,7 +1,6 @@
package com.iformall.controller; package com.iformall.controller;


import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.iformall.annotation.SystemControllerLog; import com.iformall.annotation.SystemControllerLog;
import com.iformall.common.ErrorCode; import com.iformall.common.ErrorCode;
@@ -119,7 +118,6 @@ public class PosController extends BaseController {
} }
} }


/*
@ApiOperation(value = "优惠核销接口", notes = "{" + @ApiOperation(value = "优惠核销接口", notes = "{" +
"\"dev_id\":\"string(必填)\"," + "\"dev_id\":\"string(必填)\"," +
"\"nonce_str\":\"string(必填)\"," + "\"nonce_str\":\"string(必填)\"," +
@@ -138,6 +136,7 @@ public class PosController extends BaseController {
@SystemControllerLog(description = "优惠核销接口") @SystemControllerLog(description = "优惠核销接口")
public Map<String, String> couponOrderVerify(@RequestBody Map<String, String> params) { public Map<String, String> couponOrderVerify(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject(); JSONObject payContent = new JSONObject();
JSONObject retObj = new JSONObject();


// 1. check sign // 1. check sign
Map<String, String> retMap = checkSign(params, payContent); Map<String, String> retMap = checkSign(params, payContent);
@@ -149,16 +148,16 @@ public class PosController extends BaseController {
logger.info(WxPayConstant.RES_KEY + ": " + resKey); logger.info(WxPayConstant.RES_KEY + ": " + resKey);


try { try {
retMap = posService.couponOrderVerify(params);
retObj = posService.couponOrderVerify(params);
} catch (MallinkException e) { } 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) { } catch (Exception e) {
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", 500, e.getMessage());
return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", 500, e.getMessage());
} }
doActionAfterVerify(params, retMap);
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null);
return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",null);
} }


/*
private void doActionAfterVerify(Map<String, String> params, Map<String, String> retMap) { private void doActionAfterVerify(Map<String, String> params, Map<String, String> retMap) {
String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID
String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID
@@ -178,19 +177,33 @@ public class PosController extends BaseController {
couponOrderService.sendInsideCouponVerifyMsg(tenantId, couponOrderId, buUserId); couponOrderService.sendInsideCouponVerifyMsg(tenantId, couponOrderId, buUserId);
} }
} }
*/


@ApiOperation(value = "券核销取消", notes = "{" + @ApiOperation(value = "券核销取消", notes = "{" +
"\"dev_id\":\"string(必填)\"," + "\"dev_id\":\"string(必填)\"," +
"\"nonce_str\":\"string(必填)\"," + "\"nonce_str\":\"string(必填)\"," +
"\"tenant_id\":\"string(必填)\"," + "\"tenant_id\":\"string(必填)\"," +
"\"merchant_id\":\"string(必填)\"," + "\"merchant_id\":\"string(必填)\"," +
"\"bu_user_id\":\"string(必填)\"," +
"\"coupon_order_id\":\"string(必填)\"" +
"\"pos_order_id\":\"string(必填)\"}")
"\"order_operator_id\":\"string(必填)\"," +
"\"mem_id\":\"string(选填)\"," +
"\"mem_phone_number\":\"string(选填)\"," +
"\"business_type\":\"string(0:核销1支付(必填)\"," +
"\"order_number_of_platform\":\"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单位(分)(必填)\"" +
"}}")
@PostMapping("/couponOrderVerifyCancel") @PostMapping("/couponOrderVerifyCancel")
@SystemControllerLog(description = "券核销取消") @SystemControllerLog(description = "券核销取消")
public Map<String, String> couponOrderIndependentVerifyCancel(@RequestBody Map<String, String> params) { public Map<String, String> couponOrderIndependentVerifyCancel(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject(); JSONObject payContent = new JSONObject();
JSONObject retObj = new JSONObject();


// 1. check sign // 1. check sign
Map<String, String> retMap = checkSign(params, payContent); Map<String, String> retMap = checkSign(params, payContent);
@@ -202,15 +215,15 @@ public class PosController extends BaseController {
logger.info(WxPayConstant.RES_KEY + ": " + resKey); logger.info(WxPayConstant.RES_KEY + ": " + resKey);


try { try {
retMap = posService.couponOrderVerifyCancel(params, EnumPosActionType.VERIFY_CANCEL);
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null);
retObj = posService.couponOrderVerifyCancel(params);
return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",null);
} catch (MallinkException e) { } 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) { } catch (Exception e) {
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",500, e.getMessage());
return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",500, e.getMessage());
} }
} }
/*
@ApiOperation(value = "POS支付-券", notes = "{" + @ApiOperation(value = "POS支付-券", notes = "{" +
"\"dev_id\":\"string(必填)\"," + "\"dev_id\":\"string(必填)\"," +
"\"nonce_str\":\"string(必填)\"," + "\"nonce_str\":\"string(必填)\"," +


+ 4
- 15
mallinkPosApi/src/main/java/com/iformall/service/PosService.java Просмотреть файл

@@ -1,7 +1,6 @@
package com.iformall.service; package com.iformall.service;


import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.iformall.enums.EnumPosActionType;
import com.iformall.exception.MallinkException; import com.iformall.exception.MallinkException;


import java.util.Map; import java.util.Map;
@@ -24,30 +23,20 @@ public interface PosService {
JSONObject queryAndCalcMem(Map<String, String> params) throws MallinkException; JSONObject queryAndCalcMem(Map<String, String> params) throws MallinkException;


/** /**
* 核销动作
* 优惠核销(包含核销,支付预核销)
* @param params * @param params
* @return * @return
* @throws MallinkException * @throws MallinkException
*/ */
//Map<String, String> couponOrderVerify(Map<String, String> params) throws MallinkException;
JSONObject couponOrderVerify(Map<String, String> params) throws MallinkException;


/** /**
* 核销取消(check, pre_verify, verify) for selected_coupon_list
* 优惠撤销(包含核销撤销,支付预核销撤销)
* @param params * @param params
* @param actionType
* @return * @return
* @throws MallinkException * @throws MallinkException
*/ */
//Map<String, String> couponOrderVerifyCancel(Map<String, String> params, EnumPosActionType actionType) throws MallinkException;

/**
* 核销动作(check, pre_verify, verify) for selected_coupon_list
* @param params
* @param actionType
* @return
* @throws MallinkException
*/
//Map<String, String> couponOrderVerifyListDo(Map<String, String> params, EnumPosActionType actionType) throws MallinkException;
JSONObject couponOrderVerifyCancel(Map<String, String> params) throws MallinkException;


/** /**
* 消费卡POS预支付 * 消费卡POS预支付


+ 94
- 51
mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java Просмотреть файл

@@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import springfox.documentation.spring.web.json.Json;


import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@@ -32,7 +33,7 @@ public class PosServiceImpl implements PosService {


private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Logger logger = LoggerFactory.getLogger(this.getClass());


// neu时间格式, 4位年2位月2位日2位24小时制时2位分2位秒3位毫秒
// 东软时间格式, 4位年2位月2位日2位24小时制时2位分2位秒3位毫秒 时区+8 北京时间
private final SimpleDateFormat neuDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS"); private final SimpleDateFormat neuDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
private final SimpleDateFormat mydateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private final SimpleDateFormat mydateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


@@ -705,10 +706,10 @@ public class PosServiceImpl implements PosService {
return discountObj; return discountObj;
} }


//@Override
@Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map<String, String> couponOrderVerify(Map<String, String> params) throws MallinkException {
Map<String, String> dataMap = new HashMap<>();
public JSONObject couponOrderVerify(Map<String, String> params) throws MallinkException {
JSONObject dataMap = new JSONObject();


String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID
String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID
@@ -749,6 +750,7 @@ public class PosServiceImpl implements PosService {
dataMap.put(WxPayConstant.ORDER_CREATE_SN, orderCreateSN); dataMap.put(WxPayConstant.ORDER_CREATE_SN, orderCreateSN);
} }


// 0. 场景
Integer iSceneType; Integer iSceneType;
try { try {
iSceneType = Integer.valueOf(sceneTypeStr); iSceneType = Integer.valueOf(sceneTypeStr);
@@ -796,7 +798,7 @@ public class PosServiceImpl implements PosService {
errParam(WxPayConstant.COUPON_ORDER_LIST); errParam(WxPayConstant.COUPON_ORDER_LIST);
} }
JSONArray couponOrderArr = JSON.parseArray(coListStr); JSONArray couponOrderArr = JSON.parseArray(coListStr);
if (couponOrderArr.size() > 1) {
if (couponOrderArr.size() != 1) {
String errMessage = "核销只能使用一张券"; String errMessage = "核销只能使用一张券";
logger.error(errMessage); logger.error(errMessage);
throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), errMessage); throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), errMessage);
@@ -929,8 +931,8 @@ public class PosServiceImpl implements PosService {
String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID
String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID
String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID
String posAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单总额(单位:分)
String selCoListStr = params.get(WxPayConstant.COUPON_ORDER_LIST); // 选中的优惠券列表
String posAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单总额(单位:分)
String selCoListStr = params.get(WxPayConstant.COUPON_ORDER_LIST); // 选中的优惠券列表
Integer sceneType = EnumPosSceneType.PAY.getCode(); // 此接口只有支付使用 Integer sceneType = EnumPosSceneType.PAY.getCode(); // 此接口只有支付使用


if (StringUtils.isBlank(tenantId)) { if (StringUtils.isBlank(tenantId)) {
@@ -1280,48 +1282,78 @@ public class PosServiceImpl implements PosService {
throw new MallinkException(500, errMessage); throw new MallinkException(500, errMessage);
} }


//@Override
@Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map<String, String> couponOrderVerifyCancel(Map<String, String> params, EnumPosActionType actionType) {
Map<String, String> retMap = new HashMap<>();
public JSONObject couponOrderVerifyCancel(Map<String, String> params) {
JSONObject retMap = new JSONObject();


String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID
String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID
String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID
String couponOrderIdStr = params.get(WxPayConstant.COUPON_ORDER_ID); // 券ID
String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID
String sceneTypeStr = params.get(WxPayConstant.SCENE_TYPE); // 交易场景
String orderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID
String paymentInfoStr = params.get(WxPayConstant.PAYMENT_INFO); // 优惠信息


if (StringUtils.isBlank(tenantId)) { if (StringUtils.isBlank(tenantId)) {
errParam(WxPayConstant.TENANT_ID); errParam(WxPayConstant.TENANT_ID);
} else {
retMap.put(WxPayConstant.TENANT_ID, tenantId);
} }
if (StringUtils.isBlank(merchantIdStr)) { if (StringUtils.isBlank(merchantIdStr)) {
errParam(WxPayConstant.MERCHANT_ID); errParam(WxPayConstant.MERCHANT_ID);
} else {
retMap.put(WxPayConstant.MERCHANT_ID, merchantIdStr);
} }
if (StringUtils.isBlank(buUserIdStr)) { if (StringUtils.isBlank(buUserIdStr)) {
errParam(WxPayConstant.BUSER_ID); errParam(WxPayConstant.BUSER_ID);
} else {
retMap.put(WxPayConstant.BUSER_ID, buUserIdStr);
} }
if (StringUtils.isBlank(couponOrderIdStr)) {
errParam(WxPayConstant.COUPON_ORDER_ID);
if (StringUtils.isBlank(sceneTypeStr)) {
errParam(WxPayConstant.SCENE_TYPE);
} else {
retMap.put(WxPayConstant.SCENE_TYPE, sceneTypeStr);
} }
if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) || actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) {
if (StringUtils.isBlank(posOrderIdStr)) {
errParam(WxPayConstant.POS_ORDER_ID);
}
if (StringUtils.isBlank(orderIdStr)) {
errParam(WxPayConstant.POS_ORDER_ID);
} else {
retMap.put(WxPayConstant.POS_ORDER_ID, orderIdStr);
}
if (StringUtils.isBlank(paymentInfoStr)) {
errParam(WxPayConstant.PAYMENT_INFO);
}

Integer iSceneType;
try {
iSceneType = Integer.valueOf(sceneTypeStr);
} catch (NumberFormatException e) {
logger.error(e.getMessage());
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR);
} }


Long merchantId, buUserId, posOrderId = 0L; Long merchantId, buUserId, posOrderId = 0L;
try { try {
merchantId = Long.valueOf(merchantIdStr); merchantId = Long.valueOf(merchantIdStr);
buUserId = Long.valueOf(buUserIdStr); buUserId = Long.valueOf(buUserIdStr);
posOrderId = Long.valueOf(posOrderIdStr);
posOrderId = Long.valueOf(orderIdStr);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
logger.error(e.getMessage()); logger.error(e.getMessage());
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR); throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR);
} }

// 2. check merchant // 2. check merchant
WxMerchant merchant = checkAndGetMerchant(merchantId); WxMerchant merchant = checkAndGetMerchant(merchantId);
// 3. check buUser // 3. check buUser
WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId); WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId);

JSONObject paymentInfo = JSON.parseObject(paymentInfoStr);
if (paymentInfo == null) {
errParam(WxPayConstant.PAYMENT_INFO);
}
String couponOrderIdStr = paymentInfo.getString(WxPayConstant.COUPON_ID);
if (StringUtils.isBlank(couponOrderIdStr)) {
errParam(WxPayConstant.PAYMENT_INFO);
}
// 4. check couponOrderId // 4. check couponOrderId
WxCouponOrderCVo couponOrderCVo = couponOrderService.detailCUserVo(couponOrderIdStr); WxCouponOrderCVo couponOrderCVo = couponOrderService.detailCUserVo(couponOrderIdStr);
if (couponOrderCVo == null) { if (couponOrderCVo == null) {
@@ -1341,61 +1373,72 @@ public class PosServiceImpl implements PosService {
logger.error("券: coupon-" + couponOrderCVo.getCouponId() + "核销: couponMerchantId-" + merchantIdStr + " 门店不适用"); logger.error("券: coupon-" + couponOrderCVo.getCouponId() + "核销: couponMerchantId-" + merchantIdStr + " 门店不适用");
throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL); throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL);
} }

// 5. 核销后无法反向 // 5. 核销后无法反向
WxCoupon coupon = couponMapper.selectByPrimaryKey(couponOrderCVo.getCouponId()); WxCoupon coupon = couponMapper.selectByPrimaryKey(couponOrderCVo.getCouponId());
if (coupon.getSalePrice() > 0 || if (coupon.getSalePrice() > 0 ||
(coupon.getSubsidyType() > EnumCouponSubsidyType.NO_SUBSIDY.getCode() && coupon.getSubsidyNum() > 0)) { (coupon.getSubsidyType() > EnumCouponSubsidyType.NO_SUBSIDY.getCode() && coupon.getSubsidyNum() > 0)) {
logger.error("券包ID: " + couponOrderCVo.getId() + "核销无法退回");
logger.error("券包ID: " + couponOrderIdStr + "核销无法退回");
throw new MallinkException(ErrorCode.POS_COUPON_ORDER_VERIFY_NOT_CANCEL); throw new MallinkException(ErrorCode.POS_COUPON_ORDER_VERIFY_NOT_CANCEL);
} }


WxCouponOrder couponOrder = new WxCouponOrder(); WxCouponOrder couponOrder = new WxCouponOrder();
couponOrder.setId(couponOrderCVo.getId()); couponOrder.setId(couponOrderCVo.getId());

// 预核销取消
if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode()) &&
actionType.equals(EnumPosActionType.PAY_VERIFY_PRE_CANCEL)) {
logger.info("券已被预核销: " + couponOrderIdStr);
if (!couponOrderCVo.getBUserId().equals(buUserId)) {
logger.error(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL.getMessage() + ": " + buUserIdStr);
throw new MallinkException(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL);
}
// 6. 核销撤销
if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) &&
iSceneType.equals(EnumPosSceneType.VERIFY.getCode())) {
logger.info("券已被核销无法取消: " + couponOrderIdStr);
JSONObject refundObj = new JSONObject();
String errMesg = String.format("此券核销后无法退回, 券%s抵用%s元, 购买花费%s元",
couponOrderIdStr, couponOrderCVo.getPriceStr(), couponOrderCVo.getSalePriceStr());
refundObj.put(WxPayConstant.COUPON_REFUND_ID, couponOrderIdStr);
refundObj.put(WxPayConstant.COUPON_REFUND_RESULT, "0");
refundObj.put(WxPayConstant.COUPON_REFUND_RESULT_MSG, errMesg);
refundObj.put(WxPayConstant.REFUND_TIME_FROM_IFORMALL, neuDateFormat.format(new Date()));
refundObj.put(WxPayConstant.PRICE, coupon.getPrice());
refundObj.put(WxPayConstant.SALE_PRICE, coupon.getSalePrice());
retMap.put(WxPayConstant.COUPON_REFUND_RESULT, JSON.toJSONString(refundObj));
return retMap;
/*
try { try {
cancelPreVerify(couponOrderCVo, posOrderId);
retMap.put(WxPayConstant.CANCEL, WxPayConstant.TRUE);
cancelVerify(couponOrderCVo, buUserId, posOrderId);
JSONObject refundObj = new JSONObject();
refundObj.put(WxPayConstant.COUPON_REFUND_ID, String.valueOf(couponOrderCVo.getId()));
refundObj.put(WxPayConstant.COUPON_REFUND_RESULT, "0");
refundObj.put(WxPayConstant.COUPON_REFUND_RESULT_MSG, "核销撤销成功");
refundObj.put(WxPayConstant.REFUND_TIME_FROM_IFORMALL, neuDateFormat.format(new Date()));
retMap.put(WxPayConstant.COUPON_REFUND_RESULT, JSON.toJSONString(refundObj));
return retMap; return retMap;
} catch (MallinkException e) { } catch (MallinkException e) {
logger.error(e.getMessage()); logger.error(e.getMessage());
throw new MallinkException(e.getErrorCode(), e.getMessage());
JSONObject refundObj = new JSONObject();
refundObj.put(WxPayConstant.COUPON_REFUND_ID, String.valueOf(couponOrderCVo.getId()));
refundObj.put(WxPayConstant.COUPON_REFUND_RESULT, e.getErrorCode());
refundObj.put(WxPayConstant.COUPON_REFUND_RESULT_MSG, "核销撤销失败: " + e.getMessage());
refundObj.put(WxPayConstant.REFUND_TIME_FROM_IFORMALL, neuDateFormat.format(new Date()));
retMap.put(WxPayConstant.COUPON_REFUND_RESULT, JSON.toJSONString(refundObj));
return retMap;
} }
*/
} }
// 核销取消
if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) &&
actionType.equals(EnumPosActionType.VERIFY_CANCEL)) {
// 检查是否有发放的券, 有则无法退券
// 6. 预核销取消
else if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode()) &&
iSceneType.equals(EnumPosSceneType.PAY.getCode())) {
logger.info("券已被预核销: " + couponOrderIdStr);
if (!couponOrderCVo.getBUserId().equals(buUserId)) {
logger.error(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL.getMessage() + ": " + buUserIdStr);
throw new MallinkException(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL);
}
try { try {
cancelVerify(couponOrderCVo, buUserId, posOrderId);
cancelPreVerify(couponOrderCVo, posOrderId);
retMap.put(WxPayConstant.CANCEL, WxPayConstant.TRUE); retMap.put(WxPayConstant.CANCEL, WxPayConstant.TRUE);
return retMap; return retMap;
} catch (MallinkException e) { } catch (MallinkException e) {
logger.error(e.getMessage()); logger.error(e.getMessage());
throw new MallinkException(e.getErrorCode(), e.getMessage()); throw new MallinkException(e.getErrorCode(), e.getMessage());
} }
/*
logger.info("券已被核销无法取消: " + couponOrderIdStr);
retMap.put(WxPayConstant.CANCEL, WxPayConstant.FALSE);
Map cancelMap = new HashMap();
cancelMap.put(WxPayConstant.PRICE, coupon.getPrice());
cancelMap.put(WxPayConstant.SALE_PRICE, coupon.getSalePrice());
retMap.put(WxPayConstant.CANCEL_JSON, JSON.toJSONString(cancelMap));
String errMessage = String.format("此券核销后无法退回,原价:%s元, 售价:%s元", coupon.getPriceStr(), coupon.getSalePriceStr());
// TODO 系统发放的券, 也加入核销信息中
retMap.put(WxPayConstant.CANCEL_DES, errMessage);
return retMap;
*/
} }
String errMessage = "取消异常:未知的核销状态-" + couponOrderCVo.getCouponOrderStatus()+ ", 核销action-" + actionType.getCode();

String errMessage = "取消异常:未知的核销状态-" + couponOrderCVo.getCouponOrderStatus()+ ", 场景-" + iSceneType;
logger.error(errMessage); logger.error(errMessage);
throw new MallinkException(500, errMessage); throw new MallinkException(500, errMessage);
} }


+ 23
- 12
mallinkPosApi/src/test/java/com/iformall/pos/test/PosAppTest.java Просмотреть файл

@@ -254,9 +254,29 @@ public class PosAppTest {


@Test @Test
public void couponOrderVerifyCancelTest() throws Exception { public void couponOrderVerifyCancelTest() throws Exception {
String couponOrderId = "321878223800205312";
String posOrderId = "1"; String posOrderId = "1";
doCouponOrderVerifyCancel(couponOrderId, posOrderId);
String couponOrderId = "321878223800205312";
String orderAmount = "1000";
String amountLeft = "0";
String sceneType = String.valueOf(EnumPosSceneType.VERIFY.getCode());
Map<String, String> reqObj = new HashMap<>();
JSONObject paymentInfo = new JSONObject();
paymentInfo.put(WxPayConstant.COUPON_ID, couponOrderId);
paymentInfo.put(WxPayConstant.ORDER_AMOUNT, orderAmount);
paymentInfo.put(WxPayConstant.ORDER_AMOUNT_LEFT, orderAmount);
paymentInfo.put(WxPayConstant.PROMOTION_AMOUNT, orderAmount);
paymentInfo.put(WxPayConstant.AMOUNT_LEFT_AFTER_PAY, amountLeft);
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.SCENE_TYPE, sceneType);
reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId);
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId);
reqObj.put(WxPayConstant.PAYMENT_INFO, JSON.toJSONString(paymentInfo));
boolean resSigned = sendAndRes("/couponOrderVerifyCancel", reqObj);
Assert.assertEquals(resSigned, true);
} }


@Test @Test
@@ -388,16 +408,7 @@ public class PosAppTest {
} }


private void doCouponOrderVerifyCancel(String couponOrderId, String posOrderId) throws Exception { private void doCouponOrderVerifyCancel(String couponOrderId, String posOrderId) throws Exception {
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.COUPON_ORDER_ID, couponOrderId);
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId);
boolean resSigned = sendAndRes("/couponOrderVerifyCancel", reqObj);
Assert.assertEquals(resSigned, true);

} }


private void doPreVerify(String couponOrderId, String posOrderId, String posAmount) throws Exception { private void doPreVerify(String couponOrderId, String posOrderId, String posAmount) throws Exception {


+ 8
- 0
mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java Просмотреть файл

@@ -87,6 +87,12 @@ public class WxPayConstant {
public final static String COUPON_TYPE = "coupon_type"; public final static String COUPON_TYPE = "coupon_type";
public final static String IS_SELECTED = "is_selected"; public final static String IS_SELECTED = "is_selected";


public final static String COUPON_REFUND_RESULT = "coupon_refund_result";
public final static String COUPON_REFUND_ID = "coupon_refund_id";
public final static String COUPON_REFUND_RESULT_CODE = "result_code";
public final static String COUPON_REFUND_RESULT_MSG = "result_msg";
public final static String REFUND_TIME_FROM_IFORMALL = "refund_time_from_iformall";

public final static String COUPON_PROMOTION_AMOUNT = "coupon_promotion_amount"; public final static String COUPON_PROMOTION_AMOUNT = "coupon_promotion_amount";


public final static String MEMBER_DISCOUNT = "member_discount"; public final static String MEMBER_DISCOUNT = "member_discount";
@@ -94,6 +100,8 @@ public class WxPayConstant {
public final static String PROMOTION_DATA = "promotion_data"; public final static String PROMOTION_DATA = "promotion_data";
public final static String PAYMENT_PREDICTION = "payment_prediction"; public final static String PAYMENT_PREDICTION = "payment_prediction";


public final static String PAYMENT_INFO = "payment_info";

public final static String DEDUCT_AMOUNT = "deduct_amount"; public final static String DEDUCT_AMOUNT = "deduct_amount";
public final static String REMAIN_AMOUNT = "remain_amount"; public final static String REMAIN_AMOUNT = "remain_amount";
public final static String ORDER_STATUS = "order_status"; public final static String ORDER_STATUS = "order_status";


Загрузка…
Отмена
Сохранить