Browse Source

[POS][修改]:POS接口修改

release_toaliyun_real
Stormeye Wu 6 years ago
parent
commit
4e52a87412
7 changed files with 176 additions and 219 deletions
  1. +1
    -2
      mallinkBApi/src/main/java/com/iformall/service/PosBrunService.java
  2. +86
    -131
      mallinkPosApi/src/main/java/com/iformall/controller/PosController.java
  3. +38
    -55
      mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java
  4. +24
    -24
      mallinkPosApi/src/test/java/com/iformall/pos/test/PosAppTest.java
  5. +2
    -2
      mallinkService/src/main/java/com/iformall/enums/EnumPosActionType.java
  6. +6
    -4
      mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java
  7. +19
    -1
      mallinkService/src/main/resources/mapper/WxPayOrderMapper.xml

+ 1
- 2
mallinkBApi/src/main/java/com/iformall/service/PosBrunService.java View File

@@ -19,7 +19,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;
import java.util.List;
@@ -378,7 +377,7 @@ public class PosBrunService {
return new ResultData(JSON.toJSONString(retObj));
} else {
logger.error(resStr);
return new ResultData(Result.ERROR, retObj.getString(WxPayConstant.ERR_CODE_DESC));
return new ResultData(Result.ERROR, retObj.getString(WxPayConstant.ERR_CODE_DES));
}
}
} else {


+ 86
- 131
mallinkPosApi/src/main/java/com/iformall/controller/PosController.java View File

@@ -280,18 +280,17 @@ public class PosController extends BaseController {
}
}

