瀏覽代碼

购物车和活动购物车添加相同商品时需提示该商品已添加至购物车,不能再次添加。

eganwu 1 年之前
父節點
當前提交
b1b81a861a
共有 1 個文件被更改,包括 41 次插入12 次删除
  1. 41 12
      src/custom/restcontroller/sale/shoppingcart/ShoppingCart.java

+ 41 - 12
src/custom/restcontroller/sale/shoppingcart/ShoppingCart.java

@@ -40,10 +40,27 @@ public class ShoppingCart extends Controller {
         BigDecimal qty = content.getBigDecimal("qty");
         BigDecimal length = content.getBigDecimal("length");
         BigDecimal width = content.getBigDecimal("width");
+        String cheek = content.getStringValue("cheek");
+        String colors = content.getStringValue("colors");
+        String material = content.getStringValue("material");
         String itemno = content.getString("itemno");
         String tradefield = content.getStringValue("tradefield");
         long sa_promotionid = content.getLongValue("sa_promotionid");
         long sa_promotion_itemsid = content.getLongValue("sa_promotion_itemsid");
+
+        cheek = cheek.equals("0") ? "" : cheek;
+        colors = colors.equals("0") ? "" : colors;
+        material = material.equals("0") ? "" : material;
+
+        if (dbConnect.runSqlQuery("SELECT * from sa_shoppingcart " +
+                "WHERE ifnull(length,0)=" + length + " and ifnull(width,0)=" + width +
+                " and ifnull(colors,'') ='" + colors + "' and ifnull(cheek,'')='" + cheek + "' and ifnull(material,'')='" + material + "'" +
+                " and sa_promotionid=" + sa_promotionid + " and itemid = " + itemid + " and sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "'").isNotEmpty()) {
+
+            return getErrReturnObject().setErrMsg("商品【" + itemno + "】已添加至购物车,不能再次添加。").toString();
+        }
+
+
         SQLFactory sqlFactory = new SQLFactory(this, "购物车新增");
         Long sa_shoppingcartid = 0L;
         Rows rows = dbConnect.runSqlQuery("SELECT sa_shoppingcartid FROM sa_shoppingcart WHERE siteid = '" + siteid +
@@ -80,13 +97,11 @@ public class ShoppingCart extends Controller {
         sqlFactory.addParameter("sa_brandid", sa_brandid);
         sqlFactory.addParameter("qty", qty);
         sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
-        String cheek = content.getStringValue("cheek");
-        String colors = content.getStringValue("colors");
-        String material = content.getStringValue("material");
 
-        sqlFactory.addParameter("cheek", cheek.equals("0") ? "" : cheek);
-        sqlFactory.addParameter("colors", colors.equals("0") ? "" : colors);
-        sqlFactory.addParameter("material", material.equals("0") ? "" : material);
+
+        sqlFactory.addParameter("cheek", cheek);
+        sqlFactory.addParameter("colors", colors);
+        sqlFactory.addParameter("material", material);
         sqlList.add(sqlFactory.getSQL());
 
         dbConnect.runSqlUpdate(sqlList);
@@ -114,6 +129,23 @@ public class ShoppingCart extends Controller {
             String tradefield = item.getStringValue("tradefield");
             long sa_promotionid = item.getLongValue("sa_promotionid");
             long sa_promotion_itemsid = item.getLongValue("sa_promotion_itemsid");
+            String cheek = item.getStringValue("cheek");
+            String colors = item.getStringValue("colors");
+            String material = item.getStringValue("material");
+
+            cheek = cheek.equals("0") ? "" : cheek;
+            colors = colors.equals("0") ? "" : colors;
+            material = material.equals("0") ? "" : material;
+
+            if (dbConnect.runSqlQuery("SELECT * from sa_shoppingcart " +
+                    "WHERE ifnull(length,0)=" + length + " and ifnull(width,0)=" + width +
+                    " and ifnull(colors,'') ='" + colors + "' and ifnull(cheek,'')='" + cheek + "' and ifnull(material,'')='" + material + "'" +
+                    " and sa_promotionid=" + sa_promotionid + " and itemid = " + itemid + " and sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "'").isNotEmpty()) {
+
+                return getErrReturnObject().setErrMsg("商品【" + itemno + "】已添加至购物车,不能再次添加。").toString();
+            }
+
+
             SQLFactory sqlFactory = new SQLFactory(this, "购物车新增");
             Long sa_shoppingcartid = 0L;
             Rows rows = dbConnect.runSqlQuery("SELECT sa_shoppingcartid FROM sa_shoppingcart WHERE siteid = '" + siteid +
@@ -150,13 +182,10 @@ public class ShoppingCart extends Controller {
             sqlFactory.addParameter("qty", qty);
             sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
 
-            String cheek = content.getStringValue("cheek");
-            String colors = content.getStringValue("colors");
-            String material = content.getStringValue("material");
 
-            sqlFactory.addParameter("cheek", cheek.equals("0") ? "" : cheek);
-            sqlFactory.addParameter("colors", colors.equals("0") ? "" : colors);
-            sqlFactory.addParameter("material", material.equals("0") ? "" : material);
+            sqlFactory.addParameter("cheek", cheek);
+            sqlFactory.addParameter("colors", colors);
+            sqlFactory.addParameter("material", material);
             //System.out.println(sqlFactory.getSQL());
             sqlList.add(sqlFactory.getSQL());
         }