生成财务主单和财务子单

This commit is contained in:
HH 2022-05-24 22:26:26 +08:00
parent d9de7f85f5
commit f459d3fc9c
21 changed files with 426 additions and 164 deletions

View File

@ -14,6 +14,7 @@ import com.ghy.order.request.AppOrderRequest;
import com.ghy.order.service.OrderDetailService;
import com.ghy.order.service.OrderGoodsService;
import com.ghy.order.service.OrderMasterService;
import com.ghy.payment.domain.FinancialDetail;
import com.ghy.payment.domain.FinancialMaster;
import com.ghy.payment.service.FinancialDetailService;
import com.ghy.payment.service.FinancialMasterService;
@ -37,6 +38,10 @@ import java.util.stream.Collectors;
@RequestMapping("/order")
public class OrderController extends BaseController {
private static final BigDecimal PERCENT1 = BigDecimal.valueOf(0.01);
private static final BigDecimal PERCENT2 = BigDecimal.valueOf(0.02);
private static final BigDecimal PERCENT7 = BigDecimal.valueOf(0.07);
@Autowired
private CustomerService customerService;
@ -79,8 +84,13 @@ public class OrderController extends BaseController {
Set<Long> goodsIds = appGoodsList.stream().map(AppGoodsRequest::getGoodsId).collect(Collectors.toSet());
// 所有商品
List<Goods> goodsList = goodsService.selectByIds(goodsIds);
// 商户ID
Long deptId = goodsList.get(0).getDeptId();
Assert.notNull(deptId, "deptId is null!");
// 生成主单
OrderMaster orderMaster = new OrderMaster();
orderMaster.setDeptId(deptId);
orderMaster.setCode(orderMasterService.createOrderCode());
orderMaster.setOrderType(1);
orderMaster.setOrderStatus(0);
@ -88,17 +98,23 @@ public class OrderController extends BaseController {
orderMaster.setPayStatus(0);
orderMaster.setCreateTime(new Date());
orderMasterService.insertOrderMaster(orderMaster);
Assert.notNull(orderMaster.getId(), "OrderMaster ID is null!");
Assert.notNull(orderMaster.getId(), "OrderMaster.id is null!");
// TODO 优惠金额不知道咋算 暂时先给0
BigDecimal discountMoney = BigDecimal.ZERO;
BigDecimal payMoney = totalPay.subtract(discountMoney);
// 当实付金额payType<=0时 使payType=BigDecimal.ZERO
payMoney = BigDecimal.ZERO.max(payMoney);
// 生成财务主单
FinancialMaster financialMaster = new FinancialMaster(orderMaster.getId(), orderMaster.getCode(),
// TODO 优惠金额不知道咋算 暂时先给0
totalPay, BigDecimal.ZERO, totalPay);
FinancialMaster financialMaster = new FinancialMaster(financialMasterService.createCode(), deptId,
orderMaster.getId(), orderMaster.getCode(), totalPay, discountMoney, payMoney);
financialMasterService.insertFinancialMaster(financialMaster);
Assert.notNull(financialMaster.getId(), "FinancialMaster.id is null!");
//TODO 生成细单
//TODO 生成财务细单(含分销等.)
//生成财务子单
createFinancialDetail(deptId, customer, payMoney, financialMaster);
// 生成商品订单
Map<Long, Goods> goodsMap = goodsList.stream().filter(Objects::nonNull)
@ -113,4 +129,52 @@ public class OrderController extends BaseController {
return AjaxResult.success(orderMaster);
}
/**
* 生成财务子单
*
* @param deptId 商户ID
* @param customer 消费者
* @param payMoney 实付金额
* @param financialMaster 财务主单
*/
private void createFinancialDetail(Long deptId, Customer customer, BigDecimal payMoney, FinancialMaster financialMaster) {
// 是否为0元购 是的话下面就不用多级分销了
if (BigDecimal.ZERO.equals(payMoney)) {
return;
}
// 公司抽成比例 初始10%
BigDecimal companyRatio = BigDecimal.valueOf(0.1);
// 上级分销人的 customerId
Long customerPlaceId = customer.getCustomerPlace();
if (customerPlaceId != null) {
// 子财务单的实付金额
BigDecimal fdPayMoney = payMoney.multiply(PERCENT7);
// 生成上级分销的子财务单
FinancialDetail financialDetail = new FinancialDetail(financialDetailService.createCode(), deptId,
financialMaster.getId(), fdPayMoney, 2, customerPlaceId);
financialDetailService.insertFinancialDetail(financialDetail);
companyRatio = companyRatio.subtract(PERCENT7);
}
// 祖级分销人 customerId
Long parentCustomerPlaceId = customer.getParentCustomerPlace();
if (parentCustomerPlaceId != null) {
// 子财务单的实付金额
BigDecimal fdPayMoney = payMoney.multiply(PERCENT2);
// 生成祖级分销的子财务单
FinancialDetail financialDetail = new FinancialDetail(financialDetailService.createCode(), deptId,
financialMaster.getId(), fdPayMoney, 2, parentCustomerPlaceId);
financialDetailService.insertFinancialDetail(financialDetail);
companyRatio = companyRatio.subtract(PERCENT2);
}
// 平台抽成子财务单的实付金额
BigDecimal fdPayMoney = payMoney.multiply(companyRatio);
// 生成平台抽成的子财务单
FinancialDetail financialDetail = new FinancialDetail(financialDetailService.createCode(), deptId,
financialMaster.getId(), fdPayMoney, 2, parentCustomerPlaceId);
financialDetailService.insertFinancialDetail(financialDetail);
}
}

View File

@ -1,9 +1,12 @@
package com.ghy.web.core;
import com.ghy.common.adapay.callback.PayCallback;
import com.ghy.common.adapay.model.AdapayStatusEnum;
import com.ghy.common.adapay.model.PayReply;
import com.ghy.order.service.OrderDetailService;
import com.ghy.order.service.OrderMasterService;
import com.ghy.payment.service.FinancialMasterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -15,20 +18,24 @@ import javax.annotation.Resource;
@Configuration
public class AfterPay {
private static final Logger logger = LoggerFactory.getLogger(AfterPay.class);
@Resource
OrderMasterService orderMasterService;
@Resource
OrderDetailService orderDetailService;
FinancialMasterService financialMasterService;
@Bean
public PayCallback payCallback() {
return new PayCallback() {
@Override
public void onReply(PayReply reply) {
reply.getStatus();
// TODO 修改 OrderMaster 订单状态
// TODO 修改 OrderDetail 订单状态
// TODO 保存支付结果到MySQL
if (AdapayStatusEnum.succeeded.code.equals(reply.getStatus())) {
// TODO 保存支付结果到 adapay_callback_log
// 修改财务单状态为支付成功
financialMasterService.paySucceeded(reply.getOrderNo(), reply.getPayChannel());
} else {
logger.warn("支付失败:{}", reply);
}
}
};
}

View File

@ -0,0 +1,51 @@
package com.ghy.common.adapay;
/**
* 支付渠道 https://docs.adapay.tech/api/appendix.html#id2
*
* @author HH 2022/5/23
*/
public interface PayChannel {
/**
* 支付宝 App 支付
*/
String ALIPAY = "alipay";
/**
* 支付宝正扫
*/
String ALIPAY_QR = "alipay_qr";
/**
* 支付宝 H5 支付
*/
String ALIPAY_WAP = "alipay_wap";
/**
* 支付宝小程序支付
*/
String ALIPAY_LITE = "alipay_lite";
/**
* 支付宝生活号支付
*/
String ALIPAY_PUB = "alipay_pub";
/**
* 支付宝反扫
*/
String ALIPAY_SCAN = "alipay_scan";
/**
* 这个不是支付渠道
*/
String WX = "wx";
/**
* 微信公众号支付
*/
String WX_PUB = "wx_pub";
/**
* 微信小程序支付
*/
String WX_LITE = "wx_lite";
/**
* 微信反扫
*/
String WX_SCAN = "wx_scan";
}

View File

@ -1,15 +1,22 @@
package com.ghy.common.adapay;
/**
* 支付渠道
* 支付渠道 https://docs.adapay.tech/api/appendix.html#id2
*
* @author HH 2022/3/25
*/
public enum PayChannelEnum {
ALIPAY_QR("alipay_qr", "支付宝正扫"),
WX_LITE("wx_lite", "微信小程序"),
WX_PUB("wx_pub", "微信公众号");
ALIPAY(PayChannel.ALIPAY, "支付宝App支付"),
ALIPAY_QR(PayChannel.ALIPAY_QR, "支付宝正扫"),
ALIPAY_WAP(PayChannel.ALIPAY_WAP, "支付宝H5支付"),
ALIPAY_LITE(PayChannel.ALIPAY_LITE, "支付宝小程序支付"),
ALIPAY_PUB(PayChannel.ALIPAY_PUB, "支付宝生活号支付"),
ALIPAY_SCAN(PayChannel.ALIPAY_SCAN, "支付宝反扫"),
WX_PUB(PayChannel.WX_PUB, "微信公众号"),
WX_LITE(PayChannel.WX_LITE, "微信小程序"),
WX_SCAN(PayChannel.WX_SCAN, "微信反扫");
private final String code;
private final String description;

View File

@ -11,8 +11,8 @@ public enum AdapayStatusEnum {
succeeded("succeeded", "成功"),
failed("failed", "失败");
public String code;
public String description;
public final String code;
public final String description;
AdapayStatusEnum(String code, String description) {
this.code = code;

View File

@ -4,6 +4,8 @@ import com.ghy.common.annotation.Excel;
import com.ghy.common.core.domain.BaseEntity;
import lombok.Data;
import java.util.Date;
/**
* @author clunt
* 细单表(转派后产生的订单)
@ -20,7 +22,7 @@ public class OrderDetail extends BaseEntity {
private String code;
@Excel(name = "主单id", cellType = Excel.ColumnType.NUMERIC)
private Integer orderMasterId;
private Long orderMasterId;
@Excel(name = "主单编码", cellType = Excel.ColumnType.STRING)
private String orderMasterCode;
@ -37,17 +39,14 @@ public class OrderDetail extends BaseEntity {
@Excel(name = "接单师傅id", cellType = Excel.ColumnType.NUMERIC)
private Integer workerId;
@Excel(name = "付款时间", cellType = Excel.ColumnType.STRING)
private String payTime;
@Excel(name = "接单时间", cellType = Excel.ColumnType.STRING)
private String revTime;
private Date revTime;
@Excel(name = "服务开始时间/上门时间", cellType = Excel.ColumnType.STRING)
private String workBeginTime;
private Date workBeginTime;
@Excel(name = "服务完成时间", cellType = Excel.ColumnType.STRING)
private String workFinishTime;
private Date workFinishTime;
}

View File

@ -34,7 +34,7 @@ public class OrderGoods extends BaseEntity {
@Excel(name = "已服务数量", cellType = Excel.ColumnType.NUMERIC)
private Integer serverGoodsNum;
/** 创建时间 */
@Excel(name = "完成时间", cellType = Excel.ColumnType.NUMERIC)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date finishTime;

View File

@ -4,6 +4,8 @@ import com.ghy.common.annotation.Excel;
import com.ghy.common.core.domain.BaseEntity;
import lombok.Data;
import java.util.Date;
/**
* @author clunt
* 主单表(对应付款订单)
@ -41,9 +43,9 @@ public class OrderMaster extends BaseEntity {
private Integer workerId;
@Excel(name = "付款时间", cellType = Excel.ColumnType.STRING)
private String payTime;
private Date payTime;
@Excel(name = "接单时间", cellType = Excel.ColumnType.STRING)
private String revTime;
private Date revTime;
}

View File

@ -25,14 +25,14 @@ public class OrderMasterServiceImpl implements OrderMasterService {
@Resource
private OrderMasterMapper orderMasterMapper;
AtomicLong index = new AtomicLong(1L);
private static final AtomicLong INDEX = new AtomicLong(1L);
private final static ThreadLocal<SimpleDateFormat> dateFormat = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyyMMddHHmmss"));
@Override
public String createOrderCode() {
index.compareAndSet(9999L, 1L);
return "om" + dateFormat.get().format(new Date()) + index.getAndIncrement();
INDEX.compareAndSet(9999L, 1L);
return "om" + dateFormat.get().format(new Date()) + INDEX.getAndIncrement();
}
@Override

View File

@ -13,7 +13,6 @@
<result property="orderType" column="order_type"/>
<result property="orderStatus" column="order_status"/>
<result property="workerId" column="worker_id"/>
<result property="payTime" column="pay_time"/>
<result property="revTime" column="rev_time"/>
<result property="workBeginTime" column="work_begin_time"/>
<result property="workFinishTime" column="work_finish_time"/>
@ -27,12 +26,12 @@
<sql id="selectOrderDetail">
SELECT id,
code,
order_master_id,
order_master_code,
customer_id,
order_type,
order_status,
worker_id,
pay_time,
rev_time,
work_begin_time,
work_finish_time,
@ -51,10 +50,10 @@
<if test="customerId != null and customerId != 0">
AND customer_id = #{customerId}
</if>
<if test="orderType != null and orderType != 0">
<if test="orderType != null">
AND order_type = #{orderType}
</if>
<if test="orderStatus != null and orderStatus != 0">
<if test="orderStatus != null">
AND order_status = #{orderStatus}
</if>
<if test="orderMasterCode != null and orderMasterCode != 0">
@ -67,12 +66,7 @@
</select>
<select id="selectById" parameterType="long" resultMap="OrderDetailResult">
<include refid="selectOrderDetail"/>
<where>
<if test="orderDetailId != null and orderDetailId != 0">
AND id = #{orderDetailId}
</if>
</where>
<include refid="selectOrderDetail"/> WHERE id = #{orderDetailId}
</select>
<delete id="deleteOrderDetailByIds" parameterType="Long">
@ -86,16 +80,15 @@
UPDATE order_detail
<set>
<if test="code != null and code != ''">code = #{code},</if>
<if test="orderMasterId != null and orderMasterId != ''">order_master_id = #{orderMasterId},</if>
<if test="orderMasterId != null and orderMasterId != 0">order_master_id = #{orderMasterId},</if>
<if test="orderMasterCode != null and orderMasterCode != ''">order_master_code = #{orderMasterCode},</if>
<if test="customerId != null and customerId != ''">customer_id = #{customerId},</if>
<if test="orderType != null and orderType != ''">order_type = #{orderType},</if>
<if test="orderStatus != null and orderStatus != ''">order_status = #{orderStatus},</if>
<if test="workerId != null and workerId != ''">worker_id = #{workerId},</if>
<if test="payTime != null and payTime != ''">pay_time = #{payTime},</if>
<if test="revTime != null and revTime != ''">rev_time = #{revTime},</if>
<if test="workBeginTime != null and workBeginTime != ''">work_begin_time = #{workBeginTime},</if>
<if test="workFinishTime != null and workFinishTime != ''">work_finish_time = #{workFinishTime},</if>
<if test="customerId != null and customerId != 0">customer_id = #{customerId},</if>
<if test="orderType != null">order_type = #{orderType},</if>
<if test="orderStatus != null">order_status = #{orderStatus},</if>
<if test="workerId != null and workerId != 0">worker_id = #{workerId},</if>
<if test="revTime != null">rev_time = #{revTime},</if>
<if test="workBeginTime != null">work_begin_time = #{workBeginTime},</if>
<if test="workFinishTime != null">work_finish_time = #{workFinishTime},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = SYSDATE()
</set>
@ -104,31 +97,29 @@
<insert id="insertOrderDetail" parameterType="com.ghy.order.domain.OrderDetail" useGeneratedKeys="true" keyProperty="id">
INSERT INTO order_detail(
<if test="code != null and code != 0">code,</if>
<if test="orderMasterId != null and orderMasterId != ''">order_master_id,</if>
<if test="code != null and code != ''">code,</if>
<if test="orderMasterId != null and orderMasterId != 0">order_master_id,</if>
<if test="orderMasterCode != null and orderMasterCode != ''">order_master_code,</if>
<if test="customerId != null and customerId != ''">customer_id,</if>
<if test="orderType != null and orderType != ''">order_type,</if>
<if test="orderStatus != null and orderStatus != ''">order_status,</if>
<if test="workerId != null and workerId != ''">worker_id,</if>
<if test="payTime != null and payTime != ''">pay_time,</if>
<if test="revTime != null and revTime != ''">rev_time,</if>
<if test="workBeginTime != null and workBeginTime != ''">work_begin_time,</if>
<if test="workFinishTime != null and workFinishTime != ''">work_finish_time,</if>
<if test="customerId != null and customerId != 0">customer_id,</if>
<if test="orderType != null">order_type,</if>
<if test="orderStatus != null">order_status,</if>
<if test="workerId != null and workerId != 0">worker_id,</if>
<if test="revTime != null">rev_time,</if>
<if test="workBeginTime != null">work_begin_time,</if>
<if test="workFinishTime != null">work_finish_time,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)VALUES(
<if test="code != null and code != 0">#{code},</if>
<if test="orderMasterId != null and orderMasterId != ''">o#{orderMasterId},</if>
<if test="code != null and code != ''">#{code},</if>
<if test="orderMasterId != null and orderMasterId != 0">o#{orderMasterId},</if>
<if test="orderMasterCode != null and orderMasterCode != ''">#{orderMasterCode},</if>
<if test="customerId != null and customerId != ''">#{customerId},</if>
<if test="orderType != null and orderType != ''">#{orderType},</if>
<if test="orderStatus != null and orderStatus != ''">#{orderStatus},</if>
<if test="workerId != null and workerId != ''">#{workerId},</if>
<if test="payTime != null and payTime != ''">#{payTime},</if>
<if test="revTime != null and revTime != ''">#{revTime},</if>
<if test="workBeginTime != null and workBeginTime != ''">#{workBeginTime},</if>
<if test="workFinishTime != null and workFinishTime != ''">#{workFinishTime},</if>
<if test="customerId != null and customerId != 0">#{customerId},</if>
<if test="orderType != null">#{orderType},</if>
<if test="orderStatus != null">#{orderStatus},</if>
<if test="workerId != null and workerId != 0">#{workerId},</if>
<if test="revTime != null">#{revTime},</if>
<if test="workBeginTime != null">#{workBeginTime},</if>
<if test="workFinishTime != null">#{workFinishTime},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
SYSDATE()
)

View File

@ -20,19 +20,20 @@
</resultMap>
<sql id="selectOrderGoods">
SELECT order_goods_id, order_id, goods_name, goods_num, server_goods_num, finish_time, create_by, create_time, remark
SELECT order_goods_id, order_id, goods_id, goods_name, goods_num, server_goods_num,
finish_time, create_by, create_time, update_by, update_time, remark
FROM order_goods
</sql>
<update id="updateOrderGoods" parameterType="com.ghy.order.domain.OrderGoods">
UPDATE order_goods
<set>
<if test="orderId != null and orderId != ''">order_id = #{orderId},</if>
<if test="goodsId != null and goodsId != ''">goods_id = #{goodsId},</if>
<if test="orderId != null and orderId != 0">order_id = #{orderId},</if>
<if test="goodsId != null and goodsId != 0">goods_id = #{goodsId},</if>
<if test="goodsName != null and goodsName != ''">goods_name = #{goodsName},</if>
<if test="goodsNum != null and goodsNum != ''">goods_num = #{goodsNum},</if>
<if test="serverGoodsNum != null and serverGoodsNum != ''">server_goods_num = #{serverGoodsNum},</if>
<if test="finishTime != null and finishTime != ''">finish_time = #{finishTime},</if>
<if test="goodsNum != null">goods_num = #{goodsNum},</if>
<if test="serverGoodsNum != null">server_goods_num = #{serverGoodsNum},</if>
<if test="finishTime != null">finish_time = #{finishTime},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = SYSDATE()
</set>
@ -42,21 +43,21 @@
<insert id="insertOrderGoods" parameterType="com.ghy.order.domain.OrderGoods" useGeneratedKeys="true"
keyProperty="id">
INSERT INTO order_goods(
<if test="orderId != null and orderId != ''">order_id,</if>
<if test="goodsId != null and goodsId != ''">goods_id,</if>
<if test="orderId != null and orderId != 0">order_id,</if>
<if test="goodsId != null and goodsId != 0">goods_id,</if>
<if test="goodsName != null and goodsName != ''">goods_name,</if>
<if test="goodsNum != null and goodsNum != ''">goods_num,</if>
<if test="serverGoodsNum != null and serverGoodsNum != ''">server_goods_num,</if>
<if test="finishTime != null and finishTime != ''">finish_time,</if>
<if test="goodsNum != null">goods_num,</if>
<if test="serverGoodsNum != null">server_goods_num,</if>
<if test="finishTime != null">finish_time,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)VALUES(
<if test="orderId != null and orderId != ''">#{orderId},</if>
<if test="goodsId != null and goodsId != ''">#{goodsId},</if>
<if test="orderId != null and orderId != 0">#{orderId},</if>
<if test="goodsId != null and goodsId != 0">#{goodsId},</if>
<if test="goodsName != null and goodsName != ''">#{goodsName},</if>
<if test="goodsNum != null and goodsNum != ''">#{goodsNum},</if>
<if test="serverGoodsNum != null and serverGoodsNum != ''">#{serverGoodsNum},</if>
<if test="finishTime != null and finishTime != ''">#{finishTime},</if>
<if test="goodsNum != null">#{goodsNum},</if>
<if test="serverGoodsNum != null">#{serverGoodsNum},</if>
<if test="finishTime != null">#{finishTime},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
SYSDATE()
)
@ -65,14 +66,14 @@
<select id="selectOrderGoodsList" parameterType="com.ghy.order.domain.OrderGoods" resultMap="OrderGoodsResult">
<include refid="selectOrderGoods"/>
<where>
<if test="orderId != null and orderId != ''">
AND order_id LIKE concat('%', #{orderId}, '%')
<if test="orderId != null and orderId != 0">
AND order_id = #{orderId}
</if>
<if test="goodsId != null and goodsId != 0">
AND goods_id = #{goodsId}
</if>
<if test="goodsName != null and goodsName != 0">
AND goods_name = #{goodsName}
<if test="goodsName != null and goodsName != ''">
AND goods_name LIKE concat('%', #{goodsName}, '%')
</if>
</where>
</select>
@ -87,7 +88,7 @@
</select>
<delete id="deleteOrderGoodsByIds" parameterType="Long">
DELETE FROM order_goods WHERE id IN
DELETE FROM order_goods WHERE order_goods_id IN
<foreach collection="array" item="orderGoodsId" open="(" separator="," close=")">
#{orderGoodsId}
</foreach>

View File

@ -6,6 +6,7 @@
<resultMap id="OrderMasterResult" type="com.ghy.order.domain.OrderMaster">
<id property="id" column="id"/>
<result property="deptId" column="dept_id"/>
<result property="code" column="code"/>
<result property="customerId" column="customer_id"/>
<result property="orderType" column="order_type"/>
@ -24,6 +25,7 @@
<sql id="selectOrderMaster">
SELECT id,
dept_id,
code,
customer_id,
order_type,
@ -42,22 +44,25 @@
<select id="selectOrderMasterList" parameterType="com.ghy.order.domain.OrderMaster" resultMap="OrderMasterResult">
<include refid="selectOrderMaster"/>
<where>
<if test="deptId != null and deptId != 0">
AND dept_id = #{deptId}
</if>
<if test="code != null and code != ''">
AND code LIKE concat('%', #{code}, '%')
AND `code` LIKE concat('%', #{code}, '%')
</if>
<if test="customerId != null and customerId != 0">
AND customer_id = #{customerId}
</if>
<if test="orderType != null and orderType != 0">
<if test="orderType != null">
AND order_type = #{orderType}
</if>
<if test="orderStatus != null and orderStatus != 0">
<if test="orderStatus != null">
AND order_status = #{orderStatus}
</if>
<if test="payType != null and payType != 0">
<if test="payType != null">
AND pay_type = #{payType}
</if>
<if test="payStatus != null and payStatus != 0">
<if test="payStatus != null">
AND pay_status = #{payStatus}
</if>
<if test="workerId != null and workerId != 0">
@ -86,14 +91,14 @@
UPDATE order_master
<set>
<if test="code != null and code != ''">code = #{code},</if>
<if test="customerId != null and customerId != ''">customer_id = #{customerId},</if>
<if test="orderType != null and orderType != ''">order_type = #{orderType},</if>
<if test="orderStatus != null and orderStatus != ''">order_status = #{orderStatus},</if>
<if test="payType != null and payType != ''">pay_type = #{payType},</if>
<if test="payStatus != null and payStatus != ''">pay_status = #{payStatus},</if>
<if test="workerId != null and workerId != ''">worker_id = #{workerId},</if>
<if test="payTime != null and payTime != ''">pay_time = #{payTime},</if>
<if test="revTime != null and revTime != ''">rev_time = #{revTime},</if>
<if test="customerId != null and customerId != 0">customer_id = #{customerId},</if>
<if test="orderType != null">order_type = #{orderType},</if>
<if test="orderStatus != null">order_status = #{orderStatus},</if>
<if test="payType != null">pay_type = #{payType},</if>
<if test="payStatus != null">pay_status = #{payStatus},</if>
<if test="workerId != null and workerId != 0">worker_id = #{workerId},</if>
<if test="payTime != null">pay_time = #{payTime},</if>
<if test="revTime != null">rev_time = #{revTime},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = SYSDATE()
</set>
@ -102,27 +107,29 @@
<insert id="insertOrderMaster" parameterType="com.ghy.order.domain.OrderMaster" useGeneratedKeys="true" keyProperty="id">
INSERT INTO order_master(
<if test="code != null ">code,</if>
<if test="customerId != null and customerId != ''">customer_id,</if>
<if test="orderType != null and orderType != ''">order_type,</if>
<if test="orderStatus != null and orderStatus != ''">order_status,</if>
<if test="payType != null and payType != ''">pay_type,</if>
<if test="payStatus != null and payStatus != ''">pay_status,</if>
<if test="workerId != null and workerId != ''">worker_id,</if>
<if test="payTime != null and payTime != ''">pay_time,</if>
<if test="revTime != null and revTime != ''">rev_time,</if>
<if test="deptId != null and deptId != 0">dept_id,</if>
<if test="code != null and code != ''">code,</if>
<if test="customerId != null and customerId != 0">customer_id,</if>
<if test="orderType != null">order_type,</if>
<if test="orderStatus != null">order_status,</if>
<if test="payType != null">pay_type,</if>
<if test="payStatus != null">pay_status,</if>
<if test="workerId != null and workerId != 0">worker_id,</if>
<if test="payTime != null">pay_time,</if>
<if test="revTime != null">rev_time,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)VALUES(
<if test="deptId != null and deptId != 0">#{deptId},</if>
<if test="code != null">#{code},</if>
<if test="customerId != null and customerId != ''">#{customerId},</if>
<if test="orderType != null and orderType != ''">#{orderType},</if>
<if test="orderStatus != null and orderStatus != ''">#{orderStatus},</if>
<if test="payType != null and payType != ''">#{payType},</if>
<if test="payStatus != null and payStatus != ''">#{payStatus},</if>
<if test="workerId != null and workerId != ''">#{workerId},</if>
<if test="payTime != null and payTime != ''">#{payTime},</if>
<if test="revTime != null and revTime != ''">#{revTime},</if>
<if test="customerId != null and customerId != 0">#{customerId},</if>
<if test="orderType != null">#{orderType},</if>
<if test="orderStatus != null">#{orderStatus},</if>
<if test="payType != null">#{payType},</if>
<if test="payStatus != null">#{payStatus},</if>
<if test="workerId != null and workerId != 0">#{workerId},</if>
<if test="payTime != null">#{payTime},</if>
<if test="revTime != null">#{revTime},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
SYSDATE()
)

View File

@ -18,14 +18,20 @@ public class FinancialDetail extends BaseEntity {
@Excel(name = "序号", cellType = Excel.ColumnType.NUMERIC)
private Long id;
@Excel(name = "编码")
@Excel(name = "商户ID", cellType = Excel.ColumnType.NUMERIC)
private Long deptId;
@Excel(name = "编码", cellType = Excel.ColumnType.STRING)
private String code;
@Excel(name = "子订单序号", cellType = Excel.ColumnType.NUMERIC)
private Long orderMasterId;
@Excel(name = "主财务单ID", cellType = Excel.ColumnType.NUMERIC)
private Long financialMasterId;
@Excel(name = "子订单编码", cellType = Excel.ColumnType.NUMERIC)
private String orderMasterCode;
@Excel(name = "子订单ID", cellType = Excel.ColumnType.NUMERIC)
private Long orderDetailId;
@Excel(name = "子订单编码", cellType = Excel.ColumnType.STRING)
private String orderDetailCode;
@Excel(name = "子单总金额", cellType = Excel.ColumnType.STRING)
private BigDecimal totalMoney;
@ -39,6 +45,15 @@ public class FinancialDetail extends BaseEntity {
@Excel(name = "财务子单类型,师傅转派/多级分销/平台抽成", cellType = Excel.ColumnType.NUMERIC)
private Integer financialDetailType;
/**
* 收款人ID
* 当财务子单类型是师傅转派时 收款人ID是师傅或徒弟的workerId
* 当财务子单类型是多级分销时 收款人ID是分销者的customerId
* 当财务子单类型是平台抽成 无需填写收款人ID
*/
@Excel(name = "收款人ID", cellType = Excel.ColumnType.NUMERIC)
private Long payeeId;
@Excel(name = "支付方式,微信/支付宝/线下", cellType = Excel.ColumnType.NUMERIC)
private Integer payType;
@ -48,4 +63,14 @@ public class FinancialDetail extends BaseEntity {
@Excel(name = "付款时间", cellType = Excel.ColumnType.STRING)
private String payTime;
public FinancialDetail() {
}
public FinancialDetail(String code, Long deptId, Long financialMasterId, BigDecimal payMoney, Integer financialDetailType, Long payeeId) {
this.code = code;
this.financialMasterId = financialMasterId;
this.payMoney = payMoney;
this.financialDetailType = financialDetailType;
this.payeeId = payeeId;
}
}

View File

@ -20,6 +20,12 @@ public class FinancialMaster extends BaseEntity {
@Excel(name = "序号", cellType = Excel.ColumnType.NUMERIC)
private Long id;
@Excel(name = "商户ID", cellType = Excel.ColumnType.NUMERIC)
private Long deptId;
@Excel(name = "编码", cellType = Excel.ColumnType.STRING)
private String code;
@Excel(name = "主订单序号", cellType = Excel.ColumnType.NUMERIC)
private Long orderMasterId;
@ -48,7 +54,8 @@ public class FinancialMaster extends BaseEntity {
public FinancialMaster() {
}
public FinancialMaster(Long orderMasterId, String orderMasterCode, BigDecimal totalMoney, BigDecimal discountMoney, BigDecimal payMoney) {
public FinancialMaster(String code, Long deptId, Long orderMasterId, String orderMasterCode, BigDecimal totalMoney, BigDecimal discountMoney, BigDecimal payMoney) {
this.code = code;
this.orderMasterId = orderMasterId;
this.orderMasterCode = orderMasterCode;
this.totalMoney = totalMoney;

View File

@ -43,4 +43,11 @@ public interface FinancialMasterMapper {
*/
int deleteFinancialMasterByIds(Long[] financialMasterIds);
/**
* 支付成功
*
* @param orderNo 订单号
* @param payType 支付渠道
*/
void paySucceeded(String orderNo, int payType);
}

View File

@ -49,4 +49,10 @@ public interface FinancialDetailService {
* @return 校验结果 1存在 0不存在
*/
String checkFinancialDetailCodeUnique(FinancialDetail financialDetail);
/**
* 生成子财务单ID
*/
String createCode();
}

View File

@ -42,4 +42,16 @@ public interface FinancialMasterService {
*/
int deleteFinancialMasterByIds(String ids);
/**
* 支付成功
*
* @param orderNo 订单号
* @param payChannel 支付渠道
*/
void paySucceeded(String orderNo, String payChannel);
/**
* 创建主财务单CODE
*/
String createCode();
}

View File

@ -8,11 +8,26 @@ import com.ghy.payment.service.FinancialDetailService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import static java.time.temporal.ChronoField.*;
import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
@Service
public class FinancialDetailServiceImpl implements FinancialDetailService {
private static final AtomicLong INDEX = new AtomicLong(1L);
public static final DateTimeFormatter MINI_FORMATTER = new DateTimeFormatterBuilder()
.appendValue(YEAR, 4).appendValue(MONTH_OF_YEAR, 2)
.appendValue(DAY_OF_MONTH, 2).appendValue(HOUR_OF_DAY, 2)
.appendValue(MINUTE_OF_HOUR, 2).appendValue(SECOND_OF_MINUTE, 2).toFormatter();
@Resource
private FinancialDetailMapper financialDetailMapper;
@ -51,4 +66,11 @@ public class FinancialDetailServiceImpl implements FinancialDetailService {
}
return UserConstants.FINANCIAL_CODE_UNIQUE;
}
@Override
public String createCode() {
INDEX.compareAndSet(9999L, 1L);
LocalDateTime now = LocalDateTime.now();
return "fd" + now.format(MINI_FORMATTER) + INDEX.getAndIncrement();
}
}

View File

@ -4,10 +4,21 @@ import com.ghy.common.core.text.Convert;
import com.ghy.payment.domain.FinancialMaster;
import com.ghy.payment.mapper.FinancialMasterMapper;
import com.ghy.payment.service.FinancialMasterService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import static com.ghy.common.adapay.PayChannel.ALIPAY;
import static com.ghy.common.adapay.PayChannel.WX;
import static java.time.temporal.ChronoField.*;
/**
* 商品模块实现类
@ -17,6 +28,15 @@ import java.util.List;
@Service
public class FinancialMasterServiceImpl implements FinancialMasterService {
private static final Logger logger = LoggerFactory.getLogger(FinancialMasterServiceImpl.class);
private static final AtomicLong INDEX = new AtomicLong(1L);
public static final DateTimeFormatter MINI_FORMATTER = new DateTimeFormatterBuilder()
.appendValue(YEAR, 4).appendValue(MONTH_OF_YEAR, 2)
.appendValue(DAY_OF_MONTH, 2).appendValue(HOUR_OF_DAY, 2)
.appendValue(MINUTE_OF_HOUR, 2).appendValue(SECOND_OF_MINUTE, 2).toFormatter();
@Resource
private FinancialMasterMapper financialMasterMapper;
@ -46,4 +66,28 @@ public class FinancialMasterServiceImpl implements FinancialMasterService {
return financialMasterMapper.deleteFinancialMasterByIds(financialMasterIds);
}
@Override
public void paySucceeded(String orderNo, String payChannel) {
int payType;
if (StringUtils.isBlank(payChannel)) {
payType = -1;
logger.warn("OrderNo[{}] Unknown payChannel [{}]!", orderNo, payChannel);
} else if (payChannel.startsWith(WX)) {
payType = 0;
} else if (payChannel.startsWith(ALIPAY)) {
payType = 1;
} else {
payType = -1;
logger.warn("OrderNo[{}] Unknown payChannel [{}]!", orderNo, payChannel);
}
financialMasterMapper.paySucceeded(orderNo, payType);
}
@Override
public String createCode() {
INDEX.compareAndSet(9999L, 1L);
LocalDateTime now = LocalDateTime.now();
return "fm" + now.format(MINI_FORMATTER) + INDEX.getAndIncrement();
}
}

View File

@ -6,16 +6,19 @@
<resultMap id="FinancialDetailResult" type="com.ghy.payment.domain.FinancialDetail">
<id property="id" column="id"/>
<result property="deptId" column="dept_id"/>
<result property="code" column="code"/>
<result property="orderMasterId" column="order_master_id"/>
<result property="orderMasterCode" column="order_master_code"/>
<result property="financialMasterId" column="financial_master_id"/>
<result property="orderDetailId" column="order_detail_id"/>
<result property="orderDetailCode" column="order_detail_code"/>
<result property="totalMoney" column="total_money"/>
<result property="discountMoney" column="discount_money"/>
<result property="payMoney" column="pay_money"/>
<result property="financialDetailType" column="financial_detail_type"/>
<result property="payeeId" column="payee_id"/>
<result property="payType" column="pay_type"/>
<result property="payStatus" column="pay_status"/>
<result property="payTime" column="pay_time"/>
<result property="financialDetailType" column="financial_detail_type"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>

View File

@ -6,6 +6,8 @@
<resultMap id="FinancialMasterResult" type="com.ghy.payment.domain.FinancialMaster">
<id property="id" column="id"/>
<result property="deptId" column="dept_id"/>
<result property="code" column="code"/>
<result property="orderMasterId" column="order_master_id"/>
<result property="orderMasterCode" column="order_master_code"/>
<result property="totalMoney" column="total_money"/>
@ -22,18 +24,8 @@
</resultMap>
<sql id="selectFinancialMaster">
SELECT id,
order_master_id,
order_master_code,
total_money,
discount_money,
pay_money,
pay_type,
pay_status,
pay_time,
create_by,
create_time,
remark
SELECT id, dept_id, code, order_master_id, order_master_code, total_money, discount_money, pay_money,
pay_type, pay_status, pay_time, create_by, create_time, update_by, update_time, remark
FROM financial_master
</sql>
@ -46,10 +38,10 @@
<if test="orderMasterCode != null and orderMasterCode != ''">
AND order_master_code LIKE concat('%', #{orderMasterCode}, '%')
</if>
<if test="payType != null and payType != 0">
<if test="payType != null">
AND pay_type = #{payType}
</if>
<if test="payStatus != null and payStatus != 0">
<if test="payStatus != null">
AND pay_status = #{payStatus}
</if>
</where>
@ -74,39 +66,54 @@
<update id="updateFinancialMaster" parameterType="com.ghy.payment.domain.FinancialMaster">
UPDATE financial_master
<set>
<if test="orderMasterId != null and orderMasterId != ''">order_master_id = #{orderMasterId},</if>
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="code != null and code != ''">`code` = #{code},</if>
<if test="orderMasterId != null and orderMasterId != 0">order_master_id = #{orderMasterId},</if>
<if test="orderMasterCode != null and orderMasterCode != ''">order_master_code = #{orderMasterCode},</if>
<if test="totalMoney != null and totalMoney != ''">total_money = #{totalMoney},</if>
<if test="discountMoney != null and discountMoney != ''">discount_money = #{discountMoney},</if>
<if test="payType != null and payType != ''">pay_type = #{payType},</if>
<if test="payStatus != null and payStatus != ''">pay_status = #{payStatus},</if>
<if test="totalMoney != null">total_money = #{totalMoney},</if>
<if test="discountMoney != null">discount_money = #{discountMoney},</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="payMoney != null and payMoney != ''">pay_money = #{payMoney},</if>
<if test="payMoney != null">pay_money = #{payMoney},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = SYSDATE()
</set>
WHERE id = #{id}
</update>
<update id="paySucceeded">
UPDATE financial_master SET
pay_status = #{payStatus},
pay_type = #{payType},
pay_time = SYSDATE(),
update_time = SYSDATE()
WHERE order_master_code = #{orderNo}
</update>
<insert id="insertFinancialMaster" parameterType="com.ghy.payment.domain.FinancialMaster" useGeneratedKeys="true" keyProperty="id">
INSERT INTO financial_master(
<if test="deptId != null">dept_id,</if>
<if test="code != null and code != ''">`code`,</if>
<if test="orderMasterId != null and orderMasterId != 0">order_master_id,</if>
<if test="orderMasterCode != null and orderMasterCode != ''">order_master_code,</if>
<if test="totalMoney != null and totalMoney != ''">total_money,</if>
<if test="discountMoney != null and discountMoney != ''">discount_money,</if>
<if test="payType != null and payType != ''">pay_type,</if>
<if test="payStatus != null and payStatus != ''">pay_status,</if>
<if test="payMoney != null and payMoney != ''">pay_money,</if>
<if test="totalMoney != null">total_money,</if>
<if test="discountMoney != null">discount_money,</if>
<if test="payType != null">pay_type,</if>
<if test="payStatus != null">pay_status,</if>
<if test="payMoney != null">pay_money,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)VALUES(
<if test="deptId != null">#{deptId},</if>
<if test="code != null and code != ''">#{code},</if>
<if test="orderMasterId != null and orderMasterId != 0">#{orderMasterId},</if>
<if test="orderMasterCode != null and orderMasterCode != ''">#{orderMasterCode},</if>
<if test="totalMoney != null and totalMoney != ''">#{totalMoney},</if>
<if test="discountMoney != null and discountMoney != ''">#{discountMoney},</if>
<if test="payType != null and payType != ''">#{payType},</if>
<if test="payStatus != null and payStatus != ''">#{payStatus},</if>
<if test="payMoney != null and payMoney != ''">#{payMoney},</if>
<if test="totalMoney != null">#{totalMoney},</if>
<if test="discountMoney != null">#{discountMoney},</if>
<if test="payType != null">#{payType},</if>
<if test="payStatus != null">#{payStatus},</if>
<if test="payMoney != null">#{payMoney},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
SYSDATE()
)