Browse Source

Merge branch 'develop' into devlocal

release_toaliyun_real
Burce 6 years ago
parent
commit
3645193c05
33 changed files with 1760 additions and 211 deletions
  1. +41
    -0
      mallinkAdmin/src/main/resources/db/migration/V201908221020__POS_ORDER.sql
  2. +2
    -0
      mallinkAdmin/src/main/resources/db/migration/V201908221440__L_CONTRACT.sql
  3. +181
    -0
      mallinkBApi/src/main/java/com/iformall/controller/PosController.java
  4. +87
    -0
      mallinkBApi/src/main/java/com/iformall/controller/PosOrderController.java
  5. +72
    -0
      mallinkBApi/src/main/java/com/iformall/controller/PosPayOrderController.java
  6. +0
    -66
      mallinkBApi/src/main/java/com/iformall/controller/WxPosController.java
  7. +451
    -0
      mallinkBApi/src/main/java/com/iformall/service/PosBrunService.java
  8. +9
    -5
      mallinkBApi/src/main/java/com/iformall/utils/PosUtil.java
  9. +16
    -1
      mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java
  10. +27
    -17
      mallinkSchedule/src/main/java/com/iformall/schedule/PowerBillAutoBuildSchedule.java
  11. +2
    -0
      mallinkService/src/main/java/com/iformall/common/ErrorCode.java
  12. +42
    -0
      mallinkService/src/main/java/com/iformall/domain/po/PosOrder.java
  13. +69
    -0
      mallinkService/src/main/java/com/iformall/domain/po/PosPayOrder.java
  14. +13
    -0
      mallinkService/src/main/java/com/iformall/domain/vo/RatioVo.java
  15. +32
    -0
      mallinkService/src/main/java/com/iformall/enums/EnumGetRatioFrom.java
  16. +4
    -6
      mallinkService/src/main/java/com/iformall/enums/EnumMissTimeType.java
  17. +47
    -0
      mallinkService/src/main/java/com/iformall/enums/EnumPosOrderStatus.java
  18. +38
    -0
      mallinkService/src/main/java/com/iformall/enums/EnumPosOrderType.java
  19. +38
    -0
      mallinkService/src/main/java/com/iformall/enums/EnumPosPayType.java
  20. +17
    -0
      mallinkService/src/main/java/com/iformall/mapper/PosOrderMapper.java
  21. +17
    -0
      mallinkService/src/main/java/com/iformall/mapper/PosPayOrderMapper.java
  22. +8
    -0
      mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java
  23. +48
    -0
      mallinkService/src/main/java/com/iformall/service/PosOrderService.java
  24. +48
    -0
      mallinkService/src/main/java/com/iformall/service/PosPayOrderService.java
  25. +52
    -0
      mallinkService/src/main/java/com/iformall/service/impl/PosOrderServiceImpl.java
  26. +54
    -0
      mallinkService/src/main/java/com/iformall/service/impl/PosPayOrderServiceImpl.java
  27. +9
    -8
      mallinkService/src/main/java/com/iformall/service/impl/WxActivityJoinServiceImpl.java
  28. +23
    -69
      mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java
  29. +113
    -35
      mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java
  30. +2
    -2
      mallinkService/src/main/resources/mapper/KwMerchantMeterMapper.xml
  31. +72
    -0
      mallinkService/src/main/resources/mapper/PosOrderMapper.xml
  32. +124
    -0
      mallinkService/src/main/resources/mapper/PosPayOrderMapper.xml
  33. +2
    -2
      mallinkService/src/main/resources/mapper/WxBillAllMapper.xml

+ 41
- 0
mallinkAdmin/src/main/resources/db/migration/V201908221020__POS_ORDER.sql View File

@@ -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支付订单';

+ 2
- 0
mallinkAdmin/src/main/resources/db/migration/V201908221440__L_CONTRACT.sql View File

@@ -0,0 +1,2 @@
alter table wx_bill_rent
add column `bus_discount_ratio` int(5) NULL DEFAULT NULL COMMENT '连营扣点跳点率';

+ 181
- 0
mallinkBApi/src/main/java/com/iformall/controller/PosController.java View File

@@ -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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> paramMap) {
// 0. 获取dev信息, tenantId信息
// 1. check 查询
// 2. create order
// 3. 独立核销

return new ResultData();
}
}

+ 87
- 0
mallinkBApi/src/main/java/com/iformall/controller/PosOrderController.java View File

@@ -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<PosOrder> 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));
}


}

+ 72
- 0
mallinkBApi/src/main/java/com/iformall/controller/PosPayOrderController.java View File

@@ -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<PosPayOrder> 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));
}


}

+ 0
- 66
mallinkBApi/src/main/java/com/iformall/controller/WxPosController.java View File

@@ -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<String, String> paramMap) {
// 0. 获取dev信息, tenantId信息
// 1. check 查询
// 2. create order
// 3. 独立核销

return new ResultData();
}
}

+ 451
- 0
mallinkBApi/src/main/java/com/iformall/service/PosBrunService.java View File

@@ -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();
}
}

+ 9
- 5
mallinkBApi/src/main/java/com/iformall/utils/PosUtil.java View File

@@ -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<String, String> 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);


+ 16
- 1
mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java View File

@@ -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)) {


+ 27
- 17
mallinkSchedule/src/main/java/com/iformall/schedule/PowerBillAutoBuildSchedule.java View File

@@ -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;


+ 2
- 0
mallinkService/src/main/java/com/iformall/common/ErrorCode.java View File

@@ -489,6 +489,8 @@ public enum ErrorCode{
ACTIVITY_SEND_ERROR(30004, "活动投放到宣传页失败,宣传页显示已达七条上限!"),
ACTIVITY_TIME_ERROR(30005, "活动报名结束时间不能大于活动结束时间"),
ACTIVITY_WAIT_CONFIRMED(30006, "您报名的活动还在审核中"),
ACTIVITY_EXPIRED(30007, "您报名的活动已过期"),

/**
* 文件上传
*/


+ 42
- 0
mallinkService/src/main/java/com/iformall/domain/po/PosOrder.java View File

@@ -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<Long> 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;


}

+ 69
- 0
mallinkService/src/main/java/com/iformall/domain/po/PosPayOrder.java View File

@@ -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<Long> 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;


}

+ 13
- 0
mallinkService/src/main/java/com/iformall/domain/vo/RatioVo.java View File

@@ -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;
}

+ 32
- 0
mallinkService/src/main/java/com/iformall/enums/EnumGetRatioFrom.java View File

@@ -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;
}
}

+ 4
- 6
mallinkService/src/main/java/com/iformall/enums/EnumMissTimeType.java View File

@@ -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) {


+ 47
- 0
mallinkService/src/main/java/com/iformall/enums/EnumPosOrderStatus.java View File

@@ -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;
}
}

+ 38
- 0
mallinkService/src/main/java/com/iformall/enums/EnumPosOrderType.java View File

@@ -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;
}
}

+ 38
- 0
mallinkService/src/main/java/com/iformall/enums/EnumPosPayType.java View File

@@ -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;
}
}

+ 17
- 0
mallinkService/src/main/java/com/iformall/mapper/PosOrderMapper.java View File

@@ -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<PosOrder, Long> {

List<PosOrder> findList(PosOrder posOrder);

}

+ 17
- 0
mallinkService/src/main/java/com/iformall/mapper/PosPayOrderMapper.java View File

@@ -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<PosPayOrder, Long> {

List<PosPayOrder> findList(PosPayOrder posPayOrder);

}

+ 8
- 0
mallinkService/src/main/java/com/iformall/pay/WxPayConstant.java View File

@@ -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";


+ 48
- 0
mallinkService/src/main/java/com/iformall/service/PosOrderService.java View File

@@ -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<PosOrder> 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);

}

+ 48
- 0
mallinkService/src/main/java/com/iformall/service/PosPayOrderService.java View File

@@ -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<PosPayOrder> 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);

}

+ 52
- 0
mallinkService/src/main/java/com/iformall/service/impl/PosOrderServiceImpl.java View File

@@ -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<PosOrder> 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);
}
}

+ 54
- 0
mallinkService/src/main/java/com/iformall/service/impl/PosPayOrderServiceImpl.java View File

@@ -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<PosPayOrder> 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);
}
}

+ 9
- 8
mallinkService/src/main/java/com/iformall/service/impl/WxActivityJoinServiceImpl.java View File

@@ -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) {


+ 23
- 69
mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java View File

@@ -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<String> 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());



+ 113
- 35
mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java View File

@@ -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<String> ratioList = JSONArray.parseArray(record.getBusDiscountRatio(), String.class);
BigDecimal revenue = new BigDecimal(revenueLong).divide(new BigDecimal(1000000)).setScale(4, RoundingMode.HALF_EVEN);
List<String> 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);


+ 2
- 2
mallinkService/src/main/resources/mapper/KwMerchantMeterMapper.xml View File

@@ -277,8 +277,8 @@
<select id="getMerchantMeter" resultMap="MerchantMeterMap">
select m.id as merchant_id,m.name as merchant_name,ifnull(mm.status,0) has from wx_merchant m
left join (select merchant_id,1 as status from kw_merchant_meter where status=0) mm on m.id=mm.merchant_id
where m.id not in(select merchant_id from wx_merchant_power_bill_config where tenant_id=#{tenantId})
left join (select merchant_id,1 as status from kw_merchant_meter where status=0 group by merchant_id) mm on m.id=mm.merchant_id
where m.status=1 and m.id not in(select merchant_id from wx_merchant_power_bill_config where tenant_id=#{tenantId})
</select>

</mapper>

+ 72
- 0
mallinkService/src/main/resources/mapper/PosOrderMapper.xml View File

@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.iformall.mapper.PosOrderMapper">
<resultMap id="BaseResultMap" type="com.iformall.domain.po.PosOrder">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
<result column="pos_order_no" jdbcType="VARCHAR" property="posOrderNo" />
<result column="type" jdbcType="INTEGER" property="type" />
<result column="order_status" jdbcType="INTEGER" property="orderStatus" />
<result column="bu_user_id" jdbcType="BIGINT" property="buUserId" />
<result column="payment_type" jdbcType="INTEGER" property="paymentType" />
<result column="payment" jdbcType="INTEGER" property="payment" />
<result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
</resultMap>
<sql id="allColumns">
`id`,`tenant_id`,`pos_order_no`,`type`,`order_status`,`bu_user_id`,`create_date`,`update_date`
</sql>

<sql id="dynamicWhereConditions">
where 1 = 1
<if test=" null != id ">
and `id` = #{id}
</if>
<if test=" null != tenantId ">
and `tenant_id` like concat('%', #{tenantId},'%')
</if>
<if test=" null != posOrderNo ">
and `pos_order_no` like concat('%', #{posOrderNo},'%')
</if>
<if test=" null != type ">
and `type` = #{type}
</if>
<if test=" null != orderStatus ">
and `order_status` = #{orderStatus}
</if>
<if test=" null != buUserId ">
and `bu_user_id` = #{buUserId}
</if>
<if test=" null != paymentType ">
and `payment_type` = #{paymentType}
</if>
<if test=" null != payment ">
and `payment` = #{payment}
</if>
<if test=" null != createDate ">
and `create_date` = #{createDate}
</if>
<if test=" null != updateDate ">
and `update_date` = #{updateDate}
</if>
<if test=" null != ids ">
and id in
<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
#{idItem}
</foreach>
</if>
<if test=" null != sortColumns"> order by ${sortColumns} </if>
</sql>
<select id="findList" parameterType="com.iformall.domain.po.PosOrder" resultMap="BaseResultMap">
select <include refid="allColumns" /> from pos_order
<include refid="dynamicWhereConditions" />
</select>
</mapper>

+ 124
- 0
mallinkService/src/main/resources/mapper/PosPayOrderMapper.xml View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.iformall.mapper.PosPayOrderMapper">
<resultMap id="BaseResultMap" type="com.iformall.domain.po.PosPayOrder">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="order_id" jdbcType="BIGINT" property="orderId" />
<result column="bu_user_id" jdbcType="BIGINT" property="buUserId" />
<result column="type" jdbcType="INTEGER" property="type" />
<result column="pay_from" jdbcType="INTEGER" property="payFrom" />
<result column="pay_amount" jdbcType="INTEGER" property="payAmount" />
<result column="pay_time_start" jdbcType="TIMESTAMP" property="payTimeStart" />
<result column="pay_time_end" jdbcType="TIMESTAMP" property="payTimeEnd" />
<result column="prepay_id" jdbcType="VARCHAR" property="prepayId" />
<result column="transaction_id" jdbcType="VARCHAR" property="transactionId" />
<result column="pay_vendor" jdbcType="INTEGER" property="payVendor" />
<result column="pay_order_no" jdbcType="VARCHAR" property="payOrderNo" />
<result column="pay_order_status" jdbcType="INTEGER" property="payOrderStatus" />
<result column="share" jdbcType="INTEGER" property="share" />
<result column="share_amount" jdbcType="INTEGER" property="shareAmount" />
<result column="rate_amount" jdbcType="INTEGER" property="rateAmount" />
<result column="fail_reason" jdbcType="VARCHAR" property="failReason" />
<result column="auth_code" jdbcType="VARCHAR" property="authCode" />
<result column="open_id" jdbcType="VARCHAR" property="openId" />
<result column="pay_end_from" jdbcType="INTEGER" property="payEndFrom" />
</resultMap>
<sql id="allColumns">
`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`
</sql>

<sql id="dynamicWhereConditions">
where 1 = 1
<if test=" null != id ">
and `id` = #{id}
</if>
<if test=" null != tenantId ">
and `tenant_id` like concat('%', #{tenantId},'%')
</if>
<if test=" null != createTime ">
and `create_time` = #{createTime}
</if>
<if test=" null != updateTime ">
and `update_time` = #{updateTime}
</if>
<if test=" null != orderId ">
and `order_id` = #{orderId}
</if>
<if test=" null != buUserId ">
and `bu_user_id` = #{buUserId}
</if>
<if test=" null != type ">
and `type` = #{type}
</if>
<if test=" null != payFrom ">
and `pay_from` = #{payFrom}
</if>
<if test=" null != payAmount ">
and `pay_amount` = #{payAmount}
</if>
<if test=" null != payTimeStart ">
and `pay_time_start` = #{payTimeStart}
</if>
<if test=" null != payTimeEnd ">
and `pay_time_end` = #{payTimeEnd}
</if>
<if test=" null != prepayId ">
and `prepay_id` like concat('%', #{prepayId},'%')
</if>
<if test=" null != transactionId ">
and `transaction_id` like concat('%', #{transactionId},'%')
</if>
<if test=" null != payVendor ">
and `pay_vendor` = #{payVendor}
</if>
<if test=" null != payOrderNo ">
and `pay_order_no` like concat('%', #{payOrderNo},'%')
</if>
<if test=" null != payOrderStatus ">
and `pay_order_status` = #{payOrderStatus}
</if>
<if test=" null != share ">
and `share` = #{share}
</if>
<if test=" null != shareAmount ">
and `share_amount` = #{shareAmount}
</if>
<if test=" null != rateAmount ">
and `rate_amount` = #{rateAmount}
</if>
<if test=" null != failReason ">
and `fail_reason` like concat('%', #{failReason},'%')
</if>
<if test=" null != authCode ">
and `auth_code` like concat('%', #{authCode},'%')
</if>
<if test=" null != openId ">
and `open_id` like concat('%', #{openId},'%')
</if>
<if test=" null != payEndFrom ">
and `pay_end_from` = #{payEndFrom}
</if>
<if test=" null != ids ">
and id in
<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
#{idItem}
</foreach>
</if>
<if test=" null != sortColumns"> order by ${sortColumns} </if>
</sql>
<select id="findList" parameterType="com.iformall.domain.po.PosPayOrder" resultMap="BaseResultMap">
select <include refid="allColumns" /> from pos_pay_order
<include refid="dynamicWhereConditions" />
</select>
</mapper>

+ 2
- 2
mallinkService/src/main/resources/mapper/WxBillAllMapper.xml View File

@@ -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


Loading…
Cancel
Save