Explorar o código

花材接口更换

shish %!s(int64=5) %!d(string=hai) anos
pai
achega
bfa83a5793
Modificáronse 3 ficheiros con 38 adicións e 53 borrados
  1. 24 34
      app-ghs/controllers/ProductController.php
  2. 12 18
      app-hd/controllers/ProductController.php
  3. 2 1
      sql.sql

+ 24 - 34
app-ghs/controllers/ProductController.php

@@ -56,7 +56,7 @@ class ProductController extends BaseController
         }
         $where['shopId'] = $shopId;
 
-        $itemInfoData = ProductClass::getAllByCondition($where,null,"*");
+        $itemInfoData = ProductClass::getAllByCondition($where, null, "*");
         $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
         //常用的itemIds
         $oftenItemIds = ProductClass::getOftenItemIds($shopId);
@@ -65,7 +65,7 @@ class ProductController extends BaseController
 
         //dd($itemInfoData);
         //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
-        $data = ProductService::assembleData($classIds, $itemIdsInfo,$itemInfoData, $oftenItemIds, $type);
+        $data = ProductService::assembleData($classIds, $itemIdsInfo, $itemInfoData, $oftenItemIds, $type);
 
         util::success($data);
     }
@@ -93,38 +93,28 @@ class ProductController extends BaseController
         $where['shopId'] = $shopId;
 
         $type = Yii::$app->request->get('type', '');
