ソースを参照

促销方案添加授权方式

郭齐峰 2 年 前
コミット
1db134d026

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

@@ -4716,6 +4716,11 @@ public class R {
         }
     }
 
+    public static class ID20230509100504 {
+        public static class v1 {
+        }
+    }
+
 
 }
 

+ 3 - 3
src/custom/restcontroller/webmanage/sale/order/PromotionOrder.java

@@ -41,9 +41,9 @@ public class PromotionOrder extends Controller {
             JSONObject whereObject = content.getJSONObject("where");
             if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
                 where.append(" and(");
-                where.append("t1.promnum like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t1.promname like'%").append(whereObject.getString("condition")).append("%' ");
-                where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' ");
+                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(")");
             }
         }

+ 32 - 3
src/custom/restcontroller/webmanage/sale/order/SQL/促销方案列表查询.sql

@@ -1,3 +1,29 @@
+select t.* from (SELECT t1.promnum,
+       t1.sa_promotionid,
+       t1.promname,
+       t1.remarks,
+       t1.type,
+       t1.sa_accountclassid,
+       t1.sa_brandid,
+       t1.tradefield,
+       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 t1.authmethod = 0
+  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 = $sys_enterpriseid$)
+union all
 SELECT t1.promnum,
        t1.sa_promotionid,
        t1.promname,
@@ -15,7 +41,10 @@ FROM sa_promotion t1
          LEFT JOIN sa_accountclass t3 ON t1.sa_accountclassid = t3.sa_accountclassid
     AND t1.siteid = t3.siteid
 where t1.siteid = $siteid$
-  and $where$
   and t1.status = '发布'
-  and t1.sa_promotionid in
-      (SELECT sa_promotionid from sa_promotion_auth WHERE sys_enterpriseid = $sys_enterpriseid$ and siteid = $siteid$)
+  and t1.authmethod = 1
+  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 = $sys_enterpriseid$)) t where $where$

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

@@ -1,4 +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)
-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$);
+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)
+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$);

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

@@ -1,6 +1,5 @@
 UPDATE sa_promotion
-SET 
-    changeuserid=$userid$,
+SET changeuserid=$userid$,
     changedate = CURRENT_TIME,
     changeby = $username$,
     promname= $promname$,
@@ -16,5 +15,7 @@ SET
     enddate = $enddate$,
     sa_openpromotionid=$sa_openpromotionid$,
     openamount=$openamount$,
-    isrelevancepromotion=$isrelevancepromotion$
-WHERE sa_promotionid = $sa_promotionid$ and siteid=$siteid$
+    isrelevancepromotion=$isrelevancepromotion$,
+    authmethod=$authmethod$
+WHERE sa_promotionid = $sa_promotionid$
+  and siteid = $siteid$

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

@@ -1,43 +1,42 @@
-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,
-	t4.promname openpromname,
-	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
-	LEFT JOIN sa_promotion t4 ON t4.sa_promotionid = t1.sa_openpromotionid
-	AND t4.siteid = t1.siteid
-	where t1.sa_promotionid=$sa_promotionid$
+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,
+       t4.promname              openpromname,
+       t1.openamount,
+       t2.brandname,
+       t3.accountno,
+       t3.accountname,
+       ifnull(t1.authmethod, 0) authmethod
+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
+         LEFT JOIN sa_promotion t4 ON t4.sa_promotionid = t1.sa_openpromotionid
+    AND t4.siteid = t1.siteid
+where t1.sa_promotionid = $sa_promotionid$

+ 319 - 296
src/custom/restcontroller/webmanage/sale/promotion/promotion.java

