diff --git a/mallinkAdmin/src/main/resources/db/migration/V201908221020__POS_ORDER.sql b/mallinkAdmin/src/main/resources/db/migration/V201908221020__POS_ORDER.sql new file mode 100644 index 000000000..3fe0edf87 --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V201908221020__POS_ORDER.sql @@ -0,0 +1,41 @@ +create table `pos_order` ( + `id` bigint(20) NOT NULL COMMENT '主键ID', + `tenant_id` varchar(10) NOT NULL COMMENT '租户ID', + `pos_order_no` varchar(20) NULL COMMENT 'POS订单ID', + `type` tinyint(6) NOT NULL DEFAULT 0 COMMENT '支付类型(1: 独立核销, 2:支付)', + `order_status` tinyint(6) NOT NULL DEFAULT '0' COMMENT '订单状态:0-待付款/待核销;1-已支付;2-已取消(限定时间内未付款);3-待退款;4-已退款;5-退款失败', + `bu_user_id` bigint(20) DEFAULT NULL COMMENT 'b端用户', + `payment_type` smallint(2) NOT NULL COMMENT '0: 付款 1: 退款 2:自动退款 3:A端退款 10:独立核销', + `payment` int(11) default NULL COMMENT '支付金额:允许有负数,退款时为负值。核销时,金额可以不填写', + `create_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='POS订单'; + +CREATE TABLE `pos_pay_order` ( + `id` bigint(20) NOT NULL COMMENT '主键ID', + `tenant_id` varchar(10) NOT NULL COMMENT '租户ID', + `create_time` datetime NOT NULL COMMENT '创建时间', + `update_time` datetime NOT NULL COMMENT '更新时间', + `order_id` bigint(20) NOT NULL COMMENT '订单ID', + `bu_user_id` bigint(20) DEFAULT NULL COMMENT 'b端用户', + `type` tinyint(6) NOT NULL DEFAULT 0 COMMENT '支付类型(1:独立核销 2:支付核销 3:现金支付)', + `pay_from` tinyint(6) NOT NULL DEFAULT 0 COMMENT '支付来源(0: 现金, 1:微信 2:支付核销 3:现金支付)', + `pay_amount` int(11) NOT NULL COMMENT '支付金额(分)', + `pay_time_start` datetime NOT NULL COMMENT '支付发起时间', + `pay_time_end` datetime NOT NULL COMMENT '支付结束时间', + `prepay_id` varchar(64) DEFAULT NULL COMMENT '微信预支付交易会话标识-发模板信息使用', + `transaction_id` varchar(36) DEFAULT NULL COMMENT '微信生成的订单号', + `pay_vendor` int(11) NOT NULL DEFAULT 0 COMMENT '支付渠道: 0-微信 1-支付宝 2-银联 ', + `pay_order_no` varchar(36) DEFAULT '' COMMENT '支付订单号', + `pay_order_status` int(11) NOT NULL DEFAULT 0 COMMENT '支付状态: 0-支付中;1-支付成功;2-支付失败', + `share` smallint(2) DEFAULT NULL COMMENT '是否支持分账(0:不支持,1:支持)', + `share_amount` int(11) DEFAULT NULL COMMENT '分账金额(总金额扣掉手续费后的金额)', + `rate_amount` int(11) DEFAULT NULL COMMENT '分账实际通道费', + `fail_reason` varchar(50) DEFAULT '' COMMENT '支付失败原因', + `auth_code` varchar(128) DEFAULT NULL COMMENT '扫码支付授权码', + `open_id` varchar(128) DEFAULT NULL COMMENT '微信支付后获取的open_id', + `pay_end_from` smallint(2) DEFAULT NULL COMMENT '支付后结果来源(0:callback, 1:query)', + PRIMARY KEY (`id`), + UNIQUE `id_UNIQUE` USING BTREE (`id`) comment '' +) ENGINE=`InnoDB` DEFAULT CHARSET=utf8mb4 COMMENT='POS支付订单'; \ No newline at end of file diff --git a/mallinkAdmin/src/main/resources/db/migration/V201908221440__L_CONTRACT.sql b/mallinkAdmin/src/main/resources/db/migration/V201908221440__L_CONTRACT.sql new file mode 100644 index 000000000..bbd20f642 --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V201908221440__L_CONTRACT.sql @@ -0,0 +1,2 @@ +alter table wx_bill_rent +add column `bus_discount_ratio` int(5) NULL DEFAULT NULL COMMENT '连营扣点跳点率'; \ No newline at end of file diff --git a/mallinkBApi/src/main/java/com/iformall/controller/PosController.java b/mallinkBApi/src/main/java/com/iformall/controller/PosController.java new file mode 100644 index 000000000..bde3a1398 --- /dev/null +++ b/mallinkBApi/src/main/java/com/iformall/controller/PosController.java @@ -0,0 +1,181 @@ +package com.iformall.controller; + +import com.iformall.common.ErrorCode; +import com.iformall.common.ResultData; +import com.iformall.domain.po.WxMerchantBUser; +import com.iformall.exception.MallinkException; +import com.iformall.pay.WxPayConstant; +import com.iformall.service.PosBrunService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +@RestController +@RequestMapping("/api/pos") +@Api(description = "POS服务相关接口") +public class PosController extends BaseController { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private PosBrunService posService; + + @ApiOperation(value = "检查POS Server是否正常", notes = "") + @GetMapping("checkAvaiable") + public ResultData checkAvaiable() { + return posService.checkAvaiable(); + } + + @ApiOperation(value = "商户POS用户/B端用户登录检查") + @PostMapping("checkUserPassword") + public ResultData checkUserPassword(@RequestBody Map params) { + WxMerchantBUser user = getUser(); + String phone = params.get("phone"); + String password = params.get("password"); + //登录凭证不能为空 + if (StringUtils.isBlank(phone)) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "手机号不能为空"); + } + if (StringUtils.isBlank(password)) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "密码不能为空"); + } + return posService.checkUserPassword(user, phone, password); + } + + @ApiOperation(value = "获取会员折扣/优惠券/消费卡是否启用") + @PostMapping("getPosMemConfig") + public ResultData getPosMemConfig() { + return posService.getPosMemConfig(getTenantId()); + } + + @ApiOperation(value = "获取注册二维码及小票二维码规则") + @PostMapping("getQrCode") + public ResultData getQrCode() { + return posService.getQrCode(getTenantId()); + } + + @ApiOperation(value = "会员识别") + @PostMapping("checkMem") + public ResultData checkMem(@RequestBody Map params) { + WxMerchantBUser user = getUser(); + 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.POS_AMOUNT); // POS订单金额(单位:分) + + if (StringUtils.isBlank(posOrderIdStr)) { + String errMessage = "request params[pos_order_id] error."; + logger.error(errMessage); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + } + if (StringUtils.isBlank(posAmountStr)) { + String errMessage = "request params[pos_amount] error."; + logger.error(errMessage); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + } + + if (StringUtils.isBlank(memIdStr) && StringUtils.isBlank(memPhoneStr)) { + String errMessage = "please give one value for mem_id or mem_phone"; + logger.error(errMessage); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + } + return posService.checkMem(user, memIdStr, memPhoneStr, posOrderIdStr, posAmountStr); + } + + @ApiOperation(value = "券独立核销检查") + @PostMapping("checkCouponOrderForIndepentVerify") + public ResultData checkCouponOrderForIndepentVerify(@RequestBody Map params) { + WxMerchantBUser user = getUser(); + String couponOrderIdStr = params.get(WxPayConstant.COUPON_ORDER_ID); // 券包ID + + if (StringUtils.isBlank(couponOrderIdStr)) { + String errMessage = "request params[coupon_order_id] error."; + logger.error(errMessage); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + } + String verifyType = WxPayConstant.VERIFY_TYPE_INDEPENT; + return posService.checkCouponOrderForIndepentVerify(user, verifyType, couponOrderIdStr); + } + + @ApiOperation(value = "券预核销") + @PostMapping("couponOrderPreVerify") + public ResultData couponOrderPreVerify(@RequestBody Map params) { + WxMerchantBUser user = getUser(); + String couponOrderIdStr = params.get(WxPayConstant.COUPON_ORDER_ID); // 券包ID + String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID + String posAmountStr = params.get(WxPayConstant.POS_AMOUNT); // POS订单金额(单位:分) + + if (StringUtils.isBlank(couponOrderIdStr)) { + String errMessage = "request params[coupon_order_id] error."; + logger.error(errMessage); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + } + if (StringUtils.isBlank(posOrderIdStr)) { + String errMessage = "request params[pos_order_id] error."; + logger.error(errMessage); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + } + if (StringUtils.isBlank(posAmountStr)) { + String errMessage = "request params[pos_amount] error."; + logger.error(errMessage); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + } + return posService.couponOrderPreVerify(user, couponOrderIdStr, posOrderIdStr, posAmountStr); + } + + @ApiOperation(value = "券预核销取消") + @PostMapping("couponOrderPreVerifyCancel") + public ResultData couponOrderPreVerifyCancel(@RequestBody Map params) { + WxMerchantBUser user = getUser(); + String couponOrderIdStr = params.get(WxPayConstant.COUPON_ORDER_ID); // 券包ID + String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID + String posAmountStr = params.get(WxPayConstant.POS_AMOUNT); // POS订单金额(单位:分) + + if (StringUtils.isBlank(couponOrderIdStr)) { + String errMessage = "request params[coupon_order_id] error."; + logger.error(errMessage); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + } + if (StringUtils.isBlank(posOrderIdStr)) { + String errMessage = "request params[pos_order_id] error."; + logger.error(errMessage); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + } + if (StringUtils.isBlank(posAmountStr)) { + String errMessage = "request params[pos_amount] error."; + logger.error(errMessage); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + } + return posService.couponOrderPreVerifyCancel(user, couponOrderIdStr, posOrderIdStr, posAmountStr); + } + + @ApiOperation(value = "券独立核销", notes = "{\"couponOrderId\":\"string\", \"payment\":\"string(单位:分)\"}") + @PostMapping("posVerifyIndepent") + public ResultData posVerifyIndepent(@RequestBody Map params) { + WxMerchantBUser user = getUser(); + String couponOrderId = params.get("coupon_order_id"); + String payment = params.get("payment"); + if (StringUtils.isBlank(couponOrderId)) { + String errMessage = "券ID为空"; + logger.error(errMessage); + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + } + return posService.posVerifyIndepent(user, couponOrderId, payment); + } + + @ApiOperation(value = "核销接口", notes = "{\"couponOrderId\":\"string\"}") + @PostMapping("verifyForPos") + public ResultData verifyForPos(@RequestBody Map paramMap) { + // 0. 获取dev信息, tenantId信息 + // 1. check 查询 + // 2. create order + // 3. 独立核销 + + return new ResultData(); + } +} diff --git a/mallinkBApi/src/main/java/com/iformall/controller/PosOrderController.java b/mallinkBApi/src/main/java/com/iformall/controller/PosOrderController.java new file mode 100644 index 000000000..4298e6716 --- /dev/null +++ b/mallinkBApi/src/main/java/com/iformall/controller/PosOrderController.java @@ -0,0 +1,87 @@ +package com.iformall.controller; + +import com.iformall.common.ErrorCode; +import com.iformall.service.PosBrunService; +import com.iformall.service.PosPayOrderService; +import io.swagger.annotations.Api; +import lombok.AllArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.*; + +import com.github.pagehelper.PageInfo; +import com.iformall.common.Result; +import com.iformall.common.ResultData; + +import com.iformall.domain.po.PosOrder; +import com.iformall.service.PosOrderService; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; + + +@RestController +@RequestMapping("/api/posOrder") +@AllArgsConstructor +@Api(description = "POS订单接口") +public class PosOrderController extends BaseController { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + + private final PosOrderService posOrderService; + + @ApiOperation("分页列表接口") + @GetMapping("list") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) + public ResultData list(@ModelAttribute PosOrder posOrder, Integer pageNum, Integer pageSize) { + if (null == posOrder) posOrder = new PosOrder(); + final PageInfo page = posOrderService.listAsPage(posOrder, pageNum, pageSize); + return new ResultData(page); + } + + @ApiOperation("新增POS订单接口") + @PostMapping("add") + public ResultData add(@RequestBody PosOrder posOrder) { + if (posOrder == null) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + if (posOrder.getType() == null) { + String errMessage = "订单类型为空"; + logger.error(errMessage); + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + } + if (posOrder.getBuUserId() == null) { + String errMessage = "操作员为空"; + logger.error(errMessage); + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), errMessage); + } + posOrderService.saveOrUpdate(posOrder); + return new ResultData(); + } + + @ApiOperation("根据id更新接口") + @PostMapping("update") + public ResultData update(@RequestBody PosOrder posOrder) { + posOrderService.saveOrUpdate(posOrder); + return new ResultData(); + } + + @ApiOperation("根据id删除接口") + @GetMapping("/del") + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) + public ResultData delete(Long id) { + posOrderService.deleteById(id); + return new ResultData(Result.SUCCESS, "删除成功", null); + } + + @ApiOperation("根据id查询接口") + @GetMapping("/findById") + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) + public ResultData findById(Long id) { + return new ResultData(Result.SUCCESS, "查询成功", posOrderService.getById(id)); + } + + +} diff --git a/mallinkBApi/src/main/java/com/iformall/controller/PosPayOrderController.java b/mallinkBApi/src/main/java/com/iformall/controller/PosPayOrderController.java new file mode 100644 index 000000000..d4c40aac4 --- /dev/null +++ b/mallinkBApi/src/main/java/com/iformall/controller/PosPayOrderController.java @@ -0,0 +1,72 @@ +package com.iformall.controller; + +import io.swagger.annotations.Api; +import lombok.AllArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.*; + +import com.github.pagehelper.PageInfo; +import com.iformall.common.Result; +import com.iformall.common.ResultData; + +import com.iformall.domain.po.PosPayOrder; +import com.iformall.service.PosPayOrderService; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; + +@RestController +@RequestMapping("/api/posPayOrder") +@AllArgsConstructor +@Api(description = "POS支付订单接口") +public class PosPayOrderController extends BaseController { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + private final PosPayOrderService posPayOrderService; + + + @ApiOperation("分页列表接口") + @GetMapping("list") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) + public ResultData list(@ModelAttribute PosPayOrder posPayOrder, Integer pageNum, Integer pageSize) { + if (null == posPayOrder) posPayOrder = new PosPayOrder(); + final PageInfo page = posPayOrderService.listAsPage(posPayOrder, pageNum, pageSize); + return new ResultData(page); + } + + @ApiOperation("新增POS订单接口") + @PostMapping("add") + public ResultData add(@RequestBody PosPayOrder posPayOrder) { + //Assert.notNull(posPayOrder.getName(), "角色名不能为空"); + //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); + posPayOrderService.saveOrUpdate(posPayOrder); + return new ResultData(); + } + + @ApiOperation("根据id更新接口") + @PostMapping("update") + public ResultData update(@RequestBody PosPayOrder posPayOrder) { + posPayOrderService.saveOrUpdate(posPayOrder); + return new ResultData(); + } + + @ApiOperation("根据id删除接口") + @GetMapping("/del") + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) + public ResultData delete(Long id) { + posPayOrderService.deleteById(id); + return new ResultData(Result.SUCCESS, "删除成功", null); + } + + @ApiOperation("根据id查询接口") + @GetMapping("/findById") + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) + public ResultData findById(Long id) { + return new ResultData(Result.SUCCESS, "查询成功", posPayOrderService.getById(id)); + } + + +} diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxPosController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxPosController.java deleted file mode 100644 index a6716f324..000000000 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxPosController.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.iformall.controller; - -import com.iformall.common.Result; -import com.iformall.common.ResultData; -import com.iformall.exception.MallinkException; -import com.iformall.utils.PosUtil; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import java.util.Map; - -@RestController -@RequestMapping("/api/pos") -@Api(description = "卡券相关接口") -public class WxPosController extends BaseController { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - @Autowired - private String posDevId; - - @Autowired - private String posReqKey; - - @Autowired - private String posResKey; - - @Autowired - private String posUrl; - - PosUtil posUtil = new PosUtil(); - - @ApiOperation(value = "检查POSServer是否正常", notes = "") - @GetMapping("checkAvaiable") - public ResultData checkAvaiable() { - try { - String resStr = posUtil.checkPosMemServer(posUrl); - if (resStr != null) { - return new ResultData(); - } else { - return new ResultData(Result.ERROR, "无返回值"); - } - } catch (MallinkException e) { - logger.error(e.getMessage()); - return new ResultData(e.getErrorCode(), e.getMessage()); - } catch (Exception e) { - logger.error(e.getMessage()); - return new ResultData(Result.ERROR, e.getMessage()); - } - - } - - @ApiOperation(value = "核销接口", notes = "{\"couponOrderId\":\"string\"}") - @PostMapping("verifyForPos") - public ResultData verifyForPos(@RequestBody Map paramMap) { - // 0. 获取dev信息, tenantId信息 - // 1. check 查询 - // 2. create order - // 3. 独立核销 - - return new ResultData(); - } -} diff --git a/mallinkBApi/src/main/java/com/iformall/service/PosBrunService.java b/mallinkBApi/src/main/java/com/iformall/service/PosBrunService.java new file mode 100644 index 000000000..a1a1601e9 --- /dev/null +++ b/mallinkBApi/src/main/java/com/iformall/service/PosBrunService.java @@ -0,0 +1,451 @@ +package com.iformall.service; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.iformall.common.ErrorCode; +import com.iformall.common.Result; +import com.iformall.common.ResultData; +import com.iformall.domain.po.PosOrder; +import com.iformall.domain.po.PosPayOrder; +import com.iformall.domain.po.WxMerchantBUser; +import com.iformall.enums.EnumPosOrderStatus; +import com.iformall.enums.EnumPosOrderType; +import com.iformall.enums.EnumPosPayType; +import com.iformall.exception.MallinkException; +import com.iformall.pay.WxPayConstant; +import com.iformall.pay.WxPayment; +import com.iformall.utils.PosUtil; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.Date; +import java.util.Map; + +@Service +public class PosBrunService { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private String posDevId; + + @Autowired + private String posReqKey; + + @Autowired + private String posResKey; + + @Autowired + private String posUrl; + + @Autowired + private PosOrderService posOrderService; + + @Autowired + private PosPayOrderService posPayOrderService; + + PosUtil posUtil = new PosUtil(); + + /** + * 检查POS Server是否正常 + * @return + */ + public ResultData checkAvaiable() { + try { + String resStr = posUtil.checkPosMemServer(posUrl); + if (resStr != null) { + return new ResultData(); + } else { + return new ResultData(Result.ERROR, "无返回值"); + } + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + } + + /** + * 商户POS用户/B端用户登录检查 + * @param user + * @param phone + * @param password + * @return + */ + public ResultData checkUserPassword(WxMerchantBUser user, String phone, String password) { + try { + String resStr = posUtil.checkUserPassword(posUrl, posDevId, posReqKey, + user.getTenantId(), phone, password); + if (resStr != null) { + JSONObject retObj = JSON.parseObject(resStr); + Map options = retObj; + if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { + return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); + } else { + return new ResultData(resStr); + } + } else { + return new ResultData(Result.ERROR, "无返回值"); + } + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + } + + /** + * 获取会员折扣/优惠券/消费卡是否启用 + * @param tenantId + * @return + */ + public ResultData getPosMemConfig(String tenantId) { + try { + String resStr = posUtil.getPosMemConfig(posUrl, posDevId, posReqKey, tenantId); + if (resStr != null) { + JSONObject retObj = JSON.parseObject(resStr); + Map options = retObj; + if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { + return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); + } else { + return new ResultData(resStr); + } + } else { + return new ResultData(Result.ERROR, "无返回值"); + } + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + } + + /** + * 获取注册二维码及小票二维码规则 + * @param tenantId + * @return + */ + public ResultData getQrCode(String tenantId) { + try { + String resStr = posUtil.getQrCode(posUrl, posDevId, posReqKey, tenantId); + if (resStr != null) { + JSONObject retObj = JSON.parseObject(resStr); + Map options = retObj; + if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { + return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); + } else { + return new ResultData(resStr); + } + } else { + return new ResultData(Result.ERROR, "无返回值"); + } + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + } + + /** + * 会员识别 + * @param user + * @param memIdStr + * @param memPhoneStr + * @param posOrderIdStr + * @param posAmountStr + * @return + */ + public ResultData checkMem(WxMerchantBUser user, + String memIdStr, String memPhoneStr, + String posOrderIdStr, String posAmountStr) { + try { + String resStr = posUtil.checkMem(posUrl, posDevId, posReqKey, + user.getTenantId(), String.valueOf(user.getMerchantId()), + memIdStr, memPhoneStr, posOrderIdStr, posAmountStr); + if (resStr != null) { + JSONObject retObj = JSON.parseObject(resStr); + Map options = retObj; + if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { + return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); + } else { + return new ResultData(resStr); + } + } else { + return new ResultData(Result.ERROR, "无返回值"); + } + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + } + + /** + * 券独立核销检查 + * @param user + * @param verifyType + * @param couponOrderIdStr + * @return + */ + public ResultData checkCouponOrderForIndepentVerify(WxMerchantBUser user, + String verifyType, + String couponOrderIdStr) { + try { + String resStr = posUtil.checkCouponOrderForVerify(posUrl, posDevId, posReqKey, + user.getTenantId(), String.valueOf(user.getMerchantId()), String.valueOf(user.getId()), + verifyType, couponOrderIdStr, null, null); + if (resStr != null) { + JSONObject retObj = JSON.parseObject(resStr); + Map options = retObj; + if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { + return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); + } else { + return new ResultData(resStr); + } + } else { + return new ResultData(Result.ERROR, "无返回值"); + } + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + } + + /** + * 券独立核销检查 + * @param user + * @param verifyType + * @param couponOrderIdStr + * @param posOrderIdStr + * @param posAmountStr + * @return + */ + public ResultData checkCouponOrderForVerify(WxMerchantBUser user, + String verifyType, + String couponOrderIdStr, + String posOrderIdStr, String posAmountStr) { + try { + String resStr = posUtil.checkCouponOrderForVerify(posUrl, posDevId, posReqKey, + user.getTenantId(), String.valueOf(user.getMerchantId()), String.valueOf(user.getId()), + couponOrderIdStr, verifyType, posOrderIdStr, posAmountStr); + if (resStr != null) { + JSONObject retObj = JSON.parseObject(resStr); + Map options = retObj; + if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { + return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); + } else { + return new ResultData(resStr); + } + } else { + return new ResultData(Result.ERROR, "无返回值"); + } + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + } + + /** + * 券预核销 + * @param user + * @param couponOrderIdStr + * @param posOrderIdStr + * @param posAmountStr + * @return + */ + public ResultData couponOrderPreVerify(WxMerchantBUser user, + String couponOrderIdStr, + String posOrderIdStr, String posAmountStr) { + try { + String resStr = posUtil.couponOrderPreVerify(posUrl, posDevId, posReqKey, + user.getTenantId(), String.valueOf(user.getMerchantId()), String.valueOf(user.getId()), + couponOrderIdStr, posOrderIdStr, posAmountStr); + if (resStr != null) { + JSONObject retObj = JSON.parseObject(resStr); + Map options = retObj; + if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { + return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); + } else { + return new ResultData(resStr); + } + } else { + return new ResultData(Result.ERROR, "无返回值"); + } + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + } + + /** + * 券预核销取消 + * @param user + * @param couponOrderIdStr + * @param posOrderIdStr + * @param posAmountStr + * @return + */ + public ResultData couponOrderPreVerifyCancel(WxMerchantBUser user, + String couponOrderIdStr, + String posOrderIdStr, String posAmountStr) { + try { + String resStr = posUtil.couponOrderPreVerifyCancel(posUrl, posDevId, posReqKey, + user.getTenantId(), String.valueOf(user.getMerchantId()), String.valueOf(user.getId()), + couponOrderIdStr, posOrderIdStr, posAmountStr); + if (resStr != null) { + JSONObject retObj = JSON.parseObject(resStr); + Map options = retObj; + if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { + return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); + } else { + return new ResultData(resStr); + } + } else { + return new ResultData(Result.ERROR, "无返回值"); + } + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + } + + /** + * 券独立核销 + * @param user + * @param couponOrderIdStr + * @param posOrderIdStr + * @return + */ + public ResultData couponOrderIndependentVerify(WxMerchantBUser user, String couponOrderIdStr, String posOrderIdStr) { + try { + String resStr = posUtil.couponOrderIndependentVerify(posUrl, posDevId, posReqKey, + user.getTenantId(), String.valueOf(user.getMerchantId()), String.valueOf(user.getId()), + couponOrderIdStr, posOrderIdStr); + if (resStr != null) { + JSONObject retObj = JSON.parseObject(resStr); + Map options = retObj; + if (!WxPayment.verifyNotifyHMAC(options, posResKey)) { + return new ResultData(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); + } else { + return new ResultData(resStr); + } + } else { + return new ResultData(Result.ERROR, "无返回值"); + } + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + } + + public ResultData posVerifyIndepent(WxMerchantBUser user, String couponOrderId, String payment) { + // 1. 创建 POS订单 + PosOrder posOrder = new PosOrder(); + posOrder.setTenantId(user.getTenantId()); + posOrder.setType(EnumPosOrderType.VERIFY_INDEPENDENT.getCode()); + posOrder.setBuUserId(user.getId()); + posOrder.setOrderStatus(EnumPosOrderStatus.PENDING_VERIFY.getCode()); + posOrder.setPaymentType(EnumPosPayType.PAY_VERIFY_INDEPENT.getCode()); + if (StringUtils.isNotBlank(payment)) { + posOrder.setPayment(Integer.valueOf(payment)); + } + try { + posOrderService.saveOrUpdate(posOrder); + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + // 2. 创建 POS支付订单 + Date curDate = new Date(); + PosPayOrder posPayOrder = new PosPayOrder(); + posPayOrder.setTenantId(user.getTenantId()); + posPayOrder.setBuUserId(user.getId()); + posPayOrder.setOrderId(posOrder.getId()); + posPayOrder.setType(EnumPosPayType.PAY_VERIFY_INDEPENT.getCode()); + posPayOrder.setPayTimeStart(curDate); + posPayOrder.setPayTimeEnd(curDate); + posPayOrder.setPayOrderNo(couponOrderId); + posPayOrder.setPayOrderStatus(EnumPosOrderStatus.PENDING_VERIFY.getCode()); + posPayOrder.setCreateTime(curDate); + posPayOrder.setUpdateTime(curDate); + try { + posPayOrderService.saveOrUpdate(posPayOrder); + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + + // 3. POS支付订单支付 + try { + couponOrderIndependentVerify(user, couponOrderId, posOrder.getPosOrderNo()); + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + + try { + PosPayOrder updateOrder = new PosPayOrder(); + updateOrder.setId(posPayOrder.getId()); + updateOrder.setPayOrderStatus(EnumPosOrderStatus.VERIFY_SUCCESS.getCode()); + posPayOrderService.saveOrUpdate(posPayOrder); + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + + // 4. POS订单支付 + try { + PosOrder updateOrder = new PosOrder(); + updateOrder.setId(posOrder.getId()); + posOrder.setOrderStatus(EnumPosOrderStatus.VERIFY_SUCCESS.getCode()); + posOrderService.saveOrUpdate(posOrder); + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); + return new ResultData(Result.ERROR, e.getMessage()); + } + return new ResultData(); + } +} diff --git a/mallinkBApi/src/main/java/com/iformall/utils/PosUtil.java b/mallinkBApi/src/main/java/com/iformall/utils/PosUtil.java index a7a6217aa..c5a8e57eb 100755 --- a/mallinkBApi/src/main/java/com/iformall/utils/PosUtil.java +++ b/mallinkBApi/src/main/java/com/iformall/utils/PosUtil.java @@ -254,25 +254,29 @@ public class PosUtil { * @param tenantId * @param merchantId * @param buUserId - * @param couponOrderId * @param verifyType + * @param couponOrderId * @param posOrderId * @param posAmount * @return 券是否可核销 */ public String checkCouponOrderForVerify(String baseUrl, String devId, String reqKey, String tenantId, String merchantId, String buUserId, - String couponOrderId, String verifyType, + String verifyType, String couponOrderId, String posOrderId, String posAmount) throws MallinkException { Map paramMap = new HashMap<>(); paramMap.put(WxPayConstant.DEV_ID, devId); paramMap.put(WxPayConstant.TENANT_ID, tenantId); paramMap.put(WxPayConstant.MERCHANT_ID, merchantId); paramMap.put(WxPayConstant.BUSER_ID, buUserId); - paramMap.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); paramMap.put(WxPayConstant.VERIFY_TYPE, verifyType); - paramMap.put(WxPayConstant.POS_ORDER_ID, posOrderId); - paramMap.put(WxPayConstant.POS_AMOUNT, posAmount); + paramMap.put(WxPayConstant.COUPON_ORDER_ID, couponOrderId); + if (StringUtils.isNotBlank(posOrderId)) { + paramMap.put(WxPayConstant.POS_ORDER_ID, posOrderId); + } + if (StringUtils.isNotBlank(posAmount)) { + paramMap.put(WxPayConstant.POS_AMOUNT, posAmount); + } paramMap = WxPayment.buildSignAfterParasMapForHMAC(paramMap, reqKey); String respStr = doPost(baseUrl + URL_CheckCouponOrderForVerify, paramMap); 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 cd2e9be77..5d53f3f77 100644 --- a/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java +++ b/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java @@ -13,7 +13,6 @@ import com.iformall.mapper.WxCouponMapper; import com.iformall.mapper.WxCouponMerchantMapper; import com.iformall.mapper.WxCouponOrderMapper; import com.iformall.mapper.WxOrderMapper; -import com.iformall.pay.WxPay; import com.iformall.pay.WxPayConstant; import com.iformall.service.*; import lombok.AllArgsConstructor; @@ -24,6 +23,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RequestBody; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -53,6 +53,9 @@ public class PosServiceImpl implements PosService { private final WxCouponMerchantMapper couponMerchantMapper; private final WxCouponMapper couponMapper; + + private final SimpleDateFormat mydateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + /** * 门店用户登录检查 * @param params @@ -711,11 +714,23 @@ public class PosServiceImpl implements PosService { logger.info("券可以被核销: " + couponOrderIdStr); retMap.put(WxPayConstant.ID, couponOrderIdStr); retMap.put(WxPayConstant.CHECK, WxPayConstant.TRUE); + retMap.put(WxPayConstant.MEM_ID, String.valueOf(couponOrderCVo.getCUserId())); + retMap.put(WxPayConstant.TITLE, couponOrderCVo.getTitle()); + retMap.put(WxPayConstant.COVER_IMG, couponOrderCVo.getCoverImg()); + retMap.put(WxPayConstant.EXPIRE_TIME, mydateFormat.format(couponOrderCVo.getExpiredTime())); + retMap.put(WxPayConstant.PRICE, String.valueOf(couponOrderCVo.getPrice())); + retMap.put(WxPayConstant.STATUS, EnumCouponOrderStatus.getEnum(couponOrderCVo.getCouponOrderStatus()).getMessage()); return retMap; } else if (couponOrderCVo.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode())) { logger.info("券可以被核销: " + couponOrderIdStr); retMap.put(WxPayConstant.ID, couponOrderIdStr); retMap.put(WxPayConstant.CHECK, WxPayConstant.TRUE); + retMap.put(WxPayConstant.MEM_ID, String.valueOf(couponOrderCVo.getCUserId())); + retMap.put(WxPayConstant.TITLE, couponOrderCVo.getTitle()); + retMap.put(WxPayConstant.COVER_IMG, couponOrderCVo.getCoverImg()); + retMap.put(WxPayConstant.EXPIRE_TIME, mydateFormat.format(couponOrderCVo.getExpiredTime())); + retMap.put(WxPayConstant.PRICE, String.valueOf(couponOrderCVo.getPrice())); + retMap.put(WxPayConstant.STATUS, EnumCouponOrderStatus.getEnum(couponOrderCVo.getCouponOrderStatus()).getMessage()); return retMap; } } else if (actionType.equals(EnumVerifyActionType.PRE_VERIFY)) { diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/PowerBillAutoBuildSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/PowerBillAutoBuildSchedule.java index a0696da11..92be3c8bd 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/PowerBillAutoBuildSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/PowerBillAutoBuildSchedule.java @@ -1,5 +1,6 @@ package com.iformall.schedule; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.iformall.domain.dto.KwMeterDataDto; import com.iformall.domain.po.*; @@ -24,10 +25,7 @@ import java.time.LocalDate; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.temporal.TemporalAdjusters; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -59,7 +57,7 @@ public class PowerBillAutoBuildSchedule { /** * 每天5点执行 */ - @Scheduled(cron = "0 49 13 * * ?") + @Scheduled(cron = "0 0 5 * * ?") public void powerBillAutoConfigStart() { logger.info("自动生成电费账单开始...."); int dayOfMonth = LocalDate.now().getDayOfMonth(); @@ -94,35 +92,45 @@ public class PowerBillAutoBuildSchedule { Date lastdate = monthDate.get("lastdate"); MallUserInfo mallUserInfo = getMallUserInfo(); WxBillDaily wxBillDaily = getBillDaily(wxMerchantPowerBillConfig); - JSONObject priceDetal = new JSONObject(); Date receiveDate = getReceiveDate(Integer.parseInt(wxPowerBillAutoConfig.getReceiveDay())); - long receivePay = 0L; + long receivePay; + String unitPrice; + long usedPower = 0L; Long merchantId = wxMerchantPowerBillConfig.getMerchantId(); if (wxMerchantPowerBillConfig.getBuildWay().equals(EnumPowerBillBuildWay.METER.getCode())) { //根据日期拉取电量 单价 * 电量 = 电费 - int usedPower = getUsedPower(startdate, lastdate, merchantId); + usedPower = getUsedPower(startdate, lastdate, merchantId); if (usedPower == 0) { logger.info("没有电量使用,不生成账单>>>>商户ID:" + merchantId); return; } - String price = wxMerchantPowerBillConfig.getPrice(); - priceDetal.put("unitPrice", price); - priceDetal.put("power", usedPower); - receivePay = new BigDecimal(price).multiply(new BigDecimal(100)) + //按电表 单价从商户配置表中取 因为会修改 + unitPrice = wxMerchantPowerBillConfig.getPrice(); + receivePay = new BigDecimal(unitPrice).multiply(new BigDecimal(100)) .multiply(new BigDecimal(usedPower)).longValue(); } else { - String unitPrice = wxPowerBillAutoConfig.getUnitPrice(); + //按固定金额 单位从统一配置表中取 + unitPrice = wxPowerBillAutoConfig.getUnitPrice(); String price = wxMerchantPowerBillConfig.getPrice(); - priceDetal.put("unitPrice", unitPrice); - priceDetal.put("power", 0); receivePay = new BigDecimal(price).multiply(new BigDecimal(100)).longValue(); } + + JSONArray priceDetals = new JSONArray(); + JSONObject priceDetal = new JSONObject(); + priceDetal.put("key", "unitPrice"); + priceDetal.put("value", unitPrice); + priceDetals.add(priceDetal); + priceDetal = new JSONObject(); + priceDetal.put("key", "power"); + priceDetal.put("value", usedPower); + priceDetals.add(priceDetal); + wxBillDaily.setReceivePay(receivePay); wxBillDaily.setNeedPay(receivePay); wxBillDaily.setReceiveDate(receiveDate); wxBillDaily.setStarttime(startdate); wxBillDaily.setEndtime(enddate); - wxBillDaily.setPriceDetail(priceDetal.toJSONString()); + wxBillDaily.setPriceDetail(priceDetals.toJSONString()); wxBillDailyService.saveOrUpdate(wxBillDaily, mallUserInfo); } @@ -143,7 +151,9 @@ public class PowerBillAutoBuildSchedule { kwMeterDataDto.setStartTime(startdate); kwMeterDataDto.setEndTime(lastdate); KwMeterDataVo power = kwMeterDataService.getPower(kwMeterDataDto); - usedPower += power.getUsedPower(); + if (power != null) { + usedPower += power.getUsedPower(); + } } } return usedPower; diff --git a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java index 19ad4739e..e7cc69584 100644 --- a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java @@ -489,6 +489,8 @@ public enum ErrorCode{ ACTIVITY_SEND_ERROR(30004, "活动投放到宣传页失败,宣传页显示已达七条上限!"), ACTIVITY_TIME_ERROR(30005, "活动报名结束时间不能大于活动结束时间"), ACTIVITY_WAIT_CONFIRMED(30006, "您报名的活动还在审核中"), + ACTIVITY_EXPIRED(30007, "您报名的活动已过期"), + /** * 文件上传 */ diff --git a/mallinkService/src/main/java/com/iformall/domain/po/PosOrder.java b/mallinkService/src/main/java/com/iformall/domain/po/PosOrder.java new file mode 100644 index 000000000..d1fe3ec3f --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/PosOrder.java @@ -0,0 +1,42 @@ +package com.iformall.domain.po; + +import lombok.Data; +import javax.persistence.*; +import java.util.*; +import javax.persistence.Transient; +import java.util.List; +import javax.persistence.Id; +import java.io.Serializable; + +@Table(name = "pos_order") +@Data +public class PosOrder implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + protected Long id; + + @Transient + protected List ids; + + @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") + private String tenantId; + @io.swagger.annotations.ApiModelProperty(value="POS订单ID",name="posOrderNo") + private String posOrderNo; + @io.swagger.annotations.ApiModelProperty(value="支付类型(1: 独立核销, 2:支付)",name="type") + private Integer type; + @io.swagger.annotations.ApiModelProperty(value="订单状态:0-待付款/待核销;1-已支付;2-已取消(限定时间内未付款);3-待退款;4-已退款;5-退款失败",name="orderStatus") + private Integer orderStatus; + @io.swagger.annotations.ApiModelProperty(value="b端用户",name="buUserId") + private Long buUserId; + @io.swagger.annotations.ApiModelProperty(value="0: 付款 1: 退款 2:自动退款 3:A端退款 10.核销",name="paymentType") + private Integer paymentType; + @io.swagger.annotations.ApiModelProperty(value="支付金额:允许有负数,退款时为负值。核销时,金额可以不填写",name="paymentType") + private Integer payment; + @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") + private Date createDate; + @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") + private Date updateDate; + + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/po/PosPayOrder.java b/mallinkService/src/main/java/com/iformall/domain/po/PosPayOrder.java new file mode 100644 index 000000000..a837da83f --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/PosPayOrder.java @@ -0,0 +1,69 @@ +package com.iformall.domain.po; + +import lombok.Data; +import javax.persistence.*; +import java.util.*; +import java.math.*; +import javax.persistence.Transient; +import java.util.List; +import javax.persistence.Id; +import java.io.Serializable; + +@Table(name = "pos_pay_order") +@Data +public class PosPayOrder implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + protected Long id; + + @Transient + protected List ids; + + @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") + private String tenantId; + @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createTime") + private Date createTime; + @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateTime") + private Date updateTime; + @io.swagger.annotations.ApiModelProperty(value="订单ID",name="orderId") + private Long orderId; + @io.swagger.annotations.ApiModelProperty(value="b端用户",name="buUserId") + private Long buUserId; + @io.swagger.annotations.ApiModelProperty(value="支付类型(1:独立核销 2:支付核销 3:现金支付)",name="type") + private Integer type; + @io.swagger.annotations.ApiModelProperty(value="支付来源(0: 现金, 1:微信 2:支付核销 3:现金支付, 10:券)",name="payFrom") + private Integer payFrom; + @io.swagger.annotations.ApiModelProperty(value="支付金额(分)",name="payAmount") + private Integer payAmount; + @io.swagger.annotations.ApiModelProperty(value="支付发起时间",name="payTimeStart") + private Date payTimeStart; + @io.swagger.annotations.ApiModelProperty(value="支付结束时间",name="payTimeEnd") + private Date payTimeEnd; + @io.swagger.annotations.ApiModelProperty(value="微信预支付交易会话标识-发模板信息使用",name="prepayId") + private String prepayId; + @io.swagger.annotations.ApiModelProperty(value="微信生成的订单号",name="transactionId") + private String transactionId; + @io.swagger.annotations.ApiModelProperty(value="支付渠道: 0-微信 1-支付宝 2-银联 ",name="payVendor") + private Integer payVendor; + @io.swagger.annotations.ApiModelProperty(value="支付订单号",name="payOrderNo") + private String payOrderNo; + @io.swagger.annotations.ApiModelProperty(value="支付状态: 0-支付中;1-支付成功;2-支付失败",name="payOrderStatus") + private Integer payOrderStatus; + @io.swagger.annotations.ApiModelProperty(value="是否支持分账(0:不支持,1:支持)",name="share") + private Integer share; + @io.swagger.annotations.ApiModelProperty(value="分账金额(总金额扣掉手续费后的金额)",name="shareAmount") + private Integer shareAmount; + @io.swagger.annotations.ApiModelProperty(value="分账实际通道费",name="rateAmount") + private Integer rateAmount; + @io.swagger.annotations.ApiModelProperty(value="支付失败原因",name="failReason") + private String failReason; + @io.swagger.annotations.ApiModelProperty(value="扫码支付授权码",name="authCode") + private String authCode; + @io.swagger.annotations.ApiModelProperty(value="微信支付后获取的open_id",name="openId") + private String openId; + @io.swagger.annotations.ApiModelProperty(value="支付后结果来源(0:callback, 1:query)",name="payEndFrom") + private Integer payEndFrom; + + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/RatioVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/RatioVo.java new file mode 100644 index 000000000..ff1c59b15 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/vo/RatioVo.java @@ -0,0 +1,13 @@ +package com.iformall.domain.vo; + +import lombok.Data; +import java.math.BigDecimal; + +@Data +public class RatioVo { + + //扣点率 + private Integer ratio = 0; + //超出部分金额 + private BigDecimal balance; +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumGetRatioFrom.java b/mallinkService/src/main/java/com/iformall/enums/EnumGetRatioFrom.java new file mode 100644 index 000000000..26cd88222 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumGetRatioFrom.java @@ -0,0 +1,32 @@ +package com.iformall.enums; + +public enum EnumGetRatioFrom { + RENT(1, "合同"), + BILL(2, "账单录入营业额"), + ; + + public static EnumGetRatioFrom getEnum(Integer code) { + for (EnumGetRatioFrom value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumGetRatioFrom(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumMissTimeType.java b/mallinkService/src/main/java/com/iformall/enums/EnumMissTimeType.java index 6ef644ee3..3f10dd93c 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumMissTimeType.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumMissTimeType.java @@ -1,13 +1,11 @@ package com.iformall.enums; -/** - * Created by Stormeye on 2018/08/09. - */ public enum EnumMissTimeType { - YEAR(1, "残年"), - MONTH(2, "残月"), - OTHER(3, "其他"), + YEAR(1, "年"), + MONTH(2, "月"), + PERIOD(3, "周期"), + OTHER(4, "其他"), ; public static EnumMissTimeType getEnum(Integer code) { diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumPosOrderStatus.java b/mallinkService/src/main/java/com/iformall/enums/EnumPosOrderStatus.java new file mode 100644 index 000000000..3d5db965c --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumPosOrderStatus.java @@ -0,0 +1,47 @@ +package com.iformall.enums; + + +/** + * @author Stormeye + */ + +public enum EnumPosOrderStatus { + + PENDING_PAYMENT(0, "待付款"), + PAYMENT_SUCCESS(1, "已支付"), + OVERTIME_CANCEL(2, "已取消"), + PENDING_REFUND(3, "待退款"), + REFUND_SUCCESS(4,"已退款"), + REFUND_FAILD(5, "退款失败"), + PENDING_VERIFY(10, "待核销"), + VERIFY_SUCCESS(11, "已核销"), + VERIFY_CANCEL(12, "核销待退"), + VERIFY_CANCELED(13, "核销已退") + ; + + + public static EnumPosOrderStatus getEnum(Integer code) { + for (EnumPosOrderStatus value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumPosOrderStatus(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumPosOrderType.java b/mallinkService/src/main/java/com/iformall/enums/EnumPosOrderType.java new file mode 100644 index 000000000..035ce0fac --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumPosOrderType.java @@ -0,0 +1,38 @@ +package com.iformall.enums; + + +/** + * @author Stormeye + */ + +public enum EnumPosOrderType { + + VERIFY_INDEPENDENT(1,"独立核销"), + PAY(2,"支付") + ; + + public static EnumPosOrderType getEnum(Integer code) { + for (EnumPosOrderType value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumPosOrderType(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumPosPayType.java b/mallinkService/src/main/java/com/iformall/enums/EnumPosPayType.java new file mode 100644 index 000000000..6775daf55 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumPosPayType.java @@ -0,0 +1,38 @@ +package com.iformall.enums; + +/** + * Created by Stormeye on 2018/08/09. + */ +public enum EnumPosPayType { + + PAY_PAYMENT(0, "付款"), + PAY_B_REFUND(1, "B端退款"), + PAY_AUTO_REFUND(2, "自动退款"), + PAY_ADMIN_REFUND(3, "A端退款"), + PAY_VERIFY_INDEPENT(10, "核销"), + ; + public static EnumPosPayType getEnum(Integer code) { + for (EnumPosPayType value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumPosPayType(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/PosOrderMapper.java b/mallinkService/src/main/java/com/iformall/mapper/PosOrderMapper.java new file mode 100644 index 000000000..120bccc68 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/PosOrderMapper.java @@ -0,0 +1,17 @@ +package com.iformall.mapper; + +import java.util.*; +import com.iformall.common.CommonMapper; +import org.apache.ibatis.annotations.Param; +import com.iformall.domain.po.PosOrder; + +public interface PosOrderMapper extends CommonMapper { + + List findList(PosOrder posOrder); + + + + + + +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/PosPayOrderMapper.java b/mallinkService/src/main/java/com/iformall/mapper/PosPayOrderMapper.java new file mode 100644 index 000000000..e34479bfa --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/PosPayOrderMapper.java @@ -0,0 +1,17 @@ +package com.iformall.mapper; + +import java.util.*; +import com.iformall.common.CommonMapper; +import org.apache.ibatis.annotations.Param; +import com.iformall.domain.po.PosPayOrder; + +public interface PosPayOrderMapper extends CommonMapper { + + List findList(PosPayOrder posPayOrder); + + + + + + +} diff --git a/mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java b/mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java index 80dc3ed4a..8d2cf8628 100644 --- a/mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java +++ b/mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java @@ -32,6 +32,14 @@ public class WxPayConstant { public final static String PHONE = "phone"; public final static String PASSWORD = "password"; + public final static String TITLE = "title"; + public final static String COVER_IMG = "cover_img"; + public final static String EXPIRE_TIME = "expire_time"; + public final static String VALID_START_DATE = "valid_start_date"; + public final static String VALID_END_DATE = "valid_end_date"; + public final static String PRICE = "price"; + public final static String STATUS = "status"; + public final static String VERIFY_TYPE = "verify_type"; public final static String VERIFY_TYPE_INDEPENT = "independent"; public final static String VERIFY_TYPE_PAY = "pay"; diff --git a/mallinkService/src/main/java/com/iformall/service/PosOrderService.java b/mallinkService/src/main/java/com/iformall/service/PosOrderService.java new file mode 100644 index 000000000..e739d52d1 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/PosOrderService.java @@ -0,0 +1,48 @@ +package com.iformall.service; + +import java.util.*; +import com.github.pagehelper.PageInfo; +import com.iformall.domain.po.PosOrder; + +public interface PosOrderService { + + /** + * 根据实体查询分页列表 + * + * @param record + * @param pageIndex + * @param pageSize + * @return + */ + PageInfo listAsPage(PosOrder record, Integer pageIndex, Integer pageSize); + + /** + * 根据Id获得实体 + * + * @param id + * @return + */ + PosOrder getById(Long id); + + /** + * 保存或更新实体 + * + * @param record + */ + void saveOrUpdate(PosOrder record); + + /** + * 根据Id删除实体 + * + * @param id + */ + void deleteById(Long id); + + + + + + + + +} diff --git a/mallinkService/src/main/java/com/iformall/service/PosPayOrderService.java b/mallinkService/src/main/java/com/iformall/service/PosPayOrderService.java new file mode 100644 index 000000000..823e36ab3 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/PosPayOrderService.java @@ -0,0 +1,48 @@ +package com.iformall.service; + +import java.util.*; +import com.github.pagehelper.PageInfo; +import com.iformall.domain.po.PosPayOrder; + +public interface PosPayOrderService { + + /** + * 根据实体查询分页列表 + * + * @param record + * @param pageIndex + * @param pageSize + * @return + */ + PageInfo listAsPage(PosPayOrder record, Integer pageIndex, Integer pageSize); + + /** + * 根据Id获得实体 + * + * @param id + * @return + */ + PosPayOrder getById(Long id); + + /** + * 保存或更新实体 + * + * @param record + */ + void saveOrUpdate(PosPayOrder record); + + /** + * 根据Id删除实体 + * + * @param id + */ + void deleteById(Long id); + + + + + + + + +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/PosOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/PosOrderServiceImpl.java new file mode 100644 index 000000000..33d526251 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/impl/PosOrderServiceImpl.java @@ -0,0 +1,52 @@ +package com.iformall.service.impl; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.iformall.domain.po.PosOrder; +import com.iformall.mapper.PosOrderMapper; +import com.iformall.service.PosOrderService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.iformall.common.IdWorker; + +@Service +public class PosOrderServiceImpl implements PosOrderService { + + @Autowired + PosOrderMapper posOrderMapper; + + + @Override + public PageInfo listAsPage(PosOrder record, Integer pageIndex, Integer pageSize) { + return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> posOrderMapper.findList(record)); + } + + @Override + public PosOrder getById(Long id) { + return posOrderMapper.selectByPrimaryKey(id); + } + + @Override + public void saveOrUpdate(PosOrder record) { + if (record.getId() == null) { + final IdWorker idWorker = IdWorker.get(); + record.setId(idWorker.nextId()); + posOrderMapper.insertSelective(record); + } else { + posOrderMapper.updateByPrimaryKeySelective(record); + } + } + + @Override + public void deleteById(Long id) { + posOrderMapper.deleteByPrimaryKey(id); + } + + + + + + + + +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/PosPayOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/PosPayOrderServiceImpl.java new file mode 100644 index 000000000..457077ccb --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/impl/PosPayOrderServiceImpl.java @@ -0,0 +1,54 @@ +package com.iformall.service.impl; + +import java.util.*; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.iformall.domain.po.PosPayOrder; +import com.iformall.mapper.PosPayOrderMapper; +import com.iformall.service.PosPayOrderService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.iformall.common.IdWorker; + +@Service +public class PosPayOrderServiceImpl implements PosPayOrderService { + + @Autowired + PosPayOrderMapper posPayOrderMapper; + + + @Override + public PageInfo listAsPage(PosPayOrder record, Integer pageIndex, Integer pageSize) { + return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> posPayOrderMapper.findList(record)); + } + + @Override + public PosPayOrder getById(Long id) { + return posPayOrderMapper.selectByPrimaryKey(id); + } + + @Override + public void saveOrUpdate(PosPayOrder record) { + if (record.getId() == null) { + //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); + final IdWorker idWorker = IdWorker.get(); + record.setId(idWorker.nextId()); + posPayOrderMapper.insertSelective(record); + } else { + posPayOrderMapper.updateByPrimaryKeySelective(record); + } + } + + @Override + public void deleteById(Long id) { + posPayOrderMapper.deleteByPrimaryKey(id); + } + + + + + + + + +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxActivityJoinServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxActivityJoinServiceImpl.java index f771563b9..177711dc7 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxActivityJoinServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxActivityJoinServiceImpl.java @@ -204,16 +204,17 @@ public class WxActivityJoinServiceImpl implements WxActivityJoinService { if (activityJoin == null) { return new ResultData(ErrorCode.ACTIVITY_JOIN_NOT_FOUND); } - wxActivityJoin.setStatus(EnumActivityJoinStatus.CONFIRMED.getCode()); - activityJoin = wxActivityJoinMapper.selectOne(wxActivityJoin); - if (activityJoin == null) { + if (activityJoin.getStatus().equals(EnumActivityJoinStatus.NOT_CONFIRMED.getCode())) { return new ResultData(ErrorCode.ACTIVITY_WAIT_CONFIRMED); } - activityJoin.setSignIn(EnumActivityJoinSignStatus.YES.getCode()); - wxActivityJoinMapper.updateByPrimaryKeySelective(activityJoin); - //查询活动名称 - WxActivity activity = wxActivityMapper.selectByPrimaryKey(wxActivityJoin.getActivityId()); - return new ResultData(Result.SUCCESS, "签到成功", activity.getTitle()); + if (activityJoin.getStatus().equals(EnumActivityJoinStatus.CONFIRMED.getCode())) { + activityJoin.setSignIn(EnumActivityJoinSignStatus.YES.getCode()); + wxActivityJoinMapper.updateByPrimaryKeySelective(activityJoin); + //查询活动名称 + WxActivity activity = wxActivityMapper.selectByPrimaryKey(wxActivityJoin.getActivityId()); + return new ResultData(Result.SUCCESS, "签到成功", activity.getTitle()); + } + return new ResultData(ErrorCode.ACTIVITY_EXPIRED); } private void sendMessage(WxActivityJoin join, WxActivity activity) { diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java index 2faf2b87d..bef858971 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java @@ -268,58 +268,6 @@ public class WxBillRentServiceImpl implements WxBillRentService { return months; } - - /** - * 获取设置的跳点率 - * ["1000-1200:10",">3000:20"] - * @param record - */ - public Integer getPayRatio(WxBillRent record,WxRentContract wxRentContract,EnumMissTimeType timeType){ - if(wxRentContract.getPayRatio() != null && wxRentContract.getPayRatio().intValue() > 0){ - return wxRentContract.getPayRatio(); - } - BigDecimal revenue = new BigDecimal(record.getRevenue()).divide(new BigDecimal(1000000)).setScale(4, RoundingMode.HALF_EVEN); - List ratioList = JSONArray.parseArray(wxRentContract.getBusDiscountRatio(), String.class); - long dayCount = DateUtils.startToEnd(record.getStarttime(),record.getEndtime()); - - for (String e:ratioList) { - String[] array = e.split(":"); - Integer ratio = Integer.parseInt(array[1]); - - if(e.indexOf("-") >= 0){ - String[] revenueArray = array[0].split("-"); - BigDecimal start = new BigDecimal(revenueArray[0]); - BigDecimal end = new BigDecimal(revenueArray[1]); - - //残年 (小金额 / 365 * 账单周期天数 )--(大金额 / 365 * 账单周期天数) - if(EnumMissTimeType.YEAR.getCode().equals(timeType.getCode())){ - start = new BigDecimal(revenueArray[0]).divide(new BigDecimal(365),10,BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); - end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365),10,BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); - }else if(EnumMissTimeType.MONTH.getCode().equals(timeType.getCode())){ - start = new BigDecimal(revenueArray[0]).divide(new BigDecimal(30),10,BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); - end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30),10,BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); - } - if (revenue.compareTo(start) >= 0 && revenue.compareTo(end)<= 0){ - return ratio; - } - }if(e.indexOf(">") >= 0){ - String[] revenueArray = array[0].split(">"); - BigDecimal end = new BigDecimal(revenueArray[1]); - - //残年 (小金额 / 365 * 账单周期天数 )--(大金额 / 365 * 账单周期天数) - if(EnumMissTimeType.YEAR.getCode().equals(timeType.getCode())){ - end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365),10,BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); - }else if(EnumMissTimeType.MONTH.getCode().equals(timeType.getCode())){ - end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30),10,BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); - } - if (revenue.compareTo(end) >= 0){ - return ratio; - } - } - } - return 0; - } - @Override @Transactional(rollbackFor = {Exception.class}) public ResultData updateRevenue(WxBillRent record, MallUserInfo user) { @@ -332,23 +280,30 @@ public class WxBillRentServiceImpl implements WxBillRentService { int endInt = Integer.parseInt(sdD.format(DateUtils.getDaySet(wxBillRent.getEndtime(),Calendar.DATE,1))); int months = getMonths(sdM.format(wxBillRent.getStarttime())+"-01",sdM.format(DateUtils.getDaySet(wxBillRent.getEndtime(),Calendar.DATE,1))+"-01"); + wxBillRent.setRevenue(record.getRevenue()); + Integer ratio = 0; - if(wxRentContract.getPayRatio() != null && wxRentContract.getPayRatio().intValue() >0){ - ratio = getPayRatio(wxBillRent,wxRentContract,EnumMissTimeType.OTHER); - }else if(StringUtils.isNotBlank(wxRentContract.getBusDiscountRatio())){ - if(EnumBusRatioTime.YEAR.getCode().equals(wxRentContract.getBusDiscountTime())){ - if(startInt == endInt && months == 12){ - //刚好1年 - ratio = getPayRatio(wxBillRent,wxRentContract,EnumMissTimeType.OTHER); - }else{ - ratio = getPayRatio(wxBillRent,wxRentContract,EnumMissTimeType.YEAR); - } - }else if(EnumBusRatioTime.MONTH.getCode().equals(wxRentContract.getBusDiscountTime())){ - if(startInt == endInt && months == 1){ - //刚好1个月 - ratio = getPayRatio(wxBillRent,wxRentContract,EnumMissTimeType.OTHER); - }else{ - ratio = getPayRatio(wxBillRent,wxRentContract,EnumMissTimeType.MONTH); + if(wxRentContract.getPayRatio() != null){ + ratio = wxRentContract.getPayRatio(); + }else{ + if(StringUtils.isNotBlank(wxRentContract.getBusDiscountRatio())){ + long dayCount = DateUtils.startToEnd(record.getStarttime(),record.getEndtime()); + if(EnumBusRatioTime.YEAR.getCode().equals(wxRentContract.getBusDiscountTime())){ + if(startInt == endInt && months == 12){ + //刚好1年 + ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.OTHER.getCode(),dayCount,0).getRatio(); + }else{ + ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.YEAR.getCode(),dayCount,0).getRatio(); + } + }else if(EnumBusRatioTime.MONTH.getCode().equals(wxRentContract.getBusDiscountTime())){ + if(startInt == endInt && months == 1){ + //刚好1个月 + ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.OTHER.getCode(),dayCount,0).getRatio(); + }else{ + ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.MONTH.getCode(),dayCount,0).getRatio(); + } + }else if(EnumBusRatioTime.PERIOD.getCode().equals(wxRentContract.getBusDiscountTime())){ + ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.PERIOD.getCode(),dayCount,wxRentContract.getReceivePeriod()).getRatio(); } } } @@ -364,7 +319,6 @@ public class WxBillRentServiceImpl implements WxBillRentService { Long oldPrice = wxBillRent.getReceivePay(); Long newPrice = newReceivePay; - wxBillRent.setRevenue(record.getRevenue()); //wxBillRent.setReceivePay(oldPrice.equals(newPrice) ? oldPrice : newPrice); wxBillRent.setUpdatetime(new Date()); 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 fcb2af203..46ef1f505 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -10,6 +10,7 @@ import com.iformall.common.Result; import com.iformall.common.ResultData; import com.iformall.domain.po.*; import com.iformall.domain.vo.BillTimeVo; +import com.iformall.domain.vo.RatioVo; import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.mapper.*; @@ -251,19 +252,17 @@ public class WxRentContractServiceImpl implements WxRentContractService { /** * 获取设置的跳点率 * ["1000-1200:10",">3000:20"] - * @param record */ - public void getPayRatio(WxRentContract record){ - if(record.getPayRatio() != null && record.getPayRatio().intValue() >0){ - return; - } - if(StringUtils.isBlank(record.getBusDiscountRatio())){ - return; + public static RatioVo getPayRatio(int from,Long revenueLong,String busDiscountRatio,int timeType,long dayCount,int period){ + RatioVo ratioVo = new RatioVo(); + if(StringUtils.isBlank(busDiscountRatio)){ + return ratioVo; } - BigDecimal revenue = new BigDecimal(record.getRevenue()).divide(new BigDecimal(1000000)).setScale(4, RoundingMode.HALF_EVEN); - List ratioList = JSONArray.parseArray(record.getBusDiscountRatio(), String.class); + BigDecimal revenue = new BigDecimal(revenueLong).divide(new BigDecimal(1000000)).setScale(4, RoundingMode.HALF_EVEN); + List ratioList = JSONArray.parseArray(busDiscountRatio, String.class); - for (String e:ratioList) { + for (int i = 0; i < ratioList.size(); i++) { + String e = ratioList.get(i); String[] array = e.split(":"); Integer ratio = Integer.parseInt(array[1]); @@ -271,20 +270,86 @@ public class WxRentContractServiceImpl implements WxRentContractService { String[] revenueArray = array[0].split("-"); BigDecimal start = new BigDecimal(revenueArray[0]); BigDecimal end = new BigDecimal(revenueArray[1]); + + //残年 (小金额 / 365 * 账单周期天数 )--(大金额 / 365 * 账单周期天数) + if(EnumMissTimeType.YEAR.getCode().equals(timeType)){ + if(EnumGetRatioFrom.BILL.getCode().equals(from)) { + start = new BigDecimal(revenueArray[0]).divide(new BigDecimal(365), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); + end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); + } + if(EnumGetRatioFrom.RENT.getCode().equals(from)) { + revenue = revenue.divide(new BigDecimal(12)); + } + }else if(EnumMissTimeType.MONTH.getCode().equals(timeType)){ + if(EnumGetRatioFrom.BILL.getCode().equals(from)) { + start = new BigDecimal(revenueArray[0]).divide(new BigDecimal(30), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); + end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); + } + }else if(EnumMissTimeType.PERIOD.getCode().equals(timeType)){ + if(EnumGetRatioFrom.RENT.getCode().equals(from)) { + revenue = revenue.divide(new BigDecimal(period)); + } + } + if (revenue.compareTo(start) >= 0 && revenue.compareTo(end)<= 0){ - record.setPayRatio(ratio); + ratioVo.setRatio(ratio); break; } - - }if(e.indexOf(">") >= 0){ + }else if(e.indexOf(">") >= 0){ String[] revenueArray = array[0].split(">"); BigDecimal end = new BigDecimal(revenueArray[1]); + + //残年 (小金额 / 365 * 账单周期天数 )--(大金额 / 365 * 账单周期天数) + if(EnumMissTimeType.YEAR.getCode().equals(timeType)){ + if(EnumGetRatioFrom.BILL.getCode().equals(from)) { + end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); + } + if(EnumGetRatioFrom.RENT.getCode().equals(from)) { + revenue = revenue.divide(new BigDecimal(12)); + } + }else if(EnumMissTimeType.MONTH.getCode().equals(timeType)){ + if(EnumGetRatioFrom.BILL.getCode().equals(from)) { + end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount)); + } + }else if(EnumMissTimeType.PERIOD.getCode().equals(timeType)){ + if(EnumGetRatioFrom.RENT.getCode().equals(from)) { + revenue = revenue.divide(new BigDecimal(period)); + } + } + if (revenue.compareTo(end) >= 0){ - record.setPayRatio(ratio); - break; + ratioVo.setRatio(ratio); + + //计算超出部分 + BigDecimal payRatio = new BigDecimal(ratio).divide(new BigDecimal(10000)); + BigDecimal balance = new BigDecimal(revenueLong).subtract(end.multiply(new BigDecimal(1000000))); + BigDecimal price = balance.multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); + + array = ratioList.get(i-1).split(":"); + Integer frontatio = Integer.parseInt(array[1]); + BigDecimal frontRatio = new BigDecimal(frontatio).divide(new BigDecimal(10000)); + BigDecimal frontPrice = end.multiply(new BigDecimal(1000000).multiply(frontRatio).setScale(2, RoundingMode.HALF_EVEN)); + + ratioVo.setBalance(price.add(frontPrice)); + return ratioVo; } } } + return ratioVo; + } + + /** + * 计算金额 + * @param ratio + * @param revenueLong + * @return + */ + public Long countPrice(Integer ratio,Long revenueLong){ + BigDecimal hundred = new BigDecimal(100); + BigDecimal revenue = new BigDecimal(revenueLong == null ? 0 : revenueLong).divide(hundred); + BigDecimal payRatio = new BigDecimal(ratio == null ? 0 : ratio).divide(new BigDecimal(10000)); + BigDecimal price = revenue.multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); + return price.multiply(hundred).longValue(); } @Transactional(rollbackFor = {Exception.class}) @@ -310,13 +375,23 @@ public class WxRentContractServiceImpl implements WxRentContractService { } if (record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { - getPayRatio(record); - BigDecimal hundred = new BigDecimal(100); - BigDecimal revenue = new BigDecimal(record.getRevenue() == null ? 0 : record.getRevenue()).divide(hundred); - BigDecimal payRatio = new BigDecimal(record.getPayRatio() == null ? 0 : record.getPayRatio()).divide(new BigDecimal(10000)); - - BigDecimal price = revenue.multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); - record.setPrice(price.multiply(hundred).longValue()); + if(record.getRevenue() == null || record.getRevenue().longValue() <= 0){ + record.setPrice(0l); + }else{ + if(record.getPayRatio()!=null){ + record.setPrice(countPrice(record.getPayRatio(),record.getRevenue())); + }else{ + int dayCount = record.getReceivePeriod() * 30; + RatioVo ratioVo = getPayRatio(EnumGetRatioFrom.RENT.getCode(),record.getRevenue(),record.getBusDiscountRatio(),record.getBusDiscountTime(),dayCount,record.getReceivePeriod()); + record.setPayRatio(ratioVo.getRatio()); + if(ratioVo.getBalance() != null){ + //有超出部分,在getPayRatio里计算 + record.setPrice(ratioVo.getBalance().longValue()); + }else{ + record.setPrice(countPrice(record.getPayRatio(),record.getRevenue())); + } + } + } } else { if (StringUtils.isNotEmpty(record.getPriceStr())) { record.setPrice(new BigDecimal(record.getPriceStr()).multiply(new BigDecimal(100)).longValue()); @@ -522,6 +597,8 @@ public class WxRentContractServiceImpl implements WxRentContractService { wxBillRentMapper.insertBills(record.getPreviewBillRentList()); } + + public ResultData getResultDataForUpdate(WxRentContract record, Long userId,int from,Date oldRentStartDate) { //更新租赁合同信息 WxRentContract wxRentContract = wxRentContractMapper.selectByPrimaryKey(record.getId()); @@ -538,14 +615,21 @@ public class WxRentContractServiceImpl implements WxRentContractService { instance.add(dayType, record.getLease()); instance.add(Calendar.DAY_OF_MONTH, -1); - if(from != 1){ + if(!EnumFromType.SWITCH.getCode().equals(from)){ if (record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { - getPayRatio(record); - BigDecimal hundred = new BigDecimal(100); - BigDecimal revenue = new BigDecimal(record.getRevenue() == null ? 0 : record.getRevenue()).divide(hundred); - BigDecimal payRatio = new BigDecimal(record.getPayRatio() == null ? 0 : record.getPayRatio()).divide(new BigDecimal(10000)); - BigDecimal price = revenue.multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); - record.setPrice(price.multiply(hundred).longValue()); + if(record.getPayRatio()!=null){ + record.setPrice(countPrice(record.getPayRatio(),record.getRevenue())); + }else{ + int dayCount = record.getReceivePeriod() * 30; + RatioVo ratioVo = getPayRatio(EnumGetRatioFrom.RENT.getCode(),record.getRevenue(),record.getBusDiscountRatio(),record.getBusDiscountTime(),dayCount,record.getReceivePeriod()); + record.setPayRatio(ratioVo.getRatio()); + if(ratioVo.getBalance() != null){ + //有超出部分,在getPayRatio里计算 + record.setPrice(ratioVo.getBalance().longValue()); + }else{ + record.setPrice(countPrice(record.getPayRatio(),record.getRevenue())); + } + } } else { if (StringUtils.isNotEmpty(record.getPriceStr())) { record.setPrice(new BigDecimal(record.getPriceStr()).multiply(new BigDecimal(100)).longValue()); @@ -2067,12 +2151,6 @@ public class WxRentContractServiceImpl implements WxRentContractService { Double total = new Double(0); int[] diff; - System.out.println(sd.format(start)); - System.out.println(sd.format(end)); - if(sd.format(end).equals("2020-08-18")){ - System.out.println(); - } - //同一天 if(sd.format(start).equals(sd.format(end))){ int dayCount = DateUtils.getMonthDayCount(start); diff --git a/mallinkService/src/main/resources/mapper/KwMerchantMeterMapper.xml b/mallinkService/src/main/resources/mapper/KwMerchantMeterMapper.xml index 6914819b4..5860f896f 100644 --- a/mallinkService/src/main/resources/mapper/KwMerchantMeterMapper.xml +++ b/mallinkService/src/main/resources/mapper/KwMerchantMeterMapper.xml @@ -277,8 +277,8 @@ diff --git a/mallinkService/src/main/resources/mapper/PosOrderMapper.xml b/mallinkService/src/main/resources/mapper/PosOrderMapper.xml new file mode 100644 index 000000000..b3663fc51 --- /dev/null +++ b/mallinkService/src/main/resources/mapper/PosOrderMapper.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + `id`,`tenant_id`,`pos_order_no`,`type`,`order_status`,`bu_user_id`,`create_date`,`update_date` + + + + where 1 = 1 + + and `id` = #{id} + + + and `tenant_id` like concat('%', #{tenantId},'%') + + + and `pos_order_no` like concat('%', #{posOrderNo},'%') + + + and `type` = #{type} + + + and `order_status` = #{orderStatus} + + + and `bu_user_id` = #{buUserId} + + + and `payment_type` = #{paymentType} + + + and `payment` = #{payment} + + + and `create_date` = #{createDate} + + + and `update_date` = #{updateDate} + + + and id in + + #{idItem} + + + order by ${sortColumns} + + + + + + + + + + diff --git a/mallinkService/src/main/resources/mapper/PosPayOrderMapper.xml b/mallinkService/src/main/resources/mapper/PosPayOrderMapper.xml new file mode 100644 index 000000000..8b4b28166 --- /dev/null +++ b/mallinkService/src/main/resources/mapper/PosPayOrderMapper.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + `id`,`tenant_id`,`create_time`,`update_time`,`order_id`,`bu_user_id`,`type`,`pay_from`,`pay_amount`,`pay_time_start`,`pay_time_end`,`prepay_id`,`transaction_id`,`pay_vendor`,`pay_order_no`,`pay_order_status`,`share`,`share_amount`,`rate_amount`,`fail_reason`,`auth_code`,`open_id`,`pay_end_from` + + + + where 1 = 1 + + and `id` = #{id} + + + and `tenant_id` like concat('%', #{tenantId},'%') + + + and `create_time` = #{createTime} + + + and `update_time` = #{updateTime} + + + and `order_id` = #{orderId} + + + and `bu_user_id` = #{buUserId} + + + and `type` = #{type} + + + and `pay_from` = #{payFrom} + + + and `pay_amount` = #{payAmount} + + + and `pay_time_start` = #{payTimeStart} + + + and `pay_time_end` = #{payTimeEnd} + + + and `prepay_id` like concat('%', #{prepayId},'%') + + + and `transaction_id` like concat('%', #{transactionId},'%') + + + and `pay_vendor` = #{payVendor} + + + and `pay_order_no` like concat('%', #{payOrderNo},'%') + + + and `pay_order_status` = #{payOrderStatus} + + + and `share` = #{share} + + + and `share_amount` = #{shareAmount} + + + and `rate_amount` = #{rateAmount} + + + and `fail_reason` like concat('%', #{failReason},'%') + + + and `auth_code` like concat('%', #{authCode},'%') + + + and `open_id` like concat('%', #{openId},'%') + + + and `pay_end_from` = #{payEndFrom} + + + and id in + + #{idItem} + + + order by ${sortColumns} + + + + + + + + + + diff --git a/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml b/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml index ac9346ffa..c74eaefb2 100644 --- a/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml @@ -71,8 +71,8 @@ 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 + need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime, + rent_shop_type,'[]' shop_info,price_detail as comments 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