Pārlūkot izejas kodu

商户商品查询、新增修改、上下架、删除接口开发

沈静伟 4 gadi atpakaļ
vecāks
revīzija
87f935fc17

+ 2 - 0
src/dsb/com/cnd3b/restcontroller/customer/products/SQL/商品上架.sql

@@ -0,0 +1,2 @@
+update tagents_product set fisonsale=1,fonsaleby=$username$,fonsaledate=getdate()
+where siteid=$siteid$ and tagentsid=$tagentsid$ and tagents_productid=$tagents_productid$

+ 2 - 0
src/dsb/com/cnd3b/restcontroller/customer/products/SQL/商品下架.sql

@@ -0,0 +1,2 @@
+update tagents_product set fisonsale=0,foffsaleby=$username$,foffsaledate=getdate()
+where siteid=$siteid$ and tagentsid=$tagentsid$ and tagents_productid=$tagents_productid$

+ 2 - 0
src/dsb/com/cnd3b/restcontroller/customer/products/SQL/商品列表查询.sql

@@ -0,0 +1,2 @@
+select t1.tagents_productid,t1.fprice, t1.fprodname, t1.fprodnum,t1.fprodclassname from tagents_product t1
+where t1.siteid=$siteid$ and t1.tagentsid=$tagentsid$ and $where$

+ 4 - 0
src/dsb/com/cnd3b/restcontroller/customer/products/SQL/商品详情查询.sql

@@ -0,0 +1,4 @@
+select  tagents_productid, createby, changeby, createdate, changedate,
+ fisonsale, fnotes, foffsaleby, foffsaledate, fonsaleby, fonsaledate, fprice, fprodname, fprodnum
+ , fprodclassname, fintroduction from tagents_product t1
+ where siteid=$siteid$ and tagentsid=$tagentsid$ and tagents_productid=$tagents_productid$

+ 177 - 0
src/dsb/com/cnd3b/restcontroller/customer/products/products.java