-        $showPage = Yii::$app->request->get('showPage',0);
-        if($showPage){
-            $res = ProductClass::getList("*",$where,"inTurn desc");
-            $data = $res['list'];
-        }else{
-            $data = ProductClass::getAllByCondition($where,"inTurn desc","*");
+        $showPage = Yii::$app->request->get('showPage', 0);
+        if ($showPage) {
+            $respond = ProductClass::getList("*", $where, "inTurn desc");
+            util::success($respond);
         }
+        $data = ProductClass::getAllByCondition($where, "inTurn desc", "*");
 
         $data = ProductClass::groupProductInfo($data);
         if ($type == 'waring') {
             //库存预警
             $newData = [];
-            foreach ($data as $v){
-                if($v['stock']  <= $v['stockWarning']) {
+            foreach ($data as $v) {
+                if ($v['stock'] <= $v['stockWarning']) {
                     $newData[] = $v;
                 }
             }
             util::success(['list' => $newData]);
         }
-        if($showPage){
-            $res['list'] = $data;
-            util::success(['list' => $res]);
-        }else{
-            util::success(['list' => $data]);
-        }
-
-
-
+        util::success(['list' => $data]);
     }
 
 
-
     //改价
     public function actionChangePrice()
     {
@@ -156,7 +146,7 @@ class ProductController extends BaseController
             $price = bcadd($productData['cost'], $productData['addPrice'], 2);
             ProductClass::changePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
         }
-        util::success(['price'=>$price]);
+        util::success(['price' => $price]);
     }
 
     //恢复自动调价
@@ -186,41 +176,41 @@ class ProductController extends BaseController
     {
         $productId = Yii::$app->request->post('productId', 0);
         $addPrice = Yii::$app->request->post('addPrice', '');
-        if($addPrice < 0 ){
+        if ($addPrice < 0) {
             util::fail("加价不能小于0");
         }
         $productData = ProductClass::getProductData($productId, $this->shopId);
         if (!$productData) {
             util::fail("花材不存在");
         }
-        ProductClass::changeAddPrice($productId,$addPrice);
+        ProductClass::changeAddPrice($productId, $addPrice);
         util::complete();
     }
 
     //批量修改product 排序,成本价,加价
     public function actionBatchUpdate()
     {
-        $data = Yii::$app->request->post('data',''); //data = [{id:1,inTurn:10,addPrice:2,cost:10}]
-        $type = Yii::$app->request->post('type','');
-        if(empty($data) || empty($type)){
+        $data = Yii::$app->request->post('data', ''); //data = [{id:1,inTurn:10,addPrice:2,cost:10}]
+        $type = Yii::$app->request->post('type', '');
+        if (empty($data) || empty($type)) {
             util::fail("参数错误");
         }
-        if(in_array($type,['inTurn','addPrice','cost','weight','ratio']))
-        $data = json_decode($data,true);
-        foreach ($data as $v){
+        if (in_array($type, ['inTurn', 'addPrice', 'cost', 'weight', 'ratio']))
+            $data = json_decode($data, true);
+        foreach ($data as $v) {
             $id = $v['id'];
-            $val = $v[$type]??'';
+            $val = $v[$type] ?? '';
             $where = [];
             $where['id'] = $id;
             $where['shopId'] = $this->shopId;
             $where['merchantId'] = $this->sjId;
-            if(empty($val)){
+            if (empty($val)) {
                 util::fail("参数错误1");
             }
-            $data =[
-                $type=>$val
+            $data = [
+                $type => $val
             ];
-            ProductClass::updateByCondition($where,$data);
+            ProductClass::updateByCondition($where, $data);
         }
         util::complete();
     }

+ 12 - 18
app-hd/controllers/ProductController.php

@@ -15,6 +15,7 @@ use bizGhs\item\services\ItemService;
 use common\components\noticeUtil;
 use common\components\util;
 use Yii;
+
 class ProductController extends BaseController
 {
 
@@ -47,7 +48,7 @@ class ProductController extends BaseController
         }
         $where['shopId'] = $shopId;
 
-        $itemInfoData = ProductClass::getAllByCondition($where,null,"*");
+        $itemInfoData = ProductClass::getAllByCondition($where, null, "*");
         $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
         //常用的itemIds
         $oftenItemIds = ProductClass::getOftenItemIds($shopId);
@@ -56,7 +57,7 @@ class ProductController extends BaseController
 
         //dd($itemInfoData);
         //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
-        $data = ProductService::assembleData($classIds, $itemIdsInfo,$itemInfoData, $oftenItemIds, $type);
+        $data = ProductService::assembleData($classIds, $itemIdsInfo, $itemInfoData, $oftenItemIds, $type);
 
         util::success($data);
     }
@@ -83,33 +84,26 @@ class ProductController extends BaseController
         $where['shopId'] = $shopId;
 
         $type = Yii::$app->request->get('type', '');
-        $showPage = Yii::$app->request->get('showPage',0);
-        if($showPage){
-            $res = ProductClass::getList("*",$where,"inTurn desc");
-            $data = $res['list'];
-        }else{
-            $data = ProductClass::getAllByCondition($where,"inTurn desc","*");
+        $showPage = Yii::$app->request->get('showPage', 0);
+        //需要显示分页
+        if ($showPage) {
+            $respond = ProductClass::getList("*", $where, "inTurn desc");
+            util::success($respond);
         }
+        $data = ProductClass::getAllByCondition($where, "inTurn desc", "*");
 
         $data = ProductClass::groupProductInfo($data);
         if ($type == 'waring') {
             //库存预警
             $newData = [];
-            foreach ($data as $v){
-                if($v['stock']  <= $v['stockWarning']) {
+            foreach ($data as $v) {
+                if ($v['stock'] <= $v['stockWarning']) {
                     $newData[] = $v;
                 }
             }
             util::success(['list' => $newData]);
         }
-        if($showPage){
-            $res['list'] = $data;
-            util::success(['list' => $res]);
-        }else{
-            util::success(['list' => $data]);
-        }
-
-
+        util::success(['list' => $data]);
 
     }
 

+ 2 - 1
sql.sql

@@ -2068,7 +2068,8 @@ ADD COLUMN `smallUnitId`  smallint(6) NOT NULL DEFAULT 2 COMMENT '小单位ID' A
 ====shish 2021-4-11
 ALTER TABLE `xhPurchase` ADD deadline DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '有效期' AFTER `debt`;
 ALTER TABLE xhPurchase ADD changePrice TINYINT NOT NULL DEFAULT 1 COMMENT '1可以修改价格 2不能修改' AFTER `orderSn`;
+ALTER TABLE xhGhsProduct ADD classId INT NOT NULL DEFAULT 0 COMMENT '分类id' AFTER `merchantId`;
 
-========linqh 2021.4.12
+========linqh 2021-4-12
 ALTER TABLE `xhGhsProduct`
 ADD COLUMN `inTurn`  int(10) NOT NULL DEFAULT 100 COMMENT '排序' AFTER `smallUnitId`;