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

[POS][修改]:门店用户登录,优惠试算接口修改

release_toaliyun_real
Stormeye Wu 6 лет назад
Родитель
Сommit
5bad550d01
5 измененных файлов: 466 добавлений и 408 удалений
  1. +40
    -30
      mallinkPosApi/src/main/java/com/iformall/controller/PosController.java
  2. +11
    -31
      mallinkPosApi/src/main/java/com/iformall/service/PosService.java
  3. +354
    -286
      mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java
  4. +58
    -60
      mallinkPosApi/src/test/java/com/iformall/pos/test/PosAppTest.java
  5. +3
    -1
      mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java

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

@@ -60,6 +60,7 @@ public class PosController extends BaseController {
@SystemControllerLog(description = "门店用户登录检查")
public Map<String, String> checkUserPassword(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject();
JSONObject retObj = new JSONObject();

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

try {
retMap = posService.checkUserPassword(params);
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", null);
retObj = posService.checkUserPassword(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());
}
}

@@ -97,6 +98,7 @@ public class PosController extends BaseController {
@SystemControllerLog(description = "支付计算接口")
public Map<String, String> calcForMem(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject();
JSONObject retObj = new JSONObject();

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

try {
retMap = posService.queryAndCalcMem(params);
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null);
retObj = posService.queryAndCalcMem(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());
}
}

@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(必填)\"}")
"\"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单位(分)(必填)\"," +
"\"coupon_list\":\"json array[券包ID list](必填),例[\"1\",\"2\",\"3\"]\"}")
@PostMapping("/couponOrderVerify")
@SystemControllerLog(description = "券核销")
@SystemControllerLog(description = "优惠核销接口")
public Map<String, String> couponOrderVerify(@RequestBody Map<String, String> params) {
JSONObject payContent = new JSONObject();

@@ -140,12 +149,13 @@ public class PosController extends BaseController {
logger.info(WxPayConstant.RES_KEY + ": " + resKey);

try {
retMap = posService.couponOrderVerifyDo(params, EnumPosActionType.VERIFY_INDEPENT);
retMap = posService.couponOrderVerify(params);
} 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);
}

@@ -225,13 +235,14 @@ public class PosController extends BaseController {
logger.info(WxPayConstant.RES_KEY + ": " + resKey);

try {
retMap = posService.couponOrderVerifyDo(params, EnumPosActionType.PAY_VERIFY_PRE);
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null);
//retMap = posService.couponOrderVerifyDo(params, EnumPosActionType.PAY_VERIFY_PRE);
//return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null);
} catch (MallinkException e) {
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", e.getErrorCode(), e.getMessage());
} catch (Exception e) {
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",500, e.getMessage());
}
return null;
}

@ApiOperation(value = "POS支付取消-券", notes = "{" +
@@ -305,7 +316,7 @@ public class PosController extends BaseController {
logger.info(WxPayConstant.RES_KEY + ": " + resKey);

try {
retMap = posService.couponOrderVerifyDo(params, EnumPosActionType.VERIFY_PAY);
//retMap = posService.couponOrderVerifyDo(params, EnumPosActionType.VERIFY_PAY);
} catch (MallinkException e) {
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", e.getErrorCode(), e.getMessage());
} catch (Exception e) {
@@ -435,6 +446,7 @@ public class PosController extends BaseController {
}

private Map<String, String> cardPay(@RequestBody Map<String, String> params) {
JSONObject retObj = new JSONObject();
JSONObject payContent = new JSONObject();

// 1. check sign
@@ -447,16 +459,17 @@ public class PosController extends BaseController {
logger.info(WxPayConstant.RES_KEY + ": " + resKey);

try {
retMap = posService.cardPay(params);
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", null);
retObj = posService.cardPay(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());
}
}

private Map<String, String> cardPayCancel(@RequestBody Map<String, String> params) {
JSONObject retObj = new JSONObject();
JSONObject payContent = new JSONObject();

// 1. check sign
@@ -470,14 +483,14 @@ public class PosController extends BaseController {

try {
retMap = posService.cardPayCancel(params);
return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null);
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());
}
}
*/

/**
* 构造返回map,无签名, 有错误
@@ -505,7 +518,7 @@ public class PosController extends BaseController {
* @param err
* @return
*/
private Map<String, String> buildReturnMap(Map<String, String> dataMap, String resKey, String retCode, String retMsg, ErrorCode err) {
private Map<String, String> buildReturnMap(JSONObject dataMap, String resKey, String retCode, String retMsg, ErrorCode err) {
Map<String, String> retMap = new HashMap<>();
retMap.put(WxPayConstant.RETURN_CODE, retCode);
retMap.put(WxPayConstant.RETURN_MSG, retMsg);
@@ -532,11 +545,8 @@ public class PosController extends BaseController {
* @param errMsg
* @return
*/
private Map<String, String> buildReturnMap(Map<String, String> dataMap, String resKey, String retCode, String retMsg, Integer errCode, String errMsg) {
private Map<String, String> buildReturnMap(JSONObject dataMap, String resKey, String retCode, String retMsg, Integer errCode, String errMsg) {
Map<String, String> retMap = new HashMap<>();
if(retMap == null) {
retMap = new HashMap<>();
}
retMap.put(WxPayConstant.RETURN_CODE, retCode);
retMap.put(WxPayConstant.RETURN_MSG, retMsg);
retMap.put(WxPayConstant.RESULT_CODE, "" + errCode);


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

@@ -14,42 +14,22 @@ public interface PosService {
* @param params
* @return
*/
Map<String, String> checkUserPassword(Map<String, String> params) throws MallinkException;
/**
* 获取商城会员设置状态
* @param params
* @return
*/
Map<String, String> getPosMemConfig(Map<String, String> params) throws MallinkException;
/**
* 获取商城二维码
* @param params
* @return
*/
Map<String, String> doGetQrCode(Map<String, String> params) throws MallinkException;

/**
* 识别会员
* @param params
* @return
*/
Map<String, String> checkMember(Map<String, String> params) throws MallinkException;
JSONObject checkUserPassword(Map<String, String> params) throws MallinkException;

/**
* 支付计算
* @param params
* @return
*/
Map<String, String> queryAndCalcMem(Map<String, String> params) throws MallinkException;
JSONObject queryAndCalcMem(Map<String, String> params) throws MallinkException;

/**
* 核销动作(check, pre_verify, verify)
* 核销动作
* @param params
* @param actionType
* @return
* @throws MallinkException
*/
Map<String, String> couponOrderVerifyDo(Map<String, String> params, EnumPosActionType actionType) throws MallinkException;
//Map<String, String> couponOrderVerify(Map<String, String> params) throws MallinkException;

/**
* 核销取消(check, pre_verify, verify) for selected_coupon_list
@@ -58,7 +38,7 @@ public interface PosService {
* @return
* @throws MallinkException
*/
Map<String, String> couponOrderVerifyCancel(Map<String, String> params, EnumPosActionType actionType) throws MallinkException;
//Map<String, String> couponOrderVerifyCancel(Map<String, String> params, EnumPosActionType actionType) throws MallinkException;

/**
* 核销动作(check, pre_verify, verify) for selected_coupon_list
@@ -67,7 +47,7 @@ public interface PosService {
* @return
* @throws MallinkException
*/
Map<String, String> couponOrderVerifyListDo(Map<String, String> params, EnumPosActionType actionType) throws MallinkException;
//Map<String, String> couponOrderVerifyListDo(Map<String, String> params, EnumPosActionType actionType) throws MallinkException;

/**
* 消费卡POS预支付
@@ -75,7 +55,7 @@ public interface PosService {
* @return
* @throws MallinkException
*/
Map<String, String> cardPayPre(Map<String, String> params) throws MallinkException;
//Map<String, String> cardPayPre(Map<String, String> params) throws MallinkException;

/**
* 消费卡POS预支付取消
@@ -83,7 +63,7 @@ public interface PosService {
* @return
* @throws MallinkException
*/
Map<String, String> cardPayPreCancel(Map<String, String> params) throws MallinkException;
//Map<String, String> cardPayPreCancel(Map<String, String> params) throws MallinkException;

/**
* 订单同步-Neusoft-支付或者退款成功后通知富茂
@@ -91,7 +71,7 @@ public interface PosService {
* @return
* @throws MallinkException
*/
Map<String, String> posOrderSync(Map<String, String> params) throws MallinkException;
//Map<String, String> posOrderSync(Map<String, String> params) throws MallinkException;

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


/**
@@ -108,7 +88,7 @@ public interface PosService {
* @return
* @throws MallinkException
*/
Map<String, String> cardPayCancel(Map<String, String> params) throws MallinkException;
//Map<String, String> cardPayCancel(Map<String, String> params) throws MallinkException;


}

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

@@ -62,8 +62,8 @@ public class PosServiceImpl implements PosService {
* @return
*/
@Override
public Map<String, String> checkUserPassword(Map<String, String> params) throws MallinkException {
Map<String, String> retMap = new HashMap<>();
public JSONObject checkUserPassword(Map<String, String> params) throws MallinkException {
JSONObject retMap = new JSONObject();

String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID
String phone = params.get(WxPayConstant.PHONE); // buUser's Phone
@@ -114,13 +114,18 @@ public class PosServiceImpl implements PosService {
retMap.put(WxPayConstant.MERCHANT_IMG, merchant.getImgUrl());
retMap.put(WxPayConstant.BUSER_ID, String.valueOf(user1.getId()));

retMap.put(WxPayConstant.REG_QRCODE_URL, mall.getImgQrcodeWeapp());
retMap.put(WxPayConstant.POS_QRCODE_RULE, mall.getPosQrcodeRule());
JSONObject qrCodeInfo = new JSONObject();
qrCodeInfo.put(WxPayConstant.REG_QRCODE_URL, mall.getImgQrcodeWeapp());
qrCodeInfo.put(WxPayConstant.POS_QRCODE_RULE, mall.getPosQrcodeRule());
retMap.put(WxPayConstant.QRCODE, qrCodeInfo);

JSONObject memInfo = new JSONObject();
memInfo.put(WxPayConstant.DISCOUNT, String.valueOf(config.getDiscount().equals(EnumPosEnableType.Enable.getCode())));
memInfo.put(WxPayConstant.COUPON, String.valueOf(config.getCoupon()));
memInfo.put(WxPayConstant.COUPON_DES, EnumPosCouponEnableType.getEnum(config.getCoupon()).getMessage());
memInfo.put(WxPayConstant.CARD, String.valueOf(config.getCard().equals(EnumPosEnableType.Enable.getCode())));
retMap.put(WxPayConstant.MEM_CONFIG, memInfo);

retMap.put(WxPayConstant.DISCOUNT, String.valueOf(config.getDiscount().equals(EnumPosEnableType.Enable.getCode())));
retMap.put(WxPayConstant.COUPON, String.valueOf(config.getCoupon()));
retMap.put(WxPayConstant.COUPON_DES, EnumPosCouponEnableType.getEnum(config.getCoupon()).getMessage());
retMap.put(WxPayConstant.CARD, String.valueOf(config.getCard().equals(EnumPosEnableType.Enable.getCode())));
return retMap;
} else {
logger.error(ErrorCode.PASSWORD_ERROR.getMessage());
@@ -132,179 +137,9 @@ public class PosServiceImpl implements PosService {
}
}

/**
* 获取商城会员设置状态
* @param params
* @return
*/
@Override
public Map<String, String> getPosMemConfig(Map<String, String> params) throws MallinkException {
Map<String, String> retMap = new HashMap<>();

String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID

if (StringUtils.isBlank(tenantId)) {
errParam(WxPayConstant.TENANT_ID);
}
WxMall mall = mallService.getByTenantId(tenantId);
if (mall == null) {
logger.error(ErrorCode.MALL_INFO_NOT_FOUND.getMessage());
throw new MallinkException(ErrorCode.MALL_INFO_NOT_FOUND);
}
PosMallConfig config = posMallConfigService.getByTenantId(tenantId);
if (config == null) {
logger.error(ErrorCode.MALL_INFO_NOT_FOUND.getMessage());
throw new MallinkException(ErrorCode.MALL_INFO_NOT_FOUND);
}
retMap.put(WxPayConstant.TENANT_ID, mall.getTenantId());
retMap.put(WxPayConstant.MALL_NAME, mall.getName());
retMap.put(WxPayConstant.REG_QRCODE_URL, mall.getImgQrcodeWeapp());
retMap.put(WxPayConstant.POS_QRCODE_RULE, mall.getPosQrcodeRule());

retMap.put(WxPayConstant.DISCOUNT, String.valueOf(config.getDiscount().equals(EnumPosEnableType.Enable.getCode())));
retMap.put(WxPayConstant.COUPON, String.valueOf(config.getCoupon()));
retMap.put(WxPayConstant.COUPON_DES, EnumPosCouponEnableType.getEnum(config.getCoupon()).getMessage());
retMap.put(WxPayConstant.CARD, String.valueOf(config.getCard().equals(EnumPosEnableType.Enable.getCode())));
return retMap;
}

/**
* 获取商城二维码
* @param params
* @return
*/
@Override
public Map<String, String> doGetQrCode(Map<String, String> params) throws MallinkException {
Map<String, String> retMap = new HashMap<>();

String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID

if (StringUtils.isBlank(tenantId)) {
errParam(WxPayConstant.TENANT_ID);
}
WxMall mall = mallService.getByTenantId(tenantId);
if (mall == null) {
logger.error(ErrorCode.MALL_INFO_NOT_FOUND.getMessage());
throw new MallinkException(ErrorCode.MALL_INFO_NOT_FOUND);
}
retMap.put(WxPayConstant.TENANT_ID, mall.getTenantId());
retMap.put(WxPayConstant.MALL_NAME, mall.getName());
retMap.put(WxPayConstant.REG_QRCODE_URL, mall.getImgQrcodeWeapp());
retMap.put(WxPayConstant.POS_QRCODE_RULE, mall.getPosQrcodeRule());
return retMap;
}

/**
* 识别会员
* @param params
* @return
*/
@Override
public Map<String, String> checkMember(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 memIdStr = params.get(WxPayConstant.MEM_ID); // 会员ID
String memPhoneStr = params.get(WxPayConstant.MEM_PHONE); // 会员手机
String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID
String posAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单金额(单位:分)

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 (StringUtils.isBlank(merchantIdStr)) {
errParam(WxPayConstant.MERCHANT_ID);
}
if (StringUtils.isBlank(posOrderIdStr)) {
errParam(WxPayConstant.POS_ORDER_ID);
}
if (StringUtils.isBlank(posAmountStr)) {
errParam(WxPayConstant.ORDER_AMOUNT);
}

// 1. 商户ID, B端用户ID
Long merchantId, buUserId, posOrderId;
Long posAmount = 0L;
try {
merchantId = Long.valueOf(merchantIdStr);
buUserId = Long.valueOf(buUserIdStr);
posOrderId = Long.valueOf(posOrderIdStr);
posAmount = Long.valueOf(posAmountStr);
} catch (NumberFormatException e) {
logger.error(e.getMessage());
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR);
}

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

// 3. 会员ID
if (StringUtils.isBlank(memIdStr) && StringUtils.isBlank(memPhoneStr)) {
errParam2(WxPayConstant.MEM_ID, WxPayConstant.MEM_PHONE);
}
// 4. 获取会员信息
WxCUser user = getMemUser(tenantId, memIdStr, memPhoneStr);
if (user == null) {
logger.error(ErrorCode.USER_NOT_MEMBER.getMessage());
throw new MallinkException(ErrorCode.USER_NOT_MEMBER);
}
/*
// 5. 会员level及折扣
JSONObject discountObj = new JSONObject();
posAmount = getMemLevelDiscount(discountObj, config.getDiscount(), tenantId, user, merchantId, posAmount.intValue());

retMap.put(WxPayConstant.MEM_ID, user.getId().toString());
retMap.put(WxPayConstant.MEM_PHONE, user.getPhone());

// 6. 优惠券列表
if (config.getCoupon().equals(EnumEnableType.Enable.getCode())) {
Map<String, Object> coQ = new HashMap<>();
coQ.put("tenantId", tenantId);
coQ.put("cUserId", user.getId());
coQ.put("merchantId", merchantId);
coQ.put("posOrderId", posOrderId);
coQ.put("posPayVerify", "1"); // 支付核销券需要
/// coQ.put("posIndepVerify", "1");
List<Map> couponOrderList = couponOrderService.findAvailCouponOrder(coQ);
if (couponOrderList.size() > 0) {
couponOrderList.stream().forEach( co -> {
if(co.get("type").equals(EnumCouponType.COUPON_MANJIAN.getCode())) {
co.put("type_title", EnumCouponType.COUPON_MANJIAN.getMessage());
}
if(co.get("type").equals(EnumCouponType.COUPON_DAIJIN.getCode())) {
co.put("type_title", EnumCouponType.COUPON_DAIJIN.getMessage());
}
if(co.get("type").equals(EnumCouponType.COUPON_MULTIMCH.getCode())) {
co.put("type_title", EnumCouponType.COUPON_MULTIMCH.getMessage());
}
});
retMap.put(WxPayConstant.AVAIL_CO_LIST,
JSONArray.toJSONString(couponOrderList));
} else {
retMap.put(WxPayConstant.AVAIL_CO_LIST, "[]");
}
} else {
retMap.put(WxPayConstant.AVAIL_CO_LIST, "[]");
}
*/
return retMap;
}

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

String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID
String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID
@@ -385,7 +220,7 @@ public class PosServiceImpl implements PosService {
errParam(WxPayConstant.COUPON_ORDER_LIST);
}
JSONArray couponOrderArr = JSON.parseArray(coListStr);
if (couponOrderArr.size() > 1) {
if (couponOrderArr.size() != 1) {
String errMessage = "核销只能使用一张券";
logger.error(errMessage);
throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), errMessage);
@@ -461,7 +296,7 @@ public class PosServiceImpl implements PosService {
List<WxCouponOrderCVo> avaCoList = couponOrderMapper.findAvailCouponOrder(coQ);
JSONArray selCoArr = JSONObject.parseArray(coListStr);
if (config.getCoupon().equals(EnumPosCouponEnableType.SingleEnable.getCode())) {
if (selCoArr.size() > 1) {
if (selCoArr.size() > 1) { // 为空时,返回所有可用券列表
String errMessage = "支付只能使用一张券";
logger.error(errMessage);
throw new MallinkException(ErrorCode.POS_COUPON_PAY_ERROR.getCode(), errMessage);
@@ -473,9 +308,13 @@ public class PosServiceImpl implements PosService {
JSONObject couponObj = calcOneCouponPay(promotionCalc, couponOrderCVo, selCoupon);
couponList.add(couponObj);
} catch (MallinkException e) {
throw new MallinkException(e.getErrorCode(), e.getMessage());
if (selCoupon) {
throw new MallinkException(e.getErrorCode(), e.getMessage());
}
} catch (Exception e) {
throw new MallinkException(500, e.getMessage());
if (selCoupon) {
throw new MallinkException(500, e.getMessage());
}
}
}
} else if (config.getCoupon().equals(EnumPosCouponEnableType.MultiEnable.getCode())) {
@@ -522,7 +361,7 @@ public class PosServiceImpl implements PosService {
}

/**
* 券核销计算
* 券核销计算
* @param promotionCalc
* @param merchantId
* @param couponOrderIdStr
@@ -559,9 +398,65 @@ public class PosServiceImpl implements PosService {
return retObj;
}

/**
* 单券核销
* @param promotionCalc
* @param merchantId
* @param couponOrderIdStr
* @return
*/
public JSONObject oneCouponVerify(PromotionCalc promotionCalc, String couponOrderIdStr, Long merchantId, Long buUserId, Long posOrderId) {
JSONObject retObj = new JSONObject();
Date now = new Date();
// 1. 获取券包信息
WxCouponOrderCVo couponOrderCVo = checkAndGetCouponOrder(couponOrderIdStr, merchantId, now);

// 2. 检查券类型 核销可用(4, 6, 8, 9)
EnumCouponType couponType = EnumCouponType.getEnum(couponOrderCVo.getCouponType());
if (!(couponType.getCode().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) ||
couponType.getCode().equals(EnumCouponType.COUPON_LIPIN.getCode()) ||
couponType.getCode().equals(EnumCouponType.COUPON_PRESS.getCode()) ||
couponType.getCode().equals(EnumCouponType.COUPON_GROUP.getCode()))
) {
logger.error(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT.getMessage());
throw new MallinkException(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT);
}
// 5. get coupon
WxCoupon wxCoupon = couponMapper.selectByPrimaryKey(couponOrderCVo.getCouponId());
if (wxCoupon == null) {
logger.error("券: coupon-" + wxCoupon.getId() + "不存在" + "couponOrder-" + couponOrderCVo.getId());
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL);
}

try {
doVerify(retObj, EnumPosActionType.VERIFY_INDEPENT, couponOrderCVo, wxCoupon, merchantId, buUserId, posOrderId);
} catch (MallinkException e) {
logger.error(e.getMessage());
throw new MallinkException(e.getErrorCode(), e.getMessage());
} catch (Exception e) {
logger.error(e.getMessage());
throw new MallinkException(500, e.getMessage());
}
retObj.put(WxPayConstant.COUPON_ID, couponOrderIdStr);
retObj.put(WxPayConstant.IS_SELECTED, EnumPosSelect.SELECTED.getCode());
retObj.put(WxPayConstant.TITLE, couponOrderCVo.getTitle());
retObj.put(WxPayConstant.COUPON_TYPE, couponType.getMessage());
retObj.put(WxPayConstant.COVER_IMG, couponOrderCVo.getCoverImg());
retObj.put(WxPayConstant.PRICE, couponOrderCVo.getPrice());
retObj.put(WxPayConstant.SALE_PRICE, couponOrderCVo.getSalePrice());
retObj.put(WxPayConstant.COUPON_DES, String.format("过期时间: %s", mydateFormat.format(couponOrderCVo.getExpiredTime())));
promotionCalc.setOrderAmount(couponOrderCVo.getPrice());
promotionCalc.setOrderAmountLeft(couponOrderCVo.getPrice());
promotionCalc.setPromotionAmount(couponOrderCVo.getPrice());
promotionCalc.setAmountLeftAfterPay(0);
return retObj;
}

/**
* 券支付计算
* @param promotionCalc
* @param couponOrderCVo
* @param couponSelected
* @return
*/
private JSONObject calcOneCouponPay(PromotionCalc promotionCalc, WxCouponOrderCVo couponOrderCVo, boolean couponSelected) {
@@ -617,6 +512,66 @@ public class PosServiceImpl implements PosService {
return retObj;
}

/**
* 券支付计算
* @param promotionCalc
* @param couponOrderCVo
* @param couponSelected
* @return
*/
private JSONObject oneCouponPay(PromotionCalc promotionCalc, WxCouponOrderCVo couponOrderCVo, boolean couponSelected) {
JSONObject retObj = new JSONObject();
Date now = new Date();

// 2. 检查券类型 支付可用(1, 2, 6),
EnumCouponType couponType = EnumCouponType.getEnum(couponOrderCVo.getCouponType());
if (!(couponType.getCode().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) ||
couponType.getCode().equals(EnumCouponType.COUPON_MANJIAN.getCode()) ||
couponType.getCode().equals(EnumCouponType.COUPON_DAIJIN.getCode()))) {
logger.error(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT.getMessage());
throw new MallinkException(ErrorCode.VERIFY_COUPON_TYPE_NOT_SUPPORT);
}

// 3. 满减券检查使用金额
if (couponType.equals(EnumCouponType.COUPON_MANJIAN)) {
if (promotionCalc.getOrderAmount() < couponOrderCVo.getUsePrice()) {
logger.error(ErrorCode.VERIFY_MANJIAN_USER_PRICE_NOT_TOUCH.getMessage());
throw new MallinkException(ErrorCode.VERIFY_MANJIAN_USER_PRICE_NOT_TOUCH);
}
}

// 4. 生成优惠券抵扣信息
retObj.put(WxPayConstant.COUPON_ID, couponOrderCVo.getId().toString());
retObj.put(WxPayConstant.TITLE, couponOrderCVo.getTitle());
retObj.put(WxPayConstant.COUPON_TYPE, couponType.getMessage());
retObj.put(WxPayConstant.COVER_IMG, couponOrderCVo.getCoverImg());
retObj.put(WxPayConstant.PRICE, couponOrderCVo.getPrice());
retObj.put(WxPayConstant.SALE_PRICE, couponOrderCVo.getSalePrice());
if (couponType.equals(EnumCouponType.COUPON_MANJIAN)) {
retObj.put(WxPayConstant.USE_PRICE, couponOrderCVo.getSalePrice());
String des = String.format("%s-满%s元可用,可抵%s元, 过期时间: %s",
couponType.getMessage(), couponOrderCVo.getUsePriceStr(), couponOrderCVo.getPriceStr(),
mydateFormat.format(couponOrderCVo.getExpiredTime()));
retObj.put(WxPayConstant.COUPON_DES, des);
} else {
String des = String.format("%s-可抵%s元, 过期时间: %s",
couponType.getMessage(), couponOrderCVo.getPriceStr(),
mydateFormat.format(couponOrderCVo.getExpiredTime()));
retObj.put(WxPayConstant.COUPON_DES, des);
}
if (couponSelected) {
retObj.put(WxPayConstant.IS_SELECTED, String.valueOf(EnumPosSelect.SELECTED.getCode()));
Integer remainAmount = promotionCalc.getAmountLeftAfterPay() - couponOrderCVo.getPrice();
if (remainAmount < 0) {
remainAmount = 0;
}
Integer discountAmount = promotionCalc.getAmountLeftAfterPay() - remainAmount;
promotionCalc.setPromotionAmount(discountAmount);
promotionCalc.setAmountLeftAfterPay(remainAmount);
}
return retObj;
}

private WxCouponOrderCVo checkAndGetCouponOrder(String couponOrderIdStr, Long merchantId, Date currDate) {
// 1, 获取券包信息
WxCouponOrderCVo couponOrderCVo = couponOrderService.detailCUserVo(couponOrderIdStr);
@@ -702,7 +657,7 @@ public class PosServiceImpl implements PosService {
private JSONObject getMemLevelDiscount(PromotionCalc promotionCalc, Integer discountConfig, String tenantId, WxCUser user, Long merchantId) {
JSONObject discountObj = new JSONObject();
Integer discount = 100;
if (discountConfig.equals(EnumEnableType.Enable.getCode())) {
if (discountConfig.equals(EnumPosEnableType.Enable.getCode())) {
String level = WxLevelConfigService.DEFAULT_LEVEL;
// 1. 会员级别Level
List<WxLevelConfig> levelList = levelConfigService.getByTenantId(tenantId);
@@ -750,112 +705,222 @@ public class PosServiceImpl implements PosService {
return discountObj;
}

@Override
//@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> couponOrderVerifyDo(@RequestBody Map<String, String> params, EnumPosActionType actionType) throws MallinkException {
Map<String, String> retMap = new HashMap<>();
public Map<String, String> couponOrderVerify(Map<String, String> params) throws MallinkException {
Map<String, String> dataMap = 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 sceneTypeStr = params.get(WxPayConstant.SCENE_TYPE); // 场景类型
String couponOrderIdStr = params.get(WxPayConstant.COUPON_ORDER_ID); // 券ID
String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID
String posAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单总额(单位:分)
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 sceneTypeStr = params.get(WxPayConstant.SCENE_TYPE); // 交易场景
String orderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID
String orderCreateSN = params.get(WxPayConstant.ORDER_CREATE_SN); // POS SN号
String coListStr = params.get(WxPayConstant.COUPON_ORDER_LIST); // 优惠券列表

Integer sceneType = null;
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.getCoupon().equals(EnumPosEnableType.Disable.getCode())) {
logger.error(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE.getMessage());
throw new MallinkException(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE);
} else {
dataMap.put(WxPayConstant.TENANT_ID, tenantId);
}
if (StringUtils.isBlank(merchantIdStr)) {
errParam(WxPayConstant.MERCHANT_ID);
} else {
dataMap.put(WxPayConstant.MERCHANT_ID, merchantIdStr);
}
if (StringUtils.isBlank(buUserIdStr)) {
errParam(WxPayConstant.BUSER_ID);
} else {
dataMap.put(WxPayConstant.BUSER_ID, buUserIdStr);
}
if (StringUtils.isBlank(couponOrderIdStr)) {
errParam(WxPayConstant.COUPON_ORDER_ID);
if (StringUtils.isBlank(sceneTypeStr)) {
errParam(WxPayConstant.SCENE_TYPE);
} else {
dataMap.put(WxPayConstant.SCENE_TYPE, sceneTypeStr);
}
if (actionType.equals(EnumPosActionType.CHECK)) {
if (StringUtils.isBlank(sceneTypeStr)) {
errParam(WxPayConstant.SCENE_TYPE);
}
try {
sceneType = Integer.valueOf(sceneTypeStr);
} catch (NumberFormatException e) {
logger.error(e.getMessage());
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage());
}
} else if (actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) {
sceneType = EnumPosSceneType.VERIFY.getCode();
} else if (actionType.equals(EnumPosActionType.VERIFY_PAY)) {
sceneType = EnumPosSceneType.PAY.getCode();
if (StringUtils.isBlank(orderIdStr)) {
errParam(WxPayConstant.POS_ORDER_ID);
} else {
dataMap.put(WxPayConstant.POS_ORDER_ID, orderIdStr);
}
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 (StringUtils.isBlank(orderCreateSN)) {
errParam(WxPayConstant.ORDER_CREATE_SN);
} else {
dataMap.put(WxPayConstant.ORDER_CREATE_SN, orderCreateSN);
}
if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) ||
actionType.equals(EnumPosActionType.VERIFY_PAY)) {
if (StringUtils.isBlank(posAmountStr)) {
errParam(WxPayConstant.ORDER_AMOUNT);
}

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;
Integer posAmount = 0;
// 1. POS 支持 配置
PosMallConfig config = posMallConfigService.getByTenantId(tenantId);
if (config == null) {
logger.error(ErrorCode.POS_CONFIG_NOT_FOUND.getMessage());
throw new MallinkException(ErrorCode.POS_CONFIG_NOT_FOUND);
}

// 2. 商户ID, B端用户ID
Long merchantId, buUserId, posOrderId;
try {
merchantId = Long.valueOf(merchantIdStr);
buUserId = Long.valueOf(buUserIdStr);
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.PAY_VERIFY_PRE) ||
actionType.equals(EnumPosActionType.VERIFY_PAY)) {
posAmount = Integer.valueOf(posAmountStr);
}
posOrderId = Long.valueOf(orderIdStr);
} catch (NumberFormatException e) {
logger.error(e.getMessage());
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage());
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR);
}
// 2. check merchant

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

JSONArray coRetArr = new JSONArray();
if (couponOrderIdStr != null) {
EnumPosSceneType sceneType = EnumPosSceneType.getEnum(iSceneType);
JSONObject promotionData = new JSONObject();
JSONObject promotionInfo = new JSONObject();
JSONObject promotionPayment = new JSONObject();
PromotionCalc promotionCalc = new PromotionCalc();
if (sceneType.equals(EnumPosSceneType.VERIFY)) {
if (config.getCoupon().equals(EnumPosCouponEnableType.Disable.getCode())) {
logger.error(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE.getMessage());
throw new MallinkException(ErrorCode.POS_CONFIG_MEM_COUPON_DISABLE);
}
JSONObject promotionCoupon = new JSONObject();
JSONArray couponList = new JSONArray();
if (StringUtils.isBlank(coListStr)) {
errParam(WxPayConstant.COUPON_ORDER_LIST);
}
JSONArray couponOrderArr = JSON.parseArray(coListStr);
if (couponOrderArr.size() > 1) {
String errMessage = "核销只能使用一张券";
logger.error(errMessage);
throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), errMessage);
}
String couponOrderIdStr = couponOrderArr.getString(0);
if (couponOrderIdStr != null) {
try {
JSONObject couponPromoMap = oneCouponVerify(promotionCalc, couponOrderIdStr, merchantId, buUserId, posOrderId);
couponList.add(couponPromoMap);
} catch (MallinkException e) {
throw new MallinkException(e.getErrorCode(), e.getMessage());
} catch (Exception e) {
throw new MallinkException(500, e.getMessage());
}
}
promotionCoupon.put(WxPayConstant.COUPON_ORDER_LIST, couponList);
// 券优惠总信息
promotionCoupon.put(WxPayConstant.COUPON_PROMOTION_AMOUNT, promotionCalc.getPromotionAmount());
promotionInfo.put(WxPayConstant.COUPON, promotionCoupon);
} else if(sceneType.equals(EnumPosSceneType.PAY)) {
JSONObject promotionCoupon = new JSONObject();
JSONArray couponList = new JSONArray();

String memIdStr = params.get(WxPayConstant.MEM_ID); // 会员ID
String memPhoneStr = params.get(WxPayConstant.MEM_PHONE); // 会员手机
String orderAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单金额(单位:分)
String orderAmountLeftStr = params.get(WxPayConstant.ORDER_AMOUNT_LEFT); // POS订单金额(单位:分)
if (StringUtils.isBlank(orderAmountStr)) {
errParam(WxPayConstant.ORDER_AMOUNT);
} else {
dataMap.put(WxPayConstant.ORDER_AMOUNT, orderAmountStr);
}
if (StringUtils.isBlank(orderAmountLeftStr)) {
errParam(WxPayConstant.ORDER_AMOUNT_LEFT);
} else {
dataMap.put(WxPayConstant.ORDER_AMOUNT_LEFT, orderAmountLeftStr);
}
if (StringUtils.isBlank(memIdStr) && StringUtils.isBlank(memPhoneStr)) {
errParam2(WxPayConstant.MEM_ID, WxPayConstant.MEM_PHONE);
}
// 10. 获取会员信息
WxCUser user = getMemUser(tenantId, memIdStr, memPhoneStr);
if (user == null) {
logger.error(ErrorCode.USER_NOT_MEMBER.getMessage());
throw new MallinkException(ErrorCode.USER_NOT_MEMBER);
}
if (user != null) {
dataMap.put(WxPayConstant.MEM_ID, user.getId().toString());
dataMap.put(WxPayConstant.MEM_PHONE, user.getPhone());
}
// 11. 订单金额
Integer orderAmount, orderAmountLeft;
try {
Map<String,String> oneRetMap = doVerifyActionForOneCouponOrder(
actionType, sceneType,
tenantId, merchantIdStr, merchantId,
buUserIdStr, buUserId,
posOrderIdStr, posOrderId, posAmount,
couponOrderIdStr);
coRetArr.add(oneRetMap);
} catch (MallinkException e) {
throw new MallinkException(e.getErrorCode(), e.getMessage());
orderAmount = Integer.valueOf(orderAmountStr);
orderAmountLeft = Integer.valueOf(orderAmountLeftStr);
} catch (NumberFormatException e) {
logger.error(e.getMessage());
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR);
}
promotionCalc.setOrderAmount(orderAmount);
promotionCalc.setOrderAmountLeft(orderAmountLeft);
promotionCalc.setPromotionAmount(0);
promotionCalc.setAmountLeftAfterPay(orderAmountLeft);
// 12. 会员折扣
JSONObject discountObj = getMemLevelDiscount(promotionCalc, config.getDiscount(), tenantId, user, merchantId);
promotionInfo.put(WxPayConstant.MEMBER_DISCOUNT, discountObj);
// 14. 获取用户可用券列表
if (!config.getCoupon().equals(EnumPosCouponEnableType.Disable.getCode())) {
Map<String, Object> coQ = new HashMap<>();
coQ.put("tenantId", tenantId);
coQ.put("cUserId", user.getId());
coQ.put("merchantId", merchantId);
List<WxCouponOrderCVo> avaCoList = couponOrderMapper.findAvailCouponOrder(coQ);
JSONArray selCoArr = JSONObject.parseArray(coListStr);
if (config.getCoupon().equals(EnumPosCouponEnableType.SingleEnable.getCode())) {
if (selCoArr.size() > 1) {
String errMessage = "支付只能使用一张券";
logger.error(errMessage);
throw new MallinkException(ErrorCode.POS_COUPON_PAY_ERROR.getCode(), errMessage);
}
for (int i = 0; i < avaCoList.size(); i++) {
WxCouponOrderCVo couponOrderCVo = avaCoList.get(i);
boolean selCoupon = isSelCoupon(selCoArr, couponOrderCVo.getId());
try {
JSONObject couponObj = oneCouponPay(promotionCalc, couponOrderCVo, selCoupon);
couponList.add(couponObj);
} catch (MallinkException e) {
throw new MallinkException(e.getErrorCode(), e.getMessage());
} catch (Exception e) {
throw new MallinkException(500, e.getMessage());
}
}
} else if (config.getCoupon().equals(EnumPosCouponEnableType.MultiEnable.getCode())) {
for (int i = 0; i < avaCoList.size(); i++) {
WxCouponOrderCVo couponOrderCVo = avaCoList.get(i);
boolean selCoupon = isSelCoupon(selCoArr, couponOrderCVo.getId());
try {
JSONObject couponObj = calcOneCouponPay(promotionCalc, couponOrderCVo, selCoupon);
couponList.add(couponObj);
} catch (MallinkException e) {
throw new MallinkException(e.getErrorCode(), e.getMessage());
} catch (Exception e) {
throw new MallinkException(500, e.getMessage());
}
}
}
}
promotionCoupon.put(WxPayConstant.COUPON_ORDER_LIST, couponList);
// 券优惠总信息
promotionCoupon.put(WxPayConstant.COUPON_PROMOTION_AMOUNT, promotionCalc.getPromotionAmount());
promotionInfo.put(WxPayConstant.COUPON, promotionCoupon);
}
retMap.put(WxPayConstant.RET, coRetArr.toJSONString());
return retMap;
// 构造支付信息
promotionPayment.put(WxPayConstant.ORDER_AMOUNT, promotionCalc.getOrderAmount());
promotionPayment.put(WxPayConstant.ORDER_AMOUNT_LEFT, promotionCalc.getOrderAmountLeft());
promotionPayment.put(WxPayConstant.PROMOTION_AMOUNT, promotionCalc.getPromotionAmount());
promotionPayment.put(WxPayConstant.AMOUNT_LEFT_AFTER_PAY, promotionCalc.getAmountLeftAfterPay());
promotionData.put(WxPayConstant.PAYMENT_PREDICTION, promotionPayment);
promotionData.put(WxPayConstant.PROMOTION_INFO, promotionInfo);
dataMap.put(WxPayConstant.PROMOTION_DATA, JSON.toJSONString(promotionData));
return dataMap;
}

@Override
//@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> couponOrderVerifyListDo(@RequestBody Map<String, String> params, EnumPosActionType actionType) throws MallinkException {
Map<String, String> retMap = new HashMap<>();
@@ -1190,7 +1255,7 @@ public class PosServiceImpl implements PosService {
}

try {
doVerify(actionType, couponOrderCVo, wxCoupon, merchantId, buUserId, posOrderId, retMap);
//doVerify(actionType, couponOrderCVo, wxCoupon, merchantId, buUserId, posOrderId, retMap);
Integer remainAmount = posAmount - couponOrderCVo.getPrice();
if (remainAmount < 0) {
remainAmount = 0;
@@ -1215,7 +1280,7 @@ public class PosServiceImpl implements PosService {
throw new MallinkException(500, errMessage);
}

@Override
//@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> couponOrderVerifyCancel(Map<String, String> params, EnumPosActionType actionType) {
Map<String, String> retMap = new HashMap<>();
@@ -1440,8 +1505,8 @@ public class PosServiceImpl implements PosService {
* @param buUserId
* @param posOrderId
*/
private void doVerify(EnumPosActionType actionType, WxCouponOrderCVo couponOrderCVo, WxCoupon coupon,
Long merchantId, Long buUserId, Long posOrderId, Map<String, String> retMap) {
private void doVerify(JSONObject retMap, EnumPosActionType actionType, WxCouponOrderCVo couponOrderCVo, WxCoupon coupon,
Long merchantId, Long buUserId, Long posOrderId) {
int num = 0;
// 1. insert posOrderId
PosCouponOrderVerify posCouponOrderVerify = new PosCouponOrderVerify();
@@ -1449,18 +1514,11 @@ public class PosServiceImpl implements PosService {
posCouponOrderVerify.setCouponOrderId(couponOrderCVo.getId());
posCouponOrderVerify.setPosOrderId(posOrderId);
posCouponOrderVerify.setState(EnumEnableType.Enable.getCode());
List<PosCouponOrderVerify> posCouponOrderVerifyList = posCouponOrderVerifyService.getList(posCouponOrderVerify);
if (posCouponOrderVerifyList.size() == 0) {
try {
posCouponOrderVerifyService.saveOrUpdate(posCouponOrderVerify);
} catch (Exception e) {
logger.error("db failed: couponOrder-" + couponOrderCVo.getId() + ", e:" + e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage());
}
} else if (posCouponOrderVerifyList.size() == 1){

} else if (posCouponOrderVerifyList.size() > 1){

try {
posCouponOrderVerifyService.saveOrUpdate(posCouponOrderVerify);
} catch (Exception e) {
logger.error("db failed: couponOrder-" + couponOrderCVo.getId() + ", e:" + e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage());
}
// 2. update couponOrder
Date curDate = new Date();
@@ -1497,12 +1555,22 @@ public class PosServiceImpl implements PosService {
try {
WxOrder order = orderMapper.selectByPrimaryKey(couponOrderCVo.getOrderId());
int point = scoreRulesService.addScore2(EnumScoreType.CONSUMPTION, order, couponOrderCVo.getBusinessId());
retMap.put(WxPayConstant.POINT, String.valueOf(point));
retMap.put(WxPayConstant.POINT, point);
} catch (Exception e) {
logger.error("核销成长值异常:" + e.getMessage());
}

// 4. 积分
int credit = posAddCredit(couponOrderCVo, coupon, merchantId, buUserId);
if (credit > 0) {
retMap.put(WxPayConstant.CREDIT, credit);
} else {
retMap.put(WxPayConstant.CREDIT, 0);
}
logger.info("核销已完成: " + couponOrderCVo.getId());
}

private int posAddCredit(WxCouponOrderCVo couponOrderCVo, WxCoupon coupon, Long merchantId, Long buUserId) {
try {
//-------此处为【现金支付】记录增加积分操作-------
WxCreditHistory creditHistory = new WxCreditHistory();
@@ -1519,14 +1587,14 @@ public class PosServiceImpl implements PosService {
creditHistory.setMerchantId(merchantId);
creditHistory = creditHistoryService.saveOrUpdate(creditHistory);
if (creditHistory.getCreditNum() != null) {
retMap.put(WxPayConstant.CREDIT, String.valueOf(creditHistory.getCreditNum()));
return creditHistory.getCreditNum();
} else {
retMap.put(WxPayConstant.CREDIT, "0");
return 0;
}
} catch (Exception e) {
logger.error("核销积分值异常:" + e.getMessage());
}
logger.info("核销已完成: " + couponOrderCVo.getId());
return 0;
}

/**
@@ -1612,7 +1680,7 @@ public class PosServiceImpl implements PosService {
logger.info("核销已取消: " + couponOrderCVo.getId());
}

@Override
//@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> cardPayPre(Map<String, String> params) throws MallinkException {
Map<String, String> retMap = new HashMap<>();
@@ -1735,7 +1803,7 @@ public class PosServiceImpl implements PosService {
return retMap;
}

@Override
//@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> cardPayPreCancel(@RequestBody Map<String, String> params) throws MallinkException {
Map<String, String> retMap = new HashMap<>();
@@ -1844,13 +1912,13 @@ public class PosServiceImpl implements PosService {
return retMap;
}

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

@Override
//@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> cardPayCancel(Map<String, String> params) throws MallinkException {
Map<String, String> retMap = new HashMap<>();
@@ -1967,7 +2035,7 @@ public class PosServiceImpl implements PosService {
return retMap;
}

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


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

@@ -118,52 +118,9 @@ public class PosAppTest {
boolean resSigned = sendAndRes("/checkUserPassword", reqObj);
Assert.assertEquals(resSigned, true);
}
@Test
public void getPosMemConfigTest() 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);
boolean resSigned = sendAndRes("/getPosMemConfig", reqObj);
Assert.assertEquals(resSigned, true);
}

@Test
public void getQrCodeTest() 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);
boolean resSigned = sendAndRes("/getQrCode", reqObj);
Assert.assertEquals(resSigned, true);
}

@Test
public void checkMemTest() throws Exception {
String memId = "321178010928119808";
String phone = "13910154397";
String posOrderId = "1";
String posAmount = "200";
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);
if (StringUtils.isNotBlank(memId)) {
reqObj.put(WxPayConstant.MEM_ID, memId);
}
if (StringUtils.isNotBlank(phone)) {
reqObj.put(WxPayConstant.MEM_PHONE, phone);
}
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId);
reqObj.put(WxPayConstant.ORDER_AMOUNT, posAmount);
boolean resSigned = sendAndRes("/checkMem", reqObj);
Assert.assertEquals(resSigned, true);
}

@Test
public void checkVerifyCalcTest() throws Exception {
public void verifyCalculateTest() throws Exception {
String selCoList = "[\"321872988134408192\"]";
String sceneType = String.valueOf(EnumPosSceneType.VERIFY.getCode());
Map<String, String> reqObj = new HashMap<>();
@@ -180,7 +137,7 @@ public class PosAppTest {
}

@Test
public void checkPayCalcTest() throws Exception {
public void payCalculateTest_NoCouponOrder() throws Exception {
String memId = "321178010928119808";
String phone = "13910154397";
String orderAmount = "2000";
@@ -205,7 +162,7 @@ public class PosAppTest {
}

@Test
public void checkPayCalc1Test() throws Exception {
public void payCalculateTest_WithOneCouponOrder() throws Exception {
String memId = "321178010928119808";
String phone = "13910154397";
String orderAmount = "20000";
@@ -228,30 +185,71 @@ public class PosAppTest {
boolean resSigned = sendAndRes("/queryAndCalc", reqObj);
Assert.assertEquals(resSigned, true);
}
/*
@Test
public void getPosMemConfigTest() 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);
boolean resSigned = sendAndRes("/getPosMemConfig", reqObj);
Assert.assertEquals(resSigned, true);
}

@Test
public void checkCouponOrderVerifyTest() throws Exception {
String couponOrderId = "321878223800205312";
String sceneType = "2";
String posOrderId = "1";
String posAmount = "100";
doCheckCouponOrder(couponOrderId, sceneType, posOrderId, posAmount);
public void getQrCodeTest() 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);
boolean resSigned = sendAndRes("/getQrCode", reqObj);
Assert.assertEquals(resSigned, true);
}

@Test
public void checkCouponOrderPayTest() throws Exception {
String couponOrderId = "321877927162249216";
String sceneType = "1";
public void checkMemTest() throws Exception {
String memId = "321178010928119808";
String phone = "13910154397";
String posOrderId = "1";
String posAmount = "100";
doCheckCouponOrder(couponOrderId, sceneType, posOrderId, posAmount);
String posAmount = "200";
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);
if (StringUtils.isNotBlank(memId)) {
reqObj.put(WxPayConstant.MEM_ID, memId);
}
if (StringUtils.isNotBlank(phone)) {
reqObj.put(WxPayConstant.MEM_PHONE, phone);
}
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId);
reqObj.put(WxPayConstant.ORDER_AMOUNT, posAmount);
boolean resSigned = sendAndRes("/checkMem", reqObj);
Assert.assertEquals(resSigned, true);
}
*/



@Test
public void couponOrderVerifyTest() throws Exception {
String couponOrderId = "321878223800205312";
public void verifyTest() throws Exception {
String posOrderId = "1";
doCouponOrderVerify(couponOrderId, posOrderId);
String selCoList = "[\"321878223800205312\"]";
String sceneType = String.valueOf(EnumPosSceneType.VERIFY.getCode());
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.SCENE_TYPE, sceneType);
reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId);
reqObj.put(WxPayConstant.ORDER_CREATE_SN, posSN);
reqObj.put(WxPayConstant.COUPON_ORDER_LIST, selCoList);
boolean resSigned = sendAndRes("/couponOrderVerify", reqObj);
Assert.assertEquals(resSigned, true);
}

@Test


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

@@ -29,7 +29,7 @@ public class WxPayConstant {
public final static String BUSER_ID = "order_operation_id";
public final static String COUPON_ORDER_ID = "coupon_order_id";
public final static String COUPON_ORDER_LIST = "coupon_list";
public final static String POS_ORDER_ID = "pos_order_id";
public final static String POS_ORDER_ID = "order_number_of_platform";
public final static String ORDER_CREATE_SN = "order_create_sn";
public final static String ORDER_AMOUNT = "order_amount";
public final static String ORDER_AMOUNT_LEFT = "order_amount_left";
@@ -39,6 +39,7 @@ public class WxPayConstant {
public final static String CARD_SPEND_ID = "card_spend_id";
public final static String PHONE = "phone";
public final static String PASSWORD = "password";
public final static String MEM_CONFIG = "mem_config";

public final static String PROMOTION_AMOUNT = "promotion_amount";
public final static String AMOUNT_LEFT_AFTER_PAY = "amount_left_after_pay";
@@ -69,6 +70,7 @@ public class WxPayConstant {

public final static String REG_QRCODE_URL = "qrcode_url";
public final static String POS_QRCODE_RULE = "pos_qrcode_rule";
public final static String QRCODE = "qrcode";


public final static String DISCOUNT = "discount";


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