shish 4 年 前
コミット
79bd979fee

+ 76 - 6
app-hd/controllers/ProductController.php

@@ -8,6 +8,7 @@ namespace hd\controllers;
 
 use biz\ghs\classes\GhsClass;
 use biz\item\classes\PtItemClass;
+use biz\shop\classes\ShopClass;
 use bizGhs\item\classes\ItemClassClass;
 use bizGhs\product\classes\ProductClass;
 use bizGhs\product\services\ProductService;
@@ -100,6 +101,77 @@ class ProductController extends BaseController
 
     }
 
+    //批量改价
+    public function actionBatchChangePrice()
+    {
+        util::fail('暂时无法修改');
+
+        $shopAdmin = $this->shopAdmin;
+        if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
+            util::fail('超管才能修改');
+        }
+
+        //花材价格只能在首店修改,并同步到分店
+        $shop = $this->shop;
+        $default = $shop->default ?? 0;
+        if ($default != 1) {
+            util::fail('请在首店修改');
+        }
+
+        $data = Yii::$app->request->post('data', '');
+        if (empty($data)) {
+            util::fail('没有修改');
+        }
+        $arr = json_decode($data, true);
+        if (empty($arr)) {
+            util::fail('没有修改!');
+        }
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+
+            $ids = array_column($arr, 'id');
+            $ids = array_unique(array_filter($ids));
+            if (empty($ids)) {
+                util::fail('请选择花材');
+            }
+
+            $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
+
+            foreach ($arr as $product) {
+                if (isset($product['price']) == false) {
+                    util::fail('没有价格');
+                }
+                if (isset($product['id']) == false) {
+                    util::fail('没有花材');
+                }
+                $price = $product['price'];
+                $productId = $product['id'];
+
+                $product = $productList[$productId] ?? [];
+                if (empty($product)) {
+                    util::fail('没有找到花材');
+                }
+                if (isset($product->shopId) == false || $product->shopId != $this->shopId) {
+                    util::fail('没有权限访问');
+                }
+                if (empty($price)) {
+                    continue;
+                }
+                ProductClass::changePrice($product, $price, ProductClass::PRICE_LABEL_CHANGE);
+            }
+            $transaction->commit();
+            util::complete('修改成功');
+
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("修改失败原因:" . $e->getMessage());
+            util::fail('修改失败');
+        }
+
+    }
+
     //从零售端采购入库,查看供应商的某个门店的product
     public function actionGhsItem()
     {
@@ -109,7 +181,6 @@ class ProductController extends BaseController
         if (empty($ghs)) {
             util::fail('没有找到供应商');
         }
-        $sjId = $ghs['sjId'] ?? 0;
         $shopId = $ghs['shopId'] ?? 0;
         $black = $ghs['black'] ?? 2;
         if ($black == 2) {
@@ -121,11 +192,10 @@ class ProductController extends BaseController
 
             //获取所有当前供应商的分类 (全部、常用)
             //根据分类组装分类下的花材信息
-            //中央ID
-            $classIds = ItemClassClass::getGhsItemClassAll($this->mainId);
-//            $where['sjId'] = $sjId;
-//            $where['shopId'] = $shopId;
-            $where['mainId'] = $this->mainId;
+            $shop = ShopClass::getById($shopId, true);
+            $mainId = $shop->mainId ?? 0;
+            $classIds = ItemClassClass::getGhsItemClassAll($mainId);
+            $where['mainId'] = $mainId;
             $where['delStatus'] = 0;
             $where['status'] = 1;
 

+ 9 - 4
app-hd/controllers/PurchaseController.php

@@ -5,6 +5,7 @@ namespace hd\controllers;
 use biz\admin\classes\AdminClass;
 use biz\ghs\classes\GhsClass;
 use biz\notice\classes\NoticeClass;
+use biz\shop\classes\ShopClass;
 use biz\shop\classes\ShopExpressClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\express\services\DadaExpressServices;
@@ -33,13 +34,13 @@ class PurchaseController extends BaseController
         if (empty($ghsInfo)) {
             util::fail('没有找到供应商');
         }
+        $ghsShopId = $ghsInfo['shopId'] ?? 0;
+        $ghsSjId = $ghsInfo['sjId'] ?? 0;
 
         //增加判定,若是快递配置,则判定供应商是否开通达达,若未开通,则不能现在配送
         $getType = $post['getType'] ?? 0;
         if ($getType == 1) {
             //配送
-            $ghsShopId = $ghsInfo['shopId'] ?? 0;
-            $ghsSjId = $ghsInfo['sjId'] ?? 0;
 //            $shopNo = ShopExpressClass::getShopNo($ghsSjId, $ghsShopId);
 //            if (!$shopNo) {
 //                util::fail("商家还未开通配送服务");
@@ -52,7 +53,7 @@ class PurchaseController extends BaseController
         $connection = Yii::$app->db;//事务处理
         $transaction = $connection->beginTransaction();
         try {
-            $currentShopId = $ghsInfo['shopId'] ?? 0;
+            $post['book'] = $post['book'] ?? 0;
             $post['sjId'] = $this->sjId;
             $post['shopId'] = $this->shopId;
             $post['shopAdminId'] = $this->shopAdminId;
@@ -68,8 +69,12 @@ class PurchaseController extends BaseController
             $post['shopAdminName'] = $name;
             $product = $post['product'] ?? '';
             $productList = json_decode($product, true);
+
             //判断product数据是不是同个供应商的
-            ProductClass::valid($productList, $this->mainId);
+            $ghsShopInfo = ShopClass::getById($ghsShopId, true);
+            $ghsMainId = $ghsShopInfo->mainId ?? 0;
+            ProductClass::valid($productList, $ghsMainId);
+
             $post['product'] = $productList;
             $post['sendCost'] = isset($post['sendCost']) && is_numeric($post['sendCost']) ? $post['sendCost'] : 0;
 

+ 2 - 0
biz-hd/purchase/services/PurchaseService.php

@@ -65,7 +65,9 @@ class PurchaseService extends BaseService
         $xj = $data['xj'] ?? '';
         $sendTimeWant = isset($data['sendTimeWant']) && !empty($data['sendTimeWant']) ? $data['sendTimeWant'] : date("Y-m-d");
         $orderType = 2;
+        $book = $data['book'] ?? 0;
         $arr = [
+            'book' => $book,
             'product' => $product,
             'sjId' => $currentSjId,
             'shopId' => $currentShopId,