|
@@ -0,0 +1,287 @@
|
|
|
+package restcontroller.webmanage.saletool.fad;
|
|
|
+
|
|
|
+import beans.attachment.Attachment;
|
|
|
+import beans.datatag.DataTag;
|
|
|
+import beans.time.Time;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import common.Controller;
|
|
|
+import common.YosException;
|
|
|
+import common.annotation.API;
|
|
|
+import common.data.*;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import restcontroller.R;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 商品管理
|
|
|
+ */
|
|
|
+public class FadGoods extends Controller {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
+ public FadGoods(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ String sa_fad = "sa_fad";
|
|
|
+
|
|
|
+ @API(title = "单品新增或编辑", apiversion = R.ID20240428154102.v1.class)
|
|
|
+ public String insertOrUpdate() throws YosException {
|
|
|
+ Long sa_fadid = content.getLongValue("sa_fadid");
|
|
|
+ int isonsale = content.getIntValue("isonsale");
|
|
|
+
|
|
|
+ String tag = content.getStringValue("tag");
|
|
|
+
|
|
|
+ if (sa_fadid <= 0) {
|
|
|
+ sa_fadid = createTableID(sa_fad);
|
|
|
+ InsertSQL sqlFactory = SQLFactory.createInsertSQL(this, sa_fad);
|
|
|
+ sqlFactory.setSiteid(siteid);
|
|
|
+ sqlFactory.setUniqueid(sa_fadid);
|
|
|
+ sqlFactory.setValue("itemid", content.getLongValue("itemid"));
|
|
|
+ sqlFactory.setValue("itemno", content.getStringValue("itemno"));
|
|
|
+ sqlFactory.setValue("name", content.getStringValue("name"));
|
|
|
+ sqlFactory.setValue("subtitle", content.getStringValue("subtitle"));
|
|
|
+ sqlFactory.setValue("model", content.getStringValue("model"));
|
|
|
+ sqlFactory.setValue("class", content.getJSONArray("class"));
|
|
|
+ sqlFactory.setValue("pricetype", content.getStringValue("pricetype"));
|
|
|
+ sqlFactory.setValue("price", content.getBigDecimalValue("price"));
|
|
|
+ sqlFactory.setValue("price_deposit", content.getBigDecimalValue("price_deposit"));
|
|
|
+ sqlFactory.setValue("price_store", content.getBigDecimalValue("price_store"));
|
|
|
+ sqlFactory.setValue("price_rebate", content.getBigDecimalValue("price_rebate"));
|
|
|
+ sqlFactory.setValue("unitname", content.getStringValue("unitname"));
|
|
|
+ sqlFactory.setValue("isnew", content.getBooleanValue("isnew"));
|
|
|
+ sqlFactory.setValue("sequence", content.getLongValue("sequence"));
|
|
|
+ sqlFactory.setValue("content", content.getStringValue("contentstr", true));
|
|
|
+ sqlFactory.setValue("classid", 2);
|
|
|
+ sqlFactory.setValue("parentid", content.getLongValue("parentid"));
|
|
|
+ sqlFactory.setValue("canadjust", content.getLongValue("canadjust"));
|
|
|
+ sqlFactory.setValue("sys_enterpriseid", sys_enterpriseid);
|
|
|
+
|
|
|
+ sqlFactory.insert();
|
|
|
+ content.put("sa_fadid", sa_fadid);
|
|
|
+ } else {
|
|
|
+ UpdateSQL sqlFactory = SQLFactory.createUpdateSQL(this, sa_fad);
|
|
|
+ sqlFactory.setUniqueid(sa_fadid);
|
|
|
+ sqlFactory.setSiteid(siteid);
|
|
|
+ sqlFactory.setValue("itemid", content.getLongValue("itemid"));
|
|
|
+ sqlFactory.setValue("itemno", content.getStringValue("itemno"));
|
|
|
+ sqlFactory.setValue("name", content.getStringValue("name"));
|
|
|
+ sqlFactory.setValue("subtitle", content.getStringValue("subtitle"));
|
|
|
+ sqlFactory.setValue("model", content.getStringValue("model"));
|
|
|
+ sqlFactory.setValue("class", content.getJSONArray("class"));
|
|
|
+ sqlFactory.setValue("pricetype", content.getStringValue("pricetype"));
|
|
|
+ sqlFactory.setValue("price", content.getBigDecimalValue("price"));
|
|
|
+ sqlFactory.setValue("price_deposit", content.getBigDecimalValue("price_deposit"));
|
|
|
+ sqlFactory.setValue("price_store", content.getBigDecimalValue("price_store"));
|
|
|
+ sqlFactory.setValue("price_rebate", content.getBigDecimalValue("price_rebate"));
|
|
|
+ sqlFactory.setValue("unitname", content.getStringValue("unitname"));
|
|
|
+ sqlFactory.setValue("isnew", content.getBooleanValue("isnew"));
|
|
|
+ sqlFactory.setValue("sequence", content.getLongValue("sequence"));
|
|
|
+ sqlFactory.setValue("content", content.getStringValue("contentstr", true));
|
|
|
+ sqlFactory.setValue("parentid", content.getLongValue("parentid"));
|
|
|
+ sqlFactory.setValue("canadjust", content.getLongValue("canadjust"));
|
|
|
+ sqlFactory.setValue("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ sqlFactory.update();
|
|
|
+ }
|
|
|
+
|
|
|
+ //上下架
|
|
|
+ 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");
|
|
|
+ updateSQL.update();
|
|
|
+
|
|
|
+ DataTag.deleteTag(this, "sa_fad", sa_fadid);
|
|
|
+ DataTag.createSystemTag(this, "sa_fad", sa_fadid, tag);
|
|
|
+
|
|
|
+
|
|
|
+ return detail();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "商品详情", apiversion = R.ID20240428154202.v1.class)
|
|
|
+ public String detail() throws YosException {
|
|
|
+ Long sa_fadid = content.getLongValue("sa_fadid");
|
|
|
+ String ownertable = sa_fad;
|
|
|
+
|
|
|
+ Rows fadrows = dbConnect.runSqlQuery("select * from sa_fad where sa_fadid=" + sa_fadid);
|
|
|
+ if (fadrows.isNotEmpty()) {
|
|
|
+ siteid = fadrows.get(0).getString("siteid");
|
|
|
+ }
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate("UPDATE sa_fad SET readcount=readcount+1 WHERE sa_fadid=" + sa_fadid);
|
|
|
+
|
|
|
+ QuerySQL querySQ = SQLFactory.createQuerySQL(this, sa_fad)
|
|
|
+ .setTableAlias("t1");
|
|
|
+ querySQ.setSiteid(siteid);
|
|
|
+ querySQ.setWhere("sa_fadid", sa_fadid);
|
|
|
+ Rows rows = querySQ.query();
|
|
|
+
|
|
|
+ Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
|
|
|
+
|
|
|
+
|
|
|
+ Rows attRows = getAttachmentUrl(sa_fad, sa_fadid);
|
|
|
+ attRows.sortby("sequence", "linksid");
|
|
|
+ detailRow.put("attinfos", attRows);
|
|
|
+ detailRow.put("appleturl", FadHelper.getAppletUrl(this, "FadGoodsUrl", "商品小程序链接") + sa_fadid);
|
|
|
+
|
|
|
+
|
|
|
+ QuerySQL attachmentQuery = SQLFactory.createQuerySQL(this, "sys_attachment_links").setTableAlias("t1");
|
|
|
+ attachmentQuery.setSiteid(detailRow.getString("siteid"));
|
|
|
+ attachmentQuery.setWhere("ownertable", ownertable);
|
|
|
+ attachmentQuery.setWhere("ownerid", sa_fadid);
|
|
|
+ attachmentQuery.setWhere("usetype", ownertable);
|
|
|
+ attachmentQuery.setOrderBy("t1.sequence,t1.linksid");
|
|
|
+ Rows attachmentRows = attachmentQuery.query();
|
|
|
+
|
|
|
+
|
|
|
+ ArrayList<Long> ids = attachmentRows.toArrayList("attachmentid", new ArrayList<>());
|
|
|
+
|
|
|
+ RowsMap attRowsMap = Attachment.get(this, ids).toRowsMap("attachmentid");
|
|
|
+
|
|
|
+ for (Row row : attachmentRows) {
|
|
|
+ Rows attPicRows = new Rows();
|
|
|
+ Rows tempAttRows = attRowsMap.getOrDefault(row.getString("attachmentid"), new Rows());
|
|
|
+ for (Row tempAttRow : tempAttRows) {
|
|
|
+ if (tempAttRow.getString("usetype").equals(ownertable)) {
|
|
|
+ attPicRows.add(tempAttRow);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ row.put("attinfos", attPicRows);
|
|
|
+ }
|
|
|
+
|
|
|
+ detailRow.put("attinfos_pic", attachmentRows);
|
|
|
+ detailRow.putIfAbsent("onsaledate", "");
|
|
|
+ ArrayList<String> tags = DataTag.queryTag(this, "sa_fad", detailRow.getLong("sa_fadid"), true);
|
|
|
+ detailRow.putIfAbsent("tag", StringUtils.join(tags,","));
|
|
|
+ detailRow.putIfAbsent("classnames", StringUtils.join(detailRow.getJSONArray("class"),","));
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(detailRow).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "商品删除", apiversion = R.ID20240428154302.v1.class)
|
|
|
+ public String delete() throws YosException {
|
|
|
+ JSONArray sa_fadids = content.getJSONArray("sa_fadids");
|
|
|
+ if (sa_fadids.size() == 0) {
|
|
|
+ return getErrReturnObject().setErrMsg("请选择要删除的数据").toString();
|
|
|
+ }
|
|
|
+ DeleteSQL sqlFactory = SQLFactory.createDeleteSQL(this, sa_fad);
|
|
|
+ sqlFactory.setSiteid(siteid);
|
|
|
+ sqlFactory.setWhere("sa_fadid", sa_fadids.toArray());
|
|
|
+ sqlFactory.delete();
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "商品上下架", apiversion = R.ID20240428154402.v1.class)
|
|
|
+ public String isonsale() throws YosException {
|
|
|
+ JSONArray sa_fadids = content.getJSONArray("sa_fadids");
|
|
|
+ int isonsale = content.getIntValue("isonsale");
|
|
|
+
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sa_fad);
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setWhere("sa_fadid", sa_fadids);
|
|
|
+ updateSQL.setValue("isonsale", isonsale);
|
|
|
+ updateSQL.setValue("onsaledate", isonsale == 0 ? "null" : Time.getDateTime_Str());
|
|
|
+ updateSQL.setValue("onsaleby", isonsale == 0 ? "null" : username);
|
|
|
+ updateSQL.update();
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "单品列表", apiversion = R.ID20240428154002.v1.class)
|
|
|
+ public String list() 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.name like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.tag like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (whereObject.containsKey("isonsale") && !"".equals(whereObject.getString("isonsale"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.isonsale ='").append(whereObject.getString("isonsale")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (whereObject.containsKey("canadjust") && !"".equals(whereObject.getString("canadjust"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.canadjust ='").append(whereObject.getString("canadjust")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (whereObject.containsKey("begindate_create") && !"".equals(whereObject.getString("begindate_create"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.createdate >='").append(whereObject.getString("begindate_create")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("enddate_create") && !"".equals(whereObject.getString("enddate_create"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.createdate <='").append(whereObject.getString("enddate_create")).append(" 23:59:59' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("begindate_onsale") && !"".equals(whereObject.getString("begindate_onsale"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.onsaledate >='").append(whereObject.getString("begindate_onsale")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("enddate_onsale") && !"".equals(whereObject.getString("enddate_onsale"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.onsaledate <='").append(whereObject.getString("enddate_onsale")).append(" 23:59:59' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (whereObject.containsKey("class") && !"".equals(whereObject.getString("class"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("JSON_CONTAINS(t1.class,'\"" + whereObject.getString("class") + "\"')");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, sa_fad,
|
|
|
+ "sa_fadid", "name", "isonsale", "model", "pricetype","sequence", "createby", "createdate", "onsaledate","class")
|
|
|
+ .setTableAlias("t1");
|
|
|
+
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left,"sys_datatag","t2","t2.ownertable='sa_fad' and t2.ownerid=t1.sa_fadid and t2.siteid=t1.siteid");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("classid", 2);
|
|
|
+ querySQL.setWhere(where.toString());
|
|
|
+ querySQL.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+
|
|
|
+ ArrayList<Long> ids = rows.toArrayList("sa_fadid", new ArrayList<>());
|
|
|
+ // 附件
|
|
|
+ RowsMap RowsMap = getAttachmentUrl(sa_fad, ids);
|
|
|
+ for (Row row : rows) {
|
|
|
+ Rows attRows = RowsMap.getOrDefault(row.getString("sa_fadid"), new Rows());
|
|
|
+ attRows.sortby("sequence", "linksid");
|
|
|
+ row.put("attinfos", attRows);
|
|
|
+ row.put("appleturl", FadHelper.getAppletUrl(this, "FadGoodsUrl", "商品小程序链接") + row.getString("sa_fadid"));
|
|
|
+ row.putIfAbsent("onsaledate", "");
|
|
|
+
|
|
|
+ ArrayList<String> tags = DataTag.queryTag(this, "sa_fad", row.getLong("sa_fadid"), true);
|
|
|
+ row.putIfAbsent("tag", StringUtils.join(tags,","));
|
|
|
+ row.putIfAbsent("classnames", StringUtils.join(row.getJSONArray("class"),","));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+}
|