浏览代码

套餐活动功能拓展

hu 1 年之前
父节点
当前提交
5fdb9e12fb

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

@@ -5611,6 +5611,10 @@ public class R {
         }
     }
 
+    public static class ID2024091213511703 {
+        public static class v1 {
+        }
+    }
 }
 
 

+ 23 - 0
src/custom/restcontroller/webmanage/sale/order/Order.java

@@ -1507,6 +1507,7 @@ public class Order extends Controller {
                     return getErrReturnObject().setErrMsg("该促销活动已过期,无法提交").toString();
                 }
             }
+
         }
         if (!((row.getString("status").equals("新建") && !row.getString("type").equals("特殊订单")) || (row.getString("status").equals("确认") && row.getString("type").equals("特殊订单")))) {
             return getErrReturnObject().setErrMsg("新建或非确认无法提交").toString();
@@ -1636,6 +1637,28 @@ public class Order extends Controller {
             Rows promotion = dbConnect.runSqlQuery(" select * from sa_promotion where siteid='" + siteid + "'and  sa_promotionid=" + sa_promotionid);
             Rows promotion_auth = dbConnect.runSqlQuery(" select * from sa_promotion_auth where siteid='" + siteid + "'and sys_enterpriseid=" + sys_enterpriseid + " and sa_promotionid=" + sa_promotionid);
             if (promotion.isNotEmpty()) {
+                if(promotion.get(0).getString("type").equals("套餐活动")){
+                    ArrayList<Long> sa_promotion_itemsids = new ArrayList<Long>();
+                    sa_promotion_itemsids.add((long) 0);
+                    for (Object obj : orderdetails) {
+                        JSONObject orderdetail=(JSONObject)obj;
+                        sa_promotion_itemsids.add(orderdetail.getLong("sa_promotion_itemsid"));
+                    }
+                    int eachlimitqty=promotion.get(0).getInteger("eachlimitqty");
+                    if(promotion.get(0).getBoolean("eachneedadd") && eachlimitqty>0){
+                        String sql ="select ifnull(packagetypemx,'') packagetypemx,count(1) count from  sa_promotion_items where siteid='"+siteid+"' and sa_promotionid="+sa_promotionid +" and sa_promotion_itemsid in "+sa_promotion_itemsids +" group by ifnull(packagetypemx,'')";
+                        sql = sql.replace("[", "(").replace("]", ")");
+                        Rows promotionItemsRows = dbConnect.runSqlQuery(sql);
+                        for(Row row1 :promotionItemsRows){
+                            if(StringUtils.isBlank(row1.getString("packagetypemx"))){
+                                return getErrReturnObject().setErrMsg("促销方案维护出错").toString();
+                            }
+                            if(eachlimitqty!=row1.getInteger("count")){
+                                return getErrReturnObject().setErrMsg(row1.getString("packagetypemx")+"套餐未满足限购品数"+eachlimitqty+"的要求,禁止创建订单,请修改后重试!").toString();
+                            }
+                        }
+                    }
+                }
                 promotiontype = promotion.get(0).getString("type");
                 associationamount = promotion.get(0).getBigDecimal("associationamount");
             }

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

@@ -28,6 +28,8 @@ SELECT
 	t1.changeby,
 	t1.changedate,
 	t1.sa_openpromotionid,
+    t1.eachneedadd,
+    t1.eachlimitqty,
 	t1.openamount,
 	t1.associationaccountclassid,
 	t1.rebateratio,

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

@@ -1,8 +1,8 @@
 insert into sa_promotion (siteid, sa_promotionid, createuserid, createby, createdate, promnum, changeuserid, changeby,
                           changedate, promname, remarks, type, sa_accountclassid,
                           sa_brandid, tradefield, status, orderminqty, orderaddqty, orderminamount, begdate, enddate,
-                          sa_openpromotionid, openamount, isrelevancepromotion, authmethod,associationaccountclassid,associationamount,rebateratio,packagetype)
+                          sa_openpromotionid, openamount, isrelevancepromotion, authmethod,associationaccountclassid,associationamount,rebateratio,packagetype,eachneedadd,eachlimitqty)
 values ($siteid$, $sa_promotionid$, $userid$, $username$, CURRENT_TIME, $promnum$, $userid$, $username$, CURRENT_TIME,
         $promname$, $remarks$, $type$, $sa_accountclassid$,
         $sa_brandid$, $tradefield$, '新建', $orderminqty$, $orderaddqty$, $orderminamount$, $begdate$, $enddate$,
-        $sa_openpromotionid$, $openamount$, $isrelevancepromotion$, $authmethod$,$associationaccountclassid$,$associationamount$,$rebateratio$,$packagetype$);
+        $sa_openpromotionid$, $openamount$, $isrelevancepromotion$, $authmethod$,$associationaccountclassid$,$associationamount$,$rebateratio$,$packagetype$,$eachneedadd$,$eachlimitqty$);

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

@@ -21,6 +21,8 @@ SET changeuserid=$userid$,
     associationamount=$associationamount$,
     rebateratio=$rebateratio$,
     isauth=$isauth$,
-    packagetype=$packagetype$
+    packagetype=$packagetype$,
+    eachneedadd=$eachneedadd$,
+    eachlimitqty=$eachlimitqty$
 WHERE sa_promotionid = $sa_promotionid$
   and siteid = $siteid$

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

@@ -28,6 +28,8 @@ SELECT t1.promnum,
        t1.changedate,
        t1.sa_openpromotionid,
        t1.associationaccountclassid,
+       t1.eachneedadd,
+       t1.eachlimitqty,
 	     t5.accountname associationaccountname,
 	     t5.accountno associationaccountno,
 	     t1.associationamount,

+ 41 - 1
src/custom/restcontroller/webmanage/sale/promotion/promotion.java

@@ -59,6 +59,8 @@ public class promotion extends Controller {
         Long associationaccountclassid = content.getLongValue("associationaccountclassid");
         BigDecimal rebateratio = content.getBigDecimalValue("rebateratio");
         String packagetype = content.getStringValue("packagetype");
+        boolean eachneedadd=content.getBooleanValue("eachneedadd");
+        Long eachlimitqty = content.getLongValue("eachlimitqty");
         SQLFactory sqlFactory = new SQLFactory(this, "促销方案新增");
 
         if (sa_promotionid <= 0 || dbConnect
@@ -117,6 +119,8 @@ public class promotion extends Controller {
         sqlFactory.addParameter("associationamount", associationamount);
         sqlFactory.addParameter("associationaccountclassid", associationaccountclassid);
         sqlFactory.addParameter("rebateratio", rebateratio);
+        sqlFactory.addParameter("eachneedadd", eachneedadd);
+        sqlFactory.addParameter("eachlimitqty", eachlimitqty);
 
         // 备注说明
         sqlFactory.addParameter("remarks", remarks);
@@ -527,7 +531,7 @@ public class promotion extends Controller {
         Long sa_promotionid = content.getLong("sa_promotionid");
 
         Rows rows = dbConnect
-                .runSqlQuery("select sa_promotionid,status,promnum,promname,type,associationaccountclassid,associationamount,packagetype from sa_promotion where sa_promotionid ='"
+                .runSqlQuery("select sa_promotionid,status,promnum,promname,type,associationaccountclassid,associationamount,packagetype,eachlimitqty from sa_promotion where sa_promotionid ='"
                         + sa_promotionid + "' and  siteid='" + siteid + "'");
         Rows rowsdetails = dbConnect
                 .runSqlQuery("select t2.itemno,t2.itemname,ifnull(t1.orderminqty,0) orderminqty, ifnull(t1.orderaddqty,0) orderaddqty from sa_promotion_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.sa_promotionid ='"
@@ -569,6 +573,9 @@ public class promotion extends Controller {
                     if(row.getLong("count")>100){
                         return getErrReturnObject().setErrMsg("套餐名:"+row.getString("packagetypemx")+" 商品添加数量已超上限(同一套餐最多只能添加100个商品)").toString();
                     }
+                    if(row.getLong("count")<rows.get(0).getLong("eachlimitqty")){
+                        return getErrReturnObject().setErrMsg("限购商品数大于"+row.getString("packagetypemx")+"套餐商品数,请调整后重试!").toString();
+                    }
                 }
                 Rows promotioncountRows = dbConnect.runSqlQuery("select distinct groupqty/(ifnull(t1.orderminqty,1)) count  from sa_promotion_items t1 where t1.siteid='"+siteid+"' and t1.sa_promotionid="+sa_promotionid);
                 if(promotioncountRows.size()>1){
@@ -856,4 +863,37 @@ public class promotion extends Controller {
         return getSucReturnObject().setData(valueArray).toString();
     }
 
+    @API(title = "判断套餐促销方案是否满足条件", apiversion = R.ID2024091213511703.v1.class)
+    @CACHEING
+    public String jundgePackagetype() throws YosException {
+        long sa_promotionid =content.getLong("sa_promotionid");
+        JSONArray items =content.getJSONArray("items");
+        ArrayList<Long> sa_promotion_itemsids = new ArrayList<Long>();
+        sa_promotion_itemsids.add((long) 0);
+        for (Object obj : items) {
+            JSONObject item=(JSONObject)obj;
+            sa_promotion_itemsids.add(item.getLong("sa_promotion_itemsid"));
+        }
+        Rows rows = dbConnect.runSqlQuery("select * from  sa_promotion where siteid='"+siteid+"' and type='套餐活动' and sa_promotionid="+sa_promotionid);
+        if(rows.isNotEmpty()){
+            int eachlimitqty=rows.get(0).getInteger("eachlimitqty");
+            if(rows.get(0).getBoolean("eachneedadd") && eachlimitqty>0){
+                String sql ="select ifnull(packagetypemx,'') packagetypemx,count(1) count from  sa_promotion_items where siteid='"+siteid+"' and sa_promotionid="+sa_promotionid +" and sa_promotion_itemsid in "+sa_promotion_itemsids +" group by ifnull(packagetypemx,'')";
+                sql = sql.replace("[", "(").replace("]", ")");
+                Rows promotionItemsRows = dbConnect.runSqlQuery(sql);
+                for(Row row :promotionItemsRows){
+                    if(StringUtils.isBlank(row.getString("packagetypemx"))){
+                        return getErrReturnObject().setErrMsg("促销方案维护出错").toString();
+                    }
+                    if(eachlimitqty!=row.getInteger("count")){
+                        return getErrReturnObject().setErrMsg(row.getString("packagetypemx")+"套餐未满足限购品数"+eachlimitqty+"的要求,禁止创建订单,请修改后重试!").toString();
+                    }
+                }
+            }
+
+        }
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+
 }