瀏覽代碼

促销方案授权方式调整

hu 1 年之前
父節點
當前提交
193d8ca1db

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

@@ -1,86 +1,148 @@
-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
+	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
-							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))
-			)
- ) t
-where $where$
+						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

+ 1 - 0
src/custom/restcontroller/webmanage/sale/promotion/SQL/促销方案列表查询.sql

@@ -30,6 +30,7 @@ SELECT
 	t1.openamount,
 	t1.associationaccountclassid,
 	t1.rebateratio,
+	t1.isauth,
 	t4.accountname associationaccountname,
 	t4.accountno associationaccountno,
 	t1.associationamount,

+ 2 - 1
src/custom/restcontroller/webmanage/sale/promotion/SQL/促销方案更新.sql

@@ -19,6 +19,7 @@ SET changeuserid=$userid$,
     authmethod=$authmethod$,
     associationaccountclassid=$associationaccountclassid$,
     associationamount=$associationamount$,
-    rebateratio=$rebateratio$
+    rebateratio=$rebateratio$,
+    isauth=$isauth$
 WHERE sa_promotionid = $sa_promotionid$
   and siteid = $siteid$

+ 1 - 0
src/custom/restcontroller/webmanage/sale/promotion/SQL/促销方案详情查询.sql

@@ -31,6 +31,7 @@ SELECT t1.promnum,
 	     t5.accountno associationaccountno,
 	     t1.associationamount,
 	     t1.rebateratio,
+	     t1.isauth,
        t4.promname              openpromname,
        t1.openamount,
        t2.brandname,

+ 2 - 0
src/custom/restcontroller/webmanage/sale/promotion/promotion.java

@@ -51,6 +51,7 @@ public class promotion extends Controller {
         String begdate = content.getStringValue("begdate");
         String enddate = content.getStringValue("enddate");
         Long authmethod = content.getLongValue("authmethod");
+        boolean isauth = content.getBooleanValue("isauth");
         BigDecimal associationamount = content.getBigDecimalValue("associationamount");
         Long associationaccountclassid = content.getLongValue("associationaccountclassid");
         BigDecimal rebateratio = content.getBigDecimalValue("rebateratio");
@@ -104,6 +105,7 @@ public class promotion extends Controller {
         sqlFactory.addParameter("begdate", begdate);
         sqlFactory.addParameter("enddate", enddate);
         sqlFactory.addParameter("authmethod", authmethod);
+        sqlFactory.addParameter("isauth", isauth);
         sqlFactory.addParameter("associationamount", associationamount);
         sqlFactory.addParameter("associationaccountclassid", associationaccountclassid);
         sqlFactory.addParameter("rebateratio", rebateratio);