diff --git a/mallinkAdmin/src/main/resources/db/migration/V201909031540__POS_CARD_SPEND.sql b/mallinkAdmin/src/main/resources/db/migration/V201909031540__POS_CARD_SPEND.sql new file mode 100644 index 000000000..bd6fc778a --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V201909031540__POS_CARD_SPEND.sql @@ -0,0 +1,3 @@ +ALTER TABLE `wx_card_spend` +change `from` `pay_from` tinyint(6) NOT NULL DEFAULT '0' COMMENT '来源(0:C端小程序扫一扫, 1:POS)', +drop column `pos_refund_status`; \ No newline at end of file diff --git a/mallinkAdmin/src/test/java/com/iformall/service/test/Test.java b/mallinkAdmin/src/test/java/com/iformall/service/test/Test.java index 19cb3c5de..8ec94d871 100644 --- a/mallinkAdmin/src/test/java/com/iformall/service/test/Test.java +++ b/mallinkAdmin/src/test/java/com/iformall/service/test/Test.java @@ -2,10 +2,8 @@ package com.iformall.service.test; import com.alibaba.fastjson.JSON; import com.iformall.domain.po.*; -import com.iformall.service.WxBillSettleService; -import com.iformall.service.WxCouponSendService; -import com.iformall.service.WxLevelConfigService; -import com.iformall.service.WxScoreRulesService; +import com.iformall.domain.vo.WxBillAll; +import com.iformall.service.*; import lombok.extern.slf4j.Slf4j; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.UsernamePasswordToken; @@ -61,7 +59,8 @@ public class Test { @Autowired private WxBillSettleService wxBillSettleService; - + @Autowired + private WxBillAllService wxBillAllService; @Before public void setUp() { @@ -86,8 +85,13 @@ public class Test { @org.junit.Test public void levelList() { - WxBillSettle settle = wxBillSettleService.getById(328411851323572224l); - log.debug("data:{}", JSON.toJSONString(settle)); +// WxBillSettle settle = wxBillSettleService.getById(328411851323572224l); +// log.debug("data:{}", JSON.toJSONString(settle)); + WxBillAll wxBillAll = new WxBillAll(); + wxBillAll.setMerchantId(326957139157024768l); + wxBillAll.setTenantId("456"); + wxBillAll.setBillTypeValue(10); + log.debug("data:{}", JSON.toJSONString( wxBillAllService.listBill(wxBillAll))); } diff --git a/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java b/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java index 3de5a4a64..91e412902 100644 --- a/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java +++ b/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java @@ -1,7 +1,6 @@ package com.iformall.controller; import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.iformall.annotation.SystemControllerLog; import com.iformall.common.ErrorCode; @@ -60,6 +59,7 @@ public class PosController extends BaseController { @SystemControllerLog(description = "门店用户登录检查") public Map checkUserPassword(@RequestBody Map params) { JSONObject payContent = new JSONObject(); + JSONObject retObj = new JSONObject(); // 1. check sign Map retMap = checkSign(params, payContent); @@ -71,12 +71,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 +97,7 @@ public class PosController extends BaseController { @SystemControllerLog(description = "支付计算接口") public Map calcForMem(@RequestBody Map params) { JSONObject payContent = new JSONObject(); + JSONObject retObj = new JSONObject(); // 1. check sign Map retMap = checkSign(params, payContent); @@ -108,27 +109,34 @@ 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 couponOrderVerify(@RequestBody Map params) { JSONObject payContent = new JSONObject(); + JSONObject retObj = new JSONObject(); // 1. check sign Map retMap = checkSign(params, payContent); @@ -140,33 +148,13 @@ public class PosController extends BaseController { logger.info(WxPayConstant.RES_KEY + ": " + resKey); try { - retMap = posService.couponOrderVerifyDo(params, EnumPosActionType.VERIFY_INDEPENT); + retObj = posService.couponOrderVerify(params); } 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(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null); - } - - private void doActionAfterVerify(Map params, Map retMap) { - String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID - String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID - String couponOrderIdStr = params.get(WxPayConstant.COUPON_ORDER_ID); // 券ID - Long buUserId, couponOrderId; - try { - buUserId = Long.valueOf(buUserIdStr); - couponOrderId = Long.valueOf(couponOrderIdStr); - } catch (NumberFormatException e) { - logger.error(e.getMessage()); - throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); - } - - String errCode = retMap.get(WxPayConstant.RESULT_CODE); - if(StringUtils.isBlank(errCode)||errCode.equals(WxPayConstant.RESULT_SUCCESS)) { - // 无异常信息,核销成功 - couponOrderService.sendInsideCouponVerifyMsg(tenantId, couponOrderId, buUserId); + return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", 500, e.getMessage()); } + return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",null); } @ApiOperation(value = "券核销取消", notes = "{" + @@ -174,13 +162,26 @@ public class PosController extends BaseController { "\"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单位(分)(必填)\"," + + "\"payment_info\":{" + + "\"coupon_id\":\"string(必填)\"," + + "\"order_amount\":\"string单位(分)(选填)\"," + + "\"amount_left\":\"string单位(分)(选填)\"," + + "\"promotion_amount\":\"string单位(分)(选填)\"," + + "\"amount_left_after_pay\":\"string单位(分)(选填)\"" + + "}}") @PostMapping("/couponOrderVerifyCancel") @SystemControllerLog(description = "券核销取消") public Map couponOrderIndependentVerifyCancel(@RequestBody Map params) { JSONObject payContent = new JSONObject(); + JSONObject retObj = new JSONObject(); // 1. check sign Map retMap = checkSign(params, payContent); @@ -192,77 +193,12 @@ public class PosController extends BaseController { logger.info(WxPayConstant.RES_KEY + ": " + resKey); try { - retMap = posService.couponOrderVerifyCancel(params, EnumPosActionType.VERIFY_CANCEL); - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null); + retObj = posService.couponOrderVerifyCancel(params); + return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",null); } catch (MallinkException e) { - 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()); - } - } - - @ApiOperation(value = "POS支付-券", notes = "{" + - "\"dev_id\":\"string(必填)\"," + - "\"nonce_str\":\"string(必填)\"," + - "\"tenant_id\":\"string(必填)\"," + - "\"merchant_id\":\"string(必填)\"," + - "\"bu_user_id\":\"string(必填)\"," + - "\"sel_co_list\":\"json array[券包ID list](必填),例[\"1\",\"2\",\"3\"]\"" + - "\"pos_order_id\":\"string(必填)\"," + - "\"pos_amount\":\"string(必填)\"}") - @PostMapping("/couponOrderPay") - @SystemControllerLog(description = "POS支付-券") - public Map couponOrderPay(@RequestBody Map params) { - JSONObject payContent = new JSONObject(); - - // 1. check sign - Map retMap = checkSign(params, payContent); - if (retMap != null) { - // 签名相关异常返回 - return retMap; - } - String resKey = payContent.getString(WxPayConstant.RES_KEY); - logger.info(WxPayConstant.RES_KEY + ": " + resKey); - - try { - retMap = posService.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()); - } - } - - @ApiOperation(value = "POS支付取消-券", notes = "{" + - "\"dev_id\":\"string(必填)\"," + - "\"tenant_id\":\"string(必填)\"," + - "\"merchant_id\":\"string(必填)\"," + - "\"bu_user_id\":\"string(必填)\"," + - "\"coupon_order_id\":\"string(必填)\" +" + - "\"nonce_str\":\"string(必填)\" +" + - "\"pos_order_id\":\"string(必填)\" }") - @PostMapping("/couponOrderPayCancel") - @SystemControllerLog(description = "POS支付取消-券") - public Map couponOrderPayCancel(@RequestBody Map params) { - JSONObject payContent = new JSONObject(); - - // 1. check sign - Map retMap = checkSign(params, payContent); - if (retMap != null) { - // 签名相关异常返回 - return retMap; - } - String resKey = payContent.getString(WxPayConstant.RES_KEY); - logger.info(WxPayConstant.RES_KEY + ": " + resKey); - - try { - retMap = posService.couponOrderVerifyCancel(params, EnumPosActionType.PAY_VERIFY_PRE_CANCEL); - 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 buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",500, e.getMessage()); } } @@ -272,6 +208,7 @@ public class PosController extends BaseController { public Map posOrderSync(@RequestBody Map params) { logger.info(params.toString()); JSONObject payContent = new JSONObject(); + JSONObject retObj = new JSONObject(); // 1. check sign Map retMap = checkSign(params, payContent); @@ -283,90 +220,15 @@ public class PosController extends BaseController { logger.info(WxPayConstant.RES_KEY + ": " + resKey); try { - retMap = posService.posOrderSync(params); - 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()); - } - } - - private Map couponOrderPayVerify(@RequestBody Map params) { - JSONObject payContent = new JSONObject(); - - // 1. check sign - Map retMap = checkSign(params, payContent); - if (retMap != null) { - // 签名相关异常返回 - return retMap; - } - String resKey = payContent.getString(WxPayConstant.RES_KEY); - logger.info(WxPayConstant.RES_KEY + ": " + resKey); - - try { - retMap = posService.couponOrderVerifyDo(params, EnumPosActionType.VERIFY_PAY); - } 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); - } - - private Map couponOrderPayVerifyList(@RequestBody Map params) { - JSONObject payContent = new JSONObject(); - - // 1. check sign - Map retMap = checkSign(params, payContent); - if (retMap != null) { - // 签名相关异常返回 - return retMap; - } - String resKey = payContent.getString(WxPayConstant.RES_KEY); - logger.info(WxPayConstant.RES_KEY + ": " + resKey); - - try { - retMap = posService.couponOrderVerifyListDo(params, EnumPosActionType.VERIFY_PAY); + retObj = posService.posOrderSync(params); } 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()); - } - - String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID - String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID - String arrString = retMap.get(WxPayConstant.RET); - Long buUserId; - try { - buUserId = Long.valueOf(buUserIdStr); - } catch (NumberFormatException e) { - logger.error(e.getMessage()); - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", ErrorCode.SYS_PARAMETER_CAST_ERROR); + return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", 500, e.getMessage()); } - JSONArray couponArr = JSON.parseArray(arrString); - for (int i = 0;i < couponArr.size(); i++) { - String id = retMap.get(WxPayConstant.ID); - Long couponOrderId; - try { - couponOrderId = Long.valueOf(id); - } catch (NumberFormatException e) { - logger.error(e.getMessage()); - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "", ErrorCode.SYS_PARAMETER_CAST_ERROR); - } - String errCode = retMap.get(WxPayConstant.VERIFY); - if(errCode.equalsIgnoreCase(WxPayConstant.TRUE)) { - // 核销成功 - couponOrderService.sendInsideCouponVerifyMsg(tenantId, couponOrderId, buUserId); - } - } - - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null); + return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",null); } - @ApiOperation(value = "消费卡预支付", notes = "{" + "\"dev_id\":\"string(必填)\"," + "\"nonce_str\":\"string(必填)\"," + @@ -380,6 +242,7 @@ public class PosController extends BaseController { @SystemControllerLog(description = "消费卡预支付") public Map cardPayPre(@RequestBody Map params) { JSONObject payContent = new JSONObject(); + JSONObject retObj = new JSONObject(); // 1. check sign Map retMap = checkSign(params, payContent); @@ -391,12 +254,12 @@ public class PosController extends BaseController { logger.info(WxPayConstant.RES_KEY + ": " + resKey); try { - retMap = posService.cardPayPre(params); - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null); + retObj = posService.cardPayPre(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()); } } @@ -414,6 +277,7 @@ public class PosController extends BaseController { @SystemControllerLog(description = "消费卡预支付取消") public Map cardPayPreCancel(@RequestBody Map params) { JSONObject payContent = new JSONObject(); + JSONObject retObj = new JSONObject(); // 1. check sign Map retMap = checkSign(params, payContent); @@ -425,60 +289,15 @@ public class PosController extends BaseController { logger.info(WxPayConstant.RES_KEY + ": " + resKey); try { - retMap = posService.cardPayPreCancel(params); - return buildReturnMap(retMap, resKey, WxPayConstant.RET_SUCCESS, "",null); + retObj = posService.cardPayPreCancel(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 cardPay(@RequestBody Map params) { - JSONObject payContent = new JSONObject(); - - // 1. check sign - Map retMap = checkSign(params, payContent); - if (retMap != null) { - // 签名相关异常返回 - return retMap; - } - String resKey = payContent.getString(WxPayConstant.RES_KEY); - logger.info(WxPayConstant.RES_KEY + ": " + resKey); - - try { - retMap = posService.cardPay(params); - 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()); - } - } - - private Map cardPayCancel(@RequestBody Map params) { - JSONObject payContent = new JSONObject(); - - // 1. check sign - Map retMap = checkSign(params, payContent); - if (retMap != null) { - // 签名相关异常返回 - return retMap; - } - String resKey = payContent.getString(WxPayConstant.RES_KEY); - logger.info(WxPayConstant.RES_KEY + ": " + resKey); - - try { - retMap = posService.cardPayCancel(params); - 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()); - } - } - - /** * 构造返回map,无签名, 有错误 * @param retCode @@ -505,7 +324,7 @@ public class PosController extends BaseController { * @param err * @return */ - private Map buildReturnMap(Map dataMap, String resKey, String retCode, String retMsg, ErrorCode err) { + private Map buildReturnMap(JSONObject dataMap, String resKey, String retCode, String retMsg, ErrorCode err) { Map retMap = new HashMap<>(); retMap.put(WxPayConstant.RETURN_CODE, retCode); retMap.put(WxPayConstant.RETURN_MSG, retMsg); @@ -532,11 +351,8 @@ public class PosController extends BaseController { * @param errMsg * @return */ - private Map buildReturnMap(Map dataMap, String resKey, String retCode, String retMsg, Integer errCode, String errMsg) { + private Map buildReturnMap(JSONObject dataMap, String resKey, String retCode, String retMsg, Integer errCode, String errMsg) { Map 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); diff --git a/mallinkPosApi/src/main/java/com/iformall/service/PosService.java b/mallinkPosApi/src/main/java/com/iformall/service/PosService.java index 027807468..65d640e5e 100644 --- a/mallinkPosApi/src/main/java/com/iformall/service/PosService.java +++ b/mallinkPosApi/src/main/java/com/iformall/service/PosService.java @@ -1,7 +1,6 @@ package com.iformall.service; import com.alibaba.fastjson.JSONObject; -import com.iformall.enums.EnumPosActionType; import com.iformall.exception.MallinkException; import java.util.Map; @@ -14,60 +13,30 @@ public interface PosService { * @param params * @return */ - Map checkUserPassword(Map params) throws MallinkException; - /** - * 获取商城会员设置状态 - * @param params - * @return - */ - Map getPosMemConfig(Map params) throws MallinkException; - /** - * 获取商城二维码 - * @param params - * @return - */ - Map doGetQrCode(Map params) throws MallinkException; - - /** - * 识别会员 - * @param params - * @return - */ - Map checkMember(Map params) throws MallinkException; + JSONObject checkUserPassword(Map params) throws MallinkException; /** * 支付计算 * @param params * @return */ - Map queryAndCalcMem(Map params) throws MallinkException; - - /** - * 核销动作(check, pre_verify, verify) - * @param params - * @param actionType - * @return - * @throws MallinkException - */ - Map couponOrderVerifyDo(Map params, EnumPosActionType actionType) throws MallinkException; + JSONObject queryAndCalcMem(Map params) throws MallinkException; /** - * 核销取消(check, pre_verify, verify) for selected_coupon_list + * 优惠核销(包含核销,支付预核销) * @param params - * @param actionType * @return * @throws MallinkException */ - Map couponOrderVerifyCancel(Map params, EnumPosActionType actionType) throws MallinkException; + JSONObject couponOrderVerify(Map params) throws MallinkException; /** - * 核销动作(check, pre_verify, verify) for selected_coupon_list + * 优惠撤销(包含核销撤销,支付预核销撤销) * @param params - * @param actionType * @return * @throws MallinkException */ - Map couponOrderVerifyListDo(Map params, EnumPosActionType actionType) throws MallinkException; + JSONObject couponOrderVerifyCancel(Map params) throws MallinkException; /** * 消费卡POS预支付 @@ -75,7 +44,7 @@ public interface PosService { * @return * @throws MallinkException */ - Map cardPayPre(Map params) throws MallinkException; + JSONObject cardPayPre(Map params) throws MallinkException; /** * 消费卡POS预支付取消 @@ -83,7 +52,7 @@ public interface PosService { * @return * @throws MallinkException */ - Map cardPayPreCancel(Map params) throws MallinkException; + JSONObject cardPayPreCancel(Map params) throws MallinkException; /** * 订单同步-Neusoft-支付或者退款成功后通知富茂 @@ -91,7 +60,7 @@ public interface PosService { * @return * @throws MallinkException */ - Map posOrderSync(Map params) throws MallinkException; + JSONObject posOrderSync(Map params) throws MallinkException; /** * 消费卡POS支付 @@ -99,7 +68,7 @@ public interface PosService { * @return * @throws MallinkException */ - Map cardPay(Map params) throws MallinkException; + //Map cardPay(Map params) throws MallinkException; /** @@ -108,7 +77,7 @@ public interface PosService { * @return * @throws MallinkException */ - Map cardPayCancel(Map params) throws MallinkException; + //Map cardPayCancel(Map params) throws MallinkException; } diff --git a/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java b/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java index 6b696893e..20c1d0c2f 100644 --- a/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java +++ b/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java @@ -32,7 +32,7 @@ public class PosServiceImpl implements PosService { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - // neu时间格式, 4位年2位月2位日2位24小时制时2位分2位秒3位毫秒 + // 东软时间格式, 4位年2位月2位日2位24小时制时2位分2位秒3位毫秒 时区+8 北京时间 private final SimpleDateFormat neuDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS"); private final SimpleDateFormat mydateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -62,8 +62,8 @@ public class PosServiceImpl implements PosService { * @return */ @Override - public Map checkUserPassword(Map params) throws MallinkException { - Map retMap = new HashMap<>(); + public JSONObject checkUserPassword(Map 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 getPosMemConfig(Map params) throws MallinkException { - Map 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 doGetQrCode(Map params) throws MallinkException { - Map 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 checkMember(Map params) throws MallinkException { - Map 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 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 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 queryAndCalcMem(Map params) throws MallinkException { - Map dataMap = new HashMap<>(); + public JSONObject queryAndCalcMem(Map 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 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())) { @@ -509,26 +348,52 @@ public class PosServiceImpl implements PosService { return dataMap; } - private boolean isSelCoupon(JSONArray selCoArr, Long couponOrderId) { - boolean selCoupon = false; - for (int j=0;j levelList = levelConfigService.getByTenantId(tenantId); @@ -752,110 +710,211 @@ public class PosServiceImpl implements PosService { @Override @Transactional(rollbackFor = Exception.class) - public Map couponOrderVerifyDo(@RequestBody Map params, EnumPosActionType actionType) throws MallinkException { - Map retMap = new HashMap<>(); + public JSONObject couponOrderVerify(Map params) throws MallinkException { + JSONObject dataMap = new JSONObject(); - 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); - } + + // 0. 场景 + 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 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 coQ = new HashMap<>(); + coQ.put("tenantId", tenantId); + coQ.put("cUserId", user.getId()); + coQ.put("merchantId", merchantId); + List 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); + } + } + if (config.getCoupon().equals(EnumPosCouponEnableType.SingleEnable.getCode()) || + 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 = oneCouponPay(promotionCalc, couponOrderCVo, merchantId, buUserId, posOrderId, 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 couponOrderVerifyListDo(@RequestBody Map params, EnumPosActionType actionType) throws MallinkException { Map retMap = new HashMap<>(); @@ -864,8 +923,8 @@ public class PosServiceImpl implements PosService { 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.ORDER_AMOUNT); // POS订单总额(单位:分) - String selCoListStr = params.get(WxPayConstant.COUPON_ORDER_LIST); // 选中的优惠券列表 + String posAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单总额(单位:分) + String selCoListStr = params.get(WxPayConstant.COUPON_ORDER_LIST); // 选中的优惠券列表 Integer sceneType = EnumPosSceneType.PAY.getCode(); // 此接口只有支付使用 if (StringUtils.isBlank(tenantId)) { @@ -1190,7 +1249,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; @@ -1217,46 +1276,76 @@ public class PosServiceImpl implements PosService { @Override @Transactional(rollbackFor = Exception.class) - public Map couponOrderVerifyCancel(Map params, EnumPosActionType actionType) { - Map retMap = new HashMap<>(); + public JSONObject couponOrderVerifyCancel(Map params) { + JSONObject retMap = new JSONObject(); 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 couponOrderIdStr = params.get(WxPayConstant.COUPON_ORDER_ID); // 券ID - String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID + String sceneTypeStr = params.get(WxPayConstant.SCENE_TYPE); // 交易场景 + String orderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID + String paymentInfoStr = params.get(WxPayConstant.PAYMENT_INFO); // 优惠信息 if (StringUtils.isBlank(tenantId)) { errParam(WxPayConstant.TENANT_ID); + } else { + retMap.put(WxPayConstant.TENANT_ID, tenantId); } if (StringUtils.isBlank(merchantIdStr)) { errParam(WxPayConstant.MERCHANT_ID); + } else { + retMap.put(WxPayConstant.MERCHANT_ID, merchantIdStr); } if (StringUtils.isBlank(buUserIdStr)) { errParam(WxPayConstant.BUSER_ID); + } else { + retMap.put(WxPayConstant.BUSER_ID, buUserIdStr); } - if (StringUtils.isBlank(couponOrderIdStr)) { - errParam(WxPayConstant.COUPON_ORDER_ID); + if (StringUtils.isBlank(sceneTypeStr)) { + errParam(WxPayConstant.SCENE_TYPE); + } else { + retMap.put(WxPayConstant.SCENE_TYPE, sceneTypeStr); } - if (actionType.equals(EnumPosActionType.PAY_VERIFY_PRE) || actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) { - if (StringUtils.isBlank(posOrderIdStr)) { - errParam(WxPayConstant.POS_ORDER_ID); - } + if (StringUtils.isBlank(orderIdStr)) { + errParam(WxPayConstant.POS_ORDER_ID); + } else { + retMap.put(WxPayConstant.POS_ORDER_ID, orderIdStr); + } + if (StringUtils.isBlank(paymentInfoStr)) { + errParam(WxPayConstant.PAYMENT_INFO); + } + + Integer iSceneType; + try { + iSceneType = Integer.valueOf(sceneTypeStr); + } catch (NumberFormatException e) { + logger.error(e.getMessage()); + throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR); } Long merchantId, buUserId, posOrderId = 0L; try { merchantId = Long.valueOf(merchantIdStr); buUserId = Long.valueOf(buUserIdStr); - posOrderId = Long.valueOf(posOrderIdStr); + posOrderId = Long.valueOf(orderIdStr); } 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); + + JSONObject paymentInfo = JSON.parseObject(paymentInfoStr); + if (paymentInfo == null) { + errParam(WxPayConstant.PAYMENT_INFO); + } + String couponOrderIdStr = paymentInfo.getString(WxPayConstant.COUPON_ID); + if (StringUtils.isBlank(couponOrderIdStr)) { + errParam(WxPayConstant.PAYMENT_INFO); + } // 4. check couponOrderId WxCouponOrderCVo couponOrderCVo = couponOrderService.detailCUserVo(couponOrderIdStr); if (couponOrderCVo == null) { @@ -1276,61 +1365,72 @@ public class PosServiceImpl implements PosService { logger.error("券: coupon-" + couponOrderCVo.getCouponId() + "核销: couponMerchantId-" + merchantIdStr + " 门店不适用"); throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL); } - // 5. 核销后无法反向 WxCoupon coupon = couponMapper.selectByPrimaryKey(couponOrderCVo.getCouponId()); if (coupon.getSalePrice() > 0 || (coupon.getSubsidyType() > EnumCouponSubsidyType.NO_SUBSIDY.getCode() && coupon.getSubsidyNum() > 0)) { - logger.error("券包ID: " + couponOrderCVo.getId() + "核销无法退回"); + logger.error("券包ID: " + couponOrderIdStr + "核销无法退回"); throw new MallinkException(ErrorCode.POS_COUPON_ORDER_VERIFY_NOT_CANCEL); } WxCouponOrder couponOrder = new WxCouponOrder(); couponOrder.setId(couponOrderCVo.getId()); - - // 预核销取消 - if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode()) && - actionType.equals(EnumPosActionType.PAY_VERIFY_PRE_CANCEL)) { - logger.info("券已被预核销: " + couponOrderIdStr); - if (!couponOrderCVo.getBUserId().equals(buUserId)) { - logger.error(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL.getMessage() + ": " + buUserIdStr); - throw new MallinkException(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL); - } + // 6. 核销撤销 + if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) && + iSceneType.equals(EnumPosSceneType.VERIFY.getCode())) { + logger.info("券已被核销无法取消: " + couponOrderIdStr); + JSONObject refundObj = new JSONObject(); + String errMesg = String.format("此券核销后无法退回, 券%s抵用%s元, 购买花费%s元", + couponOrderIdStr, couponOrderCVo.getPriceStr(), couponOrderCVo.getSalePriceStr()); + refundObj.put(WxPayConstant.COUPON_REFUND_ID, couponOrderIdStr); + refundObj.put(WxPayConstant.COUPON_REFUND_RESULT, "0"); + refundObj.put(WxPayConstant.COUPON_REFUND_RESULT_MSG, errMesg); + refundObj.put(WxPayConstant.REFUND_TIME_FROM_IFORMALL, neuDateFormat.format(new Date())); + refundObj.put(WxPayConstant.PRICE, coupon.getPrice()); + refundObj.put(WxPayConstant.SALE_PRICE, coupon.getSalePrice()); + retMap.put(WxPayConstant.COUPON_REFUND_RESULT, JSON.toJSONString(refundObj)); + return retMap; + /* try { - cancelPreVerify(couponOrderCVo, posOrderId); - retMap.put(WxPayConstant.CANCEL, WxPayConstant.TRUE); + cancelVerify(couponOrderCVo, buUserId, posOrderId); + JSONObject refundObj = new JSONObject(); + refundObj.put(WxPayConstant.COUPON_REFUND_ID, String.valueOf(couponOrderCVo.getId())); + refundObj.put(WxPayConstant.COUPON_REFUND_RESULT, "0"); + refundObj.put(WxPayConstant.COUPON_REFUND_RESULT_MSG, "核销撤销成功"); + refundObj.put(WxPayConstant.REFUND_TIME_FROM_IFORMALL, neuDateFormat.format(new Date())); + retMap.put(WxPayConstant.COUPON_REFUND_RESULT, JSON.toJSONString(refundObj)); return retMap; } catch (MallinkException e) { logger.error(e.getMessage()); - throw new MallinkException(e.getErrorCode(), e.getMessage()); + JSONObject refundObj = new JSONObject(); + refundObj.put(WxPayConstant.COUPON_REFUND_ID, String.valueOf(couponOrderCVo.getId())); + refundObj.put(WxPayConstant.COUPON_REFUND_RESULT, e.getErrorCode()); + refundObj.put(WxPayConstant.COUPON_REFUND_RESULT_MSG, "核销撤销失败: " + e.getMessage()); + refundObj.put(WxPayConstant.REFUND_TIME_FROM_IFORMALL, neuDateFormat.format(new Date())); + retMap.put(WxPayConstant.COUPON_REFUND_RESULT, JSON.toJSONString(refundObj)); + return retMap; } + */ } - // 核销取消 - if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) && - actionType.equals(EnumPosActionType.VERIFY_CANCEL)) { - // 检查是否有发放的券, 有则无法退券 + // 6. 预核销取消 + else if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode()) && + iSceneType.equals(EnumPosSceneType.PAY.getCode())) { + logger.info("券已被预核销: " + couponOrderIdStr); + if (!couponOrderCVo.getBUserId().equals(buUserId)) { + logger.error(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL.getMessage() + ": " + buUserIdStr); + throw new MallinkException(ErrorCode.VERIFY_PRE_BUSER_NOT_EQUAL); + } try { - cancelVerify(couponOrderCVo, buUserId, posOrderId); + cancelPreVerify(couponOrderCVo, posOrderId); retMap.put(WxPayConstant.CANCEL, WxPayConstant.TRUE); return retMap; } catch (MallinkException e) { logger.error(e.getMessage()); throw new MallinkException(e.getErrorCode(), e.getMessage()); } - /* - logger.info("券已被核销无法取消: " + couponOrderIdStr); - retMap.put(WxPayConstant.CANCEL, WxPayConstant.FALSE); - Map cancelMap = new HashMap(); - cancelMap.put(WxPayConstant.PRICE, coupon.getPrice()); - cancelMap.put(WxPayConstant.SALE_PRICE, coupon.getSalePrice()); - retMap.put(WxPayConstant.CANCEL_JSON, JSON.toJSONString(cancelMap)); - String errMessage = String.format("此券核销后无法退回,原价:%s元, 售价:%s元", coupon.getPriceStr(), coupon.getSalePriceStr()); - // TODO 系统发放的券, 也加入核销信息中 - retMap.put(WxPayConstant.CANCEL_DES, errMessage); - return retMap; - */ } - String errMessage = "取消异常:未知的核销状态-" + couponOrderCVo.getCouponOrderStatus()+ ", 核销action-" + actionType.getCode(); + + String errMessage = "取消异常:未知的核销状态-" + couponOrderCVo.getCouponOrderStatus()+ ", 场景-" + iSceneType; logger.error(errMessage); throw new MallinkException(500, errMessage); } @@ -1397,13 +1497,7 @@ public class PosServiceImpl implements PosService { posCouponOrderVerify = posCouponOrderVerifyList.get(0); if(posCouponOrderVerify != null) { try { - PosCouponOrderVerify updateCouponOrderVerify = new PosCouponOrderVerify(); - updateCouponOrderVerify.setId(posCouponOrderVerify.getId()); - updateCouponOrderVerify.setTenantId(posCouponOrderVerify.getTenantId()); - updateCouponOrderVerify.setState(EnumEnableType.Disable.getCode()); - updateCouponOrderVerify.setUpdateDate(new Date()); - posCouponOrderVerifyService.saveOrUpdate(updateCouponOrderVerify); - // posCouponOrderVerifyService.deleteById(posCouponOrderVerify.getId()); + posCouponOrderVerifyService.deleteById(posCouponOrderVerify.getId()); } catch (Exception e) { logger.error("db failed: couponOrder-" + couponOrderCVo.getId() + ", e:" + e.getMessage()); throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); @@ -1440,8 +1534,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 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 +1543,11 @@ public class PosServiceImpl implements PosService { posCouponOrderVerify.setCouponOrderId(couponOrderCVo.getId()); posCouponOrderVerify.setPosOrderId(posOrderId); posCouponOrderVerify.setState(EnumEnableType.Enable.getCode()); - List 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(); @@ -1468,18 +1555,16 @@ public class PosServiceImpl implements PosService { WxCouponOrder couponOrder = new WxCouponOrder(); couponOrder.setId(couponOrderCVo.getId()); couponOrder.setTenantId(couponOrderCVo.getTenantId()); - couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); //1核销 if (actionType.equals(EnumPosActionType.VERIFY_INDEPENT)) { couponOrder.setVerifyType(EnumCouponVerifyType.VERIFY_POS_INDEPENDENT.getCode()); + couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); } else { couponOrder.setVerifyType(EnumCouponVerifyType.VERIFY_POS_PAY.getCode()); + couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode()); } - if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.POS_PRE_VERIFY.getCode()) && - actionType.equals(EnumPosActionType.VERIFY_PAY)) { - couponOrder.setBUserId(buUserId); - } + couponOrder.setBUserId(buUserId); couponOrder.setUpdateDate(curDate); - if (couponOrder.getBUserId() == null) { + if (couponOrderCVo.getBUserId() == null) { num = couponOrderMapper.updateVerifyCouponOrder(couponOrder); } else { num = couponOrderMapper.updateVerifyCouponOrderStatus(couponOrder); @@ -1492,17 +1577,10 @@ public class PosServiceImpl implements PosService { logger.error("核销异常:update num " + num); throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), "updatete num " + num); } + logger.info("核销已完成: " + couponOrderCVo.getId()); + } - // 3. 成长值 - try { - WxOrder order = orderMapper.selectByPrimaryKey(couponOrderCVo.getOrderId()); - int point = scoreRulesService.addScore2(EnumScoreType.CONSUMPTION, order, couponOrderCVo.getBusinessId()); - retMap.put(WxPayConstant.POINT, String.valueOf(point)); - } catch (Exception e) { - logger.error("核销成长值异常:" + e.getMessage()); - } - - // 4. 积分 + private int posAddCredit(WxCouponOrderCVo couponOrderCVo, WxCoupon coupon, Long merchantId, Long buUserId) { try { //-------此处为【现金支付】记录增加积分操作------- WxCreditHistory creditHistory = new WxCreditHistory(); @@ -1519,14 +1597,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; } /** @@ -1614,14 +1692,14 @@ public class PosServiceImpl implements PosService { @Override @Transactional(rollbackFor = Exception.class) - public Map cardPayPre(Map params) throws MallinkException { - Map retMap = new HashMap<>(); + public JSONObject cardPayPre(Map params) throws MallinkException { + JSONObject retMap = new JSONObject(); 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.ORDER_AMOUNT); // POS订单总额(单位:分) + String posAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单总额(单位:分) String cardIdStr = params.get(WxPayConstant.CARD_ID); // 消费卡ID if (StringUtils.isBlank(tenantId)) { @@ -1708,7 +1786,7 @@ 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.setPayFrom(EnumCardSpendFrom.POS.getCode()); record.setTenantId(merchant.getTenantId()); record.setCardId(cardId); record.setOwnerId(couponOrder.getOwnerId()); @@ -1737,8 +1815,8 @@ public class PosServiceImpl implements PosService { @Override @Transactional(rollbackFor = Exception.class) - public Map cardPayPreCancel(@RequestBody Map params) throws MallinkException { - Map retMap = new HashMap<>(); + public JSONObject cardPayPreCancel(@RequestBody Map params) throws MallinkException { + JSONObject retMap = new JSONObject(); String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID @@ -1846,137 +1924,15 @@ public class PosServiceImpl implements PosService { @Override @Transactional(rollbackFor = Exception.class) - public Map cardPay(Map params) throws MallinkException { - return null; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public Map cardPayCancel(Map params) throws MallinkException { - Map 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.ORDER_AMOUNT); // POS订单总额(单位:分) - String cardIdStr = params.get(WxPayConstant.CARD_ID); // 消费卡ID - String cardSpendIdStr = params.get(WxPayConstant.CARD_SPEND_ID); // 消费卡花费ID - - 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.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)) { - errParam(WxPayConstant.MERCHANT_ID); - } - if (StringUtils.isBlank(buUserIdStr)) { - errParam(WxPayConstant.BUSER_ID); - } - if (StringUtils.isBlank(posOrderIdStr)) { - errParam(WxPayConstant.POS_ORDER_ID); - } - if (StringUtils.isBlank(posAmountStr)) { - errParam(WxPayConstant.ORDER_AMOUNT); - } - if (StringUtils.isBlank(cardIdStr)) { - errParam(WxPayConstant.CARD_ID); - } - if (StringUtils.isBlank(cardSpendIdStr)) { - errParam(WxPayConstant.CARD_SPEND_ID); - } - - 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 = checkAndGetMerchantUser(buUserId, merchantId); - - WxCouponOrder couponOrder = couponOrderService.getById(cardId); - if(couponOrder == null) { - logger.error("卡不存在: " + cardIdStr); - throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); - } - - WxCardSpend record = cardSpendService.getById(cardSpendId); - if (record == null) { - logger.error(ErrorCode.CARD_SPEND_IS_NOT_FOUND.getMessage() + ": " + cardSpendIdStr); - throw new MallinkException(ErrorCode.CARD_SPEND_IS_NOT_FOUND); - } - if (!record.getPayStatus().equals(EnumCardSpendStatus.PREV_PAY.getCode())) { - logger.error(ErrorCode.POS_CAR_PAY_NOT_CANCEL.getMessage()); - throw new MallinkException(ErrorCode.POS_CAR_PAY_NOT_CANCEL); - } - - try { - 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()); - } 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 posOrderSync(Map params) throws MallinkException { - Map retMap = new HashMap<>(); + public JSONObject posOrderSync(Map params) throws MallinkException { + JSONObject retMap = new JSONObject(); 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 sceneTypeStr = params.get(WxPayConstant.NEU_ORDER_SCENE_TYPE); // 场景类型 + String cuPhoneStr = params.get(WxPayConstant.NEU_MEM_PHONE); // 富茂系统会员手机号 + String sceneTypeStr = params.get(WxPayConstant.NEU_ORDER_SCENE_TYPE); // 场景类型 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订单总额 @@ -2018,13 +1974,13 @@ public class PosServiceImpl implements PosService { Long merchantId, buUserId, posOrderId, memId; Long posAmount = 0L; - Integer sceneType; + Integer iSceneType; Date orderTime = null; try { merchantId = Long.valueOf(merchantIdStr); buUserId = Long.valueOf(buUserIdStr); memId = Long.valueOf(cuUserIdStr); - sceneType = Integer.valueOf(sceneTypeStr); + iSceneType = Integer.valueOf(sceneTypeStr); posOrderId = Long.valueOf(posOrderIdStr); posAmount = Long.valueOf(posAmountStr); } catch (NumberFormatException e) { @@ -2073,8 +2029,10 @@ public class PosServiceImpl implements PosService { WxPayOrder payOrder = payOrderFromMemDiscount(merchantBUser, order, memId, neuPayOrderId, neuPaymentAmount, neuPosPayOrderTime); } else if (neuPayOrderType.equals(String.valueOf(EnumNeuPosPamentType.MEM_COUPON.getCode()))) { // 优惠券 - WxPayOrder payOrder = payOrderFromCouponVerify(merchantBUser, order, memId, sceneType, + WxPayOrder payOrder = payOrderFromCouponVerify(merchantBUser, order, memId, iSceneType, neuPayOrderId, neuPaymentAmount, neuPosPayOrderTime, neuPayThirdNo); + Long couponOrderId = Long.valueOf(neuPayThirdNo); + couponOrderService.sendInsideCouponVerifyMsg(tenantId, couponOrderId, merchantBUser.getId()); } else if (neuPayOrderType.equals(String.valueOf(EnumNeuPosPamentType.MEM_CARD.getCode()))) { // 预付卡, 不能退 WxPayOrder payOrder = payOrderFromCard(merchantBUser, order, memId, neuPayOrderId, neuPaymentAmount, neuPosPayOrderTime, neuPayThirdNo); @@ -2203,7 +2161,33 @@ public class PosServiceImpl implements PosService { Long couponOrderId = Long.valueOf(posPayOrderNo); // 2. 预核销->核销 if (sceneType.equals(EnumPosSceneType.PAY.getCode())) { - // TODO + WxCouponOrder updateCO = new WxCouponOrder(); + updateCO.setId(couponOrderId); + updateCO.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); + couponOrderMapper.updateByPrimaryKeySelective(updateCO); + } + WxCouponOrderCVo couponOrderCVo = couponOrderService.detailCUserVo(posPayOrderNo); + if (couponOrderCVo != null) { + // 3. 成长值 + try { + WxOrder scoreOrder = orderMapper.selectByPrimaryKey(couponOrderCVo.getOrderId()); + int point = scoreRulesService.addScore2(EnumScoreType.CONSUMPTION, scoreOrder, couponOrderCVo.getBusinessId()); + } catch (Exception e) { + logger.error("交易核销成长值异常:" + e.getMessage()); + } + + 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); + } + + // 4. 积分 + try { + int credit = posAddCredit(couponOrderCVo, wxCoupon, merchantBUser.getMerchantId(), merchantBUser.getId()); + } catch (Exception e) { + logger.error("交易核销积分异常:" + e.getMessage()); + } } // 3. 核销后处理 couponOrderService.sendInsideCouponVerifyMsg(merchantBUser.getTenantId(), couponOrderId, merchantBUser.getId()); @@ -2342,6 +2326,24 @@ public class PosServiceImpl implements PosService { return buUser; } + /** + * 券是否在选择列表中 + * @param selCoArr + * @param couponOrderId + * @return + */ + private boolean isSelCoupon(JSONArray selCoArr, Long couponOrderId) { + boolean selCoupon = false; + for (int j=0;j 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 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 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 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,46 +185,107 @@ public class PosAppTest { boolean resSigned = sendAndRes("/queryAndCalc", reqObj); Assert.assertEquals(resSigned, true); } + /* + @Test + public void getPosMemConfigTest() throws Exception { + Map 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 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 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 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 public void couponOrderVerifyCancelTest() throws Exception { - String couponOrderId = "321878223800205312"; String posOrderId = "1"; - doCouponOrderVerifyCancel(couponOrderId, posOrderId); + String couponOrderId = "321878223800205312"; + String orderAmount = "1000"; + String amountLeft = "0"; + String sceneType = String.valueOf(EnumPosSceneType.VERIFY.getCode()); + Map reqObj = new HashMap<>(); + JSONObject paymentInfo = new JSONObject(); + paymentInfo.put(WxPayConstant.COUPON_ID, couponOrderId); + paymentInfo.put(WxPayConstant.ORDER_AMOUNT, orderAmount); + paymentInfo.put(WxPayConstant.ORDER_AMOUNT_LEFT, orderAmount); + paymentInfo.put(WxPayConstant.PROMOTION_AMOUNT, orderAmount); + paymentInfo.put(WxPayConstant.AMOUNT_LEFT_AFTER_PAY, amountLeft); + reqObj.put(WxPayConstant.NONCE_STR, "1"); + reqObj.put(WxPayConstant.DEV_ID, devId); + reqObj.put(WxPayConstant.TENANT_ID, tenantId); + reqObj.put(WxPayConstant.MERCHANT_ID, merchantId); + reqObj.put(WxPayConstant.BUSER_ID, buUserId); + reqObj.put(WxPayConstant.SCENE_TYPE, sceneType); + reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); + reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); + reqObj.put(WxPayConstant.PAYMENT_INFO, JSON.toJSONString(paymentInfo)); + boolean resSigned = sendAndRes("/couponOrderVerifyCancel", reqObj); + Assert.assertEquals(resSigned, true); } @Test public void verifySyncTest() throws Exception { String memId = "321178010928119808"; String memPhone = "13910154397"; - String sceneType = "2"; // 核销 + String sceneType = "0"; // 核销 String posOrderId = "1"; - String posAmount = "20000"; + String posAmount = "1000"; String posPayOrderId = "1"; String posPaymentType = "4"; String posPaymentTypeDes = "优惠券"; @@ -312,6 +330,83 @@ public class PosAppTest { Assert.assertEquals(resSigned, true); } + @Test + public void payVerifyTest() throws Exception { + String memId = "321178010928119808"; + String memPhone = "13910154397"; + String posOrderId = "2"; + String orderAmount = "1000"; + String selCoList = "[\"321878223800205312\"]"; + String sceneType = String.valueOf(EnumPosSceneType.PAY.getCode()); + Map 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.MEM_ID, memId); + reqObj.put(WxPayConstant.MEM_PHONE, memPhone); + reqObj.put(WxPayConstant.SCENE_TYPE, sceneType); + reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); + reqObj.put(WxPayConstant.ORDER_AMOUNT, orderAmount); + reqObj.put(WxPayConstant.ORDER_AMOUNT_LEFT, orderAmount); + reqObj.put(WxPayConstant.ORDER_CREATE_SN, posSN); + reqObj.put(WxPayConstant.COUPON_ORDER_LIST, selCoList); + boolean resSigned = sendAndRes("/couponOrderVerify", reqObj); + Assert.assertEquals(resSigned, true); + } + + @Test + public void payVerifySyncTest() throws Exception { + String memId = "321178010928119808"; + String memPhone = "13910154397"; + String sceneType = "1"; // 支付 + String posOrderId = "2"; + String orderAmount = "1000"; + String posPayOrderId = "2"; + String posPaymentType = "4"; + String posPaymentTypeDes = "优惠券"; + String posPaymentStatus = "0"; + + String couponOrderId = "321878223800205312"; + + Date curDate = new Date(); + + Map payDetailOne = new HashMap<>(); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_ID, posPayOrderId); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_TIME, neuDateFormat.format(curDate)); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_TYPE, posPaymentType); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_TYPE_DES, posPaymentTypeDes); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_PARAM, "{}"); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_STATUS, posPaymentStatus); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_OUT_NO, couponOrderId); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_AMOUNT, orderAmount); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_OUT_TIME, neuDateFormat.format(curDate)); + + JSONArray payDetailList = new JSONArray(); + payDetailList.add(payDetailOne); + + Map reqObj = new HashMap<>(); + reqObj.put(WxPayConstant.NONCE_STR, "1"); + reqObj.put(WxPayConstant.DEV_ID, devId); + reqObj.put(WxPayConstant.NEU_TENANT_ID, tenantId); + reqObj.put(WxPayConstant.NEU_MERCHANT_ID, merchantId); + reqObj.put(WxPayConstant.NEU_BU_USER_ID, buUserId); + reqObj.put(WxPayConstant.NEU_MEM_ID, memId); + reqObj.put(WxPayConstant.NEU_MEM_PHONE, memPhone); + reqObj.put(WxPayConstant.NEU_ORDER_SCENE_TYPE, sceneType); + reqObj.put(WxPayConstant.NEU_ORDER_ID, posOrderId); + reqObj.put(WxPayConstant.NEU_ORDER_TIME, neuDateFormat.format(curDate)); + reqObj.put(WxPayConstant.NEU_ORDER_AMOUNT, orderAmount); + reqObj.put(WxPayConstant.NEU_ORDER_CREATE_SN, posSN); + reqObj.put(WxPayConstant.NEU_ORDER_STATUS, "0"); + JSONObject payDetail = new JSONObject(); + payDetail.put(WxPayConstant.NEU_PAY_DETAIL_LIST, JSON.toJSONString(payDetailList)); + reqObj.put(WxPayConstant.NEU_PAY_DETAIL, JSON.toJSONString(payDetail)); + boolean resSigned = sendAndRes("/posOrderSync", reqObj); + Assert.assertEquals(resSigned, true); + } + @Test public void couponOrderPreVerifyTest() throws Exception { String couponOrderId = "321877927162249216"; @@ -359,49 +454,6 @@ public class PosAppTest { doCardPayPreCancel(cardId, cardSpendId, posOrderId); } - - - private void doCheckCouponOrder(String couponOrderId, String sceneType, String posOrderId, String posAmount) throws Exception { - Map reqObj = new HashMap<>(); - reqObj.put(WxPayConstant.NONCE_STR, "1"); - reqObj.put(WxPayConstant.DEV_ID, devId); - reqObj.put(WxPayConstant.TENANT_ID, tenantId); - reqObj.put(WxPayConstant.MERCHANT_ID, merchantId); - reqObj.put(WxPayConstant.BUSER_ID, buUserId); - reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); - reqObj.put(WxPayConstant.SCENE_TYPE, sceneType); - reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); - reqObj.put(WxPayConstant.ORDER_AMOUNT, posAmount); - boolean resSigned = sendAndRes("/checkCouponOrder", reqObj); - Assert.assertEquals(resSigned, true); - } - - private void doCouponOrderVerify(String couponOrderId, String posOrderId) throws Exception { - Map reqObj = new HashMap<>(); - reqObj.put(WxPayConstant.NONCE_STR, "1"); - reqObj.put(WxPayConstant.DEV_ID, devId); - reqObj.put(WxPayConstant.TENANT_ID, tenantId); - reqObj.put(WxPayConstant.MERCHANT_ID, merchantId); - reqObj.put(WxPayConstant.BUSER_ID, buUserId); - reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); - reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); - boolean resSigned = sendAndRes("/couponOrderVerify", reqObj); - Assert.assertEquals(resSigned, true); - } - - private void doCouponOrderVerifyCancel(String couponOrderId, String posOrderId) throws Exception { - Map reqObj = new HashMap<>(); - reqObj.put(WxPayConstant.NONCE_STR, "1"); - reqObj.put(WxPayConstant.DEV_ID, devId); - reqObj.put(WxPayConstant.TENANT_ID, tenantId); - reqObj.put(WxPayConstant.MERCHANT_ID, merchantId); - reqObj.put(WxPayConstant.BUSER_ID, buUserId); - reqObj.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); - reqObj.put(WxPayConstant.POS_ORDER_ID, posOrderId); - boolean resSigned = sendAndRes("/couponOrderVerifyCancel", reqObj); - Assert.assertEquals(resSigned, true); - } - private void doPreVerify(String couponOrderId, String posOrderId, String posAmount) throws Exception { Map reqObj = new HashMap<>(); reqObj.put(WxPayConstant.NONCE_STR, "1"); diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillSettleBill.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillSettleBill.java index 970fb621c..75b7469a6 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillSettleBill.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillSettleBill.java @@ -44,8 +44,10 @@ public class WxBillSettleBill extends BaseEntity { @Transient private String receivePay; + @Transient @io.swagger.annotations.ApiModelProperty(value="账单开始时间",name="starttime") private Date starttime; + @Transient @io.swagger.annotations.ApiModelProperty(value="账单结束时间",name="endtime") private Date endtime; } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCardSpend.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCardSpend.java index 7fbbb9f2b..44102bb2d 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCardSpend.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCardSpend.java @@ -65,11 +65,8 @@ 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:POS支付)",name="from") - private Integer from; - - @io.swagger.annotations.ApiModelProperty(value="pos状态(1:POS线下退款开始, 2:POS线下退款成功)",name="posRefundStatus") - private Integer posRefundStatus; + @io.swagger.annotations.ApiModelProperty(value="来源(0:C端小程序扫一扫, 1:POS支付)",name="payFrom") + private Integer payFrom; @Transient @Excel(name = "消费金额(元)", width = 20, orderNum = "7") diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/WxBillAll.java b/mallinkService/src/main/java/com/iformall/domain/vo/WxBillAll.java index 7cd3707f8..4f543c6ea 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/WxBillAll.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/WxBillAll.java @@ -122,7 +122,6 @@ public class WxBillAll extends BaseEntity { private String payDate; - @Transient @io.swagger.annotations.ApiModelProperty(value = "过滤已收金额1过滤", name = "filterHasPay") private Integer filterHasPay; @@ -146,6 +145,11 @@ public class WxBillAll extends BaseEntity { @Transient private Integer balance; + + @Transient + @io.swagger.annotations.ApiModelProperty(value = "冻结状态0正常1冻结", name = "freeze") + private Integer freeze; + @io.swagger.annotations.ApiModelProperty(value = "多个类型", name = "typeStr") private String typeStr; diff --git a/mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java b/mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java index d8bc436ae..5839d0114 100644 --- a/mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java +++ b/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"; @@ -85,6 +87,12 @@ public class WxPayConstant { public final static String COUPON_TYPE = "coupon_type"; public final static String IS_SELECTED = "is_selected"; + public final static String COUPON_REFUND_RESULT = "coupon_refund_result"; + public final static String COUPON_REFUND_ID = "coupon_refund_id"; + public final static String COUPON_REFUND_RESULT_CODE = "result_code"; + public final static String COUPON_REFUND_RESULT_MSG = "result_msg"; + public final static String REFUND_TIME_FROM_IFORMALL = "refund_time_from_iformall"; + public final static String COUPON_PROMOTION_AMOUNT = "coupon_promotion_amount"; public final static String MEMBER_DISCOUNT = "member_discount"; @@ -92,6 +100,8 @@ public class WxPayConstant { public final static String PROMOTION_DATA = "promotion_data"; public final static String PAYMENT_PREDICTION = "payment_prediction"; + public final static String PAYMENT_INFO = "payment_info"; + public final static String DEDUCT_AMOUNT = "deduct_amount"; public final static String REMAIN_AMOUNT = "remain_amount"; public final static String ORDER_STATUS = "order_status"; @@ -123,7 +133,7 @@ public class WxPayConstant { 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_SCENE_TYPE = "SceneType"; // 订单场景 1:订单支付 2:核销 + public final static String NEU_ORDER_SCENE_TYPE = "BusinessType"; // 订单场景 // 0:核销 1:支付 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"; diff --git a/mallinkService/src/main/java/com/iformall/service/WxBillAllService.java b/mallinkService/src/main/java/com/iformall/service/WxBillAllService.java index b7bc24054..64a6c6751 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxBillAllService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxBillAllService.java @@ -2,6 +2,7 @@ package com.iformall.service; import com.iformall.common.ResultData; import com.iformall.domain.po.MallUserInfo; +import com.iformall.domain.po.WxBillSettle; import com.iformall.domain.vo.WxBillAll; import com.iformall.domain.vo.WxBillExcelTemplate; import com.iformall.domain.vo.WxBillExcelTemplateOther; @@ -68,6 +69,8 @@ public interface WxBillAllService { void exportOweBill(WxBillAll wxBillAll, HttpServletRequest request, HttpServletResponse response); + void exportSettleBill(WxBillSettle wxBillSettle, HttpServletRequest request, HttpServletResponse response); + ResultData updateReceivePay(WxBillAll wxBillAll, MallUserInfo user); void addBillAction(EnumBillAction billAction, Long billId, Long oldPrice, Long newPrice, MallUserInfo mallUserInfo); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java index 2c36f5030..1bd1f9838 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java @@ -779,6 +779,26 @@ public class WxBillAllServiceImpl implements WxBillAllService { String createtime = DateUtils.getSystemTime("yyyy-MM-dd"); result.put("createtime", createtime); + String templatePath = "contract-word-template/bill_owe.docx"; + String filepath = fmUploadDir; + String filename = UUID.randomUUID() + ".docx"; + String exportFileName = "催缴单.docx"; + WordUtil.exportWord(templatePath, filepath, filename, exportFileName, result, request, response); + } + + @Override + public void exportSettleBill(WxBillSettle wxBillSettle, HttpServletRequest request, HttpServletResponse response) { + //商场名称 + WxMall wxMall = wxMallMapper.getByTenantId(wxBillSettle.getTenantId()); + //映射结果 + Map result = new HashMap<>(); + result.put("mall", wxMall.getName()); + + //编号 + String number = "JF" + DateUtils.getSystemTime("yyyyMMddHHmmss"); + result.put("number", number); + + String templatePath = "contract-word-template/bill_owe.docx"; String filepath = fmUploadDir; String filename = UUID.randomUUID() + ".docx"; diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillSettleServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillSettleServiceImpl.java index dbde10048..132a1a4c2 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillSettleServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillSettleServiceImpl.java @@ -12,6 +12,7 @@ import com.iformall.service.ExcelService; import com.iformall.service.WxBillSettleService; import com.iformall.service.WxFlowService; import com.iformall.utils.DateUtils; +import org.apache.commons.collections.CollectionUtils; import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -31,6 +32,8 @@ public class WxBillSettleServiceImpl implements WxBillSettleService { @Autowired private WxBillSettleMapper wxBillSettleMapper; @Autowired + private WxMerchantMapper wxMerchantMapper; + @Autowired private WxFlowService wxFlowService; @Autowired private WxBillSettleBillMapper wxBillSettleBillMapper; @@ -69,6 +72,11 @@ public class WxBillSettleServiceImpl implements WxBillSettleService { WxBillSettle billSettle = wxBillSettleMapper.selectByPrimaryKey(id); if(billSettle != null) { + WxMerchant merchant = wxMerchantMapper.selectByPrimaryKey(billSettle.getMerchantId()); + if(merchant != null){ + billSettle.setMerchantName(merchant.getName()); + } + if(billSettle.getReceiveMoney() > billSettle.getPayMoney()){ billSettle.setSettleWay(EnumSettleWay.B.getCode()); }else{ @@ -152,6 +160,10 @@ public class WxBillSettleServiceImpl implements WxBillSettleService { @Transactional public ResultData saveOrUpdate(WxBillSettle record, MallUserInfo userInfo) { final IdWorker idWorker = IdWorker.get(); + + if (record.getFlowParams() == null || record.getFlowParams().size() == 0) { + record.setStatus(EnumSettleStatus.NOT_FINISH.getCode()); + } if (record.getId() == null) { record.setId(idWorker.nextId()); wxBillSettleMapper.insertSelective(record); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java index ca318e897..c1098eacb 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java @@ -137,7 +137,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { // 5 insert card_spend record.setId(idWorker.nextId()); record.setTenantId(cardInfo.getTenantId()); - record.setFrom(EnumCardSpendFrom.C.getCode()); + record.setPayFrom(EnumCardSpendFrom.C.getCode()); record.setPayment(payment); record.setRealPayment(real_payment); record.setCardBeforeAmount(cardInfo.getRemainingAmount()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java index bf0b130f4..d87f2b377 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java @@ -203,9 +203,9 @@ public class WxFlowServiceImpl implements WxFlowService { wxPropertyContractMapper.updateApplyStatus(wxPropertyContract); } } else if (EnumFlowKey.BILL.getCode().equals(flowType) || EnumFlowKey.NEW_BILL_CHANGE.getCode().equals(flowType)) { + Integer billType = getIngeter(getVariableByKey(variables, "billType")); if(EnumRentContractAppStatus.FINISH.getCode().intValue() == applyStatus.intValue()) { //账单审批 - Integer billType = getIngeter(getVariableByKey(variables, "billType")); MallUserInfo user = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute("userSession"); Integer billUpdateType = getIngeter(getVariableByKey(variables, "billUpdateType")); Long oldPrice = Long.parseLong(getVariableByKey(variables, "oldPrice").toString()); @@ -221,6 +221,14 @@ public class WxFlowServiceImpl implements WxFlowService { wxBillAll.setNewPrice(newPrice); } wxBillAllService.updateReceivePay(wxBillAll, user); + }else{ + //账单修改金额,冻结 + List billList = new ArrayList<>(); + WxBillSettleBill settleBill = new WxBillSettleBill(); + settleBill.setBillType(billType); + settleBill.setBillId(businessId); + billList.add(settleBill); + wxBillSettleService.updateFreeze(billList,EnumFreezeType.YES.getCode()); } } else if (EnumFlowKey.NEW_COUPON_UPLINE.getCode().equals(flowType) || EnumFlowKey.NEW_CARD_UPLINE.getCode().equals(flowType) diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java index 65d26fd38..b7d6bdba2 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -2010,7 +2010,8 @@ public class WxRentContractServiceImpl implements WxRentContractService { String ratio = new BigDecimal(integers.get(i)).divide(new BigDecimal(100)).toPlainString(); result.put("adjustRatio" + i, ratio); result.put("adjustPeriod" + i, wxRentContract.getAdjustPeriod()); - String payRatio = new BigDecimal(wxRentContract.getPayRatio()).divide(new BigDecimal(100)).toPlainString(); + Integer tempPayRatio = Optional.ofNullable(wxRentContract.getPayRatio()).orElse(0); + String payRatio = new BigDecimal(tempPayRatio).divide(new BigDecimal(100)).toPlainString(); result.put("payRatio" + i, payRatio); } @@ -2039,7 +2040,8 @@ public class WxRentContractServiceImpl implements WxRentContractService { result.put("rentalEndDateDay" + count, enddate.substring(8)); result.put("adjustRatio" + count, wxRentContract.getAdjustRatio()); result.put("adjustPeriod" + count, wxRentContract.getAdjustPeriod()); - String payRatio = new BigDecimal(wxRentContract.getPayRatio()).divide(new BigDecimal(100)).toPlainString(); + Integer tempPayRatio = Optional.ofNullable(wxRentContract.getPayRatio()).orElse(0); + String payRatio = new BigDecimal(tempPayRatio).divide(new BigDecimal(100)).toPlainString(); result.put("payRatio" + count, payRatio); } diff --git a/mallinkService/src/main/java/com/iformall/utils/WordUtil.java b/mallinkService/src/main/java/com/iformall/utils/WordUtil.java index 1439defc9..69bb316b7 100644 --- a/mallinkService/src/main/java/com/iformall/utils/WordUtil.java +++ b/mallinkService/src/main/java/com/iformall/utils/WordUtil.java @@ -2,7 +2,9 @@ package com.iformall.utils; import cn.afterturn.easypoi.word.WordExportUtil; import org.apache.commons.io.FileUtils; -import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.xwpf.usermodel.*; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.Assert; @@ -12,6 +14,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; +import java.util.List; import java.util.Map; public class WordUtil { @@ -84,4 +87,214 @@ public class WordUtil { } + /** + * 循环填充表格内容 + * @param xwpfDocument + * @param params + * @param tableIndex + * @throws Exception + */ + private void insertValueToTable(XWPFDocument xwpfDocument, List> params, int tableIndex) throws Exception { + List tableList = xwpfDocument.getTables(); + if(tableList.size()<=tableIndex){ + throw new Exception("tableIndex对应的表格不存在"); + } + XWPFTable table = tableList.get(tableIndex); + List rows = table.getRows(); + if(rows.size()<2){ + throw new Exception("tableIndex对应表格应该为2行"); + } + //模板的那一行 + XWPFTableRow tmpRow = rows.get(1); + List tmpCells = null; + List cells = null; + XWPFTableCell tmpCell = null; + tmpCells = tmpRow.getTableCells(); + + String cellText = null; + String cellTextKey = null; + Map totalMap = null; + for (int i = 0, len = params.size(); i < len; i++) { + Map map = params.get(i); + // 创建新的一行 + XWPFTableRow row = table.createRow(); + // 获取模板的行高 设置为新一行的行高 + row.setHeight(tmpRow.getHeight()); + cells = row.getTableCells(); + for (int k = 0, klen = cells.size(); k < klen; k++) { + tmpCell = tmpCells.get(k); + XWPFTableCell cell = cells.get(k); + cellText = tmpCell.getText(); + if (StringUtils.isNotBlank(cellText)) { + //转换为mapkey对应的字段 + cellTextKey = cellText.replace("$", "").replace("{", "").replace("}", ""); + if (map.containsKey(cellTextKey)) { + // 填充内容 并且复制模板行的属性 + setCellText(tmpCell,cell,map.get(cellTextKey)); + } + } + } + + } + // 删除模版行 + table.removeRow(1); + } + + /** + * 复制模板行的属性 + * @param tmpCell + * @param cell + * @param text + * @throws Exception + */ + private void setCellText(XWPFTableCell tmpCell, XWPFTableCell cell,String text) throws Exception { + CTTc cttc2 = tmpCell.getCTTc(); + CTTcPr ctPr2 = cttc2.getTcPr(); + CTTc cttc = cell.getCTTc(); + CTTcPr ctPr = cttc.addNewTcPr(); + if (ctPr2.getTcW() != null) { + ctPr.addNewTcW().setW(ctPr2.getTcW().getW()); + } + if (ctPr2.getVAlign() != null) { + ctPr.addNewVAlign().setVal(ctPr2.getVAlign().getVal()); + } + if (cttc2.getPList().size() > 0) { + CTP ctp = cttc2.getPList().get(0); + if (ctp.getPPr() != null) { + if (ctp.getPPr().getJc() != null) { + cttc.getPList().get(0).addNewPPr().addNewJc() + .setVal(ctp.getPPr().getJc().getVal()); + } + } + } + if (ctPr2.getTcBorders() != null) { + ctPr.setTcBorders(ctPr2.getTcBorders()); + } + + XWPFParagraph tmpP = tmpCell.getParagraphs().get(0); + XWPFParagraph cellP = cell.getParagraphs().get(0); + XWPFRun tmpR = null; + if (tmpP.getRuns() != null && tmpP.getRuns().size() > 0) { + tmpR = tmpP.getRuns().get(0); + } + XWPFRun cellR = cellP.createRun(); + cellR.setText(text); + // 复制字体信息 + if (tmpR != null) { + if(!cellR.isBold()){ + cellR.setBold(tmpR.isBold()); + } + cellR.setItalic(tmpR.isItalic()); + cellR.setUnderline(tmpR.getUnderline()); + cellR.setColor(tmpR.getColor()); + cellR.setTextPosition(tmpR.getTextPosition()); + if (tmpR.getFontSize() != -1) { + cellR.setFontSize(tmpR.getFontSize()); + } + if (tmpR.getFontFamily() != null) { + cellR.setFontFamily(tmpR.getFontFamily()); + } + if (tmpR.getCTR() != null) { + if (tmpR.getCTR().isSetRPr()) { + CTRPr tmpRPr = tmpR.getCTR().getRPr(); + if (tmpRPr.isSetRFonts()) { + CTFonts tmpFonts = tmpRPr.getRFonts(); + CTRPr cellRPr = cellR.getCTR().isSetRPr() ? cellR + .getCTR().getRPr() : cellR.getCTR().addNewRPr(); + CTFonts cellFonts = cellRPr.isSetRFonts() ? cellRPr + .getRFonts() : cellRPr.addNewRFonts(); + cellFonts.setAscii(tmpFonts.getAscii()); + cellFonts.setAsciiTheme(tmpFonts.getAsciiTheme()); + cellFonts.setCs(tmpFonts.getCs()); + cellFonts.setCstheme(tmpFonts.getCstheme()); + cellFonts.setEastAsia(tmpFonts.getEastAsia()); + cellFonts.setEastAsiaTheme(tmpFonts.getEastAsiaTheme()); + cellFonts.setHAnsi(tmpFonts.getHAnsi()); + cellFonts.setHAnsiTheme(tmpFonts.getHAnsiTheme()); + } + } + } + + } + // 复制段落信息 + cellP.setAlignment(tmpP.getAlignment()); + cellP.setVerticalAlignment(tmpP.getVerticalAlignment()); + cellP.setBorderBetween(tmpP.getBorderBetween()); + cellP.setBorderBottom(tmpP.getBorderBottom()); + cellP.setBorderLeft(tmpP.getBorderLeft()); + cellP.setBorderRight(tmpP.getBorderRight()); + cellP.setBorderTop(tmpP.getBorderTop()); + cellP.setPageBreak(tmpP.isPageBreak()); + if (tmpP.getCTP() != null) { + if (tmpP.getCTP().getPPr() != null) { + CTPPr tmpPPr = tmpP.getCTP().getPPr(); + CTPPr cellPPr = cellP.getCTP().getPPr() != null ? cellP + .getCTP().getPPr() : cellP.getCTP().addNewPPr(); + // 复制段落间距信息 + CTSpacing tmpSpacing = tmpPPr.getSpacing(); + if (tmpSpacing != null) { + CTSpacing cellSpacing = cellPPr.getSpacing() != null ? cellPPr + .getSpacing() : cellPPr.addNewSpacing(); + if (tmpSpacing.getAfter() != null) { + cellSpacing.setAfter(tmpSpacing.getAfter()); + } + if (tmpSpacing.getAfterAutospacing() != null) { + cellSpacing.setAfterAutospacing(tmpSpacing + .getAfterAutospacing()); + } + if (tmpSpacing.getAfterLines() != null) { + cellSpacing.setAfterLines(tmpSpacing.getAfterLines()); + } + if (tmpSpacing.getBefore() != null) { + cellSpacing.setBefore(tmpSpacing.getBefore()); + } + if (tmpSpacing.getBeforeAutospacing() != null) { + cellSpacing.setBeforeAutospacing(tmpSpacing + .getBeforeAutospacing()); + } + if (tmpSpacing.getBeforeLines() != null) { + cellSpacing.setBeforeLines(tmpSpacing.getBeforeLines()); + } + if (tmpSpacing.getLine() != null) { + cellSpacing.setLine(tmpSpacing.getLine()); + } + if (tmpSpacing.getLineRule() != null) { + cellSpacing.setLineRule(tmpSpacing.getLineRule()); + } + } + // 复制段落缩进信息 + CTInd tmpInd = tmpPPr.getInd(); + if (tmpInd != null) { + CTInd cellInd = cellPPr.getInd() != null ? cellPPr.getInd() + : cellPPr.addNewInd(); + if (tmpInd.getFirstLine() != null) { + cellInd.setFirstLine(tmpInd.getFirstLine()); + } + if (tmpInd.getFirstLineChars() != null) { + cellInd.setFirstLineChars(tmpInd.getFirstLineChars()); + } + if (tmpInd.getHanging() != null) { + cellInd.setHanging(tmpInd.getHanging()); + } + if (tmpInd.getHangingChars() != null) { + cellInd.setHangingChars(tmpInd.getHangingChars()); + } + if (tmpInd.getLeft() != null) { + cellInd.setLeft(tmpInd.getLeft()); + } + if (tmpInd.getLeftChars() != null) { + cellInd.setLeftChars(tmpInd.getLeftChars()); + } + if (tmpInd.getRight() != null) { + cellInd.setRight(tmpInd.getRight()); + } + if (tmpInd.getRightChars() != null) { + cellInd.setRightChars(tmpInd.getRightChars()); + } + } + } + } + } + + } \ No newline at end of file diff --git a/mallinkService/src/main/resources/contract-word-template/settle.docx b/mallinkService/src/main/resources/contract-word-template/settle.docx new file mode 100644 index 000000000..47a1568e5 Binary files /dev/null and b/mallinkService/src/main/resources/contract-word-template/settle.docx differ diff --git a/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml b/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml index a8feded4b..4bbb3b381 100644 --- a/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml @@ -53,46 +53,46 @@ bill.pay_date payDate,expired_day expiredDay,bill.status,bill.starttime, bill.endtime,bill.name,bill.rent_shop_type rentShopType,m.name merchantName, s.shop_number shopNumber, s.manager, s.manager_phone managerPhone,bill.shop_info - shopInfo,bill.comments,bill.price_detail,updatetime + shopInfo,bill.comments,bill.price_detail,updatetime,bill.freeze from ( select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type,case when shop_info is null then '[]' else shop_info end shop_info,comments,'' - price_detail,updatetime + price_detail,updatetime,freeze from wx_bill_rent where tenant_id=#{tenantId} and is_preview = 0 union all select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' - endtime,rent_shop_type,shop_info,NULL comments,'' price_detail,updatetime from wx_bill_rent_deposit where + endtime,rent_shop_type,shop_info,NULL comments,'' price_detail,updatetime,freeze from wx_bill_rent_deposit where tenant_id=#{tenantId} union all select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type,case when shop_info is null then '[]' else shop_info end shop_info,comments,'' - price_detail,updatetime + price_detail,updatetime,freeze from wx_bill_property where tenant_id=#{tenantId} and is_preview = 0 union all select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' - endtime,rent_shop_type,shop_info,NULL comments,'' price_detail,updatetime from wx_bill_property_deposit where + endtime,rent_shop_type,shop_info,NULL comments,'' price_detail,updatetime,freeze from wx_bill_property_deposit where tenant_id=#{tenantId} union all select id,merchant_id,shop_id,tenant_id,case when type=1 then '水费' when type=2 then '电费' else '空调费' end name, case when type=1 then 5 when type=2 then 6 else 9 end bill_type_value, case when type=1 then '水费' when type=2 then '电费' else '空调费' end bill_type,0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime, - rent_shop_type,'[]' shop_info, NULL comments,price_detail,updatetime + rent_shop_type,'[]' shop_info, NULL comments,price_detail,updatetime,freeze from wx_bill_daily where tenant_id=#{tenantId} union all select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,concat('其他费用-',name) as bill_type,0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime, - rent_shop_type,'[]' shop_info,comments,'' price_detail,updatetime + rent_shop_type,'[]' shop_info,comments,'' price_detail,updatetime,freeze from wx_bill_other where tenant_id=#{tenantId} union all select id,merchant_id,shop_id,tenant_id,comments as name,8 bill_type_value,concat('其他押金-',comments) as bill_type,0 as need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime, - rent_shop_type,'[]' shop_info,comments,'' price_detail,updatetime + rent_shop_type,'[]' shop_info,comments,'' price_detail,updatetime,freeze from wx_bill_other_deposit where tenant_id=#{tenantId} ) bill left join wx_merchant m on bill.merchant_id=m.id @@ -127,7 +127,8 @@ #{type} - + and bill.freeze = #{freeze} + order by ${sortColumns} order by bill.receive_date,bill.id desc,bill.merchant_id,bill.status diff --git a/mallinkService/src/main/resources/mapper/WxCardSpendMapper.xml b/mallinkService/src/main/resources/mapper/WxCardSpendMapper.xml index ef1395928..b7121d856 100644 --- a/mallinkService/src/main/resources/mapper/WxCardSpendMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCardSpendMapper.xml @@ -19,14 +19,14 @@ - - + - `id`,`tenant_id`,`card_id`,`owner_id`,`merchant_id`,`order_id`,`pos_order_id`,``deduction_amount`,`payment`,`real_payment`, - `card_remain_amount`,`card_before_amount`,`card_remain_real_amount`,`card_before_real_amount`, - `create_date`,`update_date`, `pay_status`, `from`, `pos_refund_status` + `id`,`tenant_id`,`card_id`,`owner_id`,`merchant_id`,`order_id`,`pos_order_id`, + `deduction_amount`,`payment`,`real_payment`, `card_remain_amount`, + `card_before_amount`,`card_remain_real_amount`,`card_before_real_amount`, + `create_date`, `update_date`, `pay_status`, `pay_from` @@ -82,11 +82,8 @@ and `pay_status` = #{payStatus} - - and `from` = #{from} - - - and `pos_refund_status` = #{posRefundStatus} + + and `pay_from` = #{payFrom} and `create_date` between #{startdate} and #{enddate} diff --git a/mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml index 21fdb9887..5c49d96cb 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml @@ -792,7 +792,7 @@ - co.id,co.coupon_id,co.coupon_type,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price,co.verify_type, + co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price,co.verify_type, c.cover_img,c.title,c.sub_title,c.sale_price,c.use_price,c.price,c.unit,c.valid_start_date,c.valid_end_date,c.auto_refund, cal.channel_type as send_channel_type @@ -877,31 +877,29 @@