Procházet zdrojové kódy

新增门店时添加product

林琦海 před 5 roky
rodič
revize
80fa979b1b

+ 25 - 2
app-ghs/controllers/ShopController.php

@@ -6,11 +6,13 @@ use biz\sj\services\MerchantExtendService;
 use bizGhs\admin\classes\AdminClass;
 use bizGhs\merchant\classes\ShopClass;
 use bizGhs\merchant\services\ShopService;
+use bizGhs\product\classes\ProductClass;
 use common\components\dirUtil;
 use common\components\httpUtil;
 use common\components\imgUtil;
 use common\components\util;
 use common\components\wxUtil;
+use jzweb\open\weixin\lib\user;
 use Yii;
 use yii\web\UrlManager;
 
@@ -56,8 +58,29 @@ class ShopController extends BaseController
     {
         $data = Yii::$app->request->post();
         $data['merchantId'] = $this->sjId;
-        ShopClass::addShop($data);
-        util::complete();
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try{
+            $shop = ShopClass::addShop($data);
+            $shopId = $shop['id'];
+            //门店product 同步数据  linqh 2021.4.18
+            $product = ProductClass::getAllProduct($this->sjId,$this->shopId,"name,cover,classId,itemId,rank,price,priceLabel,cost,addPrice,stockWarning,weight,alias,py,ratio,bigUnit,smallUnit,bigUnitId,smallUnitId,inTurn");
+            $productData = [];
+            foreach ($product as $v){
+                $tmp = $v;
+                $tmp['merchantId'] = $this->sjId;
+                $tmp['shopId'] = $shopId;
+                $tmp['adminId'] = $this->adminId;
+                $productData[] = $tmp;
+            }
+            ProductClass::batchAdd($productData);
+            $transaction->commit();
+            util::complete();
+        }catch (\Exception $exception){
+            $transaction->rollBack();
+            util::fail();
+        }
     }
 
     //PC下载微信和支付宝收款码 ssh 2020.2.29

+ 1 - 0
biz-ghs/merchant/classes/ShopClass.php

@@ -2,6 +2,7 @@
 
 namespace bizGhs\merchant\classes;
 
+use bizGhs\product\classes\ProductClass;
 use common\components\dirUtil;
 use common\components\httpUtil;
 use common\components\qrCodeUtil;

+ 10 - 0
biz-ghs/product/classes/ProductClass.php

@@ -617,4 +617,14 @@ class ProductClass extends BaseClass
             self::changePrice($productId, $product['shopId'], $price, self::PRICE_LABEL_AUTO);
         }
     }
+
+    //获取当前门店下所有的product
+    public static function getAllProduct($sjId,$shopId,$field="*")
+    {
+        $where = [
+            'merchantId'=>$sjId,
+            'shopId'=>$shopId
+        ];
+        return self::getAllByCondition($where,null,$field);
+    }
 }