From 99e77740b6b2c5a9e774e365bc136910e1b59793 Mon Sep 17 00:00:00 2001
From: 935090232@qq.com <ak473600000>
Date: Sun, 14 Mar 2021 07:21:12 +0800
Subject: [PATCH] 推广员申请接口

---
 zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/OrderTask.java      |   89 -----------------
 zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/SalesOrderTask.java |  186 +++++++++++++++++++++++++++++++++++++
 zq-erp/src/main/java/com/matrix/config/RabbitMqConfig.java                |    8 +
 3 files changed, 192 insertions(+), 91 deletions(-)

diff --git a/zq-erp/src/main/java/com/matrix/config/RabbitMqConfig.java b/zq-erp/src/main/java/com/matrix/config/RabbitMqConfig.java
index b05d58b..a1dac18 100644
--- a/zq-erp/src/main/java/com/matrix/config/RabbitMqConfig.java
+++ b/zq-erp/src/main/java/com/matrix/config/RabbitMqConfig.java
@@ -35,6 +35,9 @@
 
     public static final String MQ_EXCHANGE_A = "hive_exchange_A";
 
+    //订阅模式
+    public static final String MQ_EXCHANGE_FANOUT = "hive_exchange_fanout";
+
     @Bean
     VipCreateTask VipCreateTask() {
         return new VipCreateTask();
@@ -68,13 +71,14 @@
 
         //声明一个交换机
         rabiitMqTemplate.exchangeDeclare(MQ_EXCHANGE_A+evn, "direct");
-        rabiitMqTemplate.exchangeDeclare(MQ_EXCHANGE_A+"cf", "direct");
+        rabiitMqTemplate.exchangeDeclare(MQ_EXCHANGE_FANOUT+evn, "fanout");
 
         List<MqTask> taskList = new ArrayList<>();
 
         //注册RabbitMq任务
         taskList.add(new MqTask(MQ_EXCHANGE_A + evn, MQTaskRouting.CREATE_VIP + evn, MQTaskRouting.CREATE_VIP + evn, VipCreateTask()));
-        taskList.add(new MqTask(MQ_EXCHANGE_A + evn, MQTaskRouting.CREATE_ORDER + evn,MQTaskRouting.CREATE_ORDER + evn,OrderrCreateTask()));
+        //订阅模式
+        taskList.add(new MqTask(MQ_EXCHANGE_FANOUT + evn, MQTaskRouting.CREATE_ORDER + evn,MQTaskRouting.CREATE_ORDER + evn,OrderrCreateTask()));
         taskList.add(new MqTask(MQ_EXCHANGE_A + evn, MQTaskRouting.SEND_TEMPLATE_MSG + evn,MQTaskRouting.SEND_TEMPLATE_MSG + evn, TemplateMsgTask()));
         taskList.add(new MqTask(MQ_EXCHANGE_A + evn, MQTaskRouting.ORDER_OUT_SOTORE + evn,MQTaskRouting.ORDER_OUT_SOTORE + evn, OrderOutSotoreTask()));
         taskList.add(new MqTask(MQ_EXCHANGE_A + evn, MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG + evn,MQTaskRouting.SEND_UNIFORM_TEMPLATE_MSG + evn, UniformMsgSentTask()));
diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/OrderTask.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/OrderTask.java
index fd5b64f..0e20288 100644
--- a/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/OrderTask.java
+++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/OrderTask.java
@@ -251,96 +251,7 @@
         order.setDetails(orderDetails);
         //同步订单到erp
         synchronizationOrderToErp(order);
-        //处理分销订单
-        handleExtensionOrder(order);
 
     }
 
-    /**
-     * 处理分销订单
-     * @param order
-     */
-    @Transactional
-    void handleExtensionOrder(ShopOrder order) {
-        //判读客户是否存在上级,存在则产生上级的收益
-        BizUser bizUser = bizUserService.findByOpenId(order.getUserId());
-        if(StringUtils.isNotBlank(bizUser.getParentOpenId())){
-            LogUtil.debug("处理分销订单userOpid={}",bizUser.getOpenId());
-            //存在上级
-            ShopSalesmanOrder salesmanOrder=new ShopSalesmanOrder();
-            salesmanOrder.setCompanyId(order.getCompanyId());
-            salesmanOrder.setCreateBy(MatrixConstance.SYSTEM_USER);
-            salesmanOrder.setUpdateBy(MatrixConstance.SYSTEM_USER);
-            salesmanOrder.setCreateTime(new Date());
-            salesmanOrder.setUpdateTime(new Date());
-            salesmanOrder.setOrderId(Long.parseLong(order.getId()+""));
-            salesmanOrder.setUserId(order.getUserId());
-            salesmanOrder.setSalesUserId(bizUser.getParentOpenId());
-            salesmanOrder.setRevenueType(ShopSalesmanOrder.REVENUE_TYPE_SALES);
-            salesmanOrder.setOrderStatus(ShopSalesmanOrder.STATUS_DJS);
-            Double salesAmount=0D;
-            Double invitationAmount=0D;
-            Double orderTotal=0D;
-            Double zk=1D;
-
-            BizUser salesMan=bizUserService.findByOpenId(bizUser.getParentOpenId());
-            BizUser invitationMan=null;
-            ShopSalesmanOrder invitationOrder=null;
-            boolean hasInvitationMan=StringUtils.isNotBlank(salesMan.getParentOpenId());
-
-            //判断推广员是否还存在上级,存在则计算邀请收益
-            if(hasInvitationMan){
-                invitationMan=bizUserService.findByOpenId(salesMan.getParentOpenId());
-                 invitationOrder=new ShopSalesmanOrder();
-                BeanUtils.copyProperties(salesmanOrder,invitationOrder);
-                invitationOrder.setSalesUserId(invitationMan.getOpenId());
-                invitationOrder.setRevenueType(ShopSalesmanOrder.REVENUE_TYPE_INVITATION);
-            }
-
-            //收益计算
-            for (ShopOrderDetails item:order.getDetails() ){
-                if(StringUtils.isNotBlank(item.getShopProduct().getAttrValues())
-                && item.getShopProduct().getAttrValues().contains("分销商城")){
-                    if(item.getShopSku().getSealesPrice()==null
-                    ||item.getShopSku().getSealesPrice().doubleValue()==0){
-                        //按分销等级计算
-                        ShopSalesmanGrade shopSalesmanGrade = shopSalesmanGradeDao.selectById(salesMan.getSalesmanGrade());
-                        salesAmount+=item.getTotalPrice().doubleValue()*(shopSalesmanGrade.getSealesCommission()/100);
-
-                        if(hasInvitationMan){
-                            ShopSalesmanGrade invitationManGrade = shopSalesmanGradeDao.selectById(invitationMan.getSalesmanGrade());
-                            invitationAmount+=item.getTotalPrice().doubleValue()*(invitationManGrade.getInvitationCommission()/100);
-                        }
-
-                    }else{
-                        //按产品设置的推广金额计算
-                        salesAmount+=item.getShopSku().getSealesPrice().doubleValue()*item.getCount();
-                        if(hasInvitationMan){
-                            invitationAmount+=item.getShopSku().getInvitationPrice().doubleValue()*item.getCount();
-                        }
-                    }
-                    orderTotal+=item.getTotalPrice().doubleValue();
-                }
-            }
-            if(salesAmount>0){
-                //整体的优惠金额折算成折扣,* 佣金
-                zk=order.getOrderMoney().doubleValue()/orderTotal;
-                salesAmount=salesAmount*zk;
-                salesmanOrder.setAmount(salesAmount);
-                shopSalesmanOrderDao.insert(salesmanOrder);
-
-                if(hasInvitationMan){
-                    invitationAmount=invitationAmount*zk;
-                    invitationOrder.setAmount(invitationAmount);
-                    shopSalesmanOrderDao.insert(invitationOrder);
-                }
-            }
-
-
-        }else{
-            LogUtil.debug("不存在父级userOpid={}",bizUser.getOpenId());
-        }
-
-
-    }
 }
diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/SalesOrderTask.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/SalesOrderTask.java
new file mode 100644
index 0000000..d7f846c
--- /dev/null
+++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/mqTask/SalesOrderTask.java
@@ -0,0 +1,186 @@
+package com.matrix.system.shopXcx.mqTask;
+
+
+import com.matrix.biz.bean.BizUser;
+import com.matrix.biz.service.BizUserService;
+import com.matrix.core.constance.MatrixConstance;
+import com.matrix.core.tools.LogUtil;
+import com.matrix.core.tools.StringUtils;
+import com.matrix.system.common.dao.BusParameterSettingsDao;
+import com.matrix.system.fenxiao.dao.ShopSalesmanGradeDao;
+import com.matrix.system.fenxiao.dao.ShopSalesmanOrderDao;
+import com.matrix.system.fenxiao.entity.ShopSalesmanGrade;
+import com.matrix.system.fenxiao.entity.ShopSalesmanOrder;
+import com.matrix.system.hive.dao.SysOrderDao;
+import com.matrix.system.hive.dao.SysOrderItemDao;
+import com.matrix.system.hive.dao.SysVipInfoDao;
+import com.matrix.system.hive.service.CodeService;
+import com.matrix.system.hive.service.ShoppingGoodsService;
+import com.matrix.system.hive.service.SysOrderService;
+import com.matrix.system.shopXcx.bean.ShopOrder;
+import com.matrix.system.shopXcx.bean.ShopOrderDetails;
+import com.matrix.system.shopXcx.dao.ShopOrderDao;
+import com.matrix.system.shopXcx.dao.ShopOrderDetailsDao;
+import com.matrix.system.shopXcx.dao.ShopSkuDao;
+import com.rabbitmq.client.DeliverCallback;
+import com.rabbitmq.client.Delivery;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 微商城订单同步到erp系统
+ */
+@Component
+public class SalesOrderTask implements DeliverCallback {
+
+
+    @Autowired
+    ShopOrderDao shopOrderDao;
+    @Autowired
+    ShopOrderDetailsDao shopOrderDetailsDao;
+
+    @Autowired
+    BizUserService bizUserService;
+
+
+    @Autowired
+    private SysVipInfoDao vipDap;
+
+    @Autowired
+    SysVipInfoDao vipDao;
+
+    @Autowired
+    CodeService codeService;
+
+    @Autowired
+    SysOrderDao sysOrderDao;
+
+    @Autowired
+    ShoppingGoodsService shoppingGoodsService;
+
+    @Autowired
+    SysOrderItemDao orderItemDao;
+
+    @Autowired
+    SysOrderService orderService;
+
+    @Autowired
+    ShopSkuDao shopSkuDao;
+
+    @Autowired
+    BusParameterSettingsDao parameterSettingsDao;
+
+
+    @Autowired
+    private ShopSalesmanOrderDao shopSalesmanOrderDao;
+
+    @Autowired
+    private ShopSalesmanGradeDao shopSalesmanGradeDao;
+
+
+    @Override
+    public void handle(String consumerTag, Delivery message) throws IOException {
+
+        String orderId = new String(message.getBody(), "UTF-8");
+        LogUtil.debug("收到分销订单任务orderId={}", orderId);
+        //获取订单信息
+        ShopOrder order = shopOrderDao.selectById(Integer.valueOf(orderId));
+        //获取订单详情
+        List<ShopOrderDetails> orderDetails = shopOrderDetailsDao.selectByOrderId(Integer.valueOf(orderId));
+        //处理分销订单
+        handleExtensionOrder(order);
+
+    }
+
+    /**
+     * 处理分销订单
+     * @param order
+     */
+    @Transactional
+    void handleExtensionOrder(ShopOrder order) {
+        //判读客户是否存在上级,存在则产生上级的收益
+        BizUser bizUser = bizUserService.findByOpenId(order.getUserId());
+        if(StringUtils.isNotBlank(bizUser.getParentOpenId())){
+            LogUtil.debug("处理分销订单userOpid={}",bizUser.getOpenId());
+            //存在上级
+            ShopSalesmanOrder salesmanOrder=new ShopSalesmanOrder();
+            salesmanOrder.setCompanyId(order.getCompanyId());
+            salesmanOrder.setCreateBy(MatrixConstance.SYSTEM_USER);
+            salesmanOrder.setUpdateBy(MatrixConstance.SYSTEM_USER);
+            salesmanOrder.setCreateTime(new Date());
+            salesmanOrder.setUpdateTime(new Date());
+            salesmanOrder.setOrderId(Long.parseLong(order.getId()+""));
+            salesmanOrder.setUserId(order.getUserId());
+            salesmanOrder.setSalesUserId(bizUser.getParentOpenId());
+            salesmanOrder.setRevenueType(ShopSalesmanOrder.REVENUE_TYPE_SALES);
+            salesmanOrder.setOrderStatus(ShopSalesmanOrder.STATUS_DJS);
+            Double salesAmount=0D;
+            Double invitationAmount=0D;
+            Double orderTotal=0D;
+            Double zk=1D;
+
+            BizUser salesMan=bizUserService.findByOpenId(bizUser.getParentOpenId());
+            BizUser invitationMan=null;
+            ShopSalesmanOrder invitationOrder=null;
+            boolean hasInvitationMan=StringUtils.isNotBlank(salesMan.getParentOpenId());
+
+            //判断推广员是否还存在上级,存在则计算邀请收益
+            if(hasInvitationMan){
+                invitationMan=bizUserService.findByOpenId(salesMan.getParentOpenId());
+                 invitationOrder=new ShopSalesmanOrder();
+                BeanUtils.copyProperties(salesmanOrder,invitationOrder);
+                invitationOrder.setSalesUserId(invitationMan.getOpenId());
+                invitationOrder.setRevenueType(ShopSalesmanOrder.REVENUE_TYPE_INVITATION);
+            }
+
+            //收益计算
+            for (ShopOrderDetails item:order.getDetails() ){
+                if(StringUtils.isNotBlank(item.getShopProduct().getAttrValues())
+                && item.getShopProduct().getAttrValues().contains("分销商城")){
+                    if(item.getShopSku().getSealesPrice()==null
+                    ||item.getShopSku().getSealesPrice().doubleValue()==0){
+                        //按分销等级计算
+                        ShopSalesmanGrade shopSalesmanGrade = shopSalesmanGradeDao.selectById(salesMan.getSalesmanGrade());
+                        salesAmount+=item.getTotalPrice().doubleValue()*(shopSalesmanGrade.getSealesCommission()/100);
+
+                        if(hasInvitationMan){
+                            ShopSalesmanGrade invitationManGrade = shopSalesmanGradeDao.selectById(invitationMan.getSalesmanGrade());
+                            invitationAmount+=item.getTotalPrice().doubleValue()*(invitationManGrade.getInvitationCommission()/100);
+                        }
+
+                    }else{
+                        //按产品设置的推广金额计算
+                        salesAmount+=item.getShopSku().getSealesPrice().doubleValue()*item.getCount();
+                        if(hasInvitationMan){
+                            invitationAmount+=item.getShopSku().getInvitationPrice().doubleValue()*item.getCount();
+                        }
+                    }
+                    orderTotal+=item.getTotalPrice().doubleValue();
+                }
+            }
+            if(salesAmount>0){
+                //整体的优惠金额折算成折扣,* 佣金
+                zk=order.getOrderMoney().doubleValue()/orderTotal;
+                salesAmount=salesAmount*zk;
+                salesmanOrder.setAmount(salesAmount);
+                shopSalesmanOrderDao.insert(salesmanOrder);
+
+                if(hasInvitationMan){
+                    invitationAmount=invitationAmount*zk;
+                    invitationOrder.setAmount(invitationAmount);
+                    shopSalesmanOrderDao.insert(invitationOrder);
+                }
+            }
+        }else{
+            LogUtil.debug("不存在父级userOpid={}",bizUser.getOpenId());
+        }
+
+
+    }
+}

--
Gitblit v1.9.1