PC下单接口

This commit is contained in:
kuang.yife 2023-05-21 00:29:24 +08:00
parent f7cca0de02
commit 7d7d7ee584
3 changed files with 120 additions and 119 deletions

View File

@ -19,6 +19,7 @@ import com.ghy.order.domain.*;
import com.ghy.order.request.AppOrderAssignRequest;
import com.ghy.order.request.AppOrderRequest;
import com.ghy.order.request.SysOrderAssignRequest;
import com.ghy.order.request.SysOrderGoodsStandards;
import com.ghy.order.service.*;
import com.ghy.payment.domain.FinancialChangeRecord;
import com.ghy.payment.domain.FinancialDetail;
@ -143,6 +144,7 @@ public class OrderController extends BaseController {
@Transactional(rollbackFor = Exception.class)
public AjaxResult sysOrder(@RequestBody SysOrderAssignRequest request) {
// 判断是否有客户
SysUser sysUser = getSysUser();
Long deptId = sysUser.getDeptId();
String loginName = sysUser.getLoginName();
@ -154,6 +156,7 @@ public class OrderController extends BaseController {
customerService.insertCustomer(customer);
}
// 判断是否有客户地址
if (request.getProvinceId() == null || request.getCityId() == null || request.getCountryId() == null || StringUtils.isBlank(request.getAddress())) {
return AjaxResult.error("请填写地址");
}
@ -170,91 +173,72 @@ public class OrderController extends BaseController {
customerAddressService.insertCustomerAddress(customerAddress);
}
request.setGoodsDeptCategoryId(request.getCategory4());
List<Long> ids = new ArrayList<>();
ids.add(request.getCategory1());
ids.add(request.getCategory2());
ids.add(request.getCategory3());
ids.add(request.getCategory4());
DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.get(request.getGoodsDeptCategoryId());
OrderTemplateGoods orderTemplateGoods = new OrderTemplateGoods();
orderTemplateGoods.setGoodsName(request.getGoodsBrand() + " " + deptGoodsCategory.getGoodsCategoryName());
orderTemplateGoods.setDeptGoodsCategoryIds(ids);
orderTemplateGoods.setDeptGoodsCategoryNames(Collections.singletonList(orderTemplateGoods.getGoodsName()));
request.setGoods(Collections.singletonList(orderTemplateGoods));
String goodsBrand = request.getGoodsBrand();
List<OrderTemplateGoods> goodsList = request.getGoods();
// 订单总价 不能小于0
BigDecimal orderPrice = BigDecimal.valueOf(request.getPrice()).max(BigDecimal.ZERO);
BigDecimal orderPrice = request.getPrice().max(BigDecimal.ZERO);
Integer totalNum = 0;
for (SysOrderGoodsStandards model : request.getOrderGoodsStandards()) {
totalNum = totalNum + model.getGoodsStandardNum();
}
// 商品单价
BigDecimal goodsPrice = orderPrice.divide(BigDecimal.valueOf(goodsList.size()), RoundingMode.HALF_UP);
// 累计商品价格 用来处理商品单价除不尽的情况
BigDecimal goodsPriceAccumulative = BigDecimal.ZERO;
int goodsNum = 0;
// 新增商品 -- 商品不关联师傅,状态为不展示在商城页面
for (OrderTemplateGoods good : goodsList) {
List<Long> dgcIds = good.getDeptGoodsCategoryIds();
List<String> dgcNames = good.getDeptGoodsCategoryNames();
// 商品的4级类要完整
Assert.isTrue(dgcIds != null && dgcIds.size() == 4, "商品类型不正确");
Goods goods = new Goods();
goods.setDeptId(deptId);
goods.setGoodsName(goodsBrand + ' ' + good.getGoodsName());
goods.setGoodsImgUrl(request.getImageUrl());
goods.setGoodsVideoUrl(request.getVideoUrl());
goods.setDeptGoodsCategoryId(dgcIds.get(2));
goods.setDeptGoodsCategoryName(dgcNames.get(0));
goods.setStatus(1);
BigDecimal goodsPrice = orderPrice.divide(BigDecimal.valueOf(totalNum), RoundingMode.HALF_UP);
// 增加商品
Goods goods = new Goods();
goods.setDeptId(deptId);
// 后续改成 三级类目+品牌
goods.setGoodsName(request.getGoodsBrand());
goods.setGoodsImgUrl(request.getImageUrl());
goods.setGoodsVideoUrl(request.getVideoUrl());
goods.setDeptGoodsCategoryId(request.getCategory2());
goods.setStatus(1);
goodsService.insertGoods(goods);
List<GoodsStandard> goodsStandards = new ArrayList<>();
// 生成规格
request.getOrderGoodsStandards().forEach(list->{
DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.selectOneByGoodsCategoryId(list.getDeptCategoryId());
GoodsStandard standard = new GoodsStandard();
standard.setGoodsStandardName(good.getGoodsName());
standard.setDeptGoodsCategoryId(dgcIds.get(3));
standard.setGoodsCategoryName(dgcNames.get(0));
if ((++goodsNum) == (goodsList.size() - 1)) {
standard.setGoodsPrice(orderPrice.subtract(goodsPriceAccumulative));
} else {
standard.setGoodsPrice(goodsPrice);
goodsPriceAccumulative = goodsPriceAccumulative.add(goodsPrice);
}
goodsService.insertGoods(goods);
standard.setGoodsStandardName(deptGoodsCategory.getGoodsCategoryName());
standard.setDeptGoodsCategoryId(deptGoodsCategory.getDeptGoodsCategoryId());
standard.setGoodsCategoryName(deptGoodsCategory.getGoodsCategoryName());
standard.setGoodsPrice(goodsPrice);
standard.setGoodsId(goods.getGoodsId());
standard.setExtMoney(BigDecimal.ZERO);
standard.setGoodsNum(999);
standard.setSaleNum(0);
goodsStandardService.save(Collections.singletonList(standard));
goodsStandards.add(standard);
});
// 生成主单
OrderMaster orderMaster = new OrderMaster();
orderMaster.setDeptId(deptId);
orderMaster.setCode(orderMasterService.createOrderCode());
orderMaster.setOrderType(0);
orderMaster.setOrderStatus(OrderStatus.RECEIVE.code());
orderMaster.setAddressId(customerAddress.getCustomerAddressId());
orderMaster.setPayStatus(PayStatus.WAIT_PAY.getCode());
orderMaster.setCreateTime(new Date());
orderMaster.setCustomerId(customer.getCustomerId());
orderMaster.setGoodsId(goods.getGoodsId());
orderMasterService.insertOrderMaster(orderMaster);
Assert.notNull(orderMaster.getId(), "OrderMaster.id is null!");
// 生成主单
OrderMaster orderMaster = new OrderMaster();
orderMaster.setDeptId(deptId);
orderMaster.setCode(orderMasterService.createOrderCode());
orderMaster.setOrderType(0);
orderMaster.setOrderStatus(OrderStatus.RECEIVE.code());
orderMaster.setAddressId(customerAddress.getCustomerAddressId());
orderMaster.setPayStatus(PayStatus.WAIT_PAY.getCode());
orderMaster.setCreateTime(new Date());
orderMaster.setCustomerId(customer.getCustomerId());
orderMaster.setGoodsId(goods.getGoodsId());
orderMasterService.insertOrderMaster(orderMaster);
Assert.notNull(orderMaster.getId(), "OrderMaster.id is null!");
// 生成财务主单
FinancialMaster financialMaster = new FinancialMaster(financialMasterService.createCode(), deptId,
orderMaster.getId(), orderMaster.getCode(), standard.getGoodsPrice(), BigDecimal.ZERO, standard.getGoodsPrice());
financialMaster.setServerMoney(financialMaster.getTotalMoney());
financialMasterService.insertFinancialMaster(financialMaster);
Assert.notNull(financialMaster.getId(), "FinancialMaster.id is null!");
// 生成财务主单
FinancialMaster financialMaster = new FinancialMaster(financialMasterService.createCode(), deptId,
orderMaster.getId(), orderMaster.getCode(), request.getPrice(), BigDecimal.ZERO, request.getPrice());
financialMaster.setServerMoney(financialMaster.getTotalMoney());
financialMasterService.insertFinancialMaster(financialMaster);
Assert.notNull(financialMaster.getId(), "FinancialMaster.id is null!");
// 生成提成类子财务单
createDeptFinancialDetail(standard, deptId, financialMaster);
// 生成提成类子财务单
// createDeptFinancialDetail(standard, deptId, financialMaster);
// 生成商品订单
OrderGoods orderGoods = new OrderGoods(orderMaster.getId(), standard.getGoodsStandardId(),
standard.getGoodsStandardName(), good.getNumber(), 0);
// 生成商品订单
goodsStandards.forEach(goodsStandard -> {
OrderGoods orderGoods = new OrderGoods(orderMaster.getId(), goodsStandard.getGoodsStandardId(),
goodsStandard.getGoodsStandardName(), goodsStandard.getGoodsNum(), 0);
orderGoodsService.insertOrderGoods(orderGoods);
}
});
// 选择消费者(消费者类型为渠道商不需要) --
@ -268,48 +252,48 @@ public class OrderController extends BaseController {
return AjaxResult.success("下单成功");
}
/**
* 平台下单时生成子财务单的方法
* 只有平台扣点和截流扣点
*
* @param goodsStandard 商品
* @param deptId 企业ID
* @param financialMaster 主财务单
*/
private void createDeptFinancialDetail(GoodsStandard goodsStandard, Long deptId, FinancialMaster financialMaster) {
// 平台
BigDecimal deptMoney = BigDecimal.ZERO;
// 截流扣点
BigDecimal specialMoney = BigDecimal.ZERO;
// 服务金额
BigDecimal serverMoney = financialMaster.getServerMoney();
// 扣点设置类目
DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.get(goodsStandard.getDeptGoodsCategoryId());
// 平台扣点 = 平台金额 + 商品单价 * 扣点比例
deptMoney = deptMoney.add(deptGoodsCategory.getDeptMoney())
.add(goodsStandard.getGoodsPrice().multiply(BigDecimal.valueOf(Double.parseDouble(deptGoodsCategory.getDeptRate()))));
// 截流扣点 = 截流金额 + 商品单价 * 扣点比例
specialMoney = specialMoney.add(deptGoodsCategory.getRetainMoney())
.add(goodsStandard.getGoodsPrice().multiply(BigDecimal.valueOf(Double.parseDouble(deptGoodsCategory.getRetainRate()))));
// 平台扣点记录
FinancialDetail deptDetail = new FinancialDetail(deptId, financialDetailService.createCode(),
financialMaster.getId(), financialMaster.getCode(), deptMoney, FinancialDetailType.PLATFORM_FEE.getCode(), null);
financialDetailService.insertFinancialDetail(deptDetail);
// 剩余服务金额
serverMoney = serverMoney.subtract(deptMoney);
// 截流扣点记录
FinancialDetail retainDetail = new FinancialDetail(deptId, financialDetailService.createCode(),
financialMaster.getId(), financialMaster.getCode(), specialMoney, FinancialDetailType.PLATFORM_FEE.getCode(), null);
financialDetailService.insertFinancialDetail(retainDetail);
// 剩余服务金额
serverMoney = serverMoney.subtract(specialMoney);
FinancialMaster fmUpdate = new FinancialMaster();
fmUpdate.setId(financialMaster.getId());
fmUpdate.setServerMoney(serverMoney);
financialMasterService.updateFinancialMaster(financialMaster);
}
// /**
// * 平台下单时生成子财务单的方法
// * 只有平台扣点和截流扣点
// *
// * @param goodsStandard 商品
// * @param deptId 企业ID
// * @param financialMaster 主财务单
// */
// private void createDeptFinancialDetail(List<GoodsStandard> goodsStandard, Long deptId, FinancialMaster financialMaster) {
// // 平台
// BigDecimal deptMoney = BigDecimal.ZERO;
// // 截流扣点
// BigDecimal specialMoney = BigDecimal.ZERO;
// // 服务金额
// BigDecimal serverMoney = financialMaster.getServerMoney();
// // 扣点设置类目
// DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.get(goodsStandard.get(0).getDeptGoodsCategoryId());
// // 平台扣点 = 平台金额 + 商品单价 * 扣点比例
// deptMoney = deptMoney.add(deptGoodsCategory.getDeptMoney())
// .add(goodsStandard.getGoodsPrice().multiply(BigDecimal.valueOf(Double.parseDouble(deptGoodsCategory.getDeptRate()))));
// // 截流扣点 = 截流金额 + 商品单价 * 扣点比例
// specialMoney = specialMoney.add(deptGoodsCategory.getRetainMoney())
// .add(goodsStandard.getGoodsPrice().multiply(BigDecimal.valueOf(Double.parseDouble(deptGoodsCategory.getRetainRate()))));
// // 平台扣点记录
// FinancialDetail deptDetail = new FinancialDetail(deptId, financialDetailService.createCode(),
// financialMaster.getId(), financialMaster.getCode(), deptMoney, FinancialDetailType.PLATFORM_FEE.getCode(), null);
// financialDetailService.insertFinancialDetail(deptDetail);
// // 剩余服务金额
// serverMoney = serverMoney.subtract(deptMoney);
//
// // 截流扣点记录
// FinancialDetail retainDetail = new FinancialDetail(deptId, financialDetailService.createCode(),
// financialMaster.getId(), financialMaster.getCode(), specialMoney, FinancialDetailType.PLATFORM_FEE.getCode(), null);
// financialDetailService.insertFinancialDetail(retainDetail);
// // 剩余服务金额
// serverMoney = serverMoney.subtract(specialMoney);
//
// FinancialMaster fmUpdate = new FinancialMaster();
// fmUpdate.setId(financialMaster.getId());
// fmUpdate.setServerMoney(serverMoney);
// financialMasterService.updateFinancialMaster(financialMaster);
// }
/**
* 分配订单

View File

@ -3,18 +3,17 @@ package com.ghy.order.request;
import com.ghy.order.domain.OrderTemplateGoods;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
public class SysOrderAssignRequest {
// 商品
private List<OrderTemplateGoods> goods;
private Long category1;
private Long category2;
private Long category3;
private Long category4;
private List<SysOrderGoodsStandards> orderGoodsStandards;
// 商品品牌
private String goodsBrand;
@ -30,7 +29,7 @@ public class SysOrderAssignRequest {
// 服务地址ID
private Long addressId;
// 发布价格(限制整数)
private Integer price;
private BigDecimal price;
private Long provinceId;

View File

@ -0,0 +1,18 @@
package com.ghy.order.request;
import lombok.Data;
/**
* 第四级类目 - 规格 - 数量
* @author clunt
*/
@Data
public class SysOrderGoodsStandards {
private Long deptCategoryId;
private Long goodsStandardId;
private Integer goodsStandardNum;
}