shish 3 лет назад
Родитель
Сommit
08e7892ab1

+ 66 - 1
app-hd/controllers/PurchaseController.php

@@ -28,6 +28,71 @@ class PurchaseController extends BaseController
 
     public $guestAccess = ['detail'];
 
+    //虚拟供货商的采购 ssh 20230308
+    public function actionAddVirtualCg()
+    {
+        $post = Yii::$app->request->post();
+        $ghsId = $post['ghsId'] ?? 0;
+        $ghsInfo = GhsClass::getById($ghsId);
+        if (empty($ghsInfo)) {
+            util::fail('没有找到供货商');
+        }
+        if (isset($ghsInfo['mainId']) && !empty($ghsInfo['mainId']) && $ghsInfo['mainId'] == $ghsInfo['ownMainId']) {
+            util::fail('这个是你自己的批发店');
+        }
+
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            $post['book'] = $post['book'] ?? 0;
+            $post['sjId'] = $this->sjId;
+            $post['shopId'] = $this->shopId;
+            $post['shopAdminId'] = $this->shopAdminId;
+            $post['ghsId'] = $ghsId;
+            $post['ghsName'] = $ghsInfo['name'] ?? '';
+            $post['ghsMobile'] = $ghsInfo['mobile'] ?? '';
+            $post['ghsAvatar'] = $ghsInfo['avatar'] ?? '';
+            $post['ghsFullAddress'] = $ghsInfo['fullAddress'] ?? '';
+            $customId = $ghsInfo['customId'] ?? 0;
+            $post['customId'] = $customId;
+            $shopAdmin = $this->shopAdmin ?? null;
+            $name = $shopAdmin->name ?? '';
+            $post['shopAdminName'] = $name;
+            $post['mainId'] = $this->mainId;
+            $product = $post['product'] ?? '';
+            $productList = json_decode($product, true);
+            //判断product数据是不是同个供货商的
+            $ids = array_unique(array_filter(array_column($productList, 'productId')));
+            $productInfoList = ProductClass::getByIds($ids, null, 'id');
+            if (!empty($productInfoList)) {
+                foreach ($productInfoList as $currentInfo) {
+                    if (isset($currentInfo['mainId']) == false || $currentInfo['mainId'] != $this->mainId) {
+                        util::fail('只能选择同一家的商品哦');
+                    }
+                }
+                if (count($productInfoList) != count($ids)) {
+                    util::fail('存在无效商品');
+                }
+            } else {
+                util::fail('花材不存在');
+            }
+            //供货商预订单最低公斤数要求和每公斤服务费
+            $ghsInfo['kiloFee'] = 0;
+            $ghsInfo['miniKilo'] = 0;
+            $post['product'] = $productList;
+            $sendCost = 0;
+            $post['sendCost'] = $sendCost;
+            $packCost = 0;
+            $post['packCost'] = $packCost;
+            $respond = PurchaseService::createPurchase($post, $ghsInfo);
+            $transaction->commit();
+            util::success($respond);
+        } catch (Exception $e) {
+            $transaction->rollBack();
+            util::fail();
+        }
+    }
+
     //生成采购单 ssh 2021.1.17
     public function actionCreateOrder()
     {
@@ -60,7 +125,7 @@ class PurchaseController extends BaseController
         $ghsShopId = $ghsInfo['shopId'] ?? 0;
 
         if (isset($ghsInfo['mainId']) && !empty($ghsInfo['mainId']) && $ghsInfo['mainId'] == $ghsInfo['ownMainId']) {
-            util::fail('这个是你的批发店');
+            util::fail('这个是你自己的批发店');
         }
 
         $connection = Yii::$app->db;//事务处理

+ 1 - 1
biz-ghs/item/classes/ItemClassClass.php

@@ -147,7 +147,7 @@ class ItemClassClass extends BaseClass
         if (!$res) {
             //没有则新增
             $classData = ['mainId' => $mainId, 'name' => '默认分类', 'inTurn' => -1, 'isDefault' => 1];
-            $res = self::add($classData);
+            $res = self::add($classData, true);
         }
         return $res->id ?? 0;
     }

+ 7 - 1
biz-ghs/order/classes/OrderClass.php

@@ -384,7 +384,7 @@ class OrderClass extends BaseClass
         $data['orderSn'] = $orderSn;
         $data['payStatus'] = self::PAY_STATUS_UN_PAY;
         $data['customId'] = isset($data['customId']) && !empty($data['customId']) ? $data['customId'] : 0;
-
+        $live = isset($data['live']) ? $data['live'] : 1;
         $currentShopId = $data['shopId'] ?? 0;
         $shop = ShopClass::getLockById($currentShopId);
         if (empty($shop)) {
@@ -405,6 +405,12 @@ class OrderClass extends BaseClass
             $stockMayChange = false;
             $data['stockChange'] = 0;
         }
+
+        //花店向批发店采购,虚拟采购,批发店没有的花材需要补充
+        if ($live == 0) {
+            $product = \bizHd\product\classes\ProductClass::hdToggleGhs($product, $shop);
+        }
+
         $respond = OrderItemClass::replaceItem($orderSn, $product, $data, $stockMayChange);
 
         $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;

+ 1 - 1
biz-ghs/product/classes/ProductClass.php

@@ -1498,7 +1498,7 @@ class ProductClass extends BaseClass
             $itemId = $v['itemId'] ?? 0;
             if (!isset($hdProductData[$itemId])) {
                 //不存在,则从平台新增
-                $ptItem = \biz\item\classes\PtItemClass::getById($itemId);
+                $ptItem = PtItemClass::getById($itemId);
                 unset($ptItem['addTime']);
                 unset($ptItem['updateTime']);
                 $productData = $ptItem;

+ 42 - 0
biz-hd/product/classes/ProductClass.php

@@ -2,9 +2,11 @@
 
 namespace bizHd\product\classes;
 
+use biz\item\classes\PtItemClass;
 use bizHd\base\classes\BaseClass;
 use common\components\noticeUtil;
 use common\components\sms;
+use common\components\util;
 use Yii;
 
 class ProductClass extends BaseClass
@@ -12,6 +14,46 @@ class ProductClass extends BaseClass
 
     public static $baseFile = '\bizHd\product\models\Product';
 
+    //花店的花材转成批发店花材 ssh 20230308
+    public static function hdToggleGhs($list, $ghsShop)
+    {
+        $ghsMainId = $ghsShop->mainId ?? 0;
+        $ptItemIds = array_column($list, 'itemId');
+        $ghsHasProduct = ProductClass::getAllByCondition(['mainId' => $ghsMainId, 'itemId' => ['in', $ptItemIds]], null, '*', 'itemId');
+        $ghsSjId = $ghsShop->sjId ?? 0;
+        $ghsShopId = $ghsShop->id ?? 0;
+        $defaultClassId = \bizGhs\item\classes\ItemClassClass::getDefaultClassId($ghsMainId);
+        if (empty($defaultClassId)) {
+            util::fail('没有找到花材的默认分类');
+        }
+        foreach ($list as $k => $v) {
+            $ptItemId = $v['itemId'] ?? 0;
+            if (isset($ghsHasProduct[$ptItemId]) == false) {
+                //不存在,则从平台新增
+                $ptItem = PtItemClass::getById($ptItemId);
+                unset($ptItem['addTime']);
+                unset($ptItem['updateTime']);
+                $productData = $ptItem;
+                $productData['sjId'] = $ghsSjId;
+                $productData['shopId'] = $ghsShopId;
+                $productData['mainId'] = $ghsMainId;
+                $productData['itemId'] = $ptItemId;
+                $productData['classId'] = $defaultClassId;
+                unset($productData['id']);
+                $productData['rank'] = '';
+                $cost = $v['cost'] ?? 0;
+                $addPrice = $v['addPrice'] ?? 0;
+                $productData['price'] = bcadd($cost, $addPrice, 2);
+                $addProduct = ProductClass::addBaseData($productData);
+                $ghsProductId = $addProduct->id ?? 0;
+            } else {
+                $ghsProductId = $ghsHasProduct[$ptItemId]['id'] ?? 0;
+            }
+            $list[$k]['productId'] = $ghsProductId;
+        }
+        return $list;
+    }
+
     public static function addBaseData($data)
     {
         $respond = self::add($data, true);

+ 5 - 1
biz-hd/purchase/classes/PurchaseClass.php

@@ -388,6 +388,7 @@ class PurchaseClass extends BaseClass
         $orderSn = orderSn::getPurchaseSn();
         $data['orderSn'] = $orderSn;
         $prePrice = 0;
+        $live = isset($ghs['live']) ? $ghs['live'] : 1;
         $sendTimeWant = isset($data['sendTimeWant']) && !empty($data['sendTimeWant']) ? $data['sendTimeWant'] : date("Y-m-d");
         if ($sendTimeWant < date("Y-m-d")) {
             util::fail('您选了过去时间');
@@ -406,7 +407,10 @@ class PurchaseClass extends BaseClass
         $sjId = $data['sjId'] ?? 0;
         $mainId = $data['mainId'] ?? 0;
         $ghsId = $data['ghsId'] ?? 0;
-        $productList = ProductClass::toggleProductList($productList, $shopId, $sjId, $mainId);
+        //花店真实向批发店采购花材,则需要转化;虚拟采购不需要
+        if ($live == 1) {
+            $productList = ProductClass::toggleProductList($productList, $shopId, $sjId, $mainId);
+        }
 
         $productData = self::getProductMapData($productList, "productId");
         $hdProductData = self::getProductMapData($productList, "hdProductId");

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

@@ -47,6 +47,7 @@ class PurchaseService extends BaseService
         $sendCost = $data['sendCost'] ?? 0;
         $packCost = $data['packCost'] ?? 0;
         $customId = $ghs['customId'] ?? 0;
+        $live = isset($ghs['live']) ? $ghs['live'] : 1;
         $custom = CustomClass::getById($customId);
         if (empty($custom)) {
             util::fail('没有找到客户');
@@ -109,6 +110,7 @@ class PurchaseService extends BaseService
             'fromType' => $fromType,
             'presell' => $presell,
             'wlName' => $wlName,
+            'live' => $live,
         ];
         $result = OrderClass::addOrder($arr);
         $saleId = $result['id'] ?? 0;