@@ -24,308 +24,331 @@ import restcontroller.R;
 @API(title = "促销方案")
 public class promotion extends Controller {
 
-	public promotion(JSONObject arg0) throws YosException {
-		super(arg0);
-		// TODO Auto-generated constructor stub
-	}
-
-	@API(title = "促销方案新增更新", apiversion = R.ID20221230144503.v1.class)
-	@CACHEING_CLEAN(apiversions = { R.ID20221230144703.v1.class, R.ID20221230144803.v1.class,R.ID20220103140003.v1.class})
-	public String insertormodify_promotion() throws YosException {
-		ArrayList<String> sqlList = new ArrayList<>();
-		// 表名
-		String tableName = "sa_promotion";
-		Long sa_promotionid = content.getLong("sa_promotionid");
-		Long sa_accountclassid = content.getLong("sa_accountclassid");
-		Long sa_brandid = content.getLong("sa_brandid");
-		String promname = content.getStringValue("promname");
-		String remarks = content.getStringValue("remarks");
-		String type = content.getStringValue("type");
-		//String tradefield = content.getStringValue("tradefield");
-		JSONArray tradefield =content.getJSONArray("tradefield");
-		BigDecimal orderminqty = content.getBigDecimal("orderminqty");
-		BigDecimal orderaddqty = content.getBigDecimal("orderaddqty");
-		BigDecimal orderminamount = content.getBigDecimal("orderminamount");
-		String begdate = content.getStringValue("begdate");
-		String enddate = content.getStringValue("enddate");
-		SQLFactory sqlFactory = new SQLFactory(this, "促销方案新增");
-
-		if (sa_promotionid <= 0 || dbConnect
-				.runSqlQuery("select sa_promotionid from sa_promotion where sa_promotionid=" + sa_promotionid)
-				.isEmpty()) {
-			sa_promotionid = createTableID(tableName);
-			sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "新增", "促销方案新增成功").getSQL());
-		} else {
-			Rows rows = dbConnect
-					.runSqlQuery("SELECT status from sa_promotion WHERE sa_promotionid = " + sa_promotionid);
-			if (rows.isNotEmpty()) {
-				if (rows.get(0).getString("status").equals("新建")) {
-					sqlFactory = new SQLFactory(this, "促销方案更新");
-					sqlList.add(
-							DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "更新", "促销方案更新成功").getSQL());
-				} else {
-					return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
-				}
-			} else {
-				return getErrReturnObject().setErrMsg("该促销方案不存在").toString();
-			}
-
-		}
-
-		sqlFactory.addParameter("siteid", siteid);
-		sqlFactory.addParameter("userid", userid);
-		sqlFactory.addParameter("username", username);
-		sqlFactory.addParameter("sa_promotionid", sa_promotionid);
-		// 促销方案号createBillCode("promotionbillno")
-		sqlFactory.addParameter("promnum",createBillCode("promotionbill"));
-		sqlFactory.addParameter("promname", promname);
-		sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
-		sqlFactory.addParameter("sa_brandid", sa_brandid);
-		sqlFactory.addParameter("type", type);
-		sqlFactory.addParameter("tradefield", tradefield.toJSONString());
-		sqlFactory.addParameter("orderminqty", orderminqty);
-		sqlFactory.addParameter("orderaddqty", orderaddqty);
-		sqlFactory.addParameter("orderminamount", orderminamount);
-		sqlFactory.addParameter("sa_openpromotionid", content.getIntValue("sa_openpromotionid"));
-		sqlFactory.addParameter("openamount",  content.getBigDecimalValue("openamount"));
-		sqlFactory.addParameter("isrelevancepromotion",  content.getLongValue("isrelevancepromotion"));
-
-		sqlFactory.addParameter("begdate", begdate);
-		sqlFactory.addParameter("enddate", enddate);
-		// 备注说明
-		sqlFactory.addParameter("remarks", remarks);
-		sqlList.add(sqlFactory.getSQL());
-		dbConnect.runSqlUpdate(sqlList);
-
-		content.put("sa_promotionid", sa_promotionid);
-
-		return querypromotionMain();
-	}
-	@API(title = "促销方案详情", apiversion = R.ID20221230144703.v1.class)
-	@CACHEING
-	public String querypromotionMain() throws YosException {
-		Long sa_promotionid = content.getLong("sa_promotionid");
-		SQLFactory sqlFactory = new SQLFactory(this, "促销方案详情查询");
-		sqlFactory.addParameter("sa_promotionid", sa_promotionid);
-		sqlFactory.addParameter("siteid", siteid);
-		Rows rows = dbConnect.runSqlQuery(sqlFactory);
-		Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
-		//附件
+    public promotion(JSONObject arg0) throws YosException {
+        super(arg0);
+        // TODO Auto-generated constructor stub
+    }
+
+    @API(title = "促销方案新增更新", apiversion = R.ID20221230144503.v1.class)
+    @CACHEING_CLEAN(apiversions = {R.ID20221230144703.v1.class, R.ID20221230144803.v1.class, R.ID20220103140003.v1.class})
+    public String insertormodify_promotion() throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+        // 表名
+        String tableName = "sa_promotion";
+        Long sa_promotionid = content.getLong("sa_promotionid");
+        Long sa_accountclassid = content.getLong("sa_accountclassid");
+        Long sa_brandid = content.getLong("sa_brandid");
+        String promname = content.getStringValue("promname");
+        String remarks = content.getStringValue("remarks");
+        String type = content.getStringValue("type");
+        //String tradefield = content.getStringValue("tradefield");
+        JSONArray tradefield = content.getJSONArray("tradefield");
+        BigDecimal orderminqty = content.getBigDecimal("orderminqty");
+        BigDecimal orderaddqty = content.getBigDecimal("orderaddqty");
+        BigDecimal orderminamount = content.getBigDecimal("orderminamount");
+        String begdate = content.getStringValue("begdate");
+        String enddate = content.getStringValue("enddate");
+        Long authmethod = content.getLongValue("authmethod");
+        SQLFactory sqlFactory = new SQLFactory(this, "促销方案新增");
+
+        if (sa_promotionid <= 0 || dbConnect
+                .runSqlQuery("select sa_promotionid from sa_promotion where sa_promotionid=" + sa_promotionid)
+                .isEmpty()) {
+            sa_promotionid = createTableID(tableName);
+            sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "新增", "促销方案新增成功").getSQL());
+        } else {
+            Rows rows = dbConnect
+                    .runSqlQuery("SELECT status from sa_promotion WHERE sa_promotionid = " + sa_promotionid);
+            if (rows.isNotEmpty()) {
+                if (rows.get(0).getString("status").equals("新建")) {
+                    sqlFactory = new SQLFactory(this, "促销方案更新");
+                    sqlList.add(
+                            DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "更新", "促销方案更新成功").getSQL());
+                } else {
+                    return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
+                }
+            } else {
+                return getErrReturnObject().setErrMsg("该促销方案不存在").toString();
+            }
+
+        }
+
+        sqlFactory.addParameter("siteid", siteid);
+        sqlFactory.addParameter("userid", userid);
+        sqlFactory.addParameter("username", username);
+        sqlFactory.addParameter("sa_promotionid", sa_promotionid);
+        // 促销方案号createBillCode("promotionbillno")
+        sqlFactory.addParameter("promnum", createBillCode("promotionbill"));
+        sqlFactory.addParameter("promname", promname);
+        sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
+        sqlFactory.addParameter("sa_brandid", sa_brandid);
+        sqlFactory.addParameter("type", type);
+        sqlFactory.addParameter("tradefield", tradefield.toJSONString());
+        sqlFactory.addParameter("orderminqty", orderminqty);
+        sqlFactory.addParameter("orderaddqty", orderaddqty);
+        sqlFactory.addParameter("orderminamount", orderminamount);
+        sqlFactory.addParameter("sa_openpromotionid", content.getIntValue("sa_openpromotionid"));
+        sqlFactory.addParameter("openamount", content.getBigDecimalValue("openamount"));
+        sqlFactory.addParameter("isrelevancepromotion", content.getLongValue("isrelevancepromotion"));
+
+        sqlFactory.addParameter("begdate", begdate);
+        sqlFactory.addParameter("enddate", enddate);
+        sqlFactory.addParameter("authmethod", authmethod);
+        // 备注说明
+        sqlFactory.addParameter("remarks", remarks);
+        sqlList.add(sqlFactory.getSQL());
+        dbConnect.runSqlUpdate(sqlList);
+
+        content.put("sa_promotionid", sa_promotionid);
+
+        return querypromotionMain();
+    }
+
+    @API(title = "促销方案详情", apiversion = R.ID20221230144703.v1.class)
+    @CACHEING
+    public String querypromotionMain() throws YosException {
+        Long sa_promotionid = content.getLong("sa_promotionid");
+        SQLFactory sqlFactory = new SQLFactory(this, "促销方案详情查询");
+        sqlFactory.addParameter("sa_promotionid", sa_promotionid);
+        sqlFactory.addParameter("siteid", siteid);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory);
+        Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
+        //附件
         ArrayList<Long> ids = rows.toArrayList("sa_promotionid", new ArrayList<>());
         RowsMap attRowsMap = getAttachmentUrl("sa_promotion", ids);
