Просмотр исходного кода

促销方案支持促销范围添加营销区域

hu 2 лет назад
Родитель
Сommit
6b53a62810

+ 16 - 0
src/custom/restcontroller/R.java

@@ -4892,6 +4892,22 @@ public class R {
         public static class v1 {
         }
     }
+    public static class ID20230629140803 {
+        public static class v1 {
+        }
+    }
+    public static class ID20230629141403 {
+        public static class v1 {
+        }
+    }
+    public static class ID20230629141503 {
+        public static class v1 {
+        }
+    }
+    public static class ID20230629141603 {
+        public static class v1 {
+        }
+    }
 
 }
 

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

@@ -55,6 +55,20 @@ from (SELECT t1.promnum,
               OR NOT EXISTS(SELECT *
                             FROM sa_promotion_auth
                             WHERE sa_promotionid = t1.sa_promotionid AND siteid = t1.siteid))
+        AND exists(select 1 from sys_enterprise_tradefield where sys_enterpriseid=$sys_enterpriseid$ and sa_saleareaid in(
+with recursive salearea as (
+    select sa_saleareaid
+    from sa_salearea
+    where siteid = $siteid$
+      and sa_saleareaid in(select sa_saleareaid from sa_promotion_salearea where sa_promotionid=t1.sa_promotionid)
+    union all
+    select t2.sa_saleareaid
+    from salearea t1
+             inner join sa_salearea t2 on t1.sa_saleareaid = t2.parentid and t2.siteid ='ccyosg'
+)
+select sa_saleareaid
+from salearea))
+
       union all
       SELECT t1.promnum,
              t1.sa_promotionid,
@@ -103,6 +117,19 @@ from (SELECT t1.promnum,
                                       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 exists(select 1 from sys_enterprise_tradefield where sys_enterpriseid=$sys_enterpriseid$ and sa_saleareaid in(
+with recursive salearea as (
+    select sa_saleareaid
+    from sa_salearea
+    where siteid = $siteid$
+      and sa_saleareaid in(select sa_saleareaid from sa_promotion_salearea where sa_promotionid=t1.sa_promotionid)
+    union all
+    select t2.sa_saleareaid
+    from salearea t1
+             inner join sa_salearea t2 on t1.sa_saleareaid = t2.parentid and t2.siteid ='ccyosg'
+)
+select sa_saleareaid
+from salearea))
         AND not exists(select 1
                        from sa_promotion_auth t2
                        where t1.siteid = t2.siteid

+ 2 - 0
src/custom/restcontroller/webmanage/sale/promotion/SQL/促销方案授权营销区域新增.sql

@@ -0,0 +1,2 @@
+insert into sa_promotion_salearea (siteid, sa_promotion_saleareaid,sa_promotionid,sa_saleareaid)
+values ($siteid$, $sa_promotion_saleareaid$,$sa_promotionid$, $sa_saleareaid$);

+ 4 - 0
src/custom/restcontroller/webmanage/sale/promotion/SQL/促销方案授权营销区域更新.sql

@@ -0,0 +1,4 @@
+UPDATE sa_promotion_salearea
+SET 
+    sa_saleareaid = $sa_saleareaid$
+WHERE sa_promotion_saleareaid = $sa_promotion_saleareaid$ and siteid=$siteid$

+ 11 - 0
src/custom/restcontroller/webmanage/sale/promotion/SQL/促销方案授权营销区域查询.sql

@@ -0,0 +1,11 @@
+SELECT t1.sa_promotion_saleareaid,
+       t1.sa_promotionid,
+       t1.sa_saleareaid,
+       t2.areaname,
+       t2.areanum,
+       t2.areafullname
+FROM sa_promotion_salearea t1
+         LEFT JOIN sa_salearea t2 ON t1.sa_saleareaid = t2.sa_saleareaid and t1.siteid=t2.siteid
+where t1.siteid = $siteid$
+  and t1.sa_promotionid = $sa_promotionid$
+  and $where$

+ 4 - 0
src/custom/restcontroller/webmanage/sale/promotion/SQL/营销区域查询.sql

@@ -0,0 +1,4 @@
+select t1.*
+from sa_salearea t1
+where t1.siteid = $siteid$
+  and $where$ and t1.sa_saleareaid not in (select sa_saleareaid from sa_promotion_salearea where sa_promotionid=$sa_promotionid$)

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

@@ -0,0 +1,132 @@
+package restcontroller.webmanage.sale.promotion;
+
+import beans.data.BatchDeleteErr;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import common.Controller;
+import common.YosException;
+import common.annotation.API;
+import common.annotation.CACHEING;
+import common.annotation.CACHEING_CLEAN;
+import common.data.Rows;
+import common.data.SQLFactory;
+import restcontroller.R;
+
+import java.util.ArrayList;
+
+public class promotionSalearea extends Controller {
+    /**
+     * 构造函数
+     *
+     * @param content
+     */
+    public promotionSalearea(JSONObject content) throws YosException {
+        super(content);
+    }
+    @API(title = "促销方案授权营销区域新增更新", apiversion = R.ID20230629140803.v1.class)
+    @CACHEING_CLEAN(apiClass = {promotionSalearea.class})
+    public String insertormodify_promotionSalearea() throws YosException {
+        Long sa_promotionid = content.getLong("sa_promotionid");
+        JSONArray saleareainfos = content.getJSONArray("saleareainfos");
+        ArrayList<String> sqlList = new ArrayList<>();
+        int i = 0;
+        long[] sa_promotion_saleareaid = createTableID("sa_promotion_salearea", saleareainfos.size());
+        for (Object obj : saleareainfos) {
+            JSONObject saleareainfo = (JSONObject) obj;
+            if (saleareainfo.getLong("sa_promotion_saleareaid") <= 0 || dbConnect.runSqlQuery(
+                    "select sa_promotion_saleareaid from sa_promotion_salearea where sa_promotion_saleareaid="
+                            + saleareainfo.getLong("sa_promotion_saleareaid"))
+                    .isEmpty()) {
+                SQLFactory saleFactory = new SQLFactory(this, "促销方案授权营销区域新增");
+                saleFactory.addParameter("siteid", siteid);
+                saleFactory.addParameter("sa_promotion_saleareaid", sa_promotion_saleareaid[i]);
+                saleFactory.addParameter("sa_promotionid", sa_promotionid);
+                saleFactory.addParameter("sa_saleareaid", saleareainfo.getLong("sa_saleareaid"));
+                sqlList.add(saleFactory.getSQL());
+
+                i++;
+            } else {
+                SQLFactory saleFactory = new SQLFactory(this, "促销方案授权营销区域更新");
+                saleFactory.addParameter("sa_promotion_saleareaid", saleareainfo.getLong("sa_promotion_saleareaid"));
+                saleFactory.addParameter("siteid", siteid);
+                saleFactory.addParameter("sa_promotionid", sa_promotionid);
+                saleFactory.addParameter("sys_enterpriseid", saleareainfo.getLong("sa_saleareaid"));
+                sqlList.add(saleFactory.getSQL());
+            }
+
+        }
+
+        dbConnect.runSqlUpdate(sqlList);
+        return queryPromotionAuthList();
+    }
+
+    @API(title = "营销区域列表查询", apiversion = R.ID20230629141403.v1.class)
+    @CACHEING
+    public String query_saleareaList() throws YosException {
+
+        long sa_promotionid = content.getLong("sa_promotionid");
+        /*
+         * 过滤条件设置
+         */
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+                where.append(" and(");
+                where.append(" t1.areaname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(" or t1.areanum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+        SQLFactory sqlFactory = new SQLFactory(this, "营销区域查询", pageSize, pageNumber, pageSorting);
+        sqlFactory.addParameter_SQL("where", where);
+        sqlFactory.addParameter("sa_promotionid", sa_promotionid);
+        sqlFactory.addParameter("siteid", siteid);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "促销方案授权营销区域列表", apiversion = R.ID20230629141503.v1.class)
+    @CACHEING
+    public String queryPromotionAuthList() throws YosException {
+        /*
+         * 过滤条件设置
+         */
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+                where.append(" and(");
+                where.append(" t2.areaname like '%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+        Long sa_promotionid = content.getLong("sa_promotionid");
+        SQLFactory sqlFactory = new SQLFactory(this, "促销方案授权营销区域查询", pageSize, pageNumber, pageSorting);
+        sqlFactory.addParameter_SQL("where", where);
+        sqlFactory.addParameter("sa_promotionid", sa_promotionid);
+        sqlFactory.addParameter("siteid", siteid);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory);
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "删除明细", apiversion = R.ID20230629141603.v1.class)
+    @CACHEING_CLEAN(apiClass = {promotionSalearea.class})
+    public String deletemx() throws YosException {
+
+        JSONArray sa_promotion_saleareaids = content.getJSONArray("sa_promotion_saleareaids");
+        BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_promotion_saleareaids.size());
+        for (Object o : sa_promotion_saleareaids) {
+            long sa_promotion_saleareaid = Long.parseLong(o.toString());
+            ArrayList<String> list = new ArrayList<>();
+            SQLFactory deletesql = new SQLFactory("sql:delete from sa_promotion_salearea where siteid='" + siteid
+                    + "' and sa_promotion_saleareaid=" + sa_promotion_saleareaid);
+            list.add(deletesql.getSQL());
+
+            dbConnect.runSqlUpdate(list);
+        }
+        return batchDeleteErr.getReturnObject().toString();
+    }
+
+}