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

[POS][修改]:卡预支付及预支付取消

release_toaliyun_real
Stormeye Wu 6 лет назад
Родитель
Сommit
792501c3b6
8 измененных файлов: 306 добавлений и 54 удалений
  1. +84
    -6
      mallinkPosApi/src/main/java/com/iformall/controller/PosController.java
  2. +21
    -4
      mallinkPosApi/src/main/java/com/iformall/service/PosService.java
  3. +169
    -18
      mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java
  4. +1
    -1
      mallinkService/src/main/java/com/iformall/domain/po/WxCardSpend.java
  5. +3
    -4
      mallinkService/src/main/java/com/iformall/enums/EnumCardSpendFrom.java
  6. +15
    -6
      mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java
  7. +2
    -2
      mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java
  8. +11
    -13
      mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java

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

@@ -459,15 +459,92 @@ public class PosController extends BaseController {

@ApiOperation(value = "消费卡预支付", notes = "{" +
"\"dev_id\":\"string(必填)\"," +
"\"nonce_str\":\"string(必填)\"," +
"\"tenant_id\":\"string(必填)\"," +
"\"merchant_id\":\"string(必填)\"," +
"\"bu_user_id\":\"string(必填)\"," +
"\"nonce_str\":\"string(必填)\"," +
"\"pos_order_id\":\"string(必填)\"," +
"\"pos_amount\":\"string(必填)\"," +
"\"pos_amount\":\"string(单位:分)(必填)\"," +
"\"card_id\":\"string(必填)\" }")
@PostMapping("/cardPayPre")
@SystemControllerLog(description = "消费卡预支付")
public Map<String, String> cardPayPre(@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("resKey");
logger.info("resKey: " + resKey);

try {
retMap = posService.cardPayPre(params);
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(必填)\"," +
"\"pos_order_id\":\"string(必填)\"," +
"\"pos_amount\":\"string(单位:分)(必填)\"," +
"\"card_id\":\"string(必填)\"," +
"\"card_spend_id\":\"string(必填)\"}")
@PostMapping("/cardPayPreCancel")
@SystemControllerLog(description = "消费卡预支付取消")
public Map<String, String> cardPayPreCancel(@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("resKey");
logger.info("resKey: " + resKey);

try {
retMap = posService.cardPayPreCancel(params);
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(必填)\"," +
"\"pos_order_id\":\"string(必填)\"," +
"\"pos_amount\":\"string(单位:分)(必填)\"," +
"\"card_id\":\"string(必填)\" }")
@PostMapping("/cardPay")
@SystemControllerLog(description = "消费卡支付")
public Map<String, String> cardPay(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject();

@@ -481,7 +558,7 @@ public class PosController extends BaseController {
logger.info("resKey: " + resKey);

try {
retMap = posService.cardPay(params);
retMap = posService.cardPayPre(params);
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",
WxPayConstant.RET_SUCCESS, null);
} catch (MallinkException e) {
@@ -497,13 +574,14 @@ 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(必填)\"," +
"\"coupon_order_id\":\"string(必填)\"" +
"\"nonce_str\":\"string(必填)\"," +
"\"force\":\"string(选填true/false)\" }")
"\"pos_amount\":\"string(单位:分)(必填)\"," +
"\"card_id\":\"string(必填)\"," +
"\"card_spend_id\":\"string(必填)\"}")
@PostMapping("/cardPayCancel")
@SystemControllerLog(description = "消费卡支付取消")
public Map<String, String> cardPayCancel(@RequestBody Map<String, String> params) {


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

@@ -36,7 +36,7 @@ public interface PosService {
* @return
* @throws MallinkException
*/
Map<String, String> couponOrderVerifyDo(@RequestBody Map<String, String> params, EnumVerifyActionType actionType) throws MallinkException;
Map<String, String> couponOrderVerifyDo(Map<String, String> params, EnumVerifyActionType actionType) throws MallinkException;

/**
* 核销取消(check, pre_verify, verify) for selected_coupon_list
@@ -54,7 +54,23 @@ public interface PosService {
* @return
* @throws MallinkException
*/
Map<String, String> couponOrderVerifyListDo(@RequestBody Map<String, String> params, EnumVerifyActionType actionType) throws MallinkException;
Map<String, String> couponOrderVerifyListDo(Map<String, String> params, EnumVerifyActionType actionType) throws MallinkException;

/**
* 消费卡POS预支付
* @param params
* @return
* @throws MallinkException
*/
Map<String, String> cardPayPre(Map<String, String> params) throws MallinkException;

/**
* 消费卡POS预支付取消
* @param params
* @return
* @throws MallinkException
*/
Map<String, String> cardPayPreCancel(Map<String, String> params) throws MallinkException;

/**
* 消费卡POS支付
@@ -62,7 +78,8 @@ public interface PosService {
* @return
* @throws MallinkException
*/
Map<String, String> cardPay(@RequestBody Map<String, String> params) throws MallinkException;
Map<String, String> cardPay(Map<String, String> params) throws MallinkException;


/**
* 消费卡POS支付取消
@@ -70,5 +87,5 @@ public interface PosService {
* @return
* @throws MallinkException
*/
Map<String, String> cardPayCancel(@RequestBody Map<String, String> params) throws MallinkException;
Map<String, String> cardPayCancel(Map<String, String> params) throws MallinkException;
}

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

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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.iformall.common.ErrorCode;
@@ -12,6 +13,7 @@ import com.iformall.mapper.WxCouponMapper;
import com.iformall.mapper.WxCouponMerchantMapper;
import com.iformall.mapper.WxCouponOrderMapper;
import com.iformall.mapper.WxOrderMapper;
import com.iformall.pay.WxPay;
import com.iformall.pay.WxPayConstant;
import com.iformall.service.*;
import lombok.AllArgsConstructor;
@@ -308,14 +310,14 @@ public class PosServiceImpl implements PosService {
String errMessage = "request params[verify_type] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
}
if (!(verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_INDEPENT) || verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_PAY))) {
if (!(verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_TYPE_INDEPENT) || verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_TYPE_PAY))) {
String errMessage = "request params[verify_type] only support independent or pay.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), errMessage);
}
} else if (actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT)) {
verifyType = WxPayConstant.VERIFY_INDEPENT;
verifyType = WxPayConstant.VERIFY_TYPE_INDEPENT;
} else if (actionType.equals(EnumVerifyActionType.VERIFY_PAY)) {
verifyType = WxPayConstant.VERIFY_PAY;
verifyType = WxPayConstant.VERIFY_TYPE_PAY;
}
if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) ||
actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT) ||
@@ -401,7 +403,7 @@ public class PosServiceImpl implements PosService {
String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID
String posAmountStr = params.get(WxPayConstant.POS_AMOUNT); // POS订单总额(单位:分)
String selCoListStr = params.get(WxPayConstant.SELECTED_COUPON_ORDER_LIST); // 选中的优惠券列表
String verifyType = WxPayConstant.VERIFY_PAY; // 此接口只有支付使用
String verifyType = WxPayConstant.VERIFY_TYPE_PAY; // 此接口只有支付使用

if (StringUtils.isBlank(tenantId)) {
String errMessage = "request params[tenant_id] error.";
@@ -522,7 +524,7 @@ public class PosServiceImpl implements PosService {
}
// 4.1 检查券类型
if (actionType.equals(EnumVerifyActionType.CHECK)) {
if (verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_INDEPENT)) {
if (verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_TYPE_INDEPENT)) {
if (!(couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) ||
couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_LIPIN.getCode()) ||
couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_PRESS.getCode()) ||
@@ -532,7 +534,7 @@ public class PosServiceImpl implements PosService {
throw new MallinkException(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT);
}
}
if (verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_PAY)) {
if (verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_TYPE_PAY)) {
if (!(couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) ||
couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_MANJIAN.getCode()) ||
couponOrderCVo.getCouponType().equals(EnumCouponType.COUPON_DAIJIN.getCode())
@@ -636,12 +638,12 @@ public class PosServiceImpl implements PosService {
}
logger.info("券可以被核销: " + couponOrderIdStr);
retMap.put(WxPayConstant.ID, couponOrderIdStr);
retMap.put(WxPayConstant.CHECK, "true");
retMap.put(WxPayConstant.CHECK, WxPayConstant.TRUE);
return retMap;
} else if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode())) {
logger.info("券可以被核销: " + couponOrderIdStr);
retMap.put(WxPayConstant.ID, couponOrderIdStr);
retMap.put(WxPayConstant.CHECK, "true");
retMap.put(WxPayConstant.CHECK, WxPayConstant.TRUE);
return retMap;
}
} else if (actionType.equals(EnumVerifyActionType.PRE_VERIFY)) {
@@ -667,7 +669,7 @@ public class PosServiceImpl implements PosService {
remainAmount = 0;
}
retMap.put(WxPayConstant.ID, couponOrderIdStr);
retMap.put(WxPayConstant.PRE_VERIFY, "true");
retMap.put(WxPayConstant.PRE_VERIFY, WxPayConstant.TRUE);
retMap.put(WxPayConstant.DEDUCT_AMOUNT, String.valueOf(couponOrderCVo.getPrice()));
retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(remainAmount));
return retMap;
@@ -681,7 +683,7 @@ public class PosServiceImpl implements PosService {
remainAmount = 0;
}
retMap.put(WxPayConstant.ID, couponOrderIdStr);
retMap.put(WxPayConstant.PRE_VERIFY, "true");
retMap.put(WxPayConstant.PRE_VERIFY, WxPayConstant.TRUE);
retMap.put(WxPayConstant.DEDUCT_AMOUNT, String.valueOf(couponOrderCVo.getPrice()));
retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(remainAmount));
return retMap;
@@ -733,7 +735,7 @@ public class PosServiceImpl implements PosService {
remainAmount = 0;
}
retMap.put(WxPayConstant.ID, couponOrderIdStr);
retMap.put(WxPayConstant.VERIFY, "true");
retMap.put(WxPayConstant.VERIFY, WxPayConstant.TRUE);
retMap.put(WxPayConstant.DEDUCT_AMOUNT, String.valueOf(couponOrderCVo.getPrice()));
retMap.put(WxPayConstant.REMAIN_AMOUNT, String.valueOf(remainAmount));
return retMap;
@@ -871,6 +873,7 @@ public class PosServiceImpl implements PosService {

try {
cancelVerify(couponOrderCVo, buUserId, posOrderId);
retMap.put(WxPayConstant.CANCEL, WxPayConstant.TRUE);
return retMap;
} catch (MallinkException e) {
logger.error(e.getMessage());
@@ -1153,7 +1156,7 @@ public class PosServiceImpl implements PosService {

@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> cardPay(@RequestBody Map<String, String> params) throws MallinkException {
public Map<String, String> cardPayPre(Map<String, String> params) throws MallinkException {
Map<String, String> retMap = new HashMap<>();

String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID
@@ -1173,7 +1176,7 @@ public class PosServiceImpl implements PosService {
logger.error(ErrorCode.POS_CONFIG_NOT_FOUND.getMessage());
throw new MallinkException(ErrorCode.POS_CONFIG_NOT_FOUND);
}
if (!config.getCoupon().equals(EnumEnableType.Enable.getCode())) {
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);
}
@@ -1195,7 +1198,7 @@ public class PosServiceImpl implements PosService {
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
}
if (StringUtils.isBlank(cardIdStr)) {
String errMessage = "request params[coupon_order_id] error.";
String errMessage = "request params[card_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
}

@@ -1255,15 +1258,157 @@ 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.setTenantId(merchant.getTenantId());
record.setCardId(cardId);
record.setOwnerId(couponOrder.getOwnerId());
record.setMerchantId(merchantId);
record.setPosOrderId(posOrderId);
record.setDeductionAmount(posAmount);

try {
WxCardSpend cardSpend = cardSpendService.cardSpendForPosPrePay(record);
JSONObject retObj = new JSONObject();
retObj.put(WxPayConstant.ID, cardSpend.getId());
retObj.put(WxPayConstant.DEDUCT_AMOUNT, posAmount);
retObj.put(WxPayConstant.REMAIN_AMOUNT, cardSpend.getCardRemainAmount());
retObj.put(WxPayConstant.PRE_PAY, 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 Map<String, String> cardPayPreCancel(@RequestBody Map<String, String> params) throws MallinkException {
Map<String, String> 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.POS_AMOUNT); // POS订单总额(单位:分)
String cardIdStr = params.get(WxPayConstant.CARD_ID); // 消费卡ID
String cardSpendIdStr = params.get(WxPayConstant.CARD_SPEND_ID); // 消费卡花费ID

if (StringUtils.isBlank(tenantId)) {
String errMessage = "request params[tenant_id] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
}
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)) {
String errMessage = "request params[merchant_id] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
}
if (StringUtils.isBlank(buUserIdStr)) {
String errMessage = "request params[bu_user_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
}
if (StringUtils.isBlank(posOrderIdStr)) {
String errMessage = "request params[pos_order_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
}
if (StringUtils.isBlank(posAmountStr)) {
String errMessage = "request params[pos_amount] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
}
if (StringUtils.isBlank(cardIdStr)) {
String errMessage = "request params[card_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
}
if (StringUtils.isBlank(cardSpendIdStr)) {
String errMessage = "request params[card_spend_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
}

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 = 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() + ": " + buUserIdStr);
throw new MallinkException(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG);
}

WxCouponOrder couponOrder = couponOrderService.getById(cardId);
if(couponOrder == null) {
logger.error("卡不存在: " + cardIdStr);
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND);
}

WxCardSpend record = new WxCardSpend();
record.setId(cardSpendId);
record.setFrom(EnumCardSpendFrom.POS.getCode());
record.setTenantId(merchant.getTenantId());
record.setCardId(cardId);
record.setOwnerId(couponOrder.getOwnerId());
record.setMerchantId(merchantId);
record.setOrderId(posOrderId);
record.setPosOrderId(posOrderId);
record.setDeductionAmount(posAmount);
record.setPayStatus(EnumCardSpendStatus.PREV_PAY.getCode());

try {
//return cardSpendService.createCardSpend(record, order, couponMerchant);
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());
@@ -1271,13 +1416,19 @@ public class PosServiceImpl implements PosService {
logger.error("card spend error, req 3: " + record.toString() + ", e:" + e.getMessage());
throw new MallinkException(500, e.getMessage());
}
retMap.put(WxPayConstant.RET, "");
return retMap;
}

@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> cardPayCancel(@RequestBody Map<String, String> params) throws MallinkException {
public Map<String, String> cardPay(Map<String, String> params) throws MallinkException {
return null;
}

@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> cardPayCancel(Map<String, String> params) throws MallinkException {
return null;
}
}

+ 1
- 1
mallinkService/src/main/java/com/iformall/domain/po/WxCardSpend.java Просмотреть файл

@@ -65,7 +65,7 @@ public class WxCardSpend extends BaseEntity {
@io.swagger.annotations.ApiModelProperty(value="支付状态(0:未分帐, 1:已分账, 2:已人工分账, 10:预支付(POS))",name="payStatus")
private Integer payStatus;

@io.swagger.annotations.ApiModelProperty(value="来源(0:C端小程序扫一扫, 1:B端POS, 2:东软POS)",name="from")
@io.swagger.annotations.ApiModelProperty(value="来源(0:C端小程序扫一扫, 1:POS支付)",name="from")
private Integer from;

@io.swagger.annotations.ApiModelProperty(value="pos状态(1:POS线下退款开始, 2:POS线下退款成功)",name="posRefundStatus")


+ 3
- 4
mallinkService/src/main/java/com/iformall/enums/EnumCardSpendFrom.java Просмотреть файл

@@ -5,11 +5,10 @@ package com.iformall.enums;
*/
public enum EnumCardSpendFrom {

// 0:C端小程序扫一扫, 1:B端POS, 2:东软POS
// 0:C端小程序扫一扫, 1:POS支付

C(0, "支付"),
POS_B(1, "B端POS"),
POS_NEUSOFT(2, "东软POS"),
C(0, "小程序支付"),
POS(1, "POS支付")
;

public static EnumCardSpendFrom getEnum(Integer code) {


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

@@ -27,11 +27,19 @@ public class WxPayConstant {
public final static String POS_AMOUNT = "pos_amount";
public final static String MEM_ID = "mem_id";
public final static String MEM_PHONE = "mem_phone";
public final static String CARD_ID = "card_id";
public final static String CARD_SPEND_ID = "card_spend_id";

public final static String VERIFY_TYPE = "verify_type";
public final static String VERIFY_INDEPENT = "independent";
public final static String VERIFY_PAY = "pay";
public final static String VERIFY_TYPE_INDEPENT = "independent";
public final static String VERIFY_TYPE_PAY = "pay";

public final static String CARD_ID = "card_id";
public final static String CHECK = "check";
public final static String PRE_VERIFY = "pre_verify";
public final static String PRE_PAY= "pre_pay";
public final static String VERIFY = "verify";
public final static String PAY = "pay";
public final static String CANCEL = "cancel";

public final static String REG_QRCODE_URL = "qrcode_url";
public final static String POS_QRCODE_RULE = "pos_qrcode_rule";
@@ -43,9 +51,7 @@ public class WxPayConstant {
public final static String MEM_LEVEL = "level";
public final static String AVAIL_CO_LIST = "avail_co_list";
public final static String ID = "id";
public final static String CHECK = "check";
public final static String PRE_VERIFY = "pre_verify";
public final static String VERIFY = "verify";

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

@@ -54,7 +60,10 @@ public class WxPayConstant {
public final static String SALE_FEE = "sale_fee";

public final static String ORG_AMOUNT = "org_amount";
public final static String ORG_REMAIN_AMOUNT = "org_remain_amount";

public final static String RET = "ret";

public final static String TRUE = "true";

}

+ 2
- 2
mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java Просмотреть файл

@@ -106,6 +106,6 @@ public interface WxCardSpendService {
/**
* POS 卡支付相关接口
*/
void cardSpendForPosPrePay(WxCardSpend record) throws MallinkException;
void cardSpendForPosPrePayCancel(WxCardSpend record) throws MallinkException;
WxCardSpend cardSpendForPosPrePay(WxCardSpend record) throws MallinkException;
WxCardInfo cardSpendForPosPrePayCancel(WxCardInfo cardInfo, WxCardSpend record) throws MallinkException;
}

+ 11
- 13
mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java Просмотреть файл

@@ -549,7 +549,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
}

@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public void cardSpendForPosPrePay(WxCardSpend record) throws MallinkException {
public WxCardSpend cardSpendForPosPrePay(WxCardSpend record) throws MallinkException {
Date curDate = new Date();
final IdWorker idWorker = IdWorker.get();
// 1. get card info
@@ -628,10 +628,11 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
logger.error(errMessage);
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), errMessage);
}
return record;
}

@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public void cardSpendForPosPrePayCancel(WxCardSpend record) throws MallinkException {
public WxCardInfo cardSpendForPosPrePayCancel(WxCardInfo cardInfo, WxCardSpend record) throws MallinkException {
Date curDate = new Date();
if (record.getId() == null) {
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL);
@@ -640,12 +641,6 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
logger.error("card spend not prev pay");
throw new MallinkException(ErrorCode.CARD_SPEND_IS_NOT_PREV);
}
// 1. get card info
WxCardInfo cardInfo = wxCardInfoMapper.selectByPrimaryKey(record.getCardId());
if (cardInfo == null) {
logger.error("card not found: " + record.getCardId());
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND);
}
// 2. coupon
Integer subsidyRate = 0;
WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(cardInfo.getCouponId());
@@ -682,16 +677,17 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
WxCardInfo updateCardInfo = new WxCardInfo();
updateCardInfo.setId(record.getCardId());
if (cardInfo.getAmount().equals(remaingAmount) &&
cardInfo.getSupportTransfer().equals(EnumCouponTransfer.NO.getCode())) {
cardInfo.getSupportTransfer().equals(EnumCouponTransfer.NO.getCode()) &&
coupon.getSupportTransfer().equals(EnumCouponTransfer.YES.getCode())) {
updateCardInfo.setSupportTransfer(EnumCouponTransfer.YES.getCode());
}

// 6. update card info
cardInfo.setRemainingAmount(remaingAmount);
cardInfo.setRemainingShareFeeAmount(remain_real_pament);
cardInfo.setUpdateDate(curDate);
updateCardInfo.setRemainingAmount(remaingAmount);
updateCardInfo.setRemainingShareFeeAmount(remain_real_pament);
updateCardInfo.setUpdateDate(curDate);
try {
wxCardInfoMapper.updateByPrimaryKeySelective(cardInfo);
wxCardInfoMapper.updateByPrimaryKeySelective(updateCardInfo);
} catch (Exception e) {
String errMessage = "卡信息更新出错";
logger.error(errMessage);
@@ -707,6 +703,8 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
logger.error(errMessage);
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), errMessage);
}

return updateCardInfo;
}

}

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