@@ -0,0 +1,177 @@
+package com.cnd3b.restcontroller.customer.products;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.cnd3b.common.Controller;
+import com.cnd3b.common.D3bException;
+import com.cnd3b.common.data.Row;
+import com.cnd3b.common.data.Rows;
+import com.cnd3b.common.data.RowsMap;
+import com.cnd3b.common.data.SQLFactory;
+import p2.pao.PaoRemote;
+import p2.pao.PaoSetRemote;
+import p2.util.P2Exception;
+
+import java.util.ArrayList;
+
+public class products extends Controller {
+
+    /**
+     * 构造函数
+     *
+     * @param content
+     */
+    public products(JSONObject content) {
+        super(content);
+    }
+
+    /**
+     * 商品列表查询
+     *
+     * @return
+     */
+    public String query_productsList() {
+        /**
+         *排序条件设置
+         */
+        String[] sortfield = {"t1.fprodname"};
+        String sort = getSort(sortfield, "t1.fprodname");
+        /**
+         * 过滤条件设置
+         */
+        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.fprodname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.fprodnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.fintroduction like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+            if (whereObject.getBooleanValue("fisonsale")) {
+                where.append(" and t1.fisonsale=1 ");
+            } else {
+                where.append(" and t1.fisonsale=0 ");
+            }
+        }
+        SQLFactory sql = new SQLFactory(this, "商品列表查询", pageSize, pageNumber, sort);
+        sql.addParameter("siteid", siteid);
+        sql.addParameter("tagentsid", tagentsid);
+        sql.addParameter_SQL("where", where);
+        Rows rows = dbConnect.runSqlQuery(sql.getSQL());
+        RowsMap tagents_productMap = getAttachmentUrl("tagents_product", rows.toArrayList("tagents_productid"));
+        for (Row row : rows) {
+            row.put("attinfos", tagents_productMap.get(row.getString("tagents_productid")));
+        }
+        return getSucReturnObject().setDataByPaging(rows, sortfield).saveToDataPool().toString();
+    }
+
+    /**
+     * 商品详情查询
+     *
+     * @return
+     */
+    public String query_productsMain() {
+        SQLFactory sql = new SQLFactory(this, "商品详情查询");
+        sql.addParameter("siteid", siteid);
+        sql.addParameter("tagentsid", tagentsid);
+        sql.addParameter("tagents_productid", content.getLong("tagents_productid"));
+        Rows rows = dbConnect.runSqlQuery(sql.getSQL());
+        RowsMap tagents_productMap = getAttachmentUrl("tagents_product", rows.toArrayList("tagents_productid"));
+        for (Row row : rows) {
+            row.put("attinfos", tagents_productMap.get(row.getString("tagents_productid")));
+        }
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    /**
+     * 商品新增修改
+     *
+     * @return
+     */
+    public String insertOrModifyProducts() throws D3bException, P2Exception {
+        long tagents_productid = content.getLongValue("tagents_productid");//商品ID,新增时传0
+        String fprodnum = content.getString("fprodnum", "tagents_product.fprodnum", "商品编号");
+        String fprodname = content.getString("fprodname", "tagents_product.fprodname", "商品名称");
+        double fprice = content.getDoubleValue("fprice");
+        String fprodclassname = content.getString("fprodclassname", "tagents_product.fprodclassname", "经营类目");
+        String fintroduction = content.getString("fintroduction", "tagents_product.fintroduction", "产品介绍");
+        String fnotes = content.getString("fnotes", "tagents_product.fnotes", "备注");
+
+        PaoSetRemote tagents_productSet = getP2ServerSystemPaoSet("tagents_product", "siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tagents_productid='" + tagents_productid + "'");
+        PaoRemote tagents_product = null;
+        if (tagents_productid <= 0 || tagents_productSet.isEmpty()) {
+            tagents_product = tagents_productSet.addAtEnd();
+            tagents_product.setValue("siteid", siteid, 11L);//企业ID
+            tagents_product.setValue("tagentsid", tagentsid, 11L);//企业ID
+            tagents_product.setValue("createby", username, 11L);//录入人
+            tagents_product.setValue("createdate", sysdate, 11L);//录入时间
+        } else {
+            tagents_product = tagents_productSet.getPao(0);
+        }
+        tagents_product.setValue("fprodnum", fprodnum, 11L);//产品编号
+        tagents_product.setValue("fprodname", fprodname, 11L);//产品名称
+        tagents_product.setValue("fprice", fprice, 11L);//销售单价
+        tagents_product.setValue("fprodclassname", fprodclassname, 11L);//经营类目
+        tagents_product.setValue("fintroduction", fintroduction, 11L);//产品介绍
+        tagents_product.setValue("fnotes", fnotes, 11L);//备注
+        tagents_product.setValue("changeby", username, 11L);//修改人
+        tagents_product.setValue("changedate", sysdate, 11L);//修改时间
+        content.put("tagents_productid", tagents_product.getUniqueIDValue());
+        saveDataLog(tagents_product);
+        tagents_productSet.save();
+        return query_productsMain();
+    }
+
+    /**
+     * 商品上下架
+     *
+     * @return
+     */
+    public String updatesalestatus() throws D3bException, P2Exception {
+        ArrayList<String> sqlist = new ArrayList<>();
+        JSONArray productlistArray = content.getJSONArray("productlist");
+        for (Object o : productlistArray) {
+            JSONObject product = (JSONObject) o;
+            String tagents_productid = product.getString("tagents_productid");
+            boolean fisonsale = product.getBoolean("fisonsale");
+            SQLFactory sqlFactory = null;
+            if (fisonsale) {
+                sqlFactory = new SQLFactory(this, "商品上架");
+            } else {
+                sqlFactory = new SQLFactory(this, "商品下架");
+            }
+            sqlFactory.addParameter("username", username);
+            sqlFactory.addParameter("siteid", siteid);
+            sqlFactory.addParameter("tagentsid", tagentsid);
+            sqlFactory.addParameter("tagents_productid", tagents_productid);
+            sqlist.add(sqlFactory.getSQL());
+        }
+        String status = dbConnect.runSqlUpdate(sqlist);
+        if ("true".equals(status)) {
+            return getSucReturnObject().toString();
+        } else {
+            return getErrReturnObject().toString();
+        }
+    }
+
+    /**
+     * 商品删除
+     *
+     * @return
+     */
+    public String deleteProducts() throws D3bException, P2Exception {
+        long tagents_productid = content.getLongValue("tagents_productid");//商品ID
+        Rows rows = dbConnect.runSqlQuery("select *from tagents_product where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tagents_productid='" + tagents_productid + "'");
+        if (!rows.isEmpty() && rows.get(0).getBoolean("fisonsale")) {
+            return getErrReturnObject().setErrMsg("上架商品不可删除").toString();
+        }
+        String status = dbConnect.runSqlUpdate("delete from tagents_product where siteid='" + siteid + "' and tagentsid='" + tagentsid + "' and tagents_productid='" + tagents_productid + "'");
+        if ("true".equals(status)) {
+            return getSucReturnObject().toString();
+        } else {
+            return getErrReturnObject().toString();
+        }
+    }
+}

+ 0 - 23
src/dsb/com/cnd3b/restcontroller/system/system/docinfos.java

@@ -1,23 +0,0 @@
-package com.cnd3b.restcontroller.system.system;
-
-import com.cnd3b.common.data.Rows;
-import com.cnd3b.common.data.db.DBConnect;
-import com.cnd3b.common.Controller;
-
-import com.alibaba.fastjson.JSONObject;
-public class docinfos extends Controller {
-    /**
-     * ¹¹Ô캯Êý
-     *
-     * @param content
-     */
-    public docinfos(JSONObject content) {
-        super(content);
-    }
-
-    public String getdoctypes() {
-        DBConnect dbConnect = new DBConnect();
-        Rows rows = dbConnect.runSqlQuery("select doctype,description,suffix,maxfilesize from doctypes where doctype='Attachments' ");
-        return getSucReturnObject().setData(rows).saveToDataPool().toString();
-    }
-}