-		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());
-		}
+        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());
+        }
         return getSucReturnObject().setData(row).toString();
-	}
-
-	@API(title = "查询促销方案列表", apiversion = R.ID20221230144803.v1.class)
-	@CACHEING
-	public String querypromotionList() 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("t1.promnum like'%").append(whereObject.getString("condition")).append("%' ");
-				where.append("or t1.promname like'%").append(whereObject.getString("condition")).append("%' ");
-				where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' ");
-				where.append(")");
-			}
-			if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
-				where.append(" and t1.status ='").append(whereObject.getString("status")).append("' ");
-			}
-		}
-		SQLFactory sqlFactory = new SQLFactory(this, "促销方案列表查询", pageSize, pageNumber, pageSorting);
-		sqlFactory.addParameter("siteid", siteid);
-		sqlFactory.addParameter_SQL("where", where);
-		Rows rows = dbConnect.runSqlQuery(sqlFactory);
-		 //附件
+    }
+
+    @API(title = "查询促销方案列表", apiversion = R.ID20221230144803.v1.class)
+    @CACHEING
+    public String querypromotionList() 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("t1.promnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.promname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+            if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
+                where.append(" and t1.status ='").append(whereObject.getString("status")).append("' ");
+            }
+        }
+        SQLFactory sqlFactory = new SQLFactory(this, "促销方案列表查询", pageSize, pageNumber, pageSorting);
+        sqlFactory.addParameter("siteid", siteid);
+        sqlFactory.addParameter_SQL("where", where);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory);
+        //附件
         ArrayList<Long> ids = rows.toArrayList("sa_promotionid", new ArrayList<>());
         RowsMap attRowsMap = getAttachmentUrl("sa_promotion", ids);
         for (Row row : rows) {
-			if (!StringUtils.isBlank(row.getString("tradefield"))) {
-				row.put("tradefield", JSONArray.parseArray(row.getString("tradefield")));
-			} else {
-				row.put("tradefield", new JSONArray());
-			}
+            if (!StringUtils.isBlank(row.getString("tradefield"))) {
+                row.put("tradefield", JSONArray.parseArray(row.getString("tradefield")));
+            } else {
+                row.put("tradefield", new JSONArray());
+            }
             row.put("attinfos", attRowsMap.getOrDefault(row.getString("sa_promotionid"), new Rows()));
         }
