Browse Source

Merge branch 'develop_green' of http://124.70.211.186:3000/hxh/lsa_YOS into develop_green

hu 1 year ago
parent
commit
a4a86548b4
1 changed files with 75 additions and 137 deletions
  1. 75 137
      src/custom/restcontroller/sale/promotion/SQL/促销方案列表查询.sql

+ 75 - 137
src/custom/restcontroller/sale/promotion/SQL/促销方案列表查询.sql

@@ -1,148 +1,86 @@
-SELECT
-	t.* 
-FROM
-	(
-	SELECT
-		t1.promnum,
-		t1.sa_promotionid,
-		t1.promname,
-		t1.remarks,
-		t1.type,
-		t1.sa_accountclassid,
-		t1.sa_brandid,
-		t1.tradefield,
-		t1.orderminqty,
-		t1.orderaddqty,
-		t1.orderminamount,
-		t1.isrelevancepromotion,
-		t1.begdate,
-		t1.enddate,
-		t1.STATUS,
-		t1.createuserid,
-		t1.createby,
-		t1.createdate,
-		t1.checkby,
-		t1.checkdate,
-		t1.sendby,
-		t1.senddate,
-		t1.closeby,
-		t1.closedate,
-		t1.changeuserid,
-		t1.changeby,
-		t1.changedate,
-		t1.sa_openpromotionid,
-		t1.openamount,
-		t2.brandname,
-		t3.accountno,
-		t3.accountname 
-	FROM
-		sa_promotion t1
-		LEFT JOIN sa_brand t2 ON t1.sa_brandid = t2.sa_brandid 
-		AND t1.siteid = t2.siteid
-		LEFT JOIN sa_accountclass t3 ON t1.sa_accountclassid = t3.sa_accountclassid 
-		AND t1.siteid = t3.siteid 
-	WHERE
-		t1.siteid = $siteid$
-		AND t1.STATUS = '发布' 
-		AND DATE_FORMAT( now(), '%Y-%m-%d %H:%i:%s' ) >= DATE_FORMAT( t1.begdate, '%Y-%m-%d %H:%i:%s' ) 
-		AND DATE_FORMAT( now(), '%Y-%m-%d %H:%i:%s' ) <= DATE_FORMAT( t1.enddate, '%Y-%m-%d %H:%i:%s' ) 
-		AND t1.sa_promotionid NOT IN (
-		SELECT
-			ifnull( sa_openpromotionid, 0 ) 
-		FROM
-			sa_promotion 
-		WHERE
-			STATUS = '发布' 
-			AND DATE_FORMAT( now(), '%Y-%m-%d' ) >= DATE_FORMAT( t1.begdate, '%Y-%m-%d' ) 
-		AND DATE_FORMAT( now(), '%Y-%m-%d' ) <= DATE_FORMAT( t1.enddate, '%Y-%m-%d' )) 
-	AND
-	IF
-		(
-			t1.isauth = 0,
-		IF
-			(
-				t1.authmethod = 0,
-				(EXISTS (
-				SELECT
-					1 
-				FROM
-					sa_promotion_auth t2 
-				WHERE
-					t1.siteid = t2.siteid 
-					AND t1.sa_promotionid = t2.sa_promotionid 
-					AND t2.sys_enterpriseid =$sys_enterpriseid$
-				AND
-				IF
-				( t2.islimit = 1, t2.saledamount < t2.limitamount, 1 = 1 )) 
-				or t1.sa_promotionid IN (
-				SELECT
-					sa_promotionid 
-				FROM
-					sa_promotion_salearea 
-				WHERE
-					sa_saleareaid IN (
-						WITH recursive salearea AS (
+select t.*
+from (SELECT t1.promnum,
+             t1.sa_promotionid,
+             t1.promname,
+             t1.remarks,
+             t1.type,
+             t1.sa_accountclassid,
+             t1.sa_brandid,
+             t1.tradefield,
+             t1.orderminqty,
+             t1.orderaddqty,
+             t1.orderminamount,
+             t1.isrelevancepromotion,
+             t1.begdate,
+             t1.enddate,
+             t1.STATUS,
+             t1.createuserid,
+             t1.createby,
+             t1.createdate,
+             t1.checkby,
+             t1.checkdate,
+             t1.sendby,
+             t1.senddate,
+             t1.closeby,
+             t1.closedate,
+             t1.changeuserid,
+             t1.changeby,
+             t1.changedate,
+             t1.sa_openpromotionid,
+             t1.openamount,
+             t2.brandname,
+             t3.accountno,
+             t3.accountname
+      FROM sa_promotion t1
+               LEFT JOIN sa_brand t2 ON t1.sa_brandid = t2.sa_brandid
+          AND t1.siteid = t2.siteid
+               LEFT JOIN sa_accountclass t3 ON t1.sa_accountclassid = t3.sa_accountclassid
+          AND t1.siteid = t3.siteid
+      WHERE t1.siteid = $siteid$
+        AND t1.STATUS = '发布'
+        AND DATE_FORMAT(now(), '%Y-%m-%d %H:%i:%s') >= DATE_FORMAT(t1.begdate, '%Y-%m-%d %H:%i:%s')
+        AND DATE_FORMAT(now(), '%Y-%m-%d %H:%i:%s') <= DATE_FORMAT(t1.enddate, '%Y-%m-%d %H:%i:%s')
+        and t1.sa_promotionid not in (select ifnull(sa_openpromotionid, 0)
+                                      from sa_promotion
+                                      where STATUS = '发布'
+                                        AND DATE_FORMAT(now(), '%Y-%m-%d') >= DATE_FORMAT(t1.begdate, '%Y-%m-%d')
+                                        AND DATE_FORMAT(now(), '%Y-%m-%d') <= DATE_FORMAT(t1.enddate, '%Y-%m-%d'))
+        AND if(t1.authmethod=0,(
+        NOT EXISTS(SELECT *
+                            FROM sa_promotion_auth
+                            WHERE sa_promotionid = t1.sa_promotionid AND siteid = t1.siteid)
+              or
+              exists(select 1
+                     from sa_promotion_auth t2
+                     where t1.siteid = t2.siteid
+                       and t1.sa_promotionid = t2.sa_promotionid
+                       and t2.sys_enterpriseid = $sys_enterpriseid$
+                       and if(t2.islimit=1,t2.saledamount<t2.limitamount,1=1)) ),
+              not exists(select 1
+                       from sa_promotion_auth t2
+                       where t1.siteid = t2.siteid
+                         and t1.sa_promotionid = t2.sa_promotionid
+                         and t2.sys_enterpriseid = $sys_enterpriseid$))
+      AND if(NOT EXISTS ( SELECT * FROM sa_promotion_salearea WHERE sa_promotionid = t1.sa_promotionid AND siteid = t1.siteid),
+				NOT EXISTS ( SELECT * FROM sa_promotion_salearea WHERE sa_promotionid = t1.sa_promotionid AND siteid = t1.siteid ),
+				t1.sa_promotionid in(select sa_promotionid from sa_promotion_salearea where sa_saleareaid in(WITH recursive salearea AS (
 						SELECT
-							sa_saleareaid,
-							parentid 
+							sa_saleareaid,parentid
 						FROM
-							sa_salearea 
+							sa_salearea
 						WHERE
 							siteid = $siteid$
 							AND sa_saleareaid IN ( SELECT sa_saleareaid FROM sys_enterprise_tradefield WHERE sys_enterpriseid = $sys_enterpriseid$ ) UNION ALL
 						SELECT
-							t2.sa_saleareaid,
-							t2.parentid 
+							t2.sa_saleareaid,t2.parentid
 						FROM
 							salearea t1
-							INNER JOIN sa_salearea t2 ON t1.parentid = t2.sa_saleareaid 
+							INNER JOIN sa_salearea t2 ON t1.parentid = t2.sa_saleareaid
 							AND t2.siteid = $siteid$
 						) SELECT
-						sa_saleareaid 
+						sa_saleareaid
 					FROM
-						salearea 
-					))),
-				(NOT EXISTS (
-				SELECT
-					1 
-				FROM
-					sa_promotion_auth t2 
-				WHERE
-					t1.siteid = t2.siteid 
-					AND t1.sa_promotionid = t2.sa_promotionid 
-					AND t2.sys_enterpriseid = $sys_enterpriseid$
-				AND
-				IF
-				( t2.islimit = 1, t2.saledamount < t2.limitamount, 1 = 1 )) or t1.sa_promotionid IN (
-			SELECT
-				sa_promotionid 
-			FROM
-				sa_promotion_salearea 
-			WHERE
-				sa_saleareaid IN (
-					WITH recursive salearea AS (
-					SELECT
-						sa_saleareaid,
-						parentid 
-					FROM
-						sa_salearea 
-					WHERE
-						siteid = $siteid$
-						AND sa_saleareaid IN ( SELECT sa_saleareaid FROM sys_enterprise_tradefield WHERE sys_enterpriseid = $sys_enterpriseid$ ) UNION ALL
-					SELECT
-						t2.sa_saleareaid,
-						t2.parentid 
-					FROM
-						salearea t1
-						INNER JOIN sa_salearea t2 ON t1.parentid = t2.sa_saleareaid 
-						AND t2.siteid = $siteid$
-					) SELECT
-					sa_saleareaid 
-				FROM
-					salearea 
-				)))),
-			1 = 1 
-		) 
-	) t 
-WHERE
-	1=1
+						salearea))
+			)
+ ) t
+where $where$