浏览代码

订单提交时校验商品上架状态

eganwu 1 年之前
父节点
当前提交
295bf14bb8

+ 10 - 6
src/custom/restcontroller/webmanage/sale/order/Order.java

@@ -1404,14 +1404,18 @@ public class Order extends Controller {
         if (orderitems.isNotEmpty()) {
             return getErrReturnObject().setErrMsg("订单表体行号为【" + orderitems.get(0).getLong("rowno") + "】的商品数量为0无法提交").toString();
         }
+        OrderItemsHelper orderItemsHelper = new OrderItemsHelper(this);
         String type = row.getString("type");
+        //标准订单:提交时商品必须是上架状态,否则不允许提交
         if (type.equals("标准订单")) {
-            Rows iteminfos = dbConnect.runSqlQuery("select t2.itemno from sa_orderitems t1 inner join plm_item t2 on t1.siteid=t2.siteid and t1.itemid=t2.itemid where t1.sa_orderid=" + sa_orderid + " and t1.siteid='" + siteid + "' and t2.isonsale!=1");
-            if (iteminfos.isNotEmpty()) {
-                return getErrReturnObject().setErrMsg("检测到品号" + iteminfos.get(0).getString("itemno") + "未上架,请删除后重试").toString();
-            }
-        }   //辅助类
-        OrderItemsHelper orderItemsHelper = new OrderItemsHelper(this);
+            orderItemsHelper.checkOffOrderItems(sa_orderid, "sa_orderitems");
+        }
+        //促销订单:提交时商品必须是上架状态,并且活动方案中的商品必须也是上架状态,否则不允许提交
+        if (type.equals("促销订单")) {
+            orderItemsHelper.checkOffOrderItems(sa_orderid, "sa_orderitems");
+            orderItemsHelper.checkOffOrderItems(sa_orderid, "sa_promotion_items");
+        }
+
         if (type.equals("标准订单") || type.equals("促销订单")) {
             Rows orderiteminfos = dbConnect.runSqlQuery("select t1.* from sa_orderitems t1  where t1.sa_orderid=" + sa_orderid + " and t1.siteid='" + siteid + "'");
             for (Row row1 : orderiteminfos) {

+ 19 - 9
src/custom/restcontroller/webmanage/sale/order/OrderItemsHelper.java

@@ -22,6 +22,15 @@ public class OrderItemsHelper extends BaseClass {
         this.content = controller.content;
     }
 
+
+    public void checkOffOrderItems(Long sa_orderid, String tablename) throws YosException {
+        Rows iteminfos = dbConnect.runSqlQuery("select t2.itemno from " + tablename + " t1 inner join plm_item t2 on t1.siteid=t2.siteid and t1.itemid=t2.itemid where t1.sa_orderid="
+                + sa_orderid + " and t1.siteid='" + controller.siteid + "' and t2.isonsale!=1");
+        if (iteminfos.isNotEmpty()) {
+            new YosException(false, "检测到品号" + iteminfos.get(0).getString("itemno") + "未上架,请删除后重试");
+        }
+    }
+
     /**
      * 是否符合商品起订量和增量判断
      *
@@ -137,7 +146,7 @@ public class OrderItemsHelper extends BaseClass {
      */
     public String getCustomSpec(RowsMap itemRowsMap, JSONObject item) throws YosException {
 
-        String spec="";
+        String spec = "";
         Rows customschemeRows = dbConnect.runSqlQuery("select * from sa_customscheme_items where siteid='" + controller.siteid + "'");
         RowsMap customschemeRowsMap = customschemeRows.toRowsMap("sa_customschemeid");
 
@@ -145,9 +154,9 @@ public class OrderItemsHelper extends BaseClass {
         if (itemRowsMap.containsKey(itemid)) {
             if (itemRowsMap.get(itemid).isNotEmpty()) {
                 if (!itemRowsMap.get(itemid).get(0).getBoolean("iscustomsize")) {
-                    spec=itemRowsMap.get(itemid).get(0).getString("spec");
+                    spec = itemRowsMap.get(itemid).get(0).getString("spec");
                 } else {
-                    spec=item.getStringValue("length") + "*" + item.getStringValue("width");
+                    spec = item.getStringValue("length") + "*" + item.getStringValue("width");
                 }
 
             }
@@ -195,11 +204,11 @@ public class OrderItemsHelper extends BaseClass {
 
     String sa_orderitems = "sa_orderitems";
 
-    public InsertSQL getInsertSQL(JSONArray customproperties, long sa_orderitemsid, JSONObject item, Row itemRow, String type, BigDecimal defaultprice, BigDecimal price,BigDecimal saleprice, BigDecimal marketprice,String spec, Rows promotionitems) throws YosException {
+    public InsertSQL getInsertSQL(JSONArray customproperties, long sa_orderitemsid, JSONObject item, Row itemRow, String type, BigDecimal defaultprice, BigDecimal price, BigDecimal saleprice, BigDecimal marketprice, String spec, Rows promotionitems) throws YosException {
         Long itemid = item.getLong("itemid");
         BigDecimal qty = item.getBigDecimalValue("qty");
         RowsMap promotionitemsRowsMap = promotionitems.toRowsMap("sa_promotion_itemsid");
-        String signaturecode="";
+        String signaturecode = "";
         if (type.equals("促销订单")) {
             if (promotionitemsRowsMap.containsKey(item.getString("sa_promotion_itemsid"))) {
                 if (promotionitemsRowsMap.get(item.getString("sa_promotion_itemsid")).isNotEmpty()) {
@@ -215,7 +224,7 @@ public class OrderItemsHelper extends BaseClass {
         insertSQL.setValue("sa_orderid", content.getLongValue("sa_orderid"));
         insertSQL.setValue("rowno", 1);
         insertSQL.setValue("itemid", itemid);
-        insertSQL.setValue("remarks", item.getStringValue("remarks")+signaturecode);
+        insertSQL.setValue("remarks", item.getStringValue("remarks") + signaturecode);
         insertSQL.setValue("itemno", itemRow.getString("itemno"));
         insertSQL.setValue("itemname", itemRow.getString("itemname"));
         insertSQL.setValue("model", itemRow.getString("model"));
@@ -225,8 +234,8 @@ public class OrderItemsHelper extends BaseClass {
         insertSQL.setValue("stockno", item.getOrDefault("stockno", "null"));
         insertSQL.setValue("position", item.getOrDefault("position", "null"));
         insertSQL.setValue("batchno", item.getOrDefault("batchno", "null"));
-        insertSQL.setValue("spec",spec);
-        insertSQL.setValue("sa_promotion_itemsid",item.getLongValue("sa_promotion_itemsid"));
+        insertSQL.setValue("spec", spec);
+        insertSQL.setValue("sa_promotion_itemsid", item.getLongValue("sa_promotion_itemsid"));
         String deliverydate = item.getStringValue("deliverydate");
         Rows rows = dbConnect.runSqlQuery("SELECT deliverydate,defaultprice from sa_orderitems WHERE sa_orderitemsid =" + sa_orderitemsid);
         if (deliverydate.isEmpty()) {
@@ -287,7 +296,7 @@ public class OrderItemsHelper extends BaseClass {
         return insertSQL;
     }
 
-    public UpdateSQL getUpdateSQL(long sa_orderitemsid, JSONObject item, Row itemRow, String type, BigDecimal defaultprice, BigDecimal price,BigDecimal saleprice) throws YosException {
+    public UpdateSQL getUpdateSQL(long sa_orderitemsid, JSONObject item, Row itemRow, String type, BigDecimal defaultprice, BigDecimal price, BigDecimal saleprice) throws YosException {
         BigDecimal qty = item.getBigDecimalValue("qty");
 
         UpdateSQL updateSQL = SQLFactory.createUpdateSQL(controller, sa_orderitems);
@@ -391,6 +400,7 @@ public class OrderItemsHelper extends BaseClass {
 
         return price;
     }
+
     public BigDecimal getSalePrice(Row orderRow, ItemPrice itemPrice) throws YosException {
         String type = orderRow.getString("type");
         Long sa_promotionid = orderRow.getLong("sa_promotionid");