123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- 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 restcontroller.system.dataauth.DataAuthHelper;
- 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");
- 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);
- InsertSQL sqlFactory = FadHelper.getFadInsertSQL(this, sa_fadid, parentid);
- listSQL.add(sqlFactory.getSQL());
- content.put("sa_fadid", sa_fadid);
- } else {
- boolean temp_canadjust = fadRows.get(0).getBoolean("canadjust");
- long temp_sys_enterpriseid = fadRows.get(0).getLong("sys_enterpriseid");
- //允许经销商调整,数据是总部的,修改方为总部
- 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 + "'");
- //修改项为禁止经销商修改
- 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 (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);
- listSQL.add(sqlFactory.getSQL());
- content.put("sa_fadid", sa_fadid);
- //修改
- content.put("ownertable", "sa_fad");
- content.put("ownerid", sa_fadid);
- Long sys_dataauthid = createTableID("sys_dataauth");
- listSQL.add(DataAuthHelper.getDataAuthInsertSQL(this, sys_dataauthid).getSQL());
- listSQL.add(DataAuthHelper.getDataAuthsInsertSQL(this, "sys_enterpriseid", sys_enterpriseid).getSQL());
- } else {
- UpdateSQL sqlFactory = FadHelper.getFadUpdateSQL(this, sa_fadid);
- listSQL.add(sqlFactory.getSQL());
- }
- }
- sa_fadids.add(sa_fadid);
- for (Long id : sa_fadids) {
- listSQL.add(FadHelper.getIsOnSalesUpdateSQL(this, id).getSQL());
- }
- //上下架
- dbConnect.runSqlUpdate(listSQL);
- for (Long id : sa_fadids) {
- DataTag.deleteTag(this, "sa_fad", id);
- DataTag.createSystemTag(this, "sa_fad", id, 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.addJoinTable(JOINTYPE.left, "sys_datacollect", "t2", "t2.siteid=t1.siteid and t2.ownertable='sa_fad' and t2.type=1 and t2.ownerid=t1.sa_fadid and t2.userid='" + userid + "'");
- querySQ.addQueryFields("iscollect", "CASE WHEN t2.sys_datacollectid>0 THEN 1 ELSE 0 END");
- 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"), ","));
- //查询官方信息:价格。。。
- Long parentid = detailRow.getLong("parentid");
- if (parentid == 0) {
- parentid = sa_fadid;
- }
- Rows officalrows = dbConnect.runSqlQuery("SELECT sa_fadid,price,price_store,price_rebate,price_deposit,price_original from sa_fad WHERE siteid='" + siteid + "' and sa_fadid=" + parentid);
- Row officalrow = officalrows.isNotEmpty() ? officalrows.get(0) : new Row();
- ArrayList<String> officaltags = DataTag.queryTag(this, "sa_fad", parentid, true);
- officalrow.putIfAbsent("tag", StringUtils.join(officaltags, ","));
- detailRow.put("officialinfo", officalrow);
- 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", "canadjust", "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();
- }
- @API(title = "获取门店商品列表", apiversion = R.ID20240430094102.v1.class)
- public String getStoreList() 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("isnew") && !"".equals(whereObject.getString("isnew"))) {
- where.append(" and (");
- where.append("t1.isnew ='").append(whereObject.getString("isnew")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("class") && !"".equals(whereObject.getString("class"))) {
- where.append(" and (");
- where.append("JSON_CONTAINS(t1.class,'\"" + whereObject.getString("class") + "\"')");
- where.append(")");
- }
- if (whereObject.containsKey("iscollect") && !"".equals(whereObject.getString("iscollect"))) {
- if (whereObject.getString("iscollect").equals("1")) {
- where.append(" and (");
- where.append(" t1.sa_fadid in (SELECT ownerid from sys_datacollect WHERE ownertable='sa_fad' and type=1 and siteid='" + siteid + "' and userid=" + userid + ")");
- where.append(")");
- }
- }
- }
- ArrayList<Long> sys_enterpriseids = new ArrayList<Long>();
- Long sys_enterpriseid = content.getLongValue("sys_enterpriseid");
- if (sys_enterpriseid == -1) {
- return getSucReturnObject().setData(new Rows()).toString();
- }
- sys_enterpriseids.add(sys_enterpriseid);
- sys_enterpriseids.add(0L);
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, sa_fad,
- "sa_fadid", "name", "pricetype", "price", "price_deposit", "unitname")
- .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("not EXISTS(SELECT 1 from sa_fad WHERE sys_enterpriseid=" + sys_enterpriseid + " and parentid=t1.sa_fadid and siteid=t1.siteid)");
- querySQL.setWhere("sys_enterpriseid", sys_enterpriseids);
- querySQL.setWhere("classid", 2);
- querySQL.setWhere("isonsale", 1);
- querySQL.setWhere(where.toString());
- querySQL.setDataAuth(true);
- 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);
- ArrayList<String> tags = DataTag.queryTag(this, "sa_fad", row.getLong("sa_fadid"), true);
- row.putIfAbsent("tag", StringUtils.join(tags, ","));
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "获取门店调整商品列表", apiversion = R.ID20240515153202.v1.class)
- public String getAdjustStoreList() 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("class") && !"".equals(whereObject.getString("class"))) {
- where.append(" and (");
- where.append("JSON_CONTAINS(t1.class,'\"" + whereObject.getString("class") + "\"')");
- where.append(")");
- }
- }
- ArrayList<Long> sys_enterpriseids = new ArrayList<Long>();
- Long sys_enterpriseid = content.getLongValue("sys_enterpriseid");
- if (sys_enterpriseid == -1) {
- return getSucReturnObject().setData(new Rows()).toString();
- }
- sys_enterpriseids.add(sys_enterpriseid);
- sys_enterpriseids.add(0L);
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, sa_fad,
- "sa_fadid", "name", "pricetype", "price", "price_deposit", "unitname")
- .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("not EXISTS(SELECT 1 from sa_fad WHERE sys_enterpriseid=" + sys_enterpriseid + " and parentid=t1.sa_fadid and siteid=t1.siteid)");
- querySQL.setWhere("sys_enterpriseid", sys_enterpriseids);
- querySQL.setWhere("classid", 2);
- querySQL.setWhere("isonsale", 1);
- querySQL.setWhere("canadjust", 1);
- querySQL.setWhere(where.toString());
- querySQL.setDataAuth(true);
- 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);
- }
- return getSucReturnObject().setData(rows).toString();
- }
- }
|