PC下单接口
This commit is contained in:
parent
f7cca0de02
commit
7d7d7ee584
|
|
@ -19,6 +19,7 @@ import com.ghy.order.domain.*;
|
||||||
import com.ghy.order.request.AppOrderAssignRequest;
|
import com.ghy.order.request.AppOrderAssignRequest;
|
||||||
import com.ghy.order.request.AppOrderRequest;
|
import com.ghy.order.request.AppOrderRequest;
|
||||||
import com.ghy.order.request.SysOrderAssignRequest;
|
import com.ghy.order.request.SysOrderAssignRequest;
|
||||||
|
import com.ghy.order.request.SysOrderGoodsStandards;
|
||||||
import com.ghy.order.service.*;
|
import com.ghy.order.service.*;
|
||||||
import com.ghy.payment.domain.FinancialChangeRecord;
|
import com.ghy.payment.domain.FinancialChangeRecord;
|
||||||
import com.ghy.payment.domain.FinancialDetail;
|
import com.ghy.payment.domain.FinancialDetail;
|
||||||
|
|
@ -143,6 +144,7 @@ public class OrderController extends BaseController {
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public AjaxResult sysOrder(@RequestBody SysOrderAssignRequest request) {
|
public AjaxResult sysOrder(@RequestBody SysOrderAssignRequest request) {
|
||||||
|
|
||||||
|
// 判断是否有客户
|
||||||
SysUser sysUser = getSysUser();
|
SysUser sysUser = getSysUser();
|
||||||
Long deptId = sysUser.getDeptId();
|
Long deptId = sysUser.getDeptId();
|
||||||
String loginName = sysUser.getLoginName();
|
String loginName = sysUser.getLoginName();
|
||||||
|
|
@ -154,6 +156,7 @@ public class OrderController extends BaseController {
|
||||||
customerService.insertCustomer(customer);
|
customerService.insertCustomer(customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 判断是否有客户地址
|
||||||
if (request.getProvinceId() == null || request.getCityId() == null || request.getCountryId() == null || StringUtils.isBlank(request.getAddress())) {
|
if (request.getProvinceId() == null || request.getCityId() == null || request.getCountryId() == null || StringUtils.isBlank(request.getAddress())) {
|
||||||
return AjaxResult.error("请填写地址");
|
return AjaxResult.error("请填写地址");
|
||||||
}
|
}
|
||||||
|
|
@ -170,91 +173,72 @@ public class OrderController extends BaseController {
|
||||||
customerAddressService.insertCustomerAddress(customerAddress);
|
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
|
// 订单总价 不能小于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 goodsPrice = orderPrice.divide(BigDecimal.valueOf(totalNum), 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);
|
|
||||||
|
|
||||||
|
// 增加商品
|
||||||
|
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();
|
GoodsStandard standard = new GoodsStandard();
|
||||||
standard.setGoodsStandardName(good.getGoodsName());
|
standard.setGoodsStandardName(deptGoodsCategory.getGoodsCategoryName());
|
||||||
standard.setDeptGoodsCategoryId(dgcIds.get(3));
|
standard.setDeptGoodsCategoryId(deptGoodsCategory.getDeptGoodsCategoryId());
|
||||||
standard.setGoodsCategoryName(dgcNames.get(0));
|
standard.setGoodsCategoryName(deptGoodsCategory.getGoodsCategoryName());
|
||||||
if ((++goodsNum) == (goodsList.size() - 1)) {
|
standard.setGoodsPrice(goodsPrice);
|
||||||
standard.setGoodsPrice(orderPrice.subtract(goodsPriceAccumulative));
|
|
||||||
} else {
|
|
||||||
standard.setGoodsPrice(goodsPrice);
|
|
||||||
goodsPriceAccumulative = goodsPriceAccumulative.add(goodsPrice);
|
|
||||||
}
|
|
||||||
|
|
||||||
goodsService.insertGoods(goods);
|
|
||||||
standard.setGoodsId(goods.getGoodsId());
|
standard.setGoodsId(goods.getGoodsId());
|
||||||
standard.setExtMoney(BigDecimal.ZERO);
|
standard.setExtMoney(BigDecimal.ZERO);
|
||||||
standard.setGoodsNum(999);
|
standard.setGoodsNum(999);
|
||||||
standard.setSaleNum(0);
|
standard.setSaleNum(0);
|
||||||
goodsStandardService.save(Collections.singletonList(standard));
|
goodsStandards.add(standard);
|
||||||
|
});
|
||||||
|
|
||||||
// 生成主单
|
// 生成主单
|
||||||
OrderMaster orderMaster = new OrderMaster();
|
OrderMaster orderMaster = new OrderMaster();
|
||||||
orderMaster.setDeptId(deptId);
|
orderMaster.setDeptId(deptId);
|
||||||
orderMaster.setCode(orderMasterService.createOrderCode());
|
orderMaster.setCode(orderMasterService.createOrderCode());
|
||||||
orderMaster.setOrderType(0);
|
orderMaster.setOrderType(0);
|
||||||
orderMaster.setOrderStatus(OrderStatus.RECEIVE.code());
|
orderMaster.setOrderStatus(OrderStatus.RECEIVE.code());
|
||||||
orderMaster.setAddressId(customerAddress.getCustomerAddressId());
|
orderMaster.setAddressId(customerAddress.getCustomerAddressId());
|
||||||
orderMaster.setPayStatus(PayStatus.WAIT_PAY.getCode());
|
orderMaster.setPayStatus(PayStatus.WAIT_PAY.getCode());
|
||||||
orderMaster.setCreateTime(new Date());
|
orderMaster.setCreateTime(new Date());
|
||||||
orderMaster.setCustomerId(customer.getCustomerId());
|
orderMaster.setCustomerId(customer.getCustomerId());
|
||||||
orderMaster.setGoodsId(goods.getGoodsId());
|
orderMaster.setGoodsId(goods.getGoodsId());
|
||||||
orderMasterService.insertOrderMaster(orderMaster);
|
orderMasterService.insertOrderMaster(orderMaster);
|
||||||
Assert.notNull(orderMaster.getId(), "OrderMaster.id is null!");
|
Assert.notNull(orderMaster.getId(), "OrderMaster.id is null!");
|
||||||
|
|
||||||
// 生成财务主单
|
// 生成财务主单
|
||||||
FinancialMaster financialMaster = new FinancialMaster(financialMasterService.createCode(), deptId,
|
FinancialMaster financialMaster = new FinancialMaster(financialMasterService.createCode(), deptId,
|
||||||
orderMaster.getId(), orderMaster.getCode(), standard.getGoodsPrice(), BigDecimal.ZERO, standard.getGoodsPrice());
|
orderMaster.getId(), orderMaster.getCode(), request.getPrice(), BigDecimal.ZERO, request.getPrice());
|
||||||
financialMaster.setServerMoney(financialMaster.getTotalMoney());
|
financialMaster.setServerMoney(financialMaster.getTotalMoney());
|
||||||
financialMasterService.insertFinancialMaster(financialMaster);
|
financialMasterService.insertFinancialMaster(financialMaster);
|
||||||
Assert.notNull(financialMaster.getId(), "FinancialMaster.id is null!");
|
Assert.notNull(financialMaster.getId(), "FinancialMaster.id is null!");
|
||||||
|
|
||||||
// 生成提成类子财务单
|
// 生成提成类子财务单
|
||||||
createDeptFinancialDetail(standard, deptId, financialMaster);
|
// createDeptFinancialDetail(standard, deptId, financialMaster);
|
||||||
|
|
||||||
// 生成商品订单
|
// 生成商品订单
|
||||||
OrderGoods orderGoods = new OrderGoods(orderMaster.getId(), standard.getGoodsStandardId(),
|
goodsStandards.forEach(goodsStandard -> {
|
||||||
standard.getGoodsStandardName(), good.getNumber(), 0);
|
OrderGoods orderGoods = new OrderGoods(orderMaster.getId(), goodsStandard.getGoodsStandardId(),
|
||||||
|
goodsStandard.getGoodsStandardName(), goodsStandard.getGoodsNum(), 0);
|
||||||
orderGoodsService.insertOrderGoods(orderGoods);
|
orderGoodsService.insertOrderGoods(orderGoods);
|
||||||
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// 选择消费者(消费者类型为渠道商、不需要) --
|
// 选择消费者(消费者类型为渠道商、不需要) --
|
||||||
|
|
||||||
|
|
@ -268,48 +252,48 @@ public class OrderController extends BaseController {
|
||||||
return AjaxResult.success("下单成功");
|
return AjaxResult.success("下单成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 平台下单时生成子财务单的方法
|
// * 平台下单时生成子财务单的方法
|
||||||
* 只有平台扣点和截流扣点
|
// * 只有平台扣点和截流扣点
|
||||||
*
|
// *
|
||||||
* @param goodsStandard 商品
|
// * @param goodsStandard 商品
|
||||||
* @param deptId 企业ID
|
// * @param deptId 企业ID
|
||||||
* @param financialMaster 主财务单
|
// * @param financialMaster 主财务单
|
||||||
*/
|
// */
|
||||||
private void createDeptFinancialDetail(GoodsStandard goodsStandard, Long deptId, FinancialMaster financialMaster) {
|
// private void createDeptFinancialDetail(List<GoodsStandard> goodsStandard, Long deptId, FinancialMaster financialMaster) {
|
||||||
// 平台
|
// // 平台
|
||||||
BigDecimal deptMoney = BigDecimal.ZERO;
|
// BigDecimal deptMoney = BigDecimal.ZERO;
|
||||||
// 截流扣点
|
// // 截流扣点
|
||||||
BigDecimal specialMoney = BigDecimal.ZERO;
|
// BigDecimal specialMoney = BigDecimal.ZERO;
|
||||||
// 服务金额
|
// // 服务金额
|
||||||
BigDecimal serverMoney = financialMaster.getServerMoney();
|
// BigDecimal serverMoney = financialMaster.getServerMoney();
|
||||||
// 扣点设置类目
|
// // 扣点设置类目
|
||||||
DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.get(goodsStandard.getDeptGoodsCategoryId());
|
// DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.get(goodsStandard.get(0).getDeptGoodsCategoryId());
|
||||||
// 平台扣点 = 平台金额 + 商品单价 * 扣点比例
|
// // 平台扣点 = 平台金额 + 商品单价 * 扣点比例
|
||||||
deptMoney = deptMoney.add(deptGoodsCategory.getDeptMoney())
|
// deptMoney = deptMoney.add(deptGoodsCategory.getDeptMoney())
|
||||||
.add(goodsStandard.getGoodsPrice().multiply(BigDecimal.valueOf(Double.parseDouble(deptGoodsCategory.getDeptRate()))));
|
// .add(goodsStandard.getGoodsPrice().multiply(BigDecimal.valueOf(Double.parseDouble(deptGoodsCategory.getDeptRate()))));
|
||||||
// 截流扣点 = 截流金额 + 商品单价 * 扣点比例
|
// // 截流扣点 = 截流金额 + 商品单价 * 扣点比例
|
||||||
specialMoney = specialMoney.add(deptGoodsCategory.getRetainMoney())
|
// specialMoney = specialMoney.add(deptGoodsCategory.getRetainMoney())
|
||||||
.add(goodsStandard.getGoodsPrice().multiply(BigDecimal.valueOf(Double.parseDouble(deptGoodsCategory.getRetainRate()))));
|
// .add(goodsStandard.getGoodsPrice().multiply(BigDecimal.valueOf(Double.parseDouble(deptGoodsCategory.getRetainRate()))));
|
||||||
// 平台扣点记录
|
// // 平台扣点记录
|
||||||
FinancialDetail deptDetail = new FinancialDetail(deptId, financialDetailService.createCode(),
|
// FinancialDetail deptDetail = new FinancialDetail(deptId, financialDetailService.createCode(),
|
||||||
financialMaster.getId(), financialMaster.getCode(), deptMoney, FinancialDetailType.PLATFORM_FEE.getCode(), null);
|
// financialMaster.getId(), financialMaster.getCode(), deptMoney, FinancialDetailType.PLATFORM_FEE.getCode(), null);
|
||||||
financialDetailService.insertFinancialDetail(deptDetail);
|
// financialDetailService.insertFinancialDetail(deptDetail);
|
||||||
// 剩余服务金额
|
// // 剩余服务金额
|
||||||
serverMoney = serverMoney.subtract(deptMoney);
|
// serverMoney = serverMoney.subtract(deptMoney);
|
||||||
|
//
|
||||||
// 截流扣点记录
|
// // 截流扣点记录
|
||||||
FinancialDetail retainDetail = new FinancialDetail(deptId, financialDetailService.createCode(),
|
// FinancialDetail retainDetail = new FinancialDetail(deptId, financialDetailService.createCode(),
|
||||||
financialMaster.getId(), financialMaster.getCode(), specialMoney, FinancialDetailType.PLATFORM_FEE.getCode(), null);
|
// financialMaster.getId(), financialMaster.getCode(), specialMoney, FinancialDetailType.PLATFORM_FEE.getCode(), null);
|
||||||
financialDetailService.insertFinancialDetail(retainDetail);
|
// financialDetailService.insertFinancialDetail(retainDetail);
|
||||||
// 剩余服务金额
|
// // 剩余服务金额
|
||||||
serverMoney = serverMoney.subtract(specialMoney);
|
// serverMoney = serverMoney.subtract(specialMoney);
|
||||||
|
//
|
||||||
FinancialMaster fmUpdate = new FinancialMaster();
|
// FinancialMaster fmUpdate = new FinancialMaster();
|
||||||
fmUpdate.setId(financialMaster.getId());
|
// fmUpdate.setId(financialMaster.getId());
|
||||||
fmUpdate.setServerMoney(serverMoney);
|
// fmUpdate.setServerMoney(serverMoney);
|
||||||
financialMasterService.updateFinancialMaster(financialMaster);
|
// financialMasterService.updateFinancialMaster(financialMaster);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分配订单
|
* 分配订单
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,17 @@ package com.ghy.order.request;
|
||||||
import com.ghy.order.domain.OrderTemplateGoods;
|
import com.ghy.order.domain.OrderTemplateGoods;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class SysOrderAssignRequest {
|
public class SysOrderAssignRequest {
|
||||||
|
|
||||||
// 商品
|
|
||||||
private List<OrderTemplateGoods> goods;
|
|
||||||
|
|
||||||
private Long category1;
|
private Long category1;
|
||||||
private Long category2;
|
private Long category2;
|
||||||
private Long category3;
|
private Long category3;
|
||||||
private Long category4;
|
|
||||||
|
private List<SysOrderGoodsStandards> orderGoodsStandards;
|
||||||
|
|
||||||
// 商品品牌
|
// 商品品牌
|
||||||
private String goodsBrand;
|
private String goodsBrand;
|
||||||
|
|
@ -30,7 +29,7 @@ public class SysOrderAssignRequest {
|
||||||
// 服务地址ID
|
// 服务地址ID
|
||||||
private Long addressId;
|
private Long addressId;
|
||||||
// 发布价格(限制整数)
|
// 发布价格(限制整数)
|
||||||
private Integer price;
|
private BigDecimal price;
|
||||||
|
|
||||||
private Long provinceId;
|
private Long provinceId;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue