|
|
@@ -22,9 +22,11 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import io.seata.spring.annotation.GlobalTransactional;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.client.entity.BasicCorpsProfitChange;
|
|
|
import org.springblade.client.entity.CorpsDesc;
|
|
|
import org.springblade.client.entity.StorageDesc;
|
|
|
import org.springblade.client.feign.*;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.secure.utils.SecureUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
|
@@ -41,6 +43,8 @@ import org.springblade.deliver.goods.vo.DeliveryVO;
|
|
|
import org.springblade.deliver.goods.mapper.DeliveryMapper;
|
|
|
import org.springblade.deliver.goods.service.IDeliveryService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springblade.purchase.sales.entity.Order;
|
|
|
+import org.springblade.purchase.sales.feign.IOrderDescClient;
|
|
|
import org.springblade.purchase.sales.feign.IOrderItemsClient;
|
|
|
import org.springblade.stock.entity.StockGoods;
|
|
|
import org.springblade.stock.feign.IStockGoodsClient;
|
|
|
@@ -72,6 +76,8 @@ public class DeliveryServiceImpl extends ServiceImpl<DeliveryMapper, Delivery> i
|
|
|
private IStockGoodsClient stockGoodsClient;
|
|
|
private IOrderItemsClient iOrderItemsClient;
|
|
|
private IStorageClient iStorageClient;//库区信息
|
|
|
+ private ICorpsProfitChangeClient corpsProfitChangeClient;
|
|
|
+ private IOrderDescClient orderDescClient;
|
|
|
|
|
|
private final DeliveryItemsServiceImpl iDeliveryItemsService;
|
|
|
|
|
|
@@ -192,6 +198,40 @@ public class DeliveryServiceImpl extends ServiceImpl<DeliveryMapper, Delivery> i
|
|
|
@GlobalTransactional
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public R submit(Delivery delivery) {
|
|
|
+ //计算返利
|
|
|
+ if(delivery.getTradeType().equals("GN"))
|
|
|
+ {
|
|
|
+ Order order=new Order();
|
|
|
+ order.setOrderNo(delivery.getSrcOrderNo());
|
|
|
+ order.setBillType(delivery.getBillType());
|
|
|
+ order.setTradeType(delivery.getTradeType());
|
|
|
+ R<List<Order>> byConditions = orderDescClient.getByConditions(order);
|
|
|
+ if(!byConditions.isSuccess()||CollectionUtils.isEmpty(byConditions.getData()))
|
|
|
+ {
|
|
|
+ throw new SecurityException("修改返利:回查销售订单出错");
|
|
|
+ }
|
|
|
+ List<Order> orderList = byConditions.getData();
|
|
|
+ if(orderList.size()>1)
|
|
|
+ {
|
|
|
+ throw new SecurityException("修改返利:存在多条订单号相同的数据");
|
|
|
+ }
|
|
|
+ Order saleOrder = orderList.get(0);
|
|
|
+
|
|
|
+ //确认发货
|
|
|
+ if(delivery.getDeliveryType() == 1)
|
|
|
+ {
|
|
|
+ this.createProfit(saleOrder,delivery.getCreateProfit());
|
|
|
+ }
|
|
|
+ //撤销发货
|
|
|
+ else if(delivery.getDeliveryType() == 2)
|
|
|
+ {
|
|
|
+ this.createProfit(saleOrder,delivery.getCreateProfit().negate());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
String billStatus = null;//订单状态
|
|
|
if (delivery.getDeliveryType() != null && delivery.getDeliveryType() == DeliveryEnum.DELIVER.getType()){
|
|
|
billStatus = DeliveryStatusEnum.DELIVER.getType();
|
|
|
@@ -468,4 +508,58 @@ public class DeliveryServiceImpl extends ServiceImpl<DeliveryMapper, Delivery> i
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public void createProfit(Order order,BigDecimal createProfit)
|
|
|
+ {
|
|
|
+ //检查是否使用返利,如果使用返利
|
|
|
+ BasicCorpsProfitChange basicCorpsProfitChange=new BasicCorpsProfitChange();
|
|
|
+ basicCorpsProfitChange.setCorpId(order.getCorpId());
|
|
|
+ basicCorpsProfitChange.setOrderId(order.getId());
|
|
|
+ basicCorpsProfitChange.setOrderNo(order.getOrderNo());
|
|
|
+ basicCorpsProfitChange.setCreateTime(new Date());
|
|
|
+ basicCorpsProfitChange.setCreateUser(AuthUtil.getUserId());
|
|
|
+
|
|
|
+ //检查是否含有产生返利,如果有, 需要增加客户的本月待到账返利
|
|
|
+ if(createProfit!=null && createProfit.compareTo(BigDecimal.ZERO)==1)
|
|
|
+ {
|
|
|
+ //增加客户的月返利
|
|
|
+ basicCorpsProfitChange.setChangeMonthProfit(createProfit);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改原销售订单产生返利字段
|
|
|
+ order.setCreateProfit(order.getCreateProfit().add(createProfit));
|
|
|
+ R r = orderDescClient.updateOrder(order);
|
|
|
+ if(!r.isSuccess())
|
|
|
+ {
|
|
|
+ throw new SecurityException("回改原销售订单失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //新增返利变动记录
|
|
|
+ R save = corpsProfitChangeClient.save(basicCorpsProfitChange);
|
|
|
+ if(!save.isSuccess())
|
|
|
+ {
|
|
|
+ throw new SecurityException("保存返利变动记录失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改客户返利
|
|
|
+ R<CorpsDesc> corpMessage = corpsDescClient.getCorpMessage(order.getCorpId());
|
|
|
+ if(!corpMessage.isSuccess()||corpMessage.getData()==null)
|
|
|
+ {
|
|
|
+ throw new SecurityException("未查到客户记录");
|
|
|
+ }
|
|
|
+ CorpsDesc corpsDesc = corpMessage.getData();
|
|
|
+ corpsDesc.setMonthProfit(basicCorpsProfitChange.getChangeMonthProfit()==null?new BigDecimal("0").add(corpsDesc.getMonthProfit()):basicCorpsProfitChange.getChangeMonthProfit().add(corpsDesc.getMonthProfit()));
|
|
|
+ if(corpsDesc.getMonthProfit().compareTo(new BigDecimal("0"))==-1)
|
|
|
+ {
|
|
|
+ throw new SecurityException("修改客户返利失败:本月待到账返利不能为负数");
|
|
|
+ }
|
|
|
+ //更新客户返利情况
|
|
|
+ R corpsUpdate = corpsDescClient.corpsUpdate(corpsDesc);
|
|
|
+ if(!corpsUpdate.isSuccess())
|
|
|
+ {
|
|
|
+ throw new SecurityException("更新客户返利信息失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|