保存子订单的追加扣减记录
This commit is contained in:
parent
4929fc8d3a
commit
ea674336ff
|
|
@ -25,10 +25,11 @@ import com.ghy.order.service.*;
|
|||
import com.ghy.payment.domain.FinancialChangeRecord;
|
||||
import com.ghy.payment.domain.FinancialDetail;
|
||||
import com.ghy.payment.domain.FinancialMaster;
|
||||
import com.ghy.payment.service.*;
|
||||
import com.ghy.payment.service.FinancialChangeRecordService;
|
||||
import com.ghy.payment.service.FinancialDetailService;
|
||||
import com.ghy.payment.service.FinancialMasterService;
|
||||
import com.ghy.system.domain.SysArea;
|
||||
import com.ghy.system.service.ISysAreaService;
|
||||
import com.ghy.system.service.ISysDeptConfigService;
|
||||
import com.ghy.system.service.IWxMsgService;
|
||||
import com.ghy.web.pojo.vo.OrderChangePriceRequest;
|
||||
import com.ghy.web.pojo.vo.OrderListResponse;
|
||||
|
|
@ -87,8 +88,6 @@ public class OrderDetailController extends BaseController {
|
|||
@Resource
|
||||
private FinancialDetailService financialDetailService;
|
||||
@Resource
|
||||
private OrderFineRecordService orderFineRecordService;
|
||||
@Resource
|
||||
private IAfterServiceRecordService afterServiceRecordService;
|
||||
@Resource
|
||||
private FinancialChangeRecordService financialChangeRecordService;
|
||||
|
|
@ -99,13 +98,9 @@ public class OrderDetailController extends BaseController {
|
|||
@Resource
|
||||
private FinancialMasterService financialMasterService;
|
||||
@Resource
|
||||
private ISysDeptConfigService sysDeptConfigService;
|
||||
@Resource
|
||||
private OrderBehaviorService orderBehaviorService;
|
||||
@Resource
|
||||
private IWxMsgService wxMsgService;
|
||||
@Resource
|
||||
private AdapayService adapayService;
|
||||
|
||||
@RequiresPermissions("order:detail:view")
|
||||
@GetMapping()
|
||||
|
|
@ -118,7 +113,7 @@ public class OrderDetailController extends BaseController {
|
|||
@ResponseBody
|
||||
public TableDataInfo list(OrderDetail orderDetail) {
|
||||
startPage();
|
||||
if(this.getSysUser().getDept().getParentId() != 101){
|
||||
if (this.getSysUser().getDept().getParentId() != 101) {
|
||||
orderDetail.setDeptId(this.getSysUser().getDept().getParentId());
|
||||
}
|
||||
List<OrderDetail> orderDetails = orderDetailService.selectOrderDetailList(orderDetail);
|
||||
|
|
@ -175,7 +170,7 @@ public class OrderDetailController extends BaseController {
|
|||
}
|
||||
// 地址信息
|
||||
CustomerAddress customerAddress = addressService.selectByCustomerAddressId(orderMaster.getAddressId());
|
||||
if(customerAddress != null){
|
||||
if (customerAddress != null) {
|
||||
detail.setAddressName(customerAddress.getName());
|
||||
detail.setAddressPhone(customerAddress.getPhone());
|
||||
detail.setAddress(customerAddress.getAddress());
|
||||
|
|
@ -752,7 +747,7 @@ public class OrderDetailController extends BaseController {
|
|||
logger.info("师傅发起完单,orderDetailId={}", request.getOrderDetailId());
|
||||
// 判断是否有未完成的售后记录,如果有则不允许完单
|
||||
AfterServiceRecord unfinishedByOrderDetailId = afterServiceRecordService.getUnfinishedByOrderDetailId(request.getOrderDetailId());
|
||||
if(unfinishedByOrderDetailId != null){
|
||||
if (unfinishedByOrderDetailId != null) {
|
||||
return AjaxResult.error("存在未处理完的售后,不允许申请完单!");
|
||||
}
|
||||
// 判断工单状态是否为服务中以及是否已支付
|
||||
|
|
@ -954,4 +949,12 @@ public class OrderDetailController extends BaseController {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/add-subtract/insert")
|
||||
@ResponseBody
|
||||
public AjaxResult addOrSubtract(@Valid @RequestBody OrderAddSubtract body) {
|
||||
body.setCreateBy(getLoginName());
|
||||
int i = orderDetailService.insertOrderAddSubtract(body);
|
||||
return AjaxResult.success(i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
package com.ghy.common.utils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 处理金额工具类
|
||||
*/
|
||||
public class MoneyUtil {
|
||||
|
||||
public static boolean equals(BigDecimal a, BigDecimal b) {
|
||||
return a.compareTo(b) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* a > b
|
||||
*/
|
||||
public static boolean gt(BigDecimal a, BigDecimal b) {
|
||||
return a.compareTo(b) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* a >= b
|
||||
*/
|
||||
public static boolean gte(BigDecimal a, BigDecimal b) {
|
||||
return a.compareTo(b) >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* a < b
|
||||
*/
|
||||
public static boolean lt(BigDecimal a, BigDecimal b) {
|
||||
return a.compareTo(b) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* a <= b
|
||||
*/
|
||||
public static boolean lte(BigDecimal a, BigDecimal b) {
|
||||
return a.compareTo(b) <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* a == 0
|
||||
*/
|
||||
public static boolean equals0(BigDecimal a) {
|
||||
return equals(a, BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
/**
|
||||
* a > 0
|
||||
*/
|
||||
public static boolean gt0(BigDecimal a) {
|
||||
return gt(a, BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
/**
|
||||
* a >= 0
|
||||
*/
|
||||
public static boolean gte0(BigDecimal a) {
|
||||
return gte(a, BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
/**
|
||||
* a < 0
|
||||
*/
|
||||
public static boolean lt0(BigDecimal a) {
|
||||
return lt(a, BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
/**
|
||||
* a <= 0
|
||||
*/
|
||||
public static boolean lte0(BigDecimal a) {
|
||||
return lte(a, BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package com.ghy.order.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ghy.common.enums.PayStatus;
|
||||
import com.ghy.common.enums.PayTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 订单追加扣减
|
||||
*/
|
||||
@Data
|
||||
public class OrderAddSubtract {
|
||||
|
||||
private Long id;
|
||||
private Long orderMasterId;
|
||||
private Long orderDetailId;
|
||||
|
||||
/**
|
||||
* 金额
|
||||
*/
|
||||
@NotNull(message = "金额不能为空")
|
||||
@Max(value = 50000, message = "金额过大")
|
||||
@Min(value = -50000, message = "金额过小")
|
||||
private BigDecimal money;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 支付方式
|
||||
*
|
||||
* @see PayTypeEnum
|
||||
*/
|
||||
private Integer payType;
|
||||
|
||||
/**
|
||||
* 支付状态
|
||||
*
|
||||
* @see PayStatus
|
||||
*/
|
||||
private Integer payStatus;
|
||||
|
||||
/**
|
||||
* 付款时间
|
||||
*/
|
||||
private LocalDateTime payTime;
|
||||
|
||||
/**
|
||||
* Adapay的唯一支付ID
|
||||
*/
|
||||
private String paymentId;
|
||||
|
||||
/**
|
||||
* Adapay的撤销支付ID
|
||||
*/
|
||||
private String reverseId;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.ghy.order.mapper;
|
||||
|
||||
import com.ghy.order.domain.OrderAddSubtract;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单追加扣减 Mapper
|
||||
*/
|
||||
public interface OrderAddSubtractMapper {
|
||||
|
||||
int insert(OrderAddSubtract insert);
|
||||
|
||||
int update(OrderAddSubtract insert);
|
||||
|
||||
List<OrderAddSubtract> select(OrderAddSubtract insert);
|
||||
|
||||
OrderAddSubtract selectById(Long id);
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.ghy.order.service;
|
||||
|
||||
import com.ghy.common.enums.OrderStatus;
|
||||
import com.ghy.order.domain.OrderAddSubtract;
|
||||
import com.ghy.order.domain.OrderDetail;
|
||||
import com.ghy.order.domain.OrderStatusCount;
|
||||
import com.ghy.payment.domain.FinancialChangeRecord;
|
||||
|
|
@ -176,4 +177,13 @@ public interface OrderDetailService {
|
|||
int updateTimeout(Long id, int timeout, int timeoutFineTimes);
|
||||
|
||||
int deleteByMaster(Long masterId);
|
||||
|
||||
/**
|
||||
* 保存一条子订单的追加扣减记录
|
||||
* 并且更新子订单对应的财务单的金额
|
||||
*
|
||||
* @param body 追加扣减记录
|
||||
* @return 1
|
||||
*/
|
||||
int insertOrderAddSubtract(OrderAddSubtract body);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,10 @@ import com.ghy.common.core.text.Convert;
|
|||
import com.ghy.common.enums.*;
|
||||
import com.ghy.common.exception.base.BaseException;
|
||||
import com.ghy.common.utils.AdapayUtils;
|
||||
import com.ghy.common.utils.MoneyUtil;
|
||||
import com.ghy.common.utils.ObjectUtils;
|
||||
import com.ghy.order.domain.OrderDetail;
|
||||
import com.ghy.order.domain.OrderGoods;
|
||||
import com.ghy.order.domain.OrderMaster;
|
||||
import com.ghy.order.domain.OrderStatusCount;
|
||||
import com.ghy.order.domain.*;
|
||||
import com.ghy.order.mapper.OrderAddSubtractMapper;
|
||||
import com.ghy.order.mapper.OrderDetailMapper;
|
||||
import com.ghy.order.mapper.OrderMasterMapper;
|
||||
import com.ghy.order.service.OrderDetailService;
|
||||
|
|
@ -63,6 +62,8 @@ public class OrderDetailServiceImpl implements OrderDetailService {
|
|||
.appendValue(DAY_OF_MONTH, 2).appendValue(HOUR_OF_DAY, 2)
|
||||
.appendValue(MINUTE_OF_HOUR, 2).appendValue(SECOND_OF_MINUTE, 2).toFormatter();
|
||||
|
||||
private static final Integer ZERO = 0;
|
||||
|
||||
@Resource
|
||||
private ThreadPoolTaskExecutor executor;
|
||||
@Resource
|
||||
|
|
@ -83,6 +84,8 @@ public class OrderDetailServiceImpl implements OrderDetailService {
|
|||
private OrderGoodsService orderGoodsService;
|
||||
@Resource
|
||||
private OrderFineRecordMapper orderFineRecordMapper;
|
||||
@Resource
|
||||
private OrderAddSubtractMapper orderAddSubtractMapper;
|
||||
|
||||
// Adapay 手续费率 默认0.008
|
||||
@Value("${adapay.fee_rate:0.008}")
|
||||
|
|
@ -774,4 +777,49 @@ public class OrderDetailServiceImpl implements OrderDetailService {
|
|||
public int deleteByMaster(Long masterId) {
|
||||
return orderDetailMapper.deleteByMaster(masterId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertOrderAddSubtract(OrderAddSubtract body) {
|
||||
Assert.notNull(body.getOrderDetailId(), "订单id不能为空");
|
||||
OrderDetail orderDetail = orderDetailMapper.selectById(body.getOrderDetailId());
|
||||
Assert.notNull(orderDetail, "订单不存在");
|
||||
|
||||
boolean finish = ZERO.equals(orderDetail.getDrawCashStatus()) &&
|
||||
OrderStatus.FINISH_CHECK.code() != orderDetail.getOrderStatus() &&
|
||||
OrderStatus.FINISH.code() != orderDetail.getOrderStatus();
|
||||
Assert.isTrue(finish, "订单已经完成,不能再做追加扣减操作");
|
||||
|
||||
boolean cancel = OrderStatus.CANCEL.code() != orderDetail.getOrderStatus();
|
||||
Assert.isTrue(cancel, "订单已经取消,不能再做追加扣减操作");
|
||||
|
||||
Assert.isTrue(BigDecimal.ZERO.compareTo(body.getMoney()) != 0, "金额不能为0");
|
||||
|
||||
FinancialDetail financialDetail = financialDetailService.selectByOrderDetailId(orderDetail.getId());
|
||||
Assert.notNull(financialDetail, "找不到财务单");
|
||||
|
||||
// 派单金额 = 财务单金额 - 已支付的加价记录
|
||||
BigDecimal paiDanMoney = financialDetail.getPayMoney();
|
||||
// 已支付的加价记录
|
||||
List<FinancialChangeRecord> paidChangeRecords = financialChangeRecordService.selectByDetailIds(orderDetail.getId().toString())
|
||||
.stream().filter(x -> x.getPayStatus() == 1).collect(Collectors.toList());
|
||||
for (FinancialChangeRecord record : paidChangeRecords) {
|
||||
paiDanMoney = paiDanMoney.subtract(record.getChangeMoney());
|
||||
}
|
||||
|
||||
// 如果这是扣减操作
|
||||
if (MoneyUtil.lt0(body.getMoney())) {
|
||||
// 扣减金额不能超过派单金额
|
||||
Assert.isTrue(MoneyUtil.gte0(paiDanMoney.add(body.getMoney())), "扣减金额不能超过派单金额");
|
||||
}
|
||||
|
||||
// 保存扣减记录
|
||||
OrderAddSubtract insert = new OrderAddSubtract();
|
||||
insert.setOrderMasterId(orderDetail.getOrderMasterId());
|
||||
insert.setOrderDetailId(orderDetail.getId());
|
||||
insert.setMoney(body.getMoney());
|
||||
insert.setRemark(body.getRemark());
|
||||
insert.setCreateBy(body.getCreateBy());
|
||||
insert.setPayType(body.getPayType());
|
||||
return orderAddSubtractMapper.insert(insert);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
<?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.ghy.order.mapper.OrderAddSubtractMapper">
|
||||
|
||||
<resultMap id="ColumnMap" type="com.ghy.order.domain.OrderAddSubtract">
|
||||
<id property="id" column="id"/>
|
||||
<result property="orderMasterId" column="order_master_id"/>
|
||||
<result property="orderDetailId" column="order_detail_id"/>
|
||||
<result property="money" column="money"/>
|
||||
<result property="remark" column="remark"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
|
||||
<result property="payType" column="pay_type"/>
|
||||
<result property="payStatus" column="pay_status"/>
|
||||
<result property="payTime" column="pay_time"/>
|
||||
<result property="paymentId" column="payment_id"/>
|
||||
<result property="reverseId" column="reverse_id"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectColumns">
|
||||
SELECT id, order_master_id, order_detail_id, money, remark, create_time, create_by,
|
||||
pay_type, pay_status, pay_time, payment_id, reverse_id
|
||||
FROM order_add_subtract
|
||||
</sql>
|
||||
|
||||
<insert id="insert" parameterType="com.ghy.order.domain.OrderAddSubtract" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO order_add_subtract(order_master_id, order_detail_id, money, remark, create_by, pay_type)
|
||||
VALUES (#{orderMasterId}, #{orderDetailId}, #{money}, #{remark}, #{createBy}, #{payType})
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.ghy.order.domain.OrderAddSubtract">
|
||||
UPDATE order_add_subtract
|
||||
<set>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="payType != null">pay_type = #{payType},</if>
|
||||
<if test="payStatus != null">pay_status = #{payStatus},</if>
|
||||
<if test="payTime != null">pay_time = #{payTime},</if>
|
||||
<if test="paymentId != null">payment_id = #{paymentId},</if>
|
||||
<if test="reverseId != null">reverse_id = #{reverseId}</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="select" parameterType="com.ghy.order.domain.OrderAddSubtract" resultMap="ColumnMap">
|
||||
<include refid="selectColumns"/>
|
||||
<where>
|
||||
<if test="orderMasterId != null">
|
||||
AND order_master_id = #{orderMasterId}
|
||||
</if>
|
||||
<if test="orderDetailId != null">
|
||||
AND order_detail_id = #{orderDetailId}
|
||||
</if>
|
||||
<if test="paymentId != null and paymentId != ''">
|
||||
AND payment_id = #{paymentId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectById" parameterType="long" resultMap="ColumnMap">
|
||||
<include refid="selectColumns"/>
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
package com.ghy.order;
|
||||
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
//@SpringBootTest
|
||||
class GhyOrderApplicationTests {
|
||||
|
||||
// @Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ import org.springframework.util.CollectionUtils;
|
|||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -85,6 +86,27 @@ public class AdapayService {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询支付对象列表
|
||||
*
|
||||
* @param deptId [必填]商户ID
|
||||
* @param paymentId [必填] String(64) Adapay生成的支付对象id
|
||||
* @return 支付对象
|
||||
*/
|
||||
public JSONObject paymentList(@NotNull Long deptId, @NotNull String paymentId) {
|
||||
try {
|
||||
// 获取商户的appId
|
||||
String appId = AdapayConfig.getAppId(deptId);
|
||||
HashMap<String, Object> param = new HashMap<>();
|
||||
param.put("app_id", appId);
|
||||
param.put("paymentId", paymentId);
|
||||
return (JSONObject) Payment.queryList(param, deptId.toString());
|
||||
} catch (BaseAdaPayException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付确认
|
||||
* 适用于延时分账的场景。只有已支付完成且延时分账的Payment对象,才支持调用创建支付确认对象。
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
package com.ghy.payment;
|
||||
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
//@SpringBootTest
|
||||
class PaymentApplicationTests {
|
||||
|
||||
// @Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue