多级分销+平台扣点+截留扣点生成细单
This commit is contained in:
parent
b074e3fbce
commit
6c88cd78f9
|
|
@ -5,9 +5,11 @@ import com.ghy.common.core.domain.AjaxResult;
|
|||
import com.ghy.common.utils.StringUtils;
|
||||
import com.ghy.customer.domain.Customer;
|
||||
import com.ghy.customer.service.CustomerService;
|
||||
import com.ghy.goods.domain.DeptGoodsCategory;
|
||||
import com.ghy.goods.domain.Goods;
|
||||
import com.ghy.goods.domain.GoodsStandard;
|
||||
import com.ghy.goods.request.AppGoodsRequest;
|
||||
import com.ghy.goods.service.DeptGoodsCategoryService;
|
||||
import com.ghy.goods.service.GoodsService;
|
||||
import com.ghy.goods.service.GoodsStandardService;
|
||||
import com.ghy.order.domain.OrderDetail;
|
||||
|
|
@ -55,6 +57,9 @@ public class OrderController extends BaseController {
|
|||
@Autowired
|
||||
private GoodsService goodsService;
|
||||
|
||||
@Autowired
|
||||
private DeptGoodsCategoryService deptGoodsCategoryService;
|
||||
|
||||
@Autowired
|
||||
private WorkerService workerService;
|
||||
|
||||
|
|
@ -199,7 +204,7 @@ public class OrderController extends BaseController {
|
|||
Assert.notNull(financialMaster.getId(), "FinancialMaster.id is null!");
|
||||
|
||||
//生成财务子单
|
||||
createFinancialDetail(deptId, customer, payMoney, financialMaster);
|
||||
createFinancialDetail(goodsList.get(0).getDeptGoodsCategoryId(), deptId, customer, payMoney, financialMaster);
|
||||
|
||||
// 生成商品订单
|
||||
Map<Long, GoodsStandard> goodsMap = goodsList.stream().filter(Objects::nonNull)
|
||||
|
|
@ -217,48 +222,70 @@ public class OrderController extends BaseController {
|
|||
/**
|
||||
* 生成财务子单
|
||||
*
|
||||
* @param deptGoodsCategoryId 商品类目id
|
||||
* @param deptId 商户ID
|
||||
* @param customer 消费者
|
||||
* @param payMoney 实付金额
|
||||
* @param financialMaster 财务主单
|
||||
*/
|
||||
private void createFinancialDetail(Long deptId, Customer customer, BigDecimal payMoney, FinancialMaster financialMaster) {
|
||||
private void createFinancialDetail(Long deptGoodsCategoryId, Long deptId, Customer customer, BigDecimal payMoney, FinancialMaster financialMaster) {
|
||||
// 是否为0元购 是的话下面就不用多级分销了
|
||||
if (BigDecimal.ZERO.equals(payMoney)) {
|
||||
return;
|
||||
}
|
||||
// 公司抽成比例 初始10%
|
||||
BigDecimal companyRatio = BigDecimal.valueOf(0.1);
|
||||
|
||||
// 上级分销人的 customerId
|
||||
/* 1 平台服务服务费 */
|
||||
DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.selectOneByGoodsCategoryId(deptGoodsCategoryId);
|
||||
BigDecimal deptRate = new BigDecimal(deptGoodsCategory.getDeptRate());
|
||||
BigDecimal deptMoney = deptGoodsCategory.getDeptMoney();
|
||||
|
||||
BigDecimal deptTotal = payMoney.multiply(deptRate).add(deptMoney);
|
||||
|
||||
FinancialDetail deptDetail = new FinancialDetail(financialDetailService.createCode(), deptId,
|
||||
financialMaster.getId(), financialMaster.getCode(), deptTotal, 3, null);
|
||||
financialDetailService.insertFinancialDetail(deptDetail);
|
||||
|
||||
/* 2 截留扣点 */
|
||||
BigDecimal retainRate = new BigDecimal(deptGoodsCategory.getRetainRate());
|
||||
BigDecimal retainMoney = deptGoodsCategory.getRetainMoney();
|
||||
|
||||
BigDecimal retainTotal = payMoney.multiply(retainRate).add(retainMoney);
|
||||
|
||||
FinancialDetail retainDetail = new FinancialDetail(financialDetailService.createCode(), deptId,
|
||||
financialMaster.getId(), financialMaster.getCode(), retainTotal, 2, null);
|
||||
financialDetailService.insertFinancialDetail(retainDetail);
|
||||
|
||||
/* 3 分销扣点 */
|
||||
BigDecimal deptPlaceTotal = BigDecimal.ZERO;
|
||||
|
||||
Long customerPlaceId = customer.getCustomerPlace();
|
||||
BigDecimal onePlaceMoney = payMoney.multiply(new BigDecimal(deptGoodsCategory.getOneRate()));
|
||||
BigDecimal twoPlaceMoney = payMoney.multiply(new BigDecimal(deptGoodsCategory.getTwoRate()));
|
||||
BigDecimal threePlaceMoney = payMoney.multiply(new BigDecimal(deptGoodsCategory.getThreeRate()));
|
||||
|
||||
// 一级分销
|
||||
if (customerPlaceId != null) {
|
||||
// 子财务单的实付金额
|
||||
BigDecimal fdPayMoney = payMoney.multiply(PERCENT7);
|
||||
// 生成上级分销的子财务单
|
||||
FinancialDetail financialDetail = new FinancialDetail(financialDetailService.createCode(), deptId,
|
||||
financialMaster.getId(), financialMaster.getCode(), fdPayMoney, 2, customerPlaceId);
|
||||
financialMaster.getId(), financialMaster.getCode(), onePlaceMoney, 2, customerPlaceId);
|
||||
financialDetailService.insertFinancialDetail(financialDetail);
|
||||
companyRatio = companyRatio.subtract(PERCENT7);
|
||||
}else {
|
||||
deptPlaceTotal = deptPlaceTotal.add(onePlaceMoney);
|
||||
}
|
||||
|
||||
// 祖级分销人 customerId
|
||||
// 二级分销
|
||||
Long parentCustomerPlaceId = customer.getParentCustomerPlace();
|
||||
if (parentCustomerPlaceId != null) {
|
||||
// 子财务单的实付金额
|
||||
BigDecimal fdPayMoney = payMoney.multiply(PERCENT2);
|
||||
// 生成祖级分销的子财务单
|
||||
FinancialDetail financialDetail = new FinancialDetail(financialDetailService.createCode(), deptId,
|
||||
financialMaster.getId(), financialMaster.getCode(), fdPayMoney, 2, parentCustomerPlaceId);
|
||||
financialMaster.getId(), financialMaster.getCode(), twoPlaceMoney, 2, parentCustomerPlaceId);
|
||||
financialDetailService.insertFinancialDetail(financialDetail);
|
||||
companyRatio = companyRatio.subtract(PERCENT2);
|
||||
}else {
|
||||
deptPlaceTotal = deptPlaceTotal.add(twoPlaceMoney);
|
||||
}
|
||||
|
||||
// 平台抽成子财务单的实付金额
|
||||
BigDecimal fdPayMoney = payMoney.multiply(companyRatio);
|
||||
// 生成平台抽成的子财务单
|
||||
// 平台分销
|
||||
deptPlaceTotal = deptPlaceTotal.add(threePlaceMoney);
|
||||
FinancialDetail financialDetail = new FinancialDetail(financialDetailService.createCode(), deptId,
|
||||
financialMaster.getId(), financialMaster.getCode(), fdPayMoney, 2, parentCustomerPlaceId);
|
||||
financialMaster.getId(), financialMaster.getCode(), deptPlaceTotal, 2, null);
|
||||
financialDetailService.insertFinancialDetail(financialDetail);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@
|
|||
DELETE FROM customer WHERE customer_id = #{customerId}
|
||||
</delete>
|
||||
|
||||
<select id="selectByCustomerId" resultType="com.ghy.customer.domain.Customer">
|
||||
<select id="selectByCustomerId" resultMap="CustomerResult">
|
||||
<include refid="selectCustomer"/>
|
||||
<where>
|
||||
<if test="customerId != null and customerId != 0">
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.ghy.common.annotation.Excel;
|
|||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -32,6 +33,18 @@ public class DeptGoodsCategory extends GoodsCategory {
|
|||
@Excel(name = "三级分销扣点比例", cellType = Excel.ColumnType.STRING)
|
||||
private String threeRate;
|
||||
|
||||
@Excel(name = "平台扣点", cellType = Excel.ColumnType.STRING)
|
||||
private String deptRate;
|
||||
|
||||
@Excel(name = "平台固定扣金额", cellType = Excel.ColumnType.STRING)
|
||||
private BigDecimal deptMoney;
|
||||
|
||||
@Excel(name = "截留扣点", cellType = Excel.ColumnType.STRING)
|
||||
private String retainRate;
|
||||
|
||||
@Excel(name = "截留金额", cellType = Excel.ColumnType.STRING)
|
||||
private BigDecimal retainMoney;
|
||||
|
||||
private Long parentCategoryId;
|
||||
|
||||
private List<DeptGoodsCategory> child;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@
|
|||
<result property="oneRate" column="one_rate"/>
|
||||
<result property="twoRate" column="two_rate"/>
|
||||
<result property="threeRate" column="three_rate"/>
|
||||
<result property="deptRate" column="dept_rate"/>
|
||||
<result property="deptMoney" column="dept_money"/>
|
||||
<result property="retainRate" column="retain_rate"/>
|
||||
<result property="retainMoney" column="retain_money"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
|
|
@ -25,14 +29,15 @@
|
|||
|
||||
<sql id="selectDeptGoodsCategory">
|
||||
SELECT dept_goods_category_id, dept_id, goods_category_id, category_sort, is_hot,
|
||||
one_rate, two_rate, three_rate, create_by, create_time, remark
|
||||
one_rate, two_rate, three_rate, dept_rate, dept_money, retain_rate, retain_money, create_by, create_time, remark
|
||||
FROM dept_goods_category
|
||||
</sql>
|
||||
|
||||
<sql id="selectJoin">
|
||||
SELECT dgc.dept_goods_category_id, dgc.dept_id, dgc.goods_category_id, dgc.category_sort,
|
||||
dgc.one_rate, dgc.two_rate, dgc.three_rate, dgc.create_by, dgc.create_time, dgc.remark,
|
||||
gc.goods_category_name, dgc.is_hot, gc.level, gc.parent_category_id, gc.type, gc.status
|
||||
gc.goods_category_name, dgc.is_hot, gc.level, gc.parent_category_id, gc.type, gc.status,
|
||||
dgc.dept_rate, dgc.dept_money, dgc.retain_rate, dgc.retain_money
|
||||
FROM dept_goods_category dgc LEFT JOIN goods_category gc ON dgc.goods_category_id = gc.goods_category_id
|
||||
</sql>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue