|
|
@@ -29,14 +29,19 @@ public class FadGoods extends Controller {
|
|
|
|
|
|
String sa_fad = "sa_fad";
|
|
|
|
|
|
- @API(title = "单品新增或编辑", apiversion = R.ID20240428154102.v1.class)
|
|
|
+ @API(title = "商品新增或编辑", apiversion = R.ID20240428154102.v1.class)
|
|
|
public String insertOrUpdate() throws YosException {
|
|
|
Long sa_fadid = content.getLongValue("sa_fadid");
|
|
|
- int isonsale = content.getIntValue("isonsale");
|
|
|
+ boolean canadjust = content.getBooleanValue("canadjust");
|
|
|
String tag = content.getStringValue("tag");
|
|
|
Long parentid = 0L;
|
|
|
+ if (content.containsKey("sys_enterpriseid") && content.getLongValue("sys_enterpriseid") != 0) {
|
|
|
+ sys_enterpriseid = content.getLongValue("sys_enterpriseid");
|
|
|
+ }
|
|
|
|
|
|
ArrayList<String> listSQL = new ArrayList<>();
|
|
|
+ ArrayList<Long> sa_fadids = new ArrayList<>();
|
|
|
+
|
|
|
Rows fadRows = dbConnect.runSqlQuery("SELECT * from sa_fad WHERE sa_fadid=" + sa_fadid + " and siteid='" + siteid + "'");
|
|
|
if (sa_fadid <= 0 || fadRows.isEmpty()) {
|
|
|
sa_fadid = createTableID(sa_fad);
|
|
|
@@ -45,22 +50,31 @@ public class FadGoods extends Controller {
|
|
|
content.put("sa_fadid", sa_fadid);
|
|
|
} else {
|
|
|
|
|
|
- boolean canadjust = fadRows.get(0).getBoolean("canadjust");
|
|
|
+ boolean temp_canadjust = fadRows.get(0).getBoolean("canadjust");
|
|
|
long temp_sys_enterpriseid = fadRows.get(0).getLong("sys_enterpriseid");
|
|
|
//允许经销商调整,数据是总部的,修改方为总部
|
|
|
- if (canadjust && temp_sys_enterpriseid == 0 && sys_enterpriseid == 0) {
|
|
|
+ if (temp_canadjust && temp_sys_enterpriseid == 0 && sys_enterpriseid == 0) {
|
|
|
UpdateSQL sqlFactory = FadHelper.getFadUpdateSQL(this, sa_fadid);
|
|
|
listSQL.add(sqlFactory.getSQL());
|
|
|
//更新parentid为sa_fadid的数据
|
|
|
Rows rows = dbConnect.runSqlQuery("SELECT sa_fadid from sa_fad WHERE parentid=" + sa_fadid + " and siteid='" + siteid + "'");
|
|
|
- for (Row row : rows) {
|
|
|
- sqlFactory = FadHelper.getFadUpdateSQL(this, row.getLong("sa_fadid"));
|
|
|
- listSQL.add(sqlFactory.getSQL());
|
|
|
+ //修改项为禁止经销商修改
|
|
|
+ if (!canadjust) {
|
|
|
+ DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_fad");
|
|
|
+ deleteSQL.setSiteid(siteid);
|
|
|
+ deleteSQL.setWhere("parentid", sa_fadid);
|
|
|
+ deleteSQL.delete();
|
|
|
+ } else {
|
|
|
+ sa_fadids = rows.toArrayList("sa_fadid", new ArrayList<>());
|
|
|
+ for (Row row : rows) {
|
|
|
+ sqlFactory = FadHelper.getFadUpdateSQL(this, row.getLong("sa_fadid"));
|
|
|
+ listSQL.add(sqlFactory.getSQL());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//允许经销商调整,数据是总部的,修改方为经销商
|
|
|
- else if (canadjust && temp_sys_enterpriseid == 0 && sys_enterpriseid > 0) {
|
|
|
+ else if (temp_canadjust && temp_sys_enterpriseid == 0 && sys_enterpriseid > 0) {
|
|
|
parentid = sa_fadid;
|
|
|
sa_fadid = createTableID(sa_fad);
|
|
|
InsertSQL sqlFactory = FadHelper.getFadInsertSQL(this, sa_fadid, parentid);
|
|
|
@@ -74,18 +88,17 @@ public class FadGoods extends Controller {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ sa_fadids.add(sa_fadid);
|
|
|
+ for (Long id : sa_fadids) {
|
|
|
+ listSQL.add(FadHelper.getIsOnSalesUpdateSQL(this, id).getSQL());
|
|
|
+ }
|
|
|
//上下架
|
|
|
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sa_fad);
|
|
|
- updateSQL.setSiteid(siteid);
|
|
|
- updateSQL.setWhere("sa_fadid", sa_fadid);
|
|
|
- updateSQL.setValue("isonsale", isonsale);
|
|
|
- updateSQL.setValue("onsaledate", isonsale == 1 ? Time.getDateTime_Str() : "null");
|
|
|
- updateSQL.setValue("onsaleby", isonsale == 1 ? username : "null");
|
|
|
- listSQL.add(updateSQL.getSQL());
|
|
|
dbConnect.runSqlUpdate(listSQL);
|
|
|
|
|
|
- DataTag.deleteTag(this, "sa_fad", sa_fadid);
|
|
|
- DataTag.createSystemTag(this, "sa_fad", sa_fadid, tag);
|
|
|
+ for (Long id : sa_fadids) {
|
|
|
+ DataTag.deleteTag(this, "sa_fad", id);
|
|
|
+ DataTag.createSystemTag(this, "sa_fad", id, tag);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
return detail();
|