From b671918bc69a0cc7db13b8fae2759775bb8ca074 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Tue, 16 Mar 2021 18:13:38 +0800
Subject: [PATCH] Merge branch 'score_shop' of http://120.27.238.55:7000/r/beauty-erp into score_shop

---
 /dev/null                                                                            |   12 --
 zq-erp/src/test/java/com/matrix/JyyTests.java                                        |   47 +++++++++
 zq-erp/src/main/java/com/matrix/system/fenxiao/service/ShopSalesmanApplyService.java |  122 +++++++++++++----------
 zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxSalesmanAction.java      |   11 ++
 zq-erp/src/main/java/com/matrix/core/pojo/VerificationResult.java                    |   14 +-
 zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopOrderV2Dao.xml                  |   24 ++++
 zq-erp/src/main/java/com/matrix/system/shopXcx/dao/ShopOrderV2Dao.java               |   19 +++
 7 files changed, 177 insertions(+), 72 deletions(-)

diff --git a/zq-erp/src/main/java/com/matrix/core/pojo/VerificationResult.java b/zq-erp/src/main/java/com/matrix/core/pojo/VerificationResult.java
index a1c4c70..d4bb932 100644
--- a/zq-erp/src/main/java/com/matrix/core/pojo/VerificationResult.java
+++ b/zq-erp/src/main/java/com/matrix/core/pojo/VerificationResult.java
@@ -8,7 +8,7 @@
 @Data
 public class VerificationResult {
 
-    private boolean result;
+    private boolean judgeResult;
 
     private String  msg;
 
@@ -18,24 +18,24 @@
 
     }
 
-    public static VerificationResult buildVerificationResult(boolean result){
+    public static VerificationResult buildVerificationResult(boolean judgeResult){
         VerificationResult obj=new VerificationResult();
-        obj.result=result;
+        obj.judgeResult =judgeResult;
         return obj ;
     }
 
 
-    public static VerificationResult buildVerificationResult(boolean result,String msg){
+    public static VerificationResult buildVerificationResult(boolean judgeResult,String msg){
         VerificationResult obj=new VerificationResult();
-        obj.result=result;
+        obj.judgeResult =judgeResult;
         obj.msg=msg;
         return obj ;
     }
 
 
-    public static VerificationResult buildVerificationResult(boolean result,Object  info){
+    public static VerificationResult buildVerificationResult(boolean judgeResult,Object  info){
         VerificationResult obj=new VerificationResult();
-        obj.result=result;
+        obj.judgeResult =judgeResult;
         obj.info=info;
         return obj ;
     }
diff --git a/zq-erp/src/main/java/com/matrix/system/fenxiao/service/ShopSalesmanApplyService.java b/zq-erp/src/main/java/com/matrix/system/fenxiao/service/ShopSalesmanApplyService.java
index b797079..d9b69d5 100644
--- a/zq-erp/src/main/java/com/matrix/system/fenxiao/service/ShopSalesmanApplyService.java
+++ b/zq-erp/src/main/java/com/matrix/system/fenxiao/service/ShopSalesmanApplyService.java
@@ -25,7 +25,7 @@
 import com.matrix.system.fenxiao.entity.ShopSalesmanGrade;
 import com.matrix.system.fenxiao.vo.*;
 import com.matrix.system.hive.action.util.QueryUtil;
-import com.matrix.system.shopXcx.dao.ShopOrderDaoV2;
+import com.matrix.system.shopXcx.dao.ShopOrderV2Dao;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -59,7 +59,7 @@
     BizUserService bizUserService;
 
     @Autowired
-    ShopOrderDaoV2 shopOrderDaoV2;
+    ShopOrderV2Dao shopOrderV2Dao;
 
     /**
      * 申请成为推广员
@@ -70,60 +70,65 @@
     public ShopSalesmanApply applyToBeAnSalesman(String openId,String gradeId,String invitationId,int applyWay) {
 
         BizUser loginUser=bizUserDao.findByOpenId(openId);
-        //校验审核状态,和是否重复发起
-        QueryWrapper<ShopSalesmanApply> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("user_id",loginUser.getOpenId());
-        queryWrapper.in("apply_status",Arrays.asList("1,2".split(",")));
-        ShopSalesmanApply checkApply = shopSalesmanApplyDao.selectOne(queryWrapper);
-        if(checkApply==null||
-                checkApply.getApplyStatus()==ShopSalesmanApply.APPLY_STATUS_WTG){
+        //验证申请条件
+        VerificationResult verificationResult = isAbleToBeAnSalesman(openId);
+        if(verificationResult.isJudgeResult()){
+            //校验审核状态,和是否重复发起
+            QueryWrapper<ShopSalesmanApply> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("user_id",loginUser.getOpenId());
+            queryWrapper.in("apply_status",Arrays.asList("1,2".split(",")));
+            ShopSalesmanApply checkApply = shopSalesmanApplyDao.selectOne(queryWrapper);
+            if(checkApply==null||
+                    checkApply.getApplyStatus()==ShopSalesmanApply.APPLY_STATUS_WTG){
 
-            ShopSalesmanApply shopSalesmanApply=new ShopSalesmanApply();
-            shopSalesmanApply.setUserId(openId);
-            
-            shopSalesmanApply.setCreateBy(MatrixConstance.SYSTEM_USER);
-            shopSalesmanApply.setApplyWay(ShopSalesmanApply.APPLY_WAY_SELF);
+                ShopSalesmanApply shopSalesmanApply=new ShopSalesmanApply();
+                shopSalesmanApply.setUserId(openId);
 
-            shopSalesmanApply.setCompanyId(loginUser.getCompanyId());
-            shopSalesmanApply.setUpdateBy(MatrixConstance.SYSTEM_USER);
-            Date date = new Date();
-            shopSalesmanApply.setCreateTime(date);
-            shopSalesmanApply.setUpdateTime(date);
+                shopSalesmanApply.setCreateBy(MatrixConstance.SYSTEM_USER);
+                shopSalesmanApply.setApplyWay(ShopSalesmanApply.APPLY_WAY_SELF);
 
-            if(StringUtils.isNotBlank(invitationId)){
-                shopSalesmanApply.setParentUserId(invitationId);
-            }else if(StringUtils.isNotBlank(loginUser.getParentOpenId())){
-                //如果曾经是被邀请进来的则自动绑定为之前邀请人的下级
-                shopSalesmanApply.setParentUserId(loginUser.getParentOpenId());
-            }
-            if(StringUtils.isNotBlank(gradeId)){
-            	shopSalesmanApply.setGradeId(Long.parseLong(gradeId));
+                shopSalesmanApply.setCompanyId(loginUser.getCompanyId());
+                shopSalesmanApply.setUpdateBy(MatrixConstance.SYSTEM_USER);
+                Date date = new Date();
+                shopSalesmanApply.setCreateTime(date);
+                shopSalesmanApply.setUpdateTime(date);
+
+                if(StringUtils.isNotBlank(invitationId)){
+                    shopSalesmanApply.setParentUserId(invitationId);
+                }else if(StringUtils.isNotBlank(loginUser.getParentOpenId())){
+                    //如果曾经是被邀请进来的则自动绑定为之前邀请人的下级
+                    shopSalesmanApply.setParentUserId(loginUser.getParentOpenId());
+                }
+                if(StringUtils.isNotBlank(gradeId)){
+                    shopSalesmanApply.setGradeId(Long.parseLong(gradeId));
+                }else{
+                    //获取初始等级ID(公司id,是否为初始等级)
+                    QueryWrapper<ShopSalesmanGrade> queryWrapperOrepool = new QueryWrapper<>();
+                    queryWrapperOrepool.eq("company_id", loginUser.getCompanyId());
+                    queryWrapperOrepool.eq("is_default", 1);
+                    ShopSalesmanGrade shopSalesmanGrade = shopSalesmanGradeDao.selectOne(queryWrapperOrepool);
+                    shopSalesmanApply.setGradeId(shopSalesmanGrade.getId());
+                }
+                shopSalesmanApply.setApplyWay(applyWay);
+
+                BusParameterSettings busParameterSettings = busParameterSettingsDao.selectCompanyParamByCode(FenxiaoSettingConstant.FX_AUDIT_METHOD, loginUser.getCompanyId());
+                if(busParameterSettings!=null
+                        &&busParameterSettings.getParamValue().equals("1")){
+                    //自动审核
+                    shopSalesmanApply.setApplyStatus(ShopSalesmanApply.APPLY_STATUS_TG);
+                    bizUserService.setToBeAnSalesman(loginUser.getOpenId(),invitationId);
+
+                }else{
+                    shopSalesmanApply.setApplyStatus(ShopSalesmanApply.APPLY_STATUS_DSH);
+                }
+                shopSalesmanApplyDao.insert(shopSalesmanApply);
+                return  shopSalesmanApply;
             }else{
-                //获取初始等级ID(公司id,是否为初始等级)
-                QueryWrapper<ShopSalesmanGrade> queryWrapperOrepool = new QueryWrapper<>();
-                queryWrapperOrepool.eq("company_id", loginUser.getCompanyId());
-                queryWrapperOrepool.eq("is_default", 1);
-                ShopSalesmanGrade shopSalesmanGrade = shopSalesmanGradeDao.selectOne(queryWrapperOrepool);
-            	shopSalesmanApply.setGradeId(shopSalesmanGrade.getId());
+                throw  new GlobleException("不能重复申请");
             }
-            shopSalesmanApply.setApplyWay(applyWay);
-            
-            BusParameterSettings busParameterSettings = busParameterSettingsDao.selectCompanyParamByCode(FenxiaoSettingConstant.FX_AUDIT_METHOD, loginUser.getCompanyId());
-            if(busParameterSettings!=null
-                    &&busParameterSettings.getParamValue().equals("1")){
-                //自动审核
-                shopSalesmanApply.setApplyStatus(ShopSalesmanApply.APPLY_STATUS_TG);
-                bizUserService.setToBeAnSalesman(loginUser.getOpenId(),invitationId);
-
-            }else{
-                shopSalesmanApply.setApplyStatus(ShopSalesmanApply.APPLY_STATUS_DSH);
-            }
-            shopSalesmanApplyDao.insert(shopSalesmanApply);
-            return  shopSalesmanApply;
         }else{
-            throw  new GlobleException("不能重复申请");
+            throw  new GlobleException(verificationResult.getMsg());
         }
-
     }
 
 
@@ -140,18 +145,29 @@
                 VerificationResult.buildVerificationResult(true);
             case FenxiaoSettingConstant.FX_APPLY_CONDITION_XFZDCP:
                 VerificationResult.buildVerificationResult(true);
+                int buyZdcpCount= shopOrderV2Dao.countBuyZdcp(openId,applyCondition.getParamValue1());
+                if(buyZdcpCount>0){
+                    verificationResult= VerificationResult.buildVerificationResult(true);
+                }else{
+                    verificationResult= VerificationResult.buildVerificationResult(false,"不符合申请条件,请消费指定产品后再申请!");
+                }
+
             case FenxiaoSettingConstant.FX_APPLY_CONDITION_XFRYCP:
-
                 //判断用户是否有确认收货的产品
-                int receivedOrderCount= shopOrderDaoV2.selectReceivedOrderCount(openId);
-
+                int receivedOrderCount= shopOrderV2Dao.selectReceivedOrderCount(openId);
                 if(receivedOrderCount>0){
                     verificationResult= VerificationResult.buildVerificationResult(true);
                 }else{
                     verificationResult= VerificationResult.buildVerificationResult(false,"不符合申请条件,请消费任意产品后再申请!");
                 }
-
             case FenxiaoSettingConstant.FX_APPLY_CONDITION_XCZDJE:
+                Double zdje=Double.parseDouble(applyCondition.getParamValue2());
+                Double yxfje=shopOrderV2Dao.countOrderAmount(openId);
+                if(zdje>yxfje){
+                    verificationResult=VerificationResult.buildVerificationResult(true);
+                }else{
+                    verificationResult= VerificationResult.buildVerificationResult(false,"不符合申请条件,请消费满"+zdje+"元后再申请!");
+                }
                 VerificationResult.buildVerificationResult(true);
             default:
                 VerificationResult.buildVerificationResult(true);
diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxSalesmanAction.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxSalesmanAction.java
index 3e67c28..74cf382 100644
--- a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxSalesmanAction.java
+++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxSalesmanAction.java
@@ -100,10 +100,20 @@
     public AjaxResult applyToBeAnSalesman(@RequestBody Map<String,String> param) {
         BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class);
         String invitationId = param.get("invitationId");
+        if(StringUtils.isNotBlank(invitationId)){
+            BizUser invitationUser = bizUserDao.findByOpenId(invitationId);
+            if(invitationUser.getOpenId().equals(loginUser.getOpenId())) {
+                return AjaxResult.buildFailInstance("不能邀请自己成为推广员");
+            }
+        }
+
         ShopSalesmanApply shopSalesmanApply= shopSalesmanApplyService.applyToBeAnSalesman(loginUser.getOpenId(),"",invitationId,ShopSalesmanApply.APPLY_WAY_SELF);
         loginUser=bizUserDao.selectById(loginUser.getUserId());
         redisUserLoginUtils.updateUserInfo(loginUser);
         return AjaxResult.buildSuccessInstance(shopSalesmanApply);
+
+
+
     }
 
 
@@ -116,6 +126,7 @@
         BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class);
         QueryWrapper<ShopSalesmanApply> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("user_id",loginUser.getOpenId());
+        queryWrapper.eq("apply_status",ShopSalesmanApply.APPLY_STATUS_DSH);
         ShopSalesmanApply shopSalesmanApply = salesmanApplyDao.selectOne(queryWrapper);
         return AjaxResult.buildSuccessInstance(shopSalesmanApply);
     }
diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/dao/ShopOrderDaoV2.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/dao/ShopOrderDaoV2.java
deleted file mode 100644
index 79cdd46..0000000
--- a/zq-erp/src/main/java/com/matrix/system/shopXcx/dao/ShopOrderDaoV2.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.matrix.system.shopXcx.dao;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.matrix.system.shopXcx.bean.ShopOrder;
-
-/**
- * @description 订单表
- */
-public interface ShopOrderDaoV2 extends BaseMapper<ShopOrder> {
-
-	/** 统计已收货订单数 */
-	int selectReceivedOrderCount(String openId);
-}
\ No newline at end of file
diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/dao/ShopOrderV2Dao.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/dao/ShopOrderV2Dao.java
new file mode 100644
index 0000000..b68d63a
--- /dev/null
+++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/dao/ShopOrderV2Dao.java
@@ -0,0 +1,19 @@
+package com.matrix.system.shopXcx.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.matrix.system.shopXcx.bean.ShopOrder;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * @description 订单表
+ */
+public interface ShopOrderV2Dao extends BaseMapper<ShopOrder> {
+
+	/** 统计已收货订单数 */
+	int selectReceivedOrderCount(String openId);
+	/** 统计已收货订单金额 */
+	Double countOrderAmount(String openId);
+
+	/** 统计是否消费过了指定产品 */
+	int countBuyZdcp(@Param("openId") String openId, @Param("productIds")String productIds);
+}
\ No newline at end of file
diff --git a/zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopOrderDaoV2.xml b/zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopOrderDaoV2.xml
deleted file mode 100644
index 427ae0a..0000000
--- a/zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopOrderDaoV2.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="com.matrix.system.shopXcx.dao.ShopOrderDaoV2">
-
-	<select id="selectReceivedOrderCount" resultType="java.lang.Integer">
-		select count(*)  from shop_order where user_id = #{openId} and order_status in (4,5)
-	</select>
-
-
-</mapper>
\ No newline at end of file
diff --git a/zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopOrderV2Dao.xml b/zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopOrderV2Dao.xml
new file mode 100644
index 0000000..04cba28
--- /dev/null
+++ b/zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopOrderV2Dao.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.matrix.system.shopXcx.dao.ShopOrderV2Dao">
+
+	<select id="selectReceivedOrderCount" resultType="java.lang.Integer">
+		select count(*)  from shop_order where user_id = #{openId} and order_status in (4,5)
+	</select>
+
+	<select id="countOrderAmount" resultType="java.lang.Double">
+		select IFNULL(sum(IFNULL( order_money, 0 )),0)  from shop_order where user_id = #{openId} and order_status in (4,5)
+	</select>
+
+	<select id="countBuyZdcp" resultType="java.lang.Integer">
+		select count(*) from shop_order a
+						  left join shop_order_details b on a.id=b.order_id
+		where a.user_id=#{openId}
+		  and  order_status in (4,5)
+		  and find_in_set(b.p_id,#{productIds})
+	</select>
+
+
+</mapper>
\ No newline at end of file
diff --git a/zq-erp/src/test/java/com/matrix/JyyTests.java b/zq-erp/src/test/java/com/matrix/JyyTests.java
new file mode 100644
index 0000000..b2b3243
--- /dev/null
+++ b/zq-erp/src/test/java/com/matrix/JyyTests.java
@@ -0,0 +1,47 @@
+package com.matrix;
+
+import com.matrix.system.shopXcx.dao.ShopOrderV2Dao;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * 测试类示例
+ * 
+ * @author jiangyouyao
+ * @email 512061637@qq.com
+ * @date 2019年2月25日
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = {ZqErpApplication.class},webEnvironment =SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class JyyTests {
+
+
+	@Autowired
+	private ShopOrderV2Dao shopOrderV2Dao;
+
+
+
+	/**
+	 *
+	 */
+	@Test
+	public void testSelectReceivedOrderCount() throws InterruptedException {
+		System.out.println( shopOrderV2Dao.selectReceivedOrderCount("oJkRK4yelehsY4S7I6Ee1ydWtQMI"));
+	}
+
+	@Test
+	public void testCountOrderAmount() throws InterruptedException {
+		System.out.println( shopOrderV2Dao.countOrderAmount("oJkRK4yelehsY4S7I6Ee1ydWtQMI"));
+	}
+
+
+	@Test
+	public void countBuyZdcp() throws InterruptedException {
+		System.out.println( shopOrderV2Dao.countBuyZdcp("oJkRK4yelehsY4S7I6Ee1ydWtQMI","1167,1263,1262"));
+	}
+
+
+}

--
Gitblit v1.9.1