-		
-		return getSucReturnObject().setData(rows).toString();
-	}
-
-	@API(title = "删除", apiversion = R.ID20221230144903.v1.class)
-	@CACHEING_CLEAN(apiversions = { R.ID20221230144703.v1.class, R.ID20221230144803.v1.class, R.ID20220103140003.v1.class })
-	public String delete() throws YosException {
-
-		ArrayList<String> sqlList = new ArrayList<>();
-		JSONArray sa_promotionids = content.getJSONArray("sa_promotionids");
-		BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_promotionids.size());
-		for (Object o : sa_promotionids) {
-			long sa_promotionid = Long.parseLong(o.toString());
-			Rows RowsStatus = dbConnect.runSqlQuery("select sa_promotionid,status from sa_promotion where siteid='"
-					+ siteid + "' and sa_promotionid='" + sa_promotionid + "'");
-
-			if (RowsStatus.isNotEmpty()) {
-				if (!RowsStatus.get(0).getString("status").equals("新建")) {
-					batchDeleteErr.addErr(sa_promotionid, "非新建状态的促销方案无法删除");
-					continue;
-				}
-			}
-			sqlList.add("delete from sa_promotion where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
-			sqlList.add(
-					"delete from sa_promotion_auth where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
-			sqlList.add("delete from sa_promotion_itemgroup where siteid='" + siteid + "' and sa_promotionid="
-					+ sa_promotionid);
-			sqlList.add("delete from sa_promotion_itemprice where siteid='" + siteid + "' and sa_promotionid="
-					+ sa_promotionid);
-			sqlList.add("delete from sa_promotion_items where siteid='" + siteid + "' and sa_promotionid="
-					+ sa_promotionid);
-			dbConnect.runSqlUpdate(sqlList);
-		}
-		return batchDeleteErr.getReturnObject().toString();
-
-	}
-
-	@API(title = "审核", apiversion = R.ID20221230145003.v1.class)
-	@CACHEING_CLEAN(apiversions = { R.ID20221230144703.v1.class, R.ID20221230144803.v1.class, R.ID20220103140003.v1.class })
-	public String check() throws YosException {
-		Long sa_promotionid = content.getLong("sa_promotionid");
-
-		Rows rows = dbConnect
-				.runSqlQuery("select sa_promotionid,status,promnum,promname from sa_promotion where sa_promotionid ='"
-						+ sa_promotionid + "' and  siteid='" + siteid + "'");
-		if (rows.isEmpty()) {
-			return getErrReturnObject().setErrMsg("该促销方案不存在").toString();
-		} else {
-			if (!rows.get(0).getString("status").equals("新建")) {
-				return getErrReturnObject().setErrMsg("单号为:【" + rows.get(0).getString("promnum") + "】的促销方案为非新建状态,无法审核")
-						.toString();
-			}
-		}
-
-		ArrayList<String> sqlList = new ArrayList<>();
-
-		SQLFactory sqlFactoryupdate = new SQLFactory(this, "促销方案审核");
-		sqlFactoryupdate.addParameter("siteid", siteid);
-		sqlFactoryupdate.addParameter("sa_promotionid", sa_promotionid);
-		sqlFactoryupdate.addParameter("checkby", username);
-		sqlList.add(sqlFactoryupdate.getSQL());
-		sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "审核", "促销方案审核成功").getSQL());
-		dbConnect.runSqlUpdate(sqlList);
-		return getSucReturnObject().toString();
-
-	}
-
-	@API(title = "反审核", apiversion = R.ID20221230145103.v1.class)
-	@CACHEING_CLEAN(apiversions = { R.ID20221230144703.v1.class, R.ID20221230144803.v1.class,R.ID20220103140003.v1.class })
-	public String uncheck() throws YosException {
-		Long sa_promotionid = content.getLong("sa_promotionid");
-
-		Rows rows = dbConnect
-				.runSqlQuery("select sa_promotionid,status,promnum,promname from sa_promotion where sa_promotionid ='"
-						+ sa_promotionid + "' and  siteid='" + siteid + "'");
-		if (rows.isEmpty()) {
-			return getErrReturnObject().setErrMsg("该促销方案不存在").toString();
-		} else {
-			if (!rows.get(0).getString("status").equals("审核")) {
-				return getErrReturnObject().setErrMsg("单号为:【" + rows.get(0).getString("promnum") + "】的促销方案为非审核状态,无法反审核")
-						.toString();
-			}
-		}
-
-		ArrayList<String> sqlList = new ArrayList<>();
-
-		SQLFactory sqlFactoryupdate = new SQLFactory(this, "促销方案反审核");
-		sqlFactoryupdate.addParameter("siteid", siteid);
-		sqlFactoryupdate.addParameter("sa_promotionid", sa_promotionid);
-		sqlFactoryupdate.addParameter("checkby", username);
-		sqlList.add(sqlFactoryupdate.getSQL());
-		sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "反审核", "促销方案反审核成功").getSQL());
-		dbConnect.runSqlUpdate(sqlList);
-		return getSucReturnObject().toString();
-	}
-
-	@API(title = "发布反发布", apiversion = R.ID20221230145203.v1.class)
-	@CACHEING_CLEAN(apiversions = { R.ID20221230144703.v1.class, R.ID20221230144803.v1.class , R.ID20220103140003.v1.class })
-	public String recheck() throws YosException {
-		Long sa_promotionid = content.getLong("sa_promotionid");
-		boolean isrecheck = content.getBooleanValue("isrecheck");
-		Rows rows = dbConnect
-				.runSqlQuery("select sa_promotionid,status,promnum from sa_promotion where sa_promotionid ='"
-						+ sa_promotionid + "' and  siteid='" + siteid + "'");
-		for (Row row : rows) {
-			if (isrecheck) {
-				if (!row.getString("status").equals("审核")) {
-					return getErrReturnObject().setErrMsg("单号为:【" + row.getString("promnum") + "】的促销方案为非审核状态,无法发布")
-							.toString();
-				}
-			} else {
-				if (!row.getString("status").equals("发布")) {
-					return getErrReturnObject().setErrMsg("单号为:【" + row.getString("promnum") + "】的促销方案为非发布状态,无法反发布")
-							.toString();
-				}
-			}
-
-		}
-		ArrayList<String> sqlList = new ArrayList<>();
-		SQLFactory sqlFactoryupdate;
-		if (isrecheck) {
-			sqlFactoryupdate = new SQLFactory(this, "促销方案发布");
-			sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "发布", "促销方案发布成功").getSQL());
-		} else {
-			sqlFactoryupdate = new SQLFactory(this, "促销方案反发布");
-			sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "反发布", "促销方案反发布成功").getSQL());
-		}
-		sqlFactoryupdate.addParameter("siteid", siteid);
-		sqlFactoryupdate.addParameter("sa_promotionid", sa_promotionid);
-		sqlFactoryupdate.addParameter("sendby", username);
-		sqlList.add(sqlFactoryupdate.getSQL());
-
-		dbConnect.runSqlUpdate(sqlList);
-		return getSucReturnObject().toString();
-	}
-	@API(title = "关闭反关闭", apiversion = R.ID20230102095403.v1.class)
-	@CACHEING_CLEAN(apiversions = { R.ID20221230144703.v1.class, R.ID20221230144803.v1.class , R.ID20220103140003.v1.class})
-	public String close() throws YosException {
-		Long sa_promotionid = content.getLong("sa_promotionid");
-		boolean isclose = content.getBooleanValue("isclose");
-		Rows rows = dbConnect
-				.runSqlQuery("select sa_promotionid,status,promnum from sa_promotion where sa_promotionid ='"
-						+ sa_promotionid + "' and  siteid='" + siteid + "'");
-		for (Row row : rows) {
-			if (isclose) {
-				if (!row.getString("status").equals("发布")) {
-					return getErrReturnObject().setErrMsg("单号为:【" + row.getString("promnum") + "】的促销方案为非发布状态,无法关闭")
-							.toString();
-				}
-			} else {
-				if (!row.getString("status").equals("关闭")) {
-					return getErrReturnObject().setErrMsg("单号为:【" + row.getString("promnum") + "】的促销方案为非关闭状态,无法反关闭")
-							.toString();
-				}
-			}
-
-		}
-		ArrayList<String> sqlList = new ArrayList<>();
-		SQLFactory sqlFactoryupdate;
-		if (isclose) {
-			sqlFactoryupdate = new SQLFactory(this, "促销方案关闭");
-			sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "关闭", "促销方案关闭成功").getSQL());
-		} else {
-			sqlFactoryupdate = new SQLFactory(this, "促销方案反关闭");
-			sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "反关闭", "促销方案反关闭成功").getSQL());
-		}
-		sqlFactoryupdate.addParameter("siteid", siteid);
-		sqlFactoryupdate.addParameter("sa_promotionid", sa_promotionid);
-		sqlFactoryupdate.addParameter("closeby", username);
-		sqlList.add(sqlFactoryupdate.getSQL());
-
-		dbConnect.runSqlUpdate(sqlList);
-		return getSucReturnObject().toString();
-	}
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "删除", apiversion = R.ID20221230144903.v1.class)
+    @CACHEING_CLEAN(apiversions = {R.ID20221230144703.v1.class, R.ID20221230144803.v1.class, R.ID20220103140003.v1.class})
+    public String delete() throws YosException {
+
+        ArrayList<String> sqlList = new ArrayList<>();
+        JSONArray sa_promotionids = content.getJSONArray("sa_promotionids");
+        BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_promotionids.size());
+        for (Object o : sa_promotionids) {
+            long sa_promotionid = Long.parseLong(o.toString());
+            Rows RowsStatus = dbConnect.runSqlQuery("select sa_promotionid,status from sa_promotion where siteid='"
+                    + siteid + "' and sa_promotionid='" + sa_promotionid + "'");
+
+            if (RowsStatus.isNotEmpty()) {
+                if (!RowsStatus.get(0).getString("status").equals("新建")) {
+                    batchDeleteErr.addErr(sa_promotionid, "非新建状态的促销方案无法删除");
+                    continue;
+                }
+            }
+            sqlList.add("delete from sa_promotion where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
+            sqlList.add(
+                    "delete from sa_promotion_auth where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
+            sqlList.add("delete from sa_promotion_itemgroup where siteid='" + siteid + "' and sa_promotionid="
+                    + sa_promotionid);
+            sqlList.add("delete from sa_promotion_itemprice where siteid='" + siteid + "' and sa_promotionid="
+                    + sa_promotionid);
+            sqlList.add("delete from sa_promotion_items where siteid='" + siteid + "' and sa_promotionid="
+                    + sa_promotionid);
+            dbConnect.runSqlUpdate(sqlList);
+        }
+        return batchDeleteErr.getReturnObject().toString();
+
+    }
+
+    @API(title = "审核", apiversion = R.ID20221230145003.v1.class)
+    @CACHEING_CLEAN(apiversions = {R.ID20221230144703.v1.class, R.ID20221230144803.v1.class, R.ID20220103140003.v1.class})
+    public String check() throws YosException {
+        Long sa_promotionid = content.getLong("sa_promotionid");
+
+        Rows rows = dbConnect
+                .runSqlQuery("select sa_promotionid,status,promnum,promname from sa_promotion where sa_promotionid ='"
+                        + sa_promotionid + "' and  siteid='" + siteid + "'");
+        if (rows.isEmpty()) {
+            return getErrReturnObject().setErrMsg("该促销方案不存在").toString();
+        } else {
+            if (!rows.get(0).getString("status").equals("新建")) {
+                return getErrReturnObject().setErrMsg("单号为:【" + rows.get(0).getString("promnum") + "】的促销方案为非新建状态,无法审核")
+                        .toString();
+            }
+        }
+
+        ArrayList<String> sqlList = new ArrayList<>();
+
+        SQLFactory sqlFactoryupdate = new SQLFactory(this, "促销方案审核");
+        sqlFactoryupdate.addParameter("siteid", siteid);
+        sqlFactoryupdate.addParameter("sa_promotionid", sa_promotionid);
+        sqlFactoryupdate.addParameter("checkby", username);
+        sqlList.add(sqlFactoryupdate.getSQL());
+        sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "审核", "促销方案审核成功").getSQL());
+        dbConnect.runSqlUpdate(sqlList);
+        return getSucReturnObject().toString();
+
+    }
+
+    @API(title = "反审核", apiversion = R.ID20221230145103.v1.class)
+    @CACHEING_CLEAN(apiversions = {R.ID20221230144703.v1.class, R.ID20221230144803.v1.class, R.ID20220103140003.v1.class})
+    public String uncheck() throws YosException {
+        Long sa_promotionid = content.getLong("sa_promotionid");
+
+        Rows rows = dbConnect
+                .runSqlQuery("select sa_promotionid,status,promnum,promname from sa_promotion where sa_promotionid ='"
+                        + sa_promotionid + "' and  siteid='" + siteid + "'");
+        if (rows.isEmpty()) {
+            return getErrReturnObject().setErrMsg("该促销方案不存在").toString();
+        } else {
+            if (!rows.get(0).getString("status").equals("审核")) {
+                return getErrReturnObject().setErrMsg("单号为:【" + rows.get(0).getString("promnum") + "】的促销方案为非审核状态,无法反审核")
+                        .toString();
+            }
+        }
+
+        ArrayList<String> sqlList = new ArrayList<>();
+
+        SQLFactory sqlFactoryupdate = new SQLFactory(this, "促销方案反审核");
+        sqlFactoryupdate.addParameter("siteid", siteid);
+        sqlFactoryupdate.addParameter("sa_promotionid", sa_promotionid);
+        sqlFactoryupdate.addParameter("checkby", username);
+        sqlList.add(sqlFactoryupdate.getSQL());
+        sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "反审核", "促销方案反审核成功").getSQL());
+        dbConnect.runSqlUpdate(sqlList);
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "发布反发布", apiversion = R.ID20221230145203.v1.class)
+    @CACHEING_CLEAN(apiversions = {R.ID20221230144703.v1.class, R.ID20221230144803.v1.class, R.ID20220103140003.v1.class})
+    public String recheck() throws YosException {
+        Long sa_promotionid = content.getLong("sa_promotionid");
+        boolean isrecheck = content.getBooleanValue("isrecheck");
+        Rows rows = dbConnect
+                .runSqlQuery("select sa_promotionid,status,promnum from sa_promotion where sa_promotionid ='"
+                        + sa_promotionid + "' and  siteid='" + siteid + "'");
+        for (Row row : rows) {
+            if (isrecheck) {
+                if (!row.getString("status").equals("审核")) {
+                    return getErrReturnObject().setErrMsg("单号为:【" + row.getString("promnum") + "】的促销方案为非审核状态,无法发布")
+                            .toString();
+                }
+            } else {
+                if (!row.getString("status").equals("发布")) {
+                    return getErrReturnObject().setErrMsg("单号为:【" + row.getString("promnum") + "】的促销方案为非发布状态,无法反发布")
+                            .toString();
+                }
+            }
+
+        }
+        ArrayList<String> sqlList = new ArrayList<>();
+        SQLFactory sqlFactoryupdate;
+        if (isrecheck) {
+            sqlFactoryupdate = new SQLFactory(this, "促销方案发布");
+            sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "发布", "促销方案发布成功").getSQL());
+        } else {
+            sqlFactoryupdate = new SQLFactory(this, "促销方案反发布");
+            sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "反发布", "促销方案反发布成功").getSQL());
+        }
+        sqlFactoryupdate.addParameter("siteid", siteid);
+        sqlFactoryupdate.addParameter("sa_promotionid", sa_promotionid);
+        sqlFactoryupdate.addParameter("sendby", username);
+        sqlList.add(sqlFactoryupdate.getSQL());
+
+        dbConnect.runSqlUpdate(sqlList);
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "关闭反关闭", apiversion = R.ID20230102095403.v1.class)
+    @CACHEING_CLEAN(apiversions = {R.ID20221230144703.v1.class, R.ID20221230144803.v1.class, R.ID20220103140003.v1.class})
+    public String close() throws YosException {
+        Long sa_promotionid = content.getLong("sa_promotionid");
+        boolean isclose = content.getBooleanValue("isclose");
+        Rows rows = dbConnect
+                .runSqlQuery("select sa_promotionid,status,promnum from sa_promotion where sa_promotionid ='"
+                        + sa_promotionid + "' and  siteid='" + siteid + "'");
+        for (Row row : rows) {
+            if (isclose) {
+                if (!row.getString("status").equals("发布")) {
+                    return getErrReturnObject().setErrMsg("单号为:【" + row.getString("promnum") + "】的促销方案为非发布状态,无法关闭")
+                            .toString();
+                }
+            } else {
+                if (!row.getString("status").equals("关闭")) {
+                    return getErrReturnObject().setErrMsg("单号为:【" + row.getString("promnum") + "】的促销方案为非关闭状态,无法反关闭")
+                            .toString();
+                }
+            }
+
+        }
+        ArrayList<String> sqlList = new ArrayList<>();
+        SQLFactory sqlFactoryupdate;
+        if (isclose) {
+            sqlFactoryupdate = new SQLFactory(this, "促销方案关闭");
+            sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "关闭", "促销方案关闭成功").getSQL());
+        } else {
+            sqlFactoryupdate = new SQLFactory(this, "促销方案反关闭");
+            sqlList.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "反关闭", "促销方案反关闭成功").getSQL());
+        }
+        sqlFactoryupdate.addParameter("siteid", siteid);
+        sqlFactoryupdate.addParameter("sa_promotionid", sa_promotionid);
+        sqlFactoryupdate.addParameter("closeby", username);
+        sqlList.add(sqlFactoryupdate.getSQL());
+
+        dbConnect.runSqlUpdate(sqlList);
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "切换授权方式", apiversion = R.ID20230509100504.v1.class)
+    @CACHEING_CLEAN(apiversions = {R.ID20221230144703.v1.class})
+    public String updateAuthMethod() throws YosException {
+        Long sa_promotionid = content.getLong("sa_promotionid");
+        Rows rows = dbConnect.runSqlQuery("select sa_promotionid,status,authmethod from sa_promotion where sa_promotionid ='" + sa_promotionid + "' and  siteid='" + siteid + "'");
+        if (rows.isEmpty()) {
+            return getErrReturnObject().setErrMsg("无效促销方案").toString();
+        }
+        if (!rows.get(0).getString("status").equals("新建")) {
+            return getErrReturnObject().setErrMsg("非新建状态不能修改授权方式").toString();
+        }
+        if (rows.get(0).getLong("authmethod") == 0) {
+            dbConnect.runSqlUpdate("update sa_promotion set authmethod=1 where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
+        } else {
+            dbConnect.runSqlUpdate("update sa_promotion set authmethod=0 where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
+        }
+        return getSucReturnObject().toString();
+    }
 }