Browse Source

Merge remote-tracking branch 'origin/dev' into dev

lazhaoqian 3 years ago
parent
commit
d159251cef

+ 2 - 0
blade-service-api/blade-deliver-goods-api/src/main/java/org/springblade/deliver/goods/entity/Delivery.java

@@ -363,4 +363,6 @@ public class Delivery implements Serializable {
 	@ApiModelProperty("积分/溢付款处理类型 add 增加积分  repealAdd 撤销增加溢积分  reduce 消费溢积分  repealReduce 撤销消费溢积分")
 	@TableField(exist = false)
 	private String overpayment;
+
+	private BigDecimal createProfit;
 }

+ 6 - 0
blade-service-api/blade-purchase-sales-api/src/main/java/org/springblade/purchase/sales/feign/IOrderDescClient.java

@@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import java.util.List;
+
 /**
  * @author caifc
  * @date 2021-10-21 22:28
@@ -22,6 +24,7 @@ public interface IOrderDescClient {
 	String UPDATE_ORDER=API_PREFIX+"/updateOrder";
 	String GET_BY_ORDER_NO=API_PREFIX+"/getByOrderNo";
 	String GET_BY_ID=API_PREFIX+"/getById";
+	String GET_BY_CONDITIONS=API_PREFIX+"/getByConditions";
 
 	/**
 	 * 修改采购订单状态
@@ -37,4 +40,7 @@ public interface IOrderDescClient {
 	@GetMapping(GET_BY_ID)
 	Order getById(@RequestParam("id") Long id);
 
+	@PostMapping(GET_BY_CONDITIONS)
+	R<List<Order>> getByConditions(@RequestBody Order order);
+
 }

+ 94 - 0
blade-service/blade-deliver-goods/src/main/java/org/springblade/deliver/goods/service/impl/DeliveryServiceImpl.java

@@ -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("更新客户返利信息失败");
+		}
+	}
+
 }

+ 27 - 0
blade-service/blade-purchase-sales/src/main/java/org/springblade/purchase/sales/feign/OrderDescClient.java

@@ -3,6 +3,7 @@ package org.springblade.purchase.sales.feign;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 
 
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import lombok.AllArgsConstructor;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tenant.annotation.NonDS;
@@ -15,6 +16,9 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RestController;
 import springfox.documentation.annotations.ApiIgnore;
 
+import java.util.Collections;
+import java.util.List;
+
 @NonDS
 @ApiIgnore()
 @RestController
@@ -52,5 +56,28 @@ public class OrderDescClient implements IOrderDescClient {
 		return iOrderService.getById(id);
 	}
 
+	//销售专用查询
+	@Override
+	@PostMapping(GET_BY_CONDITIONS)
+	public R<List<Order>> getByConditions(Order order)
+	{
+		LambdaQueryWrapper<Order> orderLambdaQueryWrapper=new LambdaQueryWrapper<>();
+		orderLambdaQueryWrapper.eq(Order::getTenantId, AuthUtil.getTenantId());
+		orderLambdaQueryWrapper.eq(Order::getIsDeleted, 0);
+		orderLambdaQueryWrapper.eq(Order::getOrderNo,order.getOrderNo());
+		orderLambdaQueryWrapper.eq(Order::getBillType,"XS");
+		orderLambdaQueryWrapper.eq(Order::getTradeType,order.getTradeType());
+		List<Order> list = iOrderService.list(orderLambdaQueryWrapper);
+		if(CollectionUtils.isNotEmpty(list))
+		{
+			return R.data(list);
+		}
+		else
+		{
+			return R.data(Collections.EMPTY_LIST);
+		}
+
+	}
+
 
 }