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

[POS][修改]:POS code 整理

release_toaliyun_real
Stormeye Wu 6 лет назад
Родитель
Сommit
d7836012ac
6 измененных файлов: 396 добавлений и 200 удалений
  1. +10
    -0
      mallinkPosApi/src/main/java/com/iformall/service/PosService.java
  2. +265
    -200
      mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java
  3. +1
    -0
      mallinkService/src/main/java/com/iformall/common/ErrorCode.java
  4. +41
    -0
      mallinkService/src/main/java/com/iformall/enums/EnumPosPamentType.java
  5. +42
    -0
      mallinkService/src/main/java/com/iformall/enums/EnumPosRefundType.java
  6. +37
    -0
      mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java

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

@@ -78,6 +78,14 @@ public interface PosService {
*/
Map<String, String> cardPayPreCancel(Map<String, String> params) throws MallinkException;

/**
* 订单同步-Neusoft-支付或者退款成功后通知富茂
* @param params
* @return
* @throws MallinkException
*/
Map<String, String> posOrderSync(Map<String, String> params) throws MallinkException;

/**
* 消费卡POS支付
* @param params
@@ -94,4 +102,6 @@ public interface PosService {
* @throws MallinkException
*/
Map<String, String> cardPayCancel(Map<String, String> params) throws MallinkException;


}

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

@@ -70,19 +70,13 @@ public class PosServiceImpl implements PosService {
String password = params.get(WxPayConstant.PASSWORD); // buUser's password

if (StringUtils.isBlank(tenantId)) {
String errMessage = "request params[tenant_id] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.TENANT_ID);
}
if (StringUtils.isBlank(phone)) {
String errMessage = "request params[phone] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.PHONE);
}
if (StringUtils.isBlank(password)) {
String errMessage = "request params[password] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.PASSWORD);
}
WxMerchantBUser user = new WxMerchantBUser();
user.setTenantId(tenantId);
@@ -93,26 +87,12 @@ public class PosServiceImpl implements PosService {
try {
user1 = merchantBUserService.getBUserByAppId(user);
} catch (Exception e) {
String errMessage = "B端用户不存在或者已被禁用, phone: " + phone + ", " +e.getMessage();
throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), errMessage);
String errMessage = ErrorCode.MERCHANT_BUSER_NOT_VALID.getMessage() + "phone: " + phone + ", " +e.getMessage();
throw new MallinkException(ErrorCode.MERCHANT_BUSER_NOT_VALID.getCode(), errMessage);
}
if (user1 != null) {
// check merchant 状态
WxMerchant merchant = null;
try {
merchant = merchantService.getById(user1.getMerchantId());
} catch (Exception e) {
String errMessage = ErrorCode.DB_FAIL.getMessage() + ": " + user1.getMerchantId() + e.getMessage();
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), errMessage);
}
if (merchant == null) {
logger.error(ErrorCode.MERCHANT_INFO_NOT_FOUND.getMessage() + ": " + user1.getMerchantId());
throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND);
}
if (merchant.getStatus().equals(EnumMerchantStatus.NOT_VALID.getCode())) {
logger.error(ErrorCode.MERCHANT_INFO_NOT_VALID.getMessage() + ": " + user1.getMerchantId());
throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID);
}
WxMerchant merchant = checkAndGetMerchant(user1.getMerchantId());
// check password
if (user1.getUserPwd().equalsIgnoreCase(password)) {
retMap.put(WxPayConstant.TENANT_ID, user1.getTenantId());
@@ -141,9 +121,7 @@ public class PosServiceImpl implements PosService {
String tenantId = params.get(WxPayConstant.TENANT_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);
errParam(WxPayConstant.TENANT_ID);
}
PosMallConfig config = posMallConfigService.getByTenantId(tenantId);
if (config == null) {
@@ -168,9 +146,7 @@ public class PosServiceImpl implements PosService {
String tenantId = params.get(WxPayConstant.TENANT_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);
errParam(WxPayConstant.TENANT_ID);
}
WxMall mall = mallService.getByTenantId(tenantId);
if (mall == null) {
@@ -199,9 +175,7 @@ public class PosServiceImpl implements PosService {
String posAmountStr = params.get(WxPayConstant.POS_AMOUNT); // POS订单金额(单位:分)

if (StringUtils.isBlank(tenantId)) {
String errMessage = "request params[tenant_id] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.TENANT_ID);
}

PosMallConfig config = posMallConfigService.getByTenantId(tenantId);
@@ -211,19 +185,13 @@ public class PosServiceImpl implements PosService {
}

if (StringUtils.isBlank(merchantIdStr)) {
String errMessage = "request params[merchant_id] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.MERCHANT_ID);
}
if (StringUtils.isBlank(posOrderIdStr)) {
String errMessage = "request params[pos_order_id] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.POS_ORDER_ID);
}
if (StringUtils.isBlank(posAmountStr)) {
String errMessage = "request params[pos_amount] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.POS_AMOUNT);
}

if (StringUtils.isBlank(memIdStr) && StringUtils.isBlank(memPhoneStr)) {
@@ -354,9 +322,7 @@ public class PosServiceImpl implements PosService {
String posAmountStr = params.get(WxPayConstant.POS_AMOUNT); // POS订单总额(单位:分)

if (StringUtils.isBlank(tenantId)) {
String errMessage = "request params[tenant_id] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.TENANT_ID);
}
PosMallConfig config = posMallConfigService.getByTenantId(tenantId);
if (config == null) {
@@ -368,22 +334,17 @@ public class PosServiceImpl implements PosService {
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);
errParam(WxPayConstant.MERCHANT_ID);
}
if (StringUtils.isBlank(buUserIdStr)) {
String errMessage = "request params[bu_user_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.BUSER_ID);
}
if (StringUtils.isBlank(couponOrderIdStr)) {
String errMessage = "request params[coupon_order_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.COUPON_ORDER_ID);
}
if (actionType.equals(EnumVerifyActionType.CHECK)) {
if (StringUtils.isBlank(verifyType)) {
String errMessage = "request params[verify_type] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.VERIFY_TYPE);
}
if (!(verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_TYPE_INDEPENT) || verifyType.equalsIgnoreCase(WxPayConstant.VERIFY_TYPE_PAY))) {
String errMessage = "request params[verify_type] only support independent or pay.";
@@ -398,15 +359,13 @@ public class PosServiceImpl implements PosService {
actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT) ||
actionType.equals(EnumVerifyActionType.VERIFY_PAY)) {
if (StringUtils.isBlank(posOrderIdStr)) {
String errMessage = "request params[pos_order_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.POS_ORDER_ID);
}
}
if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) ||
actionType.equals(EnumVerifyActionType.VERIFY_PAY)) {
if (StringUtils.isBlank(posAmountStr)) {
String errMessage = "request params[pos_amount] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.POS_AMOUNT);
}
}

@@ -429,25 +388,9 @@ public class PosServiceImpl implements PosService {
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage());
}
// 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);
}
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() + ": " + buUserIdStr);
throw new MallinkException(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG);
}
WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId);

