shish преди 1 година
родител
ревизия
eb73eb6e22
променени са 1 файла, в които са добавени 118 реда и са изтрити 1 реда
  1. 118 1
      app-ghs/controllers/PurchaseOrderController.php

+ 118 - 1
app-ghs/controllers/PurchaseOrderController.php

@@ -1000,8 +1000,125 @@ class PurchaseOrderController extends BaseController
                 }
                 $arr[] = $rowData;
             }
-            print_r($arr);die;
             array_shift($arr);
+            $productIds = [];
+            foreach ($arr as $k => $v) {
+                $productId = $v[0] ?? 0;
+                $productId = trim($productId);
+                if (is_numeric($productId) && $productId > 0) {
+                    $productIds[] = $productId;
+                }
+            }
+            if (empty($productIds)) {
+                util::fail('没有识别出花材');
+            }
+            $productInfo = ProductClass::getByIds($productIds, null, 'id');
+            if (empty($productInfo)) {
+                util::fail('没有找到有效花材');
+            }
+            $ghsItemInfo = [];
+            foreach ($arr as $k => $v) {
+                $productId = $v[0] ?? 0;
+                $productId = trim($productId);
+                $num = $v[2] ?? 0;
+                $num = trim($num);
+                $unitPrice = $v[3] ?? 0;
+                $unitPrice = trim($unitPrice);
+                if (is_numeric($productId) && $productId > 0 && $num > 0 && $unitPrice > 0) {
+                    $price = bcmul($unitPrice,$num,2);
+                    $product = $productInfo[$productId] ?? [];
+                    $ptItemId = $product['itemId'] ?? 0;
+                    $ratio = $product['ratio']??20;
+                    $ratioType = $product['ratioType']??0;
+                    $ghsItemInfo[] = [
+                        'productId'=>$productId,
+                        'bigNum'=>$num,
+                        'smallNum'=>0,
+                        'itemId'=>$ptItemId,
+                        'itemPrice'=>$unitPrice,
+                        'totalPrice'=>$price,
+                        'assignSeat'=>0,
+                        'ratio'=>$ratio,
+                        'ratioType'=>$ratioType,
+                        'aboutPrice'=>0,
+                    ];
+                }
+            }
+
+            ini_set('memory_limit', '2045M');
+            set_time_limit(0);
+
+            $post = [];
+            $post['sjId'] = $this->sjId;
+            $post['shopId'] = $this->shopId;
+            $post['adminId'] = $this->adminId;
+            $post['mainId'] = $this->mainId;
+            $staff = $this->shopAdmin;
+            //以下二个都需要保留
+            $post['staffId'] = $staff->id ?? 0;
+            $post['staffName'] = $staff->name ?? '';
+            $post['shopAdminId'] = $staff->id ?? 0;
+            $post['shopAdminName'] = $staff->name ?? '';
+
+            $shopAdmin = $this->shopAdmin;
+            if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
+                util::fail('没有权限导入库存');
+            }
+
+            if (getenv('YII_ENV') == 'production') {
+                //小向花卉采购控制
+                if ($this->mainId == 23390) {
+                    if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655, 28521, 4])) {
+                        util::fail('你不能采购哦');
+                    }
+                }
+            }
+
+            $shop = $this->shop;
+            $carSale = $shop->carSale ?? 0;
+            if ($carSale == 1) {
+                util::fail('车销不能采购');
+            }
+
+            $connection = Yii::$app->db;
+            $transaction = $connection->beginTransaction();
+            try {
+
+                //合并
+                $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
+                //判断花材格式,是否属于当前门店
+                ProductClass::valid($ghsItemInfo, $this->mainId);
+
+                //获取供货商信息
+                $ghsId = $post['ghsId'];
+                if (empty($ghsId)) {
+                    util::fail("请选择供货商");
+                }
+                $ghsInfo = GhsClass::getGhsInfo($ghsId);
+                GhsClass::valid($ghsInfo, $this->shopId);
+                $post['ghsInfo'] = json_encode($ghsInfo);
+                $post['ghsName'] = $ghsInfo['name'] ?? '';
+                $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
+                $shop = $this->shop;
+                $post['itemInfo'] = $ghsItemInfo;
+                //0稍后入库 1直接入库
+                $inType = $post['inType'] ?? PurchaseOrderClass::IN_TYPE_NOW;
+                if ($shop->pfLevel == 1) {
+                    //昆明批发,不要直接入库
+                    $inType = PurchaseOrderClass::IN_TYPE_LATER;
+                    $post['inType'] = $inType;
+                }
+                $debtStatus = $inType == 1 ? PurchaseOrderClass::DEBT_YES : PurchaseOrderClass::DEBT_UNKNOWN;
+                $post['debt'] = $debtStatus;
+                $order = PurchaseOrderClass::addOrder($post);
+                $transaction->commit();
+                util::success($order);
+            } catch (\Exception $e) {
+                $transaction->rollBack();
+                noticeUtil::push('导入失败,失败原因:' . $e->getMessage(), '15280215347');
+                Yii::error("导入失败原因:" . $e->getMessage());
+                util::fail('导入失败');
+            }
         } else {
             util::fail('fail');
         }