@ApiOperation(value = "券核销", notes = "{" +
@ApiOperation(value = "券核销", notes = "{" +
"\"dev_id\":\"string(必填)\"," +
"\"nonce_str\":\"string(必填)\"," +
"\"tenant_id\":\"string(必填)\"," +
"\"merchant_id\":\"string(必填)\"," +
"\"bu_user_id\":\"string(必填)\"," +
"\"coupon_order_id\":\"string(必填)\"," +
"\"pos_order_id\":\"string(必填)\"," +
"\"pos_amount\":\"string(必填)\"}")
@PostMapping("/couponOrderPreVerify")
@SystemControllerLog(description = "券预核销")
public Map<String, String> couponOrderPreVerify(@RequestBody Map<String, String> params) {
"\"pos_order_id\":\"string(必填)\"}")
@PostMapping("/couponOrderVerify")
@SystemControllerLog(description = "券核销")
public Map<String, String> couponOrderVerify(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject();

// 1. check sign
@@ -304,9 +303,7 @@ public class PosController extends BaseController {
logger.info(WxPayConstant.RES_KEY + ": " + resKey);

try {
retMap = posService.couponOrderVerifyDo(params, EnumPosActionType.PRE_VERIFY);
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",
WxPayConstant.RET_SUCCESS, null);
retMap = posService.couponOrderVerifyDo(params, EnumPosActionType.VERIFY_INDEPENT);
} catch (MallinkException e) {
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",
WxPayConstant.RET_FAIL,
@@ -316,19 +313,42 @@ 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
Long buUserId, couponOrderId;
try {
buUserId = Long.valueOf(buUserIdStr);
couponOrderId = Long.valueOf(couponOrderIdStr);
} catch (NumberFormatException e) {
logger.error(e.getMessage());
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage());
}

String errCode = retMap.get(WxPayConstant.ERR_CODE);
if(StringUtils.isBlank(errCode)) {
// 无异常信息,核销成功
couponOrderService.sendInsideCouponVerifyMsg(tenantId, couponOrderId, buUserId, verifyType.getCode());
}
}

@ApiOperation(value = "券预核销取消", notes = "{" +
@ApiOperation(value = "券核销取消", notes = "{" +
"\"dev_id\":\"string(必填)\"," +
"\"nonce_str\":\"string(必填)\"," +
"\"tenant_id\":\"string(必填)\"," +
"\"merchant_id\":\"string(必填)\"," +
"\"bu_user_id\":\"string(必填)\"," +
"\"coupon_order_id\":\"string(必填)\" +" +
"\"nonce_str\":\"string(必填)\" +" +
"\"pos_order_id\":\"string(必填)\" }")
@PostMapping("/couponOrderPreVerifyCancel")
@SystemControllerLog(description = "券预核销取消")
public Map<String, String> couponOrderPreVerifyCancel(@RequestBody Map<String, String> params) {
"\"coupon_order_id\":\"string(必填)\"" +
"\"pos_order_id\":\"string(必填)\"}")
@PostMapping("/couponOrderVerifyCancel")
@SystemControllerLog(description = "券核销取消")
public Map<String, String> couponOrderIndependentVerifyCancel(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject();

// 1. check sign
@@ -341,7 +361,7 @@ public class PosController extends BaseController {
logger.info(WxPayConstant.RES_KEY + ": " + resKey);

try {
retMap = posService.couponOrderVerifyCancel(params, EnumPosActionType.PRE_VERIFY_CANCEL);
retMap = posService.couponOrderVerifyCancel(params, EnumPosActionType.VERIFY_CANCEL);
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",
WxPayConstant.RET_SUCCESS, null);
} catch (MallinkException e) {
@@ -355,17 +375,18 @@ public class PosController extends BaseController {
}
}

@ApiOperation(value = "券独立核销", notes = "{" +
@ApiOperation(value = "POS支付-券", notes = "{" +
"\"dev_id\":\"string(必填)\"," +
"\"nonce_str\":\"string(必填)\"," +
"\"tenant_id\":\"string(必填)\"," +
"\"merchant_id\":\"string(必填)\"," +
"\"bu_user_id\":\"string(必填)\"," +
"\"coupon_order_id\":\"string(必填)\"," +
"\"pos_order_id\":\"string(必填)\"}")
@PostMapping("/couponOrderIndependentVerify")
@SystemControllerLog(description = "券独立核销")
public Map<String, String> couponOrderIndependentVerify(@RequestBody Map<String, String> params) {
"\"sel_co_list\":\"json array[券包ID list](必填),例[\"1\",\"2\",\"3\"]\"" +
"\"pos_order_id\":\"string(必填)\"," +
"\"pos_amount\":\"string(必填)\"}")
@PostMapping("/couponOrderPay")
@SystemControllerLog(description = "POS支付-券")
public Map<String, String> couponOrderPay(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject();

// 1. check sign
@@ -378,7 +399,9 @@ public class PosController extends BaseController {
logger.info(WxPayConstant.RES_KEY + ": " + resKey);

try {
retMap = posService.couponOrderVerifyDo(params, EnumPosActionType.VERIFY_INDEPENT);
retMap = posService.couponOrderVerifyDo(params, EnumPosActionType.PAY_VERIFY_PRE);
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",
WxPayConstant.RET_SUCCESS, null);
} catch (MallinkException e) {
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",
WxPayConstant.RET_FAIL,
@@ -388,43 +411,46 @@ 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
Long buUserId, couponOrderId;
try {
buUserId = Long.valueOf(buUserIdStr);
couponOrderId = Long.valueOf(couponOrderIdStr);
} catch (NumberFormatException e) {
logger.error(e.getMessage());
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage());
@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<String, String> couponOrderPayCancel(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject();

// 1. check sign
Map<String, String> retMap = checkSign(params, payContent);
if (retMap != null) {
// 签名相关异常返回
return retMap;
}
String resKey = payContent.getString(WxPayConstant.RES_KEY);
logger.info(WxPayConstant.RES_KEY + ": " + resKey);

String errCode = retMap.get(WxPayConstant.ERR_CODE);
if(StringUtils.isBlank(errCode)) {
// 无异常信息,核销成功
couponOrderService.sendInsideCouponVerifyMsg(tenantId, couponOrderId, buUserId, verifyType.getCode());
try {
retMap = posService.couponOrderVerifyCancel(params, EnumPosActionType.PAY_VERIFY_PRE_CANCEL);
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",
WxPayConstant.RET_SUCCESS, null);
} catch (MallinkException e) {
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",
WxPayConstant.RET_FAIL,
e.getErrorCode(), e.getMessage());
} catch (Exception e) {
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",
WxPayConstant.RET_FAIL,
500, e.getMessage());
}
}

@ApiOperation(value = "券交易核销-单个优惠券接口", notes = "{" +
"\"dev_id\":\"string(必填)\"," +
"\"nonce_str\":\"string(必填)\"," +
"\"tenant_id\":\"string(必填)\"," +
"\"merchant_id\":\"string(必填)\"," +
"\"bu_user_id\":\"string(必填)\"," +
"\"coupon_order_id\":\"string(必填)\"," +
"\"pos_order_id\":\"string(必填)\"," +
"\"pos_amount\":\"string(单位:分)(必填)\"}")
@PostMapping("/couponOrderPayVerifyOne")
@SystemControllerLog(description = "券交易核销-单个优惠券接口")
public Map<String, String> couponOrderPayVerify(@RequestBody Map<String, String> params) {
private Map<String, String> couponOrderPayVerify(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject();

// 1. check sign
@@ -453,18 +479,7 @@ public class PosController extends BaseController {
WxPayConstant.RET_SUCCESS, null);
}

@ApiOperation(value = "券交易核销-优惠券列表接口", notes = "{" +
"\"dev_id\":\"string(必填)\"," +
"\"nonce_str\":\"string(必填)\"" +
"\"tenant_id\":\"string(必填)\"," +
"\"merchant_id\":\"string(必填)\"," +
"\"bu_user_id\":\"string(必填)\"," +
"\"sel_co_list\":\"json array(必填),例[\"1\",\"2\",\"3\"]\"" +
"\"pos_order_id\":\"string(必填)\"" +
"\"pay_amount\":\"单位(分)(必填)\" }")
@PostMapping("/couponOrderPayVerifyList")
@SystemControllerLog(description = "券交易核销-优惠券列表接口")
public Map<String, String> couponOrderPayVerifyList(@RequestBody Map<String, String> params) {
private Map<String, String> couponOrderPayVerifyList(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject();

// 1. check sign
@@ -524,43 +539,6 @@ public class PosController extends BaseController {
WxPayConstant.RET_SUCCESS, null);
}

@ApiOperation(value = "券核销取消", notes = "{" +
"\"dev_id\":\"string(必填)\"," +
"\"nonce_str\":\"string(必填)\"," +
"\"tenant_id\":\"string(必填)\"," +
"\"merchant_id\":\"string(必填)\"," +
"\"bu_user_id\":\"string(必填)\"," +
"\"coupon_order_id\":\"string(必填)\"" +
"\"pos_order_id\":\"string(必填)\"}")
@PostMapping("/couponOrderVerifyCancel")
@SystemControllerLog(description = "券核销取消")
public Map<String, String> couponOrderIndependentVerifyCancel(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject();

// 1. check sign
Map<String, String> 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.VERIFY_CANCEL);
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",
WxPayConstant.RET_SUCCESS, null);
} catch (MallinkException e) {
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",
WxPayConstant.RET_FAIL,
e.getErrorCode(), e.getMessage());
} catch (Exception e) {
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",
WxPayConstant.RET_FAIL,
500, e.getMessage());
}
}

@ApiOperation(value = "消费卡预支付", notes = "{" +
"\"dev_id\":\"string(必填)\"," +
"\"nonce_str\":\"string(必填)\"," +
@@ -638,18 +616,7 @@ public class PosController extends BaseController {
}
}

@ApiOperation(value = "消费卡支付", notes = "{" +
"\"dev_id\":\"string(必填)\"," +
"\"nonce_str\":\"string(必填)\"," +
"\"tenant_id\":\"string(必填)\"," +
"\"merchant_id\":\"string(必填)\"," +
"\"bu_user_id\":\"string(必填)\"," +
"\"pos_order_id\":\"string(必填)\"," +
"\"pos_amount\":\"string(单位:分)(必填)\"," +
"\"card_id\":\"string(必填)\" }")
@PostMapping("/cardPay")
@SystemControllerLog(description = "消费卡支付")
public Map<String, String> cardPay(@RequestBody Map<String, String> params) {
private Map<String, String> cardPay(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject();

// 1. check sign
@@ -676,19 +643,7 @@ public class PosController extends BaseController {
}
}

@ApiOperation(value = "消费卡支付取消", notes = "{" +
"\"dev_id\":\"string(必填)\"," +
"\"nonce_str\":\"string(必填)\"," +
"\"tenant_id\":\"string(必填)\"," +
"\"merchant_id\":\"string(必填)\"," +
"\"bu_user_id\":\"string(必填)\"," +
"\"pos_order_id\":\"string(必填)\"," +
"\"pos_amount\":\"string(单位:分)(必填)\"," +
"\"card_id\":\"string(必填)\"," +
"\"card_spend_id\":\"string(必填)\"}")
@PostMapping("/cardPayCancel")
@SystemControllerLog(description = "消费卡支付取消")
public Map<String, String> cardPayCancel(@RequestBody Map<String, String> params) {
private Map<String, String> cardPayCancel(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject();

// 1. check sign
@@ -761,7 +716,7 @@ public class PosController extends BaseController {
retMap.put(WxPayConstant.RETURN_MSG, retMsg);
retMap.put(WxPayConstant.RESULT_CODE, resCode);
retMap.put(WxPayConstant.ERR_CODE, "" + errCode);
retMap.put(WxPayConstant.ERR_CODE_DESC, errMsg);
retMap.put(WxPayConstant.ERR_CODE_DES, errMsg);
return retMap;
}

@@ -784,7 +739,7 @@ public class PosController extends BaseController {
retMap.put(WxPayConstant.RESULT_CODE, resCode);
if (err != null) {
retMap.put(WxPayConstant.ERR_CODE, "" + err.getCode());
retMap.put(WxPayConstant.ERR_CODE_DESC, err.getMessage());
retMap.put(WxPayConstant.ERR_CODE_DES, err.getMessage());
}
return WxPayment.buildSignAfterParasMapForHMAC(retMap, resKey);
}
@@ -808,7 +763,7 @@ public class PosController extends BaseController {
retMap.put(WxPayConstant.RETURN_MSG, retMsg);
retMap.put(WxPayConstant.RESULT_CODE, resCode);
retMap.put(WxPayConstant.ERR_CODE, "" + errCode);
retMap.put(WxPayConstant.ERR_CODE_DESC, errMsg);
retMap.put(WxPayConstant.ERR_CODE_DES, errMsg);
return WxPayment.buildSignAfterParasMapForHMAC(retMap, resKey);
}



+ 38
- 55
mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java View File

@@ -121,7 +121,7 @@ public class PosServiceImpl implements PosService {

retMap.put(WxPayConstant.MEM_DISCOUNT, String.valueOf(config.getDiscount().equals(EnumPosEnableType.Enable.getCode())));
retMap.put(WxPayConstant.MEM_COUPON, String.valueOf(config.getCoupon()));
retMap.put(WxPayConstant.MEM_COUPON_DESC, EnumPosCouponEnableType.getEnum(config.getCoupon()).getMessage());
retMap.put(WxPayConstant.MEM_COUPON_DES, EnumPosCouponEnableType.getEnum(config.getCoupon()).getMessage());
retMap.put(WxPayConstant.MEM_CARD, String.valueOf(config.getCard().equals(EnumPosEnableType.Enable.getCode())));
return retMap;
} else {
@@ -165,7 +165,7 @@ public class PosServiceImpl implements PosService {

retMap.put(WxPayConstant.MEM_DISCOUNT, String.valueOf(config.getDiscount().equals(EnumPosEnableType.Enable.getCode())));
retMap.put(WxPayConstant.MEM_COUPON, String.valueOf(config.getCoupon()));
retMap.put(WxPayConstant.MEM_COUPON_DESC, EnumPosCouponEnableType.getEnum(config.getCoupon()).getMessage());
retMap.put(WxPayConstant.MEM_COUPON_DES, EnumPosCouponEnableType.getEnum(config.getCoupon()).getMessage());
retMap.put(WxPayConstant.MEM_CARD, String.valueOf(config.getCard().equals(EnumPosEnableType.Enable.getCode())));
return retMap;
}
@@ -595,14 +595,14 @@ public class PosServiceImpl implements PosService {
} else if (actionType.equals(EnumPosActionType.VERIFY_PAY)) {
sceneType = EnumPosSceneType.PAY.getCode();
}
if (actionType.equals(EnumPosActionType.PRE_VERIFY) ||
if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) ||
actionType.equals(EnumPosActionType.VERIFY_INDEPENT) ||
actionType.equals(EnumPosActionType.VERIFY_PAY)) {
if (StringUtils.isBlank(posOrderIdStr)) {
errParam(WxPayConstant.POS_ORDER_ID);
}
}
if (actionType.equals(EnumPosActionType.PRE_VERIFY) ||
if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) ||
actionType.equals(EnumPosActionType.VERIFY_PAY)) {
if (StringUtils.isBlank(posAmountStr)) {
errParam(WxPayConstant.POS_AMOUNT);
@@ -614,12 +614,12 @@ public class PosServiceImpl implements PosService {
try {
merchantId = Long.valueOf(merchantIdStr);
buUserId = Long.valueOf(buUserIdStr);
if (actionType.equals(EnumPosActionType.PRE_VERIFY) ||
if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) ||
actionType.equals(EnumPosActionType.VERIFY_INDEPENT) ||
actionType.equals(EnumPosActionType.VERIFY_PAY)) {
posOrderId = Long.valueOf(posOrderIdStr);
}
if (actionType.equals(EnumPosActionType.PRE_VERIFY) ||
if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) ||
actionType.equals(EnumPosActionType.VERIFY_PAY)) {
posAmount = Integer.valueOf(posAmountStr);
}
@@ -684,7 +684,7 @@ public class PosServiceImpl implements PosService {
if (StringUtils.isBlank(selCoListStr)) {
errParam(WxPayConstant.SELECTED_COUPON_ORDER_LIST);
}
if (actionType.equals(EnumPosActionType.PRE_VERIFY) || actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) {
if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) || actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) {
if (StringUtils.isBlank(posOrderIdStr)) {
errParam(WxPayConstant.POS_ORDER_ID);
}
@@ -698,7 +698,7 @@ public class PosServiceImpl implements PosService {
try {
merchantId = Long.valueOf(merchantIdStr);
buUserId = Long.valueOf(buUserIdStr);
if (actionType.equals(EnumPosActionType.PRE_VERIFY) ||
if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) ||
actionType.equals(EnumPosActionType.VERIFY_INDEPENT) ||
actionType.equals(EnumPosActionType.VERIFY_PAY)) {
posOrderId = Long.valueOf(posOrderIdStr);
@@ -777,7 +777,7 @@ public class PosServiceImpl implements PosService {
throw new MallinkException(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT);
}
}
} else if (actionType.equals(EnumPosActionType.PRE_VERIFY) || actionType.equals(EnumPosActionType.VERIFY_PAY)) {
} else if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) || actionType.equals(EnumPosActionType.VERIFY_PAY)) {
if (!(couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) ||
couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_MANJIAN.getCode()) ||
couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_DAIJIN.getCode())
@@ -884,7 +884,9 @@ public class PosServiceImpl implements PosService {
retMap.put(WxPayConstant.COVER_IMG, couponOrderCVo.getCoverImg());
retMap.put(WxPayConstant.EXPIRE_TIME, mydateFormat.format(couponOrderCVo.getExpiredTime()));
retMap.put(WxPayConstant.PRICE, String.valueOf(couponOrderCVo.getPrice()));
retMap.put(WxPayConstant.STATUS, EnumCouponOrderStatus.getEnum(couponOrderCVo.getCouponOrderStatus()).getMessage());
EnumCouponOrderStatus couponOrderStatus = EnumCouponOrderStatus.getEnum(couponOrderCVo.getCouponOrderStatus());
retMap.put(WxPayConstant.STATUS, String.valueOf(couponOrderStatus.getCode()));
retMap.put(WxPayConstant.STATUS_DES, couponOrderStatus.getMessage());
return retMap;
} else if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode())) {
logger.info("券可以被核销: " + couponOrderIdStr);
@@ -895,10 +897,12 @@ public class PosServiceImpl implements PosService {
retMap.put(WxPayConstant.COVER_IMG, couponOrderCVo.getCoverImg());
retMap.put(WxPayConstant.EXPIRE_TIME, mydateFormat.format(couponOrderCVo.getExpiredTime()));
retMap.put(WxPayConstant.PRICE, String.valueOf(couponOrderCVo.getPrice()));
retMap.put(WxPayConstant.STATUS, EnumCouponOrderStatus.getEnum(couponOrderCVo.getCouponOrderStatus()).getMessage());
EnumCouponOrderStatus couponOrderStatus = EnumCouponOrderStatus.getEnum(couponOrderCVo.getCouponOrderStatus());
retMap.put(WxPayConstant.STATUS, String.valueOf(couponOrderStatus.getCode()));
retMap.put(WxPayConstant.STATUS_DES, couponOrderStatus.getMessage());
return retMap;
}
} else if (actionType.equals(EnumPosActionType.PRE_VERIFY)) {
} else if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE)) {
if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode())) {
logger.info("券已被预核销: " + couponOrderIdStr);
if (!couponOrderCVo.getBUserId().equals(buUserId)) {
@@ -1015,8 +1019,7 @@ public class PosServiceImpl implements PosService {
String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户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 forceStr = params.get(WxPayConstant.FORCE); // 是否强制
String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID

if (StringUtils.isBlank(tenantId)) {
errParam(WxPayConstant.TENANT_ID);
@@ -1030,7 +1033,7 @@ public class PosServiceImpl implements PosService {
if (StringUtils.isBlank(couponOrderIdStr)) {
errParam(WxPayConstant.COUPON_ORDER_ID);
}
if (actionType.equals(EnumPosActionType.PRE_VERIFY) || actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) {
if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) || actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) {
if (StringUtils.isBlank(posOrderIdStr)) {
errParam(WxPayConstant.POS_ORDER_ID);
}
@@ -1046,21 +1049,9 @@ public class PosServiceImpl implements PosService {
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR);
}
// 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);
}
WxMerchant merchant = checkAndGetMerchant(merchantId);
// 3. check buUser
WxMerchantBUser buUser = merchantBUserService.getById(buUserId);
if (buUser == null) {
logger.error(ErrorCode.USER_IS_EMPTY.getMessage() + ": " + buUserIdStr);
throw new MallinkException(ErrorCode.USER_IS_EMPTY);
}
if (buUser.getMerchantId().equals(merchantId)) {
logger.error(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG.getMessage() + ": " + buUserId);
throw new MallinkException(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG);
}
WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId);
// 4. check couponOrderId
WxCouponOrderCVo couponOrderCVo = couponOrderService.detailCUserVo(couponOrderIdStr);
if (couponOrderCVo == null) {
@@ -1071,14 +1062,7 @@ public class PosServiceImpl implements PosService {
logger.error("券包ID: " + couponOrderCVo.getId() + "未核销");
throw new MallinkException(ErrorCode.POS_COUPON_ORDER_NOT_VERIFY);
}
// 5. 有价券无法反向, 补贴券无法反向
WxCoupon coupon = couponMapper.selectByPrimaryKey(couponOrderCVo.getCouponId());
if (coupon.getSalePrice() > 0 ||
(coupon.getSubsidyType() > EnumCouponSubsidyType.NO_SUBSIDY.getCode() && coupon.getSubsidyNum() > 0)) {
logger.error("券包ID: " + couponOrderCVo.getId() + "核销无法退回");
throw new MallinkException(ErrorCode.POS_COUPON_ORDER_VERIFY_NOT_CANCEL);
}
// 6. 检查适用门店
// 5. 检查适用门店
WxCouponMerchant wxCouponMerchant = new WxCouponMerchant();
wxCouponMerchant.setProductId(couponOrderCVo.getCouponId());
wxCouponMerchant.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode());
@@ -1088,12 +1072,20 @@ public class PosServiceImpl implements PosService {
throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL);
}

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

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

// 预核销取消
if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode()) &&
actionType.equals(EnumPosActionType.PRE_VERIFY_CANCEL)) {
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);
@@ -1111,21 +1103,12 @@ public class PosServiceImpl implements PosService {
// 核销取消
if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) &&
actionType.equals(EnumPosActionType.VERIFY_CANCEL)) {
logger.info("券已被核销: " + couponOrderIdStr);
boolean force = false;
if (StringUtils.isNotBlank(forceStr)) {
force = Boolean.valueOf(forceStr);
}
// 检查是否有发放的券, 有则无法退券

try {
cancelVerify(couponOrderCVo, buUserId, posOrderId);
retMap.put(WxPayConstant.CANCEL, WxPayConstant.TRUE);
return retMap;
} catch (MallinkException e) {
logger.error(e.getMessage());
throw new MallinkException(e.getErrorCode(), e.getMessage());
}
logger.info("券已被核销无法取消: " + couponOrderIdStr);
retMap.put(WxPayConstant.CANCEL, WxPayConstant.FALSE);
String errMessage = String.format("此券核销后无法退回,原价:%s元, 售价:%s元", coupon.getPriceStr(), couponOrderCVo.getCouponPriceStr());
// TODO 系统发放的券
retMap.put(WxPayConstant.CANCEL_DES, errMessage);
return retMap;
}
String errMessage = "取消异常:未知的核销状态-" + couponOrderCVo.getCouponOrderStatus()+ ", 核销action-" + actionType.getCode();
logger.error(errMessage);
@@ -1289,8 +1272,6 @@ 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());
@@ -1318,6 +1299,8 @@ public class PosServiceImpl implements PosService {
creditHistory = creditHistoryService.saveOrUpdate(creditHistory);
if (creditHistory.getCreditNum() != null) {
retMap.put(WxPayConstant.CREDIT, String.valueOf(creditHistory.getCreditNum()));
} else {
retMap.put(WxPayConstant.CREDIT, "0");
}
} catch (Exception e) {
logger.error("核销积分值异常:" + e.getMessage());


+ 24
- 24
mallinkPosApi/src/test/java/com/iformall/pos/test/PosAppTest.java View File

@@ -52,16 +52,16 @@ public class PosAppTest {
private static final String password = "drpos345";

/*
可用的交易券, 支付可用(1, 2, 6), 独立核销可用(4, 6, 8, 9)
可用的交易券, 支付可用(1, 2, 6), 核销可用(4, 6, 8, 9)
coupon_order_id, coupon_type, 售价, 面额, cancellable
321872988134408192, 4, 0, 2000, NO
321877927162249216, 2, 0, 10000, YES
321878123232591872, 2, 1, 10000, NO
321878185355214848, 1, 0, 10000, NO
321878223800205312, 6, 0, 1000, YES
321878329906921472, 6, 1, 1000, NO
321882224846667776, 8, 1, 1500, NO
321883878446825472, 100, 1, 50000, NO
321872988134408192, 4, 0, 2000, NO
321877927162249216, 2, 0, 10000, YES
321878123232591872, 2, 1, 10000, NO
321878185355214848, 1, 0, 10000, NO
321878223800205312, 6, 0, 1000, YES
321878329906921472, 6, 1, 1000, NO
321882224846667776, 8, 1, 1500, NO
321883878446825472, 100, 1, 50000, NO
*/

@Test
@@ -186,35 +186,35 @@ public class PosAppTest {
}

@Test
public void checkCouponOrderForIndeepdentVerifyTest() throws Exception {
String couponOrderId = "321877927162249216";
String verifyType = "independent";
public void checkCouponOrderVerifyTest() throws Exception {
String couponOrderId = "321878223800205312";
String sceneType = "2";
String posOrderId = "1";
String posAmount = "100";
doCheckVerify(couponOrderId, verifyType, posOrderId, posAmount);
doCheckCouponOrder(couponOrderId, sceneType, posOrderId, posAmount);
}

@Test
public void checkCouponOrderForPayVerifyTest() throws Exception {
public void checkCouponOrderPayTest() throws Exception {
String couponOrderId = "321877927162249216";
String verifyType = "pay";
String sceneType = "1";
String posOrderId = "1";
String posAmount = "100";
doCheckVerify(couponOrderId, verifyType, posOrderId, posAmount);
doCheckCouponOrder(couponOrderId, sceneType, posOrderId, posAmount);
}

@Test
public void couponOrderIndependentVerifyTest() throws Exception {
public void couponOrderVerifyTest() throws Exception {
String couponOrderId = "321878223800205312";
String posOrderId = "1";
doIndependentVerify(couponOrderId, posOrderId);
doCouponOrderVerify(couponOrderId, posOrderId);
}

@Test
public void couponOrderVerifyCancelTest() throws Exception {
String couponOrderId = "321878223800205312";
String posOrderId = "1";
doVerifyCancel(couponOrderId, posOrderId);
doCouponOrderVerifyCancel(couponOrderId, posOrderId);
}

@Test
@@ -326,7 +326,7 @@ public class PosAppTest {
Assert.assertEquals(resSigned, true);
}

private void doCheckVerify(String couponOrderId, String verifyType, String posOrderId, String posAmount) throws Exception {
private void doCheckCouponOrder(String couponOrderId, String sceneType, String posOrderId, String posAmount) throws Exception {
Map<String, String> reqObj = new HashMap<>();
reqObj.put(WxPayConstant.NONCE_STR, "1");
reqObj.put(WxPayConstant.DEV_ID, devId);
@@ -334,7 +334,7 @@ public class PosAppTest {
reqObj.put(WxPayConstant.MERCHANT_ID, merchantId);
reqObj.put(WxPayConstant.BUSER_ID, buUserId);
reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId);
reqObj.put(WxPayConstant.SCENE_TYPE, verifyType);
reqObj.put(WxPayConstant.SCENE_TYPE, sceneType);
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId);
reqObj.put(WxPayConstant.POS_AMOUNT, posAmount);
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey));
@@ -353,7 +353,7 @@ public class PosAppTest {
Assert.assertEquals(resSigned, true);
}

private void doIndependentVerify(String couponOrderId, String posOrderId) throws Exception {
private void doCouponOrderVerify(String couponOrderId, String posOrderId) throws Exception {
Map<String, String> reqObj = new HashMap<>();
reqObj.put(WxPayConstant.NONCE_STR, "1");
reqObj.put(WxPayConstant.DEV_ID, devId);
@@ -365,7 +365,7 @@ public class PosAppTest {
reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey));
String reqJsonStr = JSONObject.toJSONString(reqObj);
MvcResult result = mockMvc.perform(
MockMvcRequestBuilders.post("/couponOrderIndependentVerify")
MockMvcRequestBuilders.post("/couponOrderVerify")
.contentType(MediaType.APPLICATION_JSON)
.content(reqJsonStr))
.andExpect(MockMvcResultMatchers.status().isOk())
@@ -379,7 +379,7 @@ public class PosAppTest {
Assert.assertEquals(resSigned, true);
}

private void doVerifyCancel(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);


+ 2
- 2
mallinkService/src/main/java/com/iformall/enums/EnumPosActionType.java View File

@@ -9,8 +9,8 @@ public enum EnumPosActionType {

CHECK(0, "检查"),
CALC(1, "计算"),
PRE_VERIFY(2, "预核销"),
PRE_VERIFY_CANCEL(3, "预核销撤销"),
PAY_VERIFY_PRE(2, "交易预核销"),
PAY_VERIFY_PRE_CANCEL(3, "交易预核销撤销"),
VERIFY_INDEPENT(4,"独立核销"),
VERIFY_PAY(5,"交易核销"),
VERIFY_CANCEL(6,"核销撤销")


+ 6
- 4
mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java View File

@@ -11,7 +11,7 @@ public class WxPayConstant {
public final static String RETURN_MSG = "return_msg";
public final static String RESULT_CODE = "result_code";
public final static String ERR_CODE = "err_code";
public final static String ERR_CODE_DESC = "err_code_des";
public final static String ERR_CODE_DES = "err_code_des";
public final static String NONCE_STR = "nonce_str";
public final static String DEV_ID = "dev_id";
public final static String SIGN = "sign";
@@ -42,6 +42,7 @@ public class WxPayConstant {
public final static String VALID_END_DATE = "valid_end_date";
public final static String PRICE = "price";
public final static String STATUS = "status";
public final static String STATUS_DES = "status_des";

public final static String SCENE_TYPE = "scene_type";
public final static String SCENE_VERIFY = "2";
@@ -53,6 +54,7 @@ public class WxPayConstant {
public final static String VERIFY = "verify";
public final static String PAY = "pay";
public final static String CANCEL = "cancel";
public final static String CANCEL_DES = "cancel_des";

public final static String REG_QRCODE_URL = "qrcode_url";
public final static String POS_QRCODE_RULE = "pos_qrcode_rule";
@@ -62,7 +64,7 @@ public class WxPayConstant {
public final static String MEM_DISCOUNT_RATE = "discount_rate";
public final static String MEM_COUPON = "coupon";
public final static String MEM_COUPONS = "coupons";
public final static String MEM_COUPON_DESC = "coupon_desc";
public final static String MEM_COUPON_DES = "coupon_des";
public final static String MEM_CARD = "card";
public final static String MEM_LEVEL = "level";
public final static String AVAIL_CO_LIST = "avail_co_list";
@@ -105,7 +107,7 @@ public class WxPayConstant {
public final static String NEU_PAY_ORDER_ID = "PaymentNumberOfPlatform"; // 东软平台支付订单号
public final static String NEU_PAY_ORDER_TIME = "PaymentOrderTime"; // 东软平台支付订单创建时间
public final static String NEU_PAY_ORDER_TYPE = "PaymentType"; // 支付方式: 0微信;1支付宝;2现金;3会员折扣;4优惠券;5预付卡;6银行卡
public final static String NEU_PAY_ORDER_TYPE_DESC = "PaymentTypeDescription"; // 支付方式描述:微信或支付宝或现金或会员折扣或优惠券或预付卡或银行卡
public final static String NEU_PAY_ORDER_TYPE_DES = "PaymentTypeDescription"; // 支付方式描述:微信或支付宝或现金或会员折扣或优惠券或预付卡或银行卡
public final static String NEU_PAY_ORDER_PARAM = "PaymentThirdPartyString"; // 第三方使用数据,JSON存储,包含富茂所需的系统要素
public final static String NEU_PAY_ORDER_STATUS = "PaymentStatus"; // 支付状态:0非手动同步, 1手动同步
public final static String NEU_PAY_ORDER_OUT_NO = "OuterPaymentNumber"; // 第三方(微信、支付宝、富茂预付卡)支付订单流水号,富茂优惠券ID,现金和富茂会员折扣时为空
@@ -117,7 +119,7 @@ public class WxPayConstant {
public final static String NEU_REFUND_ORDER_TIME = "RefundOrderTime"; // 东软平台退款订单创建时间
public final static String NEU_REFUND_ORDER_TYPE = "RefundType"; // 退款方式: 0微信;1支付宝;2现金;3会员折扣;4优惠券;5预付卡;6银行卡;7记账;
// 退款方式可以与支付方式不同,但只能是记账,作为线下手动操作退款方式
public final static String NEU_REFUND_ORDER_TYPE_DESC = "RefundTypeDescription"; // 退款方式描述:微信或支付宝或现金或会员折扣或优惠券或预付卡或银行卡或记账
public final static String NEU_REFUND_ORDER_TYPE_DES = "RefundTypeDescription"; // 退款方式描述:微信或支付宝或现金或会员折扣或优惠券或预付卡或银行卡或记账
public final static String NEU_REFUND_ORDER_PARAM = "RefundThirdPartyString"; // 第三方使用数据,JSON存储,包含富茂所需的系统要素
public final static String NEU_REFUND_ORDER_STATUS = "RefundStatus"; // 退款状态:0非手动, 1手动退款, 2手动释放同步
public final static String NEU_REFUND_ORDER_OUT_NO = "OuterRefundNumber"; // 第三方(微信、支付宝、富茂预付卡)支付订单流水号,富茂优惠券ID,现金和富茂会员折扣时为空


+ 19
- 1
mallinkService/src/main/resources/mapper/WxPayOrderMapper.xml View File

@@ -23,13 +23,19 @@
<result column="share_amount" jdbcType="INTEGER" property="shareAmount"/>
<result column="rate_amount" jdbcType="INTEGER" property="rateAmount"/>
<result column="fail_reason" jdbcType="VARCHAR" property="failReason"/>
<result column="pos_pay_order_id" jdbcType="BIGINT" property="posPayOrderId"/>
<result column="pos_pay_order_time" jdbcType="BIGINT" property="posPayOrderTime"/>
<result column="pos_payment_type" jdbcType="INTEGER" property="posPaymentType"/>
<result column="pos_pay_order_no" jdbcType="INTEGER" property="posPayOrderNo"/>
<result column="pos_pay_detail" jdbcType="INTEGER" property="posPayDetail"/>
</resultMap>

<sql id="allColumns">
`id`,`tenant_id`,`create_time`,`update_time`,`order_id`,`c_user_id`,`b_user_id`,
`auth_code`,`ip`,`pay_amount`,`pay_time_start`,`pay_time_end`,
`prepay_id`,`transaction_id`,`pay_vendor`,`pay_order_no`,
`pay_order_status`,`share`,`share_amount`,`rate_amount`,`fail_reason`
`pay_order_status`,`share`,`share_amount`,`rate_amount`,`fail_reason`,
`pos_pay_order_id`,`pos_pay_order_time`,`pos_payment_type`,`pos_pay_order_no`,`pos_pay_detail`
</sql>

<sql id="dynamicWhereConditions">
@@ -111,6 +117,18 @@
<if test=" null != failReason ">
and `fail_reason` like concat('%', #{failReason},'%')
</if>
<if test=" null != posPayOrderId ">
and `pos_pay_order_id` = #{posPayOrderId}
</if>
<if test=" null != posPayOrderTime ">
and `pos_pay_order_time` = #{posPayOrderTime}
</if>
<if test=" null != posPaymentType ">
and `pos_payment_type` = #{posPaymentType}
</if>
<if test=" null != posPayOrderNo ">
and `pos_pay_order_no` = #{posPayOrderNo}
</if>
<if test=" null != ids ">
and id in
<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">


Loading…
Cancel
Save