JSONArray coRetArr = new JSONArray();
if (couponOrderIdStr != null) {
@@ -481,9 +424,7 @@ public class PosServiceImpl implements PosService {
String verifyType = WxPayConstant.VERIFY_TYPE_PAY; // 此接口只有支付使用

if (StringUtils.isBlank(tenantId)) {
String errMessage = "request params[tenant_id] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.TENANT_ID);
}
PosMallConfig config = posMallConfigService.getByTenantId(tenantId);
if (config == null) {
@@ -495,26 +436,20 @@ public class PosServiceImpl implements PosService {
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);
errParam(WxPayConstant.MERCHANT_ID);
}
if (StringUtils.isBlank(buUserIdStr)) {
String errMessage = "request params[bu_user_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.BUSER_ID);
}
if (StringUtils.isBlank(selCoListStr)) {
String errMessage = "request params[sel_co_list] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.SELECTED_COUPON_ORDER_LIST);
}
if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT)) {
if (StringUtils.isBlank(posOrderIdStr)) {
String errMessage = "request params[pos_order_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.POS_ORDER_ID);
}
if (StringUtils.isBlank(posAmountStr)) {
String errMessage = "request params[pos_amount] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.POS_AMOUNT);
}
}

@@ -534,25 +469,9 @@ public class PosServiceImpl implements PosService {
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage());
}
// 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);
}
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() + ": " + buUserIdStr);
throw new MallinkException(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG);
}
WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId);

JSONArray selCoArr = JSONObject.parseArray(selCoListStr);
if (selCoArr.size() <= 0) {
@@ -657,11 +576,10 @@ public class PosServiceImpl implements PosService {
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_USED);
}

Long couponOrderId = couponOrderCVo.getId();

Date now = new Date();
// 5. 检查有效期
if (couponOrderCVo.getValidStartDate() != null && couponOrderCVo.getValidEndDate() != null) {
Date now = new Date();
if (couponOrderCVo.getValidStartDate().getTime() > now.getTime()) {
logger.error("此券有效期未开始:" + couponOrderIdStr);
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE);
@@ -671,6 +589,13 @@ public class PosServiceImpl implements PosService {
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE);
}
}
// 5.1 券已过期
if (couponOrderCVo.getExpiredTime().before(now)) {
logger.error("此券已过期:" + couponOrderIdStr);
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE);
}

Long couponOrderId = couponOrderCVo.getId();

// 6. 检查适用门店
WxCouponMerchant wxCouponMerchant = new WxCouponMerchant();
@@ -854,30 +779,20 @@ public class PosServiceImpl implements PosService {
String forceStr = params.get(WxPayConstant.FORCE); // 是否强制

if (StringUtils.isBlank(tenantId)) {
String errMessage = "request params[tenant_id] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.TENANT_ID);
}
if (StringUtils.isBlank(merchantIdStr)) {
String errMessage = "request params[merchant_id] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.MERCHANT_ID);
}
if (StringUtils.isBlank(buUserIdStr)) {
String errMessage = "request params[bu_user_id] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.BUSER_ID);
}
if (StringUtils.isBlank(couponOrderIdStr)) {
String errMessage = "request params[coupon_order_id] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.COUPON_ORDER_ID);
}
if (actionType.equals(EnumVerifyActionType.PRE_VERIFY) || actionType.equals(EnumVerifyActionType.VERIFY_INDEPENT)) {
if (StringUtils.isBlank(posOrderIdStr)) {
String errMessage = "request params[pos_order_id] error.";
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.POS_ORDER_ID);
}
}

@@ -902,6 +817,10 @@ public class PosServiceImpl implements PosService {
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);
}
// 4. check couponOrderId
WxCouponOrderCVo couponOrderCVo = couponOrderService.detailCUserVo(couponOrderIdStr);
if (couponOrderCVo == null) {
@@ -1078,7 +997,8 @@ public class PosServiceImpl implements PosService {
* @param buUserId
* @param posOrderId
*/
private void doVerify(EnumVerifyActionType actionType, WxCouponOrderCVo couponOrderCVo, WxCoupon coupon, Long merchantId, Long buUserId, Long posOrderId, Map<String, String> retMap) {
private void doVerify(EnumVerifyActionType actionType, WxCouponOrderCVo couponOrderCVo, WxCoupon coupon,
Long merchantId, Long buUserId, Long posOrderId, Map<String, String> retMap) {
int num = 0;
// 1. insert posOrderId
PosCouponOrderVerify posCouponOrderVerify = new PosCouponOrderVerify();
@@ -1135,7 +1055,7 @@ public class PosServiceImpl implements PosService {
try {
WxOrder order = orderMapper.selectByPrimaryKey(couponOrderCVo.getOrderId());
int point = scoreRulesService.addScore2(EnumScoreType.CONSUMPTION, order, couponOrderCVo.getBusinessId());
retMap.put("point", String.valueOf(point));
retMap.put(WxPayConstant.POINT, String.valueOf(point));
} catch (Exception e) {
logger.error("核销成长值异常:" + e.getMessage());
}
@@ -1157,7 +1077,7 @@ public class PosServiceImpl implements PosService {
creditHistory.setMerchantId(merchantId);
creditHistory = creditHistoryService.saveOrUpdate(creditHistory);
if (creditHistory.getCreditNum() != null) {
retMap.put("credit", String.valueOf(creditHistory.getCreditNum()));
retMap.put(WxPayConstant.CREDIT, String.valueOf(creditHistory.getCreditNum()));
}
} catch (Exception e) {
logger.error("核销积分值异常:" + e.getMessage());
@@ -1275,25 +1195,19 @@ public class PosServiceImpl implements PosService {
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);
errParam(WxPayConstant.MERCHANT_ID);
}
if (StringUtils.isBlank(buUserIdStr)) {
String errMessage = "request params[bu_user_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.BUSER_ID);
}
if (StringUtils.isBlank(posOrderIdStr)) {
String errMessage = "request params[pos_order_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.POS_ORDER_ID);
}
if (StringUtils.isBlank(posAmountStr)) {
String errMessage = "request params[pos_amount] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.POS_AMOUNT);
}
if (StringUtils.isBlank(cardIdStr)) {
String errMessage = "request params[card_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.CARD_ID);
}

Long merchantId, buUserId, posOrderId, cardId;
@@ -1393,9 +1307,7 @@ public class PosServiceImpl implements PosService {
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);
errParam(WxPayConstant.TENANT_ID);
}
PosMallConfig config = posMallConfigService.getByTenantId(tenantId);
if (config == null) {
@@ -1407,29 +1319,22 @@ public class PosServiceImpl implements PosService {
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);
errParam(WxPayConstant.MERCHANT_ID);
}
if (StringUtils.isBlank(buUserIdStr)) {
String errMessage = "request params[bu_user_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.BUSER_ID);
}
if (StringUtils.isBlank(posOrderIdStr)) {
String errMessage = "request params[pos_order_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.POS_ORDER_ID);
}
if (StringUtils.isBlank(posAmountStr)) {
String errMessage = "request params[pos_amount] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.POS_AMOUNT);
}
if (StringUtils.isBlank(cardIdStr)) {
String errMessage = "request params[card_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.CARD_ID);
}
if (StringUtils.isBlank(cardSpendIdStr)) {
String errMessage = "request params[card_spend_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.CARD_SPEND_ID);
}

Long merchantId, buUserId, posOrderId, cardId, cardSpendId;
@@ -1458,25 +1363,9 @@ public class PosServiceImpl implements PosService {
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);
}
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() + ": " + buUserIdStr);
throw new MallinkException(ErrorCode.VERIFY_BUSER_MERCHANT_NOT_BELONG);
}
WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId);

WxCouponOrder couponOrder = couponOrderService.getById(cardId);
if(couponOrder == null) {
@@ -1533,9 +1422,7 @@ public class PosServiceImpl implements PosService {
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);
errParam(WxPayConstant.TENANT_ID);
}
PosMallConfig config = posMallConfigService.getByTenantId(tenantId);
if (config == null) {
@@ -1547,29 +1434,22 @@ public class PosServiceImpl implements PosService {
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);
errParam(WxPayConstant.MERCHANT_ID);
}
if (StringUtils.isBlank(buUserIdStr)) {
String errMessage = "request params[bu_user_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.BUSER_ID);
}
if (StringUtils.isBlank(posOrderIdStr)) {
String errMessage = "request params[pos_order_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.POS_ORDER_ID);
}
if (StringUtils.isBlank(posAmountStr)) {
String errMessage = "request params[pos_amount] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.POS_AMOUNT);
}
if (StringUtils.isBlank(cardIdStr)) {
String errMessage = "request params[card_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.CARD_ID);
}
if (StringUtils.isBlank(cardSpendIdStr)) {
String errMessage = "request params[card_spend_id] error.";
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
errParam(WxPayConstant.CARD_SPEND_ID);
}

Long merchantId, buUserId, posOrderId, cardId, cardSpendId;
@@ -1608,15 +1488,7 @@ public class PosServiceImpl implements PosService {
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);
}
WxMerchantBUser buUser = checkAndGetMerchantUser(buUserId, merchantId);

WxCouponOrder couponOrder = couponOrderService.getById(cardId);
if(couponOrder == null) {
@@ -1652,4 +1524,197 @@ public class PosServiceImpl implements PosService {

return retMap;
}

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

String tenantId = params.get(WxPayConstant.NEU_TENANT_ID); // 租户ID
String merchantIdStr = params.get(WxPayConstant.NEU_MERCHANT_ID); // 商户ID
String buUserIdStr = params.get(WxPayConstant.NEU_BU_USER_ID); // POS操作员ID
String cuUserIdStr = params.get(WxPayConstant.NEU_MEM_ID); // 富茂系统会员ID
String posOrderIdStr = params.get(WxPayConstant.NEU_ORDER_ID); // POS订单ID
String posOrderTimeStr = params.get(WxPayConstant.NEU_ORDER_TIME); // POS订单时间
String posAmountStr = params.get(WxPayConstant.NEU_ORDER_AMOUNT); // POS订单总额
String posStatusStr = params.get(WxPayConstant.NEU_ORDER_STATUS); // 订单状态: 0有效,1取消,根据订单状态处理优惠券;有效:优惠券从预核销处理为核销;

// 1. check params
if (StringUtils.isBlank(tenantId)) {
errParam(WxPayConstant.NEU_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.NEU_MERCHANT_ID);
}
if (StringUtils.isBlank(buUserIdStr)) {
errParam(WxPayConstant.NEU_BU_USER_ID);
}
if (StringUtils.isBlank(cuUserIdStr)) {
errParam(WxPayConstant.NEU_MEM_ID);
}
if (StringUtils.isBlank(posOrderIdStr)) {
errParam(WxPayConstant.NEU_ORDER_ID);
}
if (StringUtils.isBlank(posOrderTimeStr)) {
errParam(WxPayConstant.NEU_ORDER_TIME);
}
if (StringUtils.isBlank(posAmountStr)) {
errParam(WxPayConstant.NEU_ORDER_AMOUNT);
}
if (StringUtils.isBlank(posStatusStr)) {
errParam(WxPayConstant.NEU_ORDER_STATUS);
}
Long merchantId, buUserId, posOrderId, cardId;
Integer posAmount = 0;
try {
merchantId = Long.valueOf(merchantIdStr);
buUserId = Long.valueOf(buUserIdStr);
posOrderId = Long.valueOf(posOrderIdStr);
posAmount = Integer.valueOf(posAmountStr);
} catch (NumberFormatException e) {
logger.error(e.getMessage());
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage());
}
// 2. check merchant
WxMerchant merchant = checkAndGetMerchant(merchantId);
// 3. check buUser
WxMerchantBUser merchantBUser = checkAndGetMerchantUser(merchantId, buUserId);
if (posStatusStr.equalsIgnoreCase("0")) {
// TODO
// add to wx_order
String payDetail = params.get(WxPayConstant.NEU_PAY_DETAIL);
JSONObject payDetailObj = JSON.parseObject(payDetail);
JSONArray payDetailList = payDetailObj.getJSONArray(WxPayConstant.NEU_PAY_DETAIL_LIST);
for (int i=0;i<payDetailList.size();i++) {
JSONObject payOrderObj = payDetailList.getJSONObject(i);
// ADD to wx_pay_order
String neuPayOrderType = payOrderObj.getString(WxPayConstant.NEU_PAY_ORDER_TYPE);
if (neuPayOrderType.equalsIgnoreCase(String.valueOf(EnumPosPamentType.MEM_DISCOUNT.getCode()))) {
// 会员折扣
} else if (neuPayOrderType.equalsIgnoreCase(String.valueOf(EnumPosPamentType.MEM_COUPON.getCode()))) {
// 优惠券, 交易核销
String couponOrderIdStr = payOrderObj.getString(WxPayConstant.NEU_PAY_ORDER_OUT_NO);
} else if (neuPayOrderType.equalsIgnoreCase(String.valueOf(EnumPosPamentType.MEM_CARD.getCode()))) {
// 预付卡, 不能退
}

}
} else if (posStatusStr.equalsIgnoreCase("1")) {
// TODO
// add to wx_order
String refundDetail = params.get(WxPayConstant.NEU_REFUND_DETAIL);
JSONObject refundDetailObj = JSON.parseObject(refundDetail);
JSONArray refundDetailList = refundDetailObj.getJSONArray(WxPayConstant.NEU_REFUND_DETAIL_LIST);
for (int i=0;i<refundDetailList.size();i++) {
JSONObject refundOrderObj = refundDetailList.getJSONObject(i);
// TODO
// ADD to wx_pay_order
String neuRefundOrderType = refundOrderObj.getString(WxPayConstant.NEU_REFUND_ORDER_TYPE);
if (neuRefundOrderType.equalsIgnoreCase(String.valueOf(EnumPosRefundType.MEM_DISCOUNT.getCode()))) {
// 会员折扣,
} else if (neuRefundOrderType.equalsIgnoreCase(String.valueOf(EnumPosRefundType.MEM_COUPON.getCode()))) {
// 优惠券, 退优惠券
} else if (neuRefundOrderType.equalsIgnoreCase(String.valueOf(EnumPosRefundType.MEM_CARD.getCode()))) {
// 预付卡, 不能退
} else if (neuRefundOrderType.equalsIgnoreCase(String.valueOf(EnumPosRefundType.BOOK.getCode()))) {
// 记账
}
}
}

return retMap;
}


/**
* 检查及获取商户信息
* @param merchantId
* @return
*/
private WxMerchant checkAndGetMerchant(Long merchantId) {
WxMerchant merchant = merchantService.getById(merchantId);
if (merchant == null) {
logger.error(ErrorCode.MERCHANT_INFO_NOT_FOUND.getMessage() + ": " + merchantId);
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() + ": " + merchantId);
throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID);
}
return merchant;
}

/**
* 检查及获取商户用户
* @param buUserId
* @param merchantId
*/
private WxMerchantBUser checkAndGetMerchantUser(Long buUserId, Long merchantId) {
WxMerchantBUser buUser = merchantBUserService.getById(buUserId);
if (buUser == null) {
logger.error(ErrorCode.USER_IS_EMPTY.getMessage() + ": " + buUserId);
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);
}
if (buUser.getStatus().equals(EnumMerchantStatus.NOT_VALID.getCode())) {
logger.error(ErrorCode.MERCHANT_BUSER_NOT_VALID.getMessage() + ": " + buUserId);
throw new MallinkException(ErrorCode.MERCHANT_BUSER_NOT_VALID);
}
return buUser;
}

/**
* 输入参数错误
* @param paramStr
* @throws MallinkException
*/
private void errParam(String paramStr) throws MallinkException {
String errMessage = String.format("request params[%s] error.", paramStr);
logger.error(errMessage);
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage);
}

/**
* POS订单添加
* @return
* @throws MallinkException
*/
private WxOrder addToWxOrder(String tenantId, String merchantNo, String buUserNo, String memNo, String memPhone,
String posOrderNo, String posOrderTimeStr, String posOrderAmount, String posOrderStatus) throws MallinkException {

// 1. 根据posOrderNo查找
return null;
}

/**
* POS支付订单
* @return
* @throws MallinkException
*/
private WxPayOrder addToWxPayOrder(WxOrder orderRecord,
String posPayOrderNo, String posPayOrderTime,
String paymentType, String thirdParam, String payOrderNo, String payAmount, String payTime) throws MallinkException {
return null;
}

/**
* POS支付退款订单
* @return
* @throws MallinkException
*/
private WxPayOrder addToWxRefundOrder(WxOrder orderRecord,
String posPayOrderNo, String posRefundOrderNo, String posRefundOrderTime,
String refundType, String thirdParam, String refundStatusStr,
String refundOrderNo, String refundAmount, String refundTime) throws MallinkException {
return null;
}
}

+ 1
- 0
mallinkService/src/main/java/com/iformall/common/ErrorCode.java Просмотреть файл

@@ -98,6 +98,7 @@ public enum ErrorCode{
MERCHANT_REPORT_DATE_NOT_VALID(999, "上报日期大于当天"),
MERCHANT_NAME_IS_FOUND(2014, "商户名称已存在"),
MERCHANT_CAR_NOT_DEL(2015, "停车商户不能被删除"),
MERCHANT_BUSER_NOT_VALID(2016, "商户用户不存在或已被禁用"),
/**
* 券
*/


+ 41
- 0
mallinkService/src/main/java/com/iformall/enums/EnumPosPamentType.java Просмотреть файл

@@ -0,0 +1,41 @@
package com.iformall.enums;

/**
* Created by Stormeye on 2018/08/09.
*/
public enum EnumPosPamentType {

// 来源于Neusoft的定义 0微信;1支付宝;2现金;3会员折扣;4优惠券;5预付卡;6银行卡
WECHAT(0, "微信"),
ALIPAY(1, "支付宝"),
CASH(2, "现金"),
MEM_DISCOUNT(3, "会员折扣"),
MEM_COUPON(4, "优惠券"),
MEM_CARD(5, "预付卡"),
MEM_BANKCARD(6, "银行卡"),
;
public static EnumPosPamentType getEnum(Integer code) {
for (EnumPosPamentType value : values()) {
if (value.getCode().equals(code)) {
return value;
}
}
return null;
}

private Integer code;
private String message;

EnumPosPamentType(Integer code, String message) {
this.code = code;
this.message = message;
}

public Integer getCode() {
return code;
}

public String getMessage() {
return message;
}
}

+ 42
- 0
mallinkService/src/main/java/com/iformall/enums/EnumPosRefundType.java Просмотреть файл

@@ -0,0 +1,42 @@
package com.iformall.enums;

/**
* Created by Stormeye on 2018/08/09.
*/
public enum EnumPosRefundType {

// 来源于Neusoft的定义 0微信;1支付宝;2现金;3会员折扣;4优惠券;5预付卡;6银行卡;7记账
WECHAT(0, "微信"),
ALIPAY(1, "支付宝"),
CASH(2, "现金"),
MEM_DISCOUNT(3, "会员折扣"),
MEM_COUPON(4, "优惠券"),
MEM_CARD(5, "预付卡"),
MEM_BANKCARD(6, "银行卡"),
BOOK(7, "记账"),
;
public static EnumPosRefundType getEnum(Integer code) {
for (EnumPosRefundType value : values()) {
if (value.getCode().equals(code)) {
return value;
}
}
return null;
}

private Integer code;
private String message;

EnumPosRefundType(Integer code, String message) {
this.code = code;
this.message = message;
}

public Integer getCode() {
return code;
}

public String getMessage() {
return message;
}
}

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

@@ -66,6 +66,9 @@ public class WxPayConstant {
public final static String REMAIN_AMOUNT = "remain_amount";
public final static String ORDER_STATUS = "order_status";

public final static String POINT = "point";
public final static String CREDIT = "credit";

public final static String REAL_AMOUNT = "real_amount";
public final static String SALE_PRICE = "sale_price";
public final static String SALE_FEE = "sale_fee";
@@ -78,4 +81,38 @@ public class WxPayConstant {
public final static String TRUE = "true";
public final static String FALSE = "false";


public final static String NEU_TENANT_ID = "TenantID"; // 富茂系统商场ID
public final static String NEU_MERCHANT_ID = "MerchantID"; // 富茂系统商户ID
public final static String NEU_BU_USER_ID = "OrderOperatorID"; // 富茂系统登录操作员ID
public final static String NEU_MEM_ID = "MemberID"; // 富茂系统会员ID
public final static String NEU_MEM_PHONE = "MemberPhoneNumber"; // 富茂系统会员手机号
public final static String NEU_ORDER_ID = "OrderNumberofPlatform"; // 东软平台订单号
public final static String NEU_ORDER_TIME = "OrderTimeOfPlatform"; // 平台订单创建时间, 格式:4位年2位月2位日2位24小时制时2位分2位秒3位毫秒
public final static String NEU_ORDER_AMOUNT = "OrderAmount"; // 订单价格
public final static String NEU_ORDER_CREATE_SN = "OrderCreateSN"; // 创建订单的POS SN号
public final static String NEU_ORDER_STATUS = "OrderStatus"; // 必要,订单状态: 0有效,1取消,根据订单状态处理优惠券;有效:优惠券从预核销处理为核销;
public final static String NEU_PAY_DETAIL = "PaymentDetail";
public final static String NEU_PAY_DETAIL_LIST = "PaymentDetailList";
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_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,现金和富茂会员折扣时为空
public final static String NEU_PAY_ORDER_AMOUNT = "PaymentAmount"; // 支付金额
public final static String NEU_PAY_ORDER_OUT_TIME = "PayTime"; // 第三方支付系统返回的支付时间,现金和富茂会员折扣时为空
public final static String NEU_REFUND_DETAIL = "RefundDetail";
public final static String NEU_REFUND_DETAIL_LIST = "RefundDetailList";
public final static String NEU_REFUND_ORDER_ID = "RefundNumberOfPlatform"; // 东软平台退款订单号
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_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,现金和富茂会员折扣时为空
public final static String NEU_REFUND_ORDER_AMOUNT = "RefundAmount"; // 退款金额
public final static String NEU_REFUND_ORDER_OUT_TIME = "RefundTime"; // 第三方支付系统返回的支付时间,现金和富茂会员折扣时为空
}

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