瀏覽代碼

促销方案区域经理查询

hu 1 年之前
父節點
當前提交
b21ae08e3a

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

@@ -5326,6 +5326,14 @@ public class R {
         public static class v1 {
         }
     }
+    public static class ID20231025144003 {
+        public static class v1 {
+        }
+    }
+    public static class ID20231025144103 {
+        public static class v1 {
+        }
+    }
 
 }
 

+ 140 - 0
src/custom/restcontroller/sale/promotion/SQL/促销方案列表查询(区域经理).sql

@@ -0,0 +1,140 @@
+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.authmethod = 0
+        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 (
+              exists(select 1
+                     from sa_promotion_auth t2
+                     where t1.siteid = t2.siteid
+                       and t1.sa_promotionid = t2.sa_promotionid
+                       and t2.sys_enterpriseid in (select sys_enterpriseid from sys_enterprise_tradefield where sa_saleareaid in $sa_saleareaids$)
+                       and if(t2.islimit=1,t2.saledamount<t2.limitamount,1=1))
+              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 in (select sys_enterpriseid from sys_enterprise_tradefield where sa_saleareaid in $sa_saleareaids$) 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 =$siteid$
+)
+select sa_saleareaid
+from salearea))
+OR NOT EXISTS ( SELECT * FROM sa_promotion_salearea WHERE sa_promotionid = t1.sa_promotionid AND siteid = t1.siteid ) )
+
+      union all
+      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.authmethod = 1
+        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 exists(select 1 from sys_enterprise_tradefield where sys_enterpriseid in (select sys_enterpriseid from sys_enterprise_tradefield where sa_saleareaid in $sa_saleareaids$) 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 =$siteid$
+)
+select sa_saleareaid
+from salearea))
+        AND 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 in (select sys_enterpriseid from sys_enterprise_tradefield where sa_saleareaid in $sa_saleareaids$))) t
+where $where$

+ 32 - 0
src/custom/restcontroller/sale/promotion/SQL/促销方案商品查询(区域经理).sql

@@ -0,0 +1,32 @@
+SELECT
+    t1.sa_promotion_itemsid,
+	t1.sa_promotionid,
+	t1.sa_promotion_itemgroupid,
+	t1.groupqty,
+	t1.orderaddqty,
+	t1.orderminqty,
+	t1.saledqty,
+	t1.islimit,
+	t1.isonsale,
+	t1.itemid,
+	t1.signaturecode,
+	t2.iscustomsize,
+  t2.widthschemeid,
+  t2.lengthschemeid,
+  t2.sa_customschemeid,
+	t2.itemno,
+	t2.itemname,
+	t2.spec,
+	t2.model,
+	t2.packageqty,
+	t3.unitname,
+	t5.oldprice,
+    t5.pricegrade,
+    t5.price,
+    t1.orderminqty qty
+FROM
+	sa_promotion_items t1
+	left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid
+	left join plm_unit t3 on t2.unitid=t3.unitid and t2.siteid=t3.siteid
+	 LEFT JOIN sa_promotion_itemprice t5 ON t5.sa_promotion_itemsid = t1.sa_promotion_itemsid and t5.siteid = t1.siteid and  t1.sa_promotionid=t5.sa_promotionid
+	where  t1.siteid=$siteid$ and t1.sa_promotionid=$sa_promotionid$ and t1.isonsale=1 and $where$  and t5.pricegrade = 1

+ 11 - 0
src/custom/restcontroller/sale/promotion/SQL/区域经理查询下属营销区域.sql

@@ -0,0 +1,11 @@
+SELECT distinct t1.sa_saleareaid
+from sa_salearea t1
+         LEFT JOIN sa_salearea_hr t2 on t1.sa_saleareaid= t2.sa_saleareaid and t1.siteid=t2.siteid
+				 LEFT JOIN sys_hr t3 on t2.hrid=t3.hrid and t2.siteid=t3.siteid
+         left join sys_department t4 on t4.siteid = t3.siteid and t4.departmentid = t3.departmentid
+WHERE t2.hrid = $hrid$ and t4.depname='销售部'
+  and t1.siteid = $siteid$
+
+union all
+
+SELECT 0 sa_saleareaid

+ 176 - 0
src/custom/restcontroller/sale/promotion/promotion.java

@@ -1,5 +1,6 @@
 package restcontroller.sale.promotion;
 
+import beans.salearea.SaleArea;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import common.Controller;
@@ -201,4 +202,179 @@ public class promotion extends Controller {
         return getSucReturnObject().setData(rows).toString();
     }
 
+    @API(title = "查询促销方案列表(区域经理)", apiversion = R.ID20231025144003.v1.class)
+    @CACHEING
+    public String querypromotionList_regionalManager() 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("t.promnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t.promname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t.remarks like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+
+        SQLFactory areasqlFactory = new SQLFactory(this, "区域经理查询下属营销区域");
+        areasqlFactory.addParameter("siteid", siteid);
+        areasqlFactory.addParameter("hrid", hrid);
+        Rows arearows = dbConnect.runSqlQuery(areasqlFactory);
+        ArrayList<Long> arrayList =arearows.toArrayList("sa_saleareaid", new ArrayList<Long>());
+        arrayList.addAll(SaleArea.getSubSaleAreaIds(this, arrayList));
+
+
+        SQLFactory sqlFactory = new SQLFactory(this, "促销方案列表查询(区域经理)", pageSize, pageNumber, pageSorting);
+        sqlFactory.addParameter("siteid", siteid);
+        sqlFactory.addParameter_in("sa_saleareaids", arrayList);
+        sqlFactory.addParameter_SQL("where", where);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory);
+        //默认商品图片
+        Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
+        //附件
+        ArrayList<Long> ids = rows.toArrayList("sa_promotionid", new ArrayList<>());
+        RowsMap attRowsMap = getAttachmentUrl("sa_promotion", ids);
+
+//        SQLFactory sqlFactory1 = new SQLFactory(this, "促销订单金额合计查询");
+//        sqlFactory1.addParameter("siteid", siteid);
+//        sqlFactory1.addParameter("sys_enterpriseid", sys_enterpriseid);
+//        Rows sumAmountRows =  dbConnect.runSqlQuery(sqlFactory1.getSQL());
+//        RowsMap sumAmountRowsMap = sumAmountRows.toRowsMap("sa_promotionid");
+//
+//        SQLFactory sqlFactory2 = new SQLFactory(this, "促销方案列表查询(触发的促销方案)");
+//        sqlFactory2.addParameter("siteid", siteid);
+//        sqlFactory2.addParameter("sys_enterpriseid", sys_enterpriseid);
+//        Rows openPromotionsRows =  dbConnect.runSqlQuery(sqlFactory2.getSQL());
+//        RowsMap openPromotionsRowsMap = openPromotionsRows.toRowsMap("sa_promotionid");
+//
+//        ListIterator<Row> iterator = rows.listIterator();
+//        while (iterator.hasNext()) {
+//            Row row = iterator.next();
+//            if(row.getLong("sa_openpromotionid")!=0){
+//                if(sumAmountRowsMap.containsKey(row.getString("sa_promotionid"))){
+//                    BigDecimal sumamount = sumAmountRowsMap.get(row.getString("sa_promotionid")).get(0).getBigDecimal("sumamount");
+//                    if(sumamount.compareTo(row.getBigDecimal("openamount"))>=0){
+//                        if(openPromotionsRowsMap.containsKey(row.getString("sa_openpromotionid"))){
+//                            iterator.add(openPromotionsRowsMap.get(row.getString("sa_openpromotionid")).get(0));
+//                        }
+//                    }
+//                }
+//            }
+//        }
+        //Rows promotionAuthRows = dbConnect.runSqlQuery("select t1.sa_promotionid,ifnull(t1.limitamount,0)-ifnull(t1.saledamount,0) canuseamount from sa_promotion_auth t1 inner join sa_promotion t2 on t1.sa_promotionid=t2.sa_promotionid and t1.siteid=t2.siteid where t1.sys_enterpriseid="+sys_enterpriseid);
+       // RowsMap promotionAuthRowsMap =  promotionAuthRows.toRowsMap("sa_promotionid");
+        for (Row row : rows) {
+            if ((attRowsMap.getOrDefault(row.getString("sa_promotionid"), new Rows())).isEmpty()) {
+                row.put("attinfos", defaultImageRows);
+            } else {
+                row.put("attinfos", attRowsMap.getOrDefault(row.getString("sa_promotionid"), new Rows()));
+            }
+            if (!StringUtils.isBlank(row.getString("tradefield"))) {
+                row.put("tradefield", JSONArray.parseArray(row.getString("tradefield")));
+            } else {
+                row.put("tradefield", new JSONArray());
+            }
+
+//            if(row.getString("type").equals("返利促销")){
+//                if(promotionAuthRowsMap.containsKey(row.getString("sa_promotionid"))){
+//                    row.put("canuseamount", promotionAuthRowsMap.get(row.getString("sa_promotionid")).get(0).getBigDecimal("canuseamount"));
+//                }else {
+//                    row.put("canuseamount", 0);
+//                }
+//
+//            }else{
+//                row.put("canuseamount", 0);
+//            }
+
+        }
+
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "促销方案商品列表(区域经理)", apiversion = R.ID20231025144103.v1.class)
+    @CACHEING
+    public String queryPromotionItemsList_regionalManager() 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.itemname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+        Long sa_promotionid = content.getLong("sa_promotionid");
+//        Long sa_promotion_itemgroupid = content.getLong("sa_promotion_itemgroupid");
+        SQLFactory sqlFactory = new SQLFactory(this, "促销方案商品查询(区域经理)", pageSize, pageNumber, pageSorting);
+        sqlFactory.addParameter_SQL("where", where);
+        sqlFactory.addParameter("sa_promotionid", sa_promotionid);
+//        sqlFactory.addParameter("sa_promotion_itemgroupid", sa_promotion_itemgroupid);
+        sqlFactory.addParameter("siteid", siteid);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory);
+
+        ArrayList ids = rows.toArrayList("itemid", new ArrayList<>());
+        //默认商品图片
+        Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
+        // 附件
+        RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
+        //商品领域
+        RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
+        Rows sizecustomizedschemes=dbConnect.runSqlQuery("select * from sa_sizecustomizedscheme where siteid='"+siteid+"' ");
+        RowsMap sizecustomizedschemesRowsMap=sizecustomizedschemes.toRowsMap("sa_sizecustomizedschemeid");
+        Rows sizeschemedetails=dbConnect.runSqlQuery("select * from sa_sizeschemedetail where siteid='"+siteid+"' ");
+        RowsMap sizeschemedetailsRowsMap=sizeschemedetails.toRowsMap("sa_sizecustomizedschemeid");
+        for (Row row : rows) {
+            if ((attRowsMap.getOrDefault(row.getString("itemid"), new Rows())).isEmpty()) {
+                row.put("attinfos", defaultImageRows);
+            } else {
+                row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
+            }
+
+            row.put("tradefield", tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
+
+            if(row.getLong("widthschemeid")!=0){
+                if(sizecustomizedschemesRowsMap.containsKey(row.getString("widthschemeid"))){
+                    if(sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).isNotEmpty()){
+                        row.put("widthtype",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getString("type"));
+                        row.put("widthmin",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("min"));
+                        row.put("widthmax",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("max"));
+                        row.put("widthdecimalplaces",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("decimalplaces"));
+                        if(sizeschemedetailsRowsMap.containsKey(row.getString("widthschemeid"))){
+                            row.put("widthschemedetails",sizeschemedetailsRowsMap.get(row.getString("widthschemeid")));
+                        }else{
+                            row.put("widthschemedetails",new JSONArray());
+                        }
+
+                    }
+
+                }
+            }
+            if(row.getLong("lengthschemeid")!=0){
+                if(sizecustomizedschemesRowsMap.containsKey(row.getString("lengthschemeid"))){
+                    if(sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).isNotEmpty()){
+                        row.put("lengthtype",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getString("type"));
+                        row.put("lengthmin",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("min"));
+                        row.put("lengthmax",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("max"));
+                        row.put("lengthdecimalplaces",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("decimalplaces"));
+                        if(sizeschemedetailsRowsMap.containsKey(row.getString("lengthschemeid"))){
+                            row.put("lengthschemedetails",sizeschemedetailsRowsMap.get(row.getString("lengthschemeid")));
+                        }else{
+                            row.put("lengthschemedetails",new JSONArray());
+                        }
+                    }
+
+                }
+            }
+        }
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
 }

+ 2 - 0
src/custom/restcontroller/webmanage/lsak3/item/item.java

@@ -161,6 +161,8 @@ public class item extends Controller {
                         sqlFactory.addParameter("status",customitemRows.get(0).getString("status"));
                         sqlFactory.addParameter("isonsale",customitemRows.get(0).getString("isonsale"));
                     }else {
+                        sqlFactory.addParameter("status","审核");
+                        sqlFactory.addParameter("isonsale",0);
                         Rows rowscount = dbConnect.runSqlQuery("select count(1) count from sa_itemgroupmx where sa_itemgroupid in(select t1.sa_itemgroupid from sa_itemgroupmx t1 inner join sa_itemgroup t2 on t1.sa_itemgroupid=t2.sa_itemgroupid and t1.siteid=t2.siteid  where itemid="+itemid+")");
                         if(rowscount.isNotEmpty()){
                             if(rowscount.get(0).getInteger("count")>1){