|
@@ -5,7 +5,9 @@ import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -68,6 +70,16 @@ import com.zhongzheng.modules.order.vo.OrderPayVo;
|
|
|
import com.zhongzheng.modules.order.vo.OrderVo;
|
|
|
import com.zhongzheng.modules.system.domain.SysOldOrg;
|
|
|
import com.zhongzheng.modules.system.service.ISysOldOrgService;
|
|
|
+import com.zhongzheng.modules.top.financial.domain.TopCostTp;
|
|
|
+import com.zhongzheng.modules.top.financial.domain.TopCostTpItem;
|
|
|
+import com.zhongzheng.modules.top.financial.service.ITopCostTpItemService;
|
|
|
+import com.zhongzheng.modules.top.financial.service.ITopCostTpService;
|
|
|
+import com.zhongzheng.modules.top.financial.vo.TopCostTpItemVo;
|
|
|
+import com.zhongzheng.modules.top.financial.vo.TopCostTpVo;
|
|
|
+import com.zhongzheng.modules.top.goods.bo.TopOldOrderGoodsAddBo;
|
|
|
+import com.zhongzheng.modules.top.goods.domain.TopCourseBusiness;
|
|
|
+import com.zhongzheng.modules.top.goods.domain.TopCourseEducationType;
|
|
|
+import com.zhongzheng.modules.top.goods.domain.TopCourseProjectType;
|
|
|
import com.zhongzheng.modules.user.domain.User;
|
|
|
import com.zhongzheng.modules.user.domain.UserExamGoods;
|
|
|
import com.zhongzheng.modules.user.service.IUserExamGoodsService;
|
|
@@ -169,6 +181,11 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
@Autowired
|
|
|
private IActivityGoodsPriceService iActivityGoodsPriceService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ITopCostTpService topCostTpService;
|
|
|
+ @Autowired
|
|
|
+ private ITopCostTpItemService topCostTpItemService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public OrderVo queryById(Long orderId) {
|
|
@@ -699,6 +716,13 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
}
|
|
|
add.setStatus(1);
|
|
|
}
|
|
|
+ if (ObjectUtils.isNotNull(bo.getCreateSysUserId()) && bo.getCreateSysUserId() == -1){
|
|
|
+ //todo 旧系统订单
|
|
|
+
|
|
|
+
|
|
|
+ }else {
|
|
|
+ orderCostHandle(add);
|
|
|
+ }
|
|
|
this.save(add);
|
|
|
//处理收费商品,生成计费单
|
|
|
Map<String, Object> billRs = null;
|
|
@@ -910,6 +934,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
payAddBo.setPayPrice(payPrice);
|
|
|
iOrderPayService.insertByAddBo(payAddBo);
|
|
|
}
|
|
|
+ //C端订单成本处理
|
|
|
+ orderCostHandle(add);
|
|
|
this.save(add);
|
|
|
|
|
|
//判断是否红包活动订单
|
|
@@ -943,6 +969,87 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
return payResult;
|
|
|
}
|
|
|
|
|
|
+ private void orderCostHandle(Order add) {
|
|
|
+ add.setCheckStatus(1);//C端订单不需要审核
|
|
|
+ add.setRefundStatus(0);
|
|
|
+ add.setInvoiceStatus(0);
|
|
|
+ add.setCreditStatus(0);
|
|
|
+ add.setOrderRefund(BigDecimal.ZERO);
|
|
|
+ add.setOrderRefunded(BigDecimal.ZERO);
|
|
|
+ add.setOrderUncollected(add.getPayPrice());
|
|
|
+ add.setOrderReceived(BigDecimal.ZERO);
|
|
|
+ add.setOrderCost(BigDecimal.ZERO);
|
|
|
+ add.setOrderProfit(BigDecimal.ZERO);
|
|
|
+
|
|
|
+ String TenantId = ServletUtils.getRequest().getHeader("TenantId");
|
|
|
+ //成本和盈亏
|
|
|
+ // 获取企业默认成本模板
|
|
|
+ TopCostTp costTp = topCostTpService.getOne(new LambdaQueryWrapper<TopCostTp>()
|
|
|
+ .eq(TopCostTp::getTenantId, TenantId).eq(TopCostTp::getDefaultStatus, 1).last("limit 1"));
|
|
|
+ if (ObjectUtils.isNotNull(costTp)){
|
|
|
+ List<OrderGoods> orderGoodsList = iOrderGoodsService
|
|
|
+ .list(new LambdaQueryWrapper<OrderGoods>()
|
|
|
+ .eq(OrderGoods::getOrderSn, add.getOrderSn())
|
|
|
+ .eq(OrderGoods::getStatus, 1));
|
|
|
+
|
|
|
+ TopCostTpVo topCostTpVo = BeanUtil.toBean(costTp, TopCostTpVo.class);
|
|
|
+ List<TopCostTpItemVo> itemVoList = new ArrayList<>();
|
|
|
+ //成本项
|
|
|
+ BigDecimal costTotal = new BigDecimal("0.00");//成本
|
|
|
+ BigDecimal profitTotal = new BigDecimal("0.00"); //盈亏
|
|
|
+ for (OrderGoods orderGoods : orderGoodsList) {
|
|
|
+ BigDecimal goodsPrice = orderGoods.getGoodsRealPrice();
|
|
|
+ //商品业务层 新系统默认是学校业务
|
|
|
+ String businessName = iOrderGoodsService.getBusinessById(orderGoods.getOrderGoodsId());
|
|
|
+ List<TopCostTpItem> items = topCostTpItemService.getCostByBusiness(businessName, costTp.getTpId());
|
|
|
+ if (CollectionUtils.isEmpty(items)) {
|
|
|
+ //匹配不到成本项
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //根据订单金额匹配成本阶梯
|
|
|
+ List<TopCostTpItem> tpItems = items.stream().filter(x ->
|
|
|
+ (ObjectUtils.isNull(x.getMinValue()) && ObjectUtils.isNull(x.getMaxValue()))
|
|
|
+ || (goodsPrice.compareTo(x.getMinValue()) > 0 && goodsPrice.compareTo(x.getMaxValue()) < 0)
|
|
|
+ || (goodsPrice.compareTo(x.getMinValue()) == 0 && goodsPrice.compareTo(x.getMaxValue()) == 0)).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(tpItems)) {
|
|
|
+ //匹配不到成本项阶梯值
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (tpItems.size() > 1) {
|
|
|
+ //匹配到多个成本项
|
|
|
+ throw new CustomException(String.format("成本项阶梯匹配有误!(有多个)请检查【%s,价格:%s】", businessName, goodsPrice.toString()));
|
|
|
+ }
|
|
|
+ //换算订单成本和盈亏
|
|
|
+ TopCostTpItem topCostTpItem = tpItems.stream().findFirst().get();
|
|
|
+ BigDecimal cost = new BigDecimal("0.00");//成本
|
|
|
+ BigDecimal profit = new BigDecimal("0.00"); //盈亏
|
|
|
+ BigDecimal bigDecimal = new BigDecimal("100");
|
|
|
+ switch (topCostTpItem.getItemType()) {
|
|
|
+ case 1://百分比
|
|
|
+ BigDecimal divide = topCostTpItem.getTypeValue().divide(bigDecimal);
|
|
|
+ cost = goodsPrice.multiply(divide);
|
|
|
+ profit = goodsPrice.subtract(cost);
|
|
|
+ break;
|
|
|
+ case 2://固定金额
|
|
|
+ cost = topCostTpItem.getTypeValue();
|
|
|
+ profit = goodsPrice.subtract(cost);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ costTotal = costTotal.add(cost);
|
|
|
+ profitTotal = profitTotal.add(profit);
|
|
|
+ itemVoList.add(BeanUtil.toBean(topCostTpItem, TopCostTpItemVo.class));
|
|
|
+ topCostTpVo.setItemList(itemVoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ add.setOrderCost(costTotal);
|
|
|
+ add.setOrderProfit(profitTotal);
|
|
|
+ add.setCostJson(JSONObject.toJSONString(topCostTpVo));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Map<String, String> placeGzhOrder(OrderAddBo bo) {
|
|
|
String key = "ORDER-" + "-" + bo.getUserId();
|
|
@@ -1101,6 +1208,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
payAddBo.setPayPrice(payPrice);
|
|
|
iOrderPayService.insertByAddBo(payAddBo);
|
|
|
}
|
|
|
+ //C端订单成本处理
|
|
|
+ orderCostHandle(add);
|
|
|
this.save(add);
|
|
|
//处理免费商品
|
|
|
for (OrderGoods orderGoods : freeList) {
|
|
@@ -1254,6 +1363,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
payAddBo.setPayPrice(payPrice);
|
|
|
iOrderPayService.insertByAddBo(payAddBo);
|
|
|
}
|
|
|
+ //C端订单成本处理
|
|
|
+ orderCostHandle(add);
|
|
|
this.save(add);
|
|
|
|
|
|
//处理免费商品
|