request->get('py', ''); $type = Yii::$app->request->get('type', ''); //获取所有当前供应商的分类 (全部、常用) //根据分类组装分类下的花材信息 $classIds = ItemClassClass::getGhsItemClassAll($this->sjId); $where['sjId'] = $this->sjId; if ($py) { $pyName = strtolower($py); $where['py'] = $pyName; } $shopId = $this->shopId; //库存预警 if ($type == 'waring') { //shopId 改为可以前端传,默认是当前shopId linqh 2021.1.26 $shopId = Yii::$app->request->get('shopId', 0); if (!$shopId) { $shopId = $this->shopId; } } $where['shopId'] = $shopId; $where['delStatus'] = 0; $itemInfoData = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*"); $itemInfoData = ProductClass::groupProductInfo($itemInfoData); //常用的itemIds $oftenItemIds = ProductClass::getOftenItemIds($shopId); //获取供应商下所有花材ID (itemIds) $itemIdsInfo = ItemService::getGhsItemIds($this->sjId); //dd($itemInfoData); //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}] $data = ProductService::assembleData($classIds, $itemIdsInfo, $itemInfoData, $oftenItemIds, $type); util::success($data); } //当前门店所有花材分类 public function actionList() { $classId = Yii::$app->request->get('classId', 0); $pyName = Yii::$app->request->get('py', ''); // $itemInfo = ItemClass::getGhsItemAll($this->sjId); // $itemIds = array_column($itemInfo, 'itemId'); $where['sjId'] = $this->sjId; if ($pyName) { // $pyNameItemIds = ItemClass::getItemIdsByPyName($pyName); // $itemIds = array_intersect($itemIds, $pyNameItemIds); $pyName = strtolower($pyName); $where['py'] = $pyName; } $shopId = Yii::$app->request->get('shopId', 0); if (!$shopId) { $shopId = $this->shopId; } $where['shopId'] = $shopId; if (!empty($classId)) { $where['classId'] = $classId; } $type = Yii::$app->request->get('type', ''); $showPage = Yii::$app->request->get('showPage', 0); //需要显示分页 if ($showPage) { $respond = ProductClass::getList("*", $where, "inTurn desc"); $respond['list'] = ProductClass::groupClassName($this->sjId, $respond['list']); $respond['list'] = ProductClass::groupProductInfo($respond['list']); 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']) { $newData[] = $v; } } util::success(['list' => $newData]); } util::success(['list' => $data]); } //从零售端采购入库,查看供应商的某个门店的product public function actionGhsItem() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; if (!empty($id)) { $ghs = GhsClass::getGhsInfo($id); if (empty($ghs)) { util::fail('没有找到供应商'); } $sjId = $ghs['sjId'] ?? 0; $shopId = $ghs['shopId'] ?? 0; } else { $shopId = $get['shopId'] ?? 0; if (empty($shopId)) { util::fail('没有供应商信息'); } $shop = ShopClass::getShopInfo($shopId); if (empty($shop)) { util::fail('没有供应商门店'); } $sjId = $shop['sjId'] ?? 0; } $connection = Yii::$app->db;//事务处理 $transaction = $connection->beginTransaction(); try { //获取所有当前供应商的分类 (全部、常用) //根据分类组装分类下的花材信息 $classIds = ItemClassClass::getGhsItemClassAll($sjId); $where['sjId'] = $sjId; $where['shopId'] = $shopId; $where['delStatus'] = 0; $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], "*"); $itemInfoData = ProductClass::groupProductInfo($itemInfoData); //常用的itemIds $oftenItemIds = ProductClass::getOftenItemIds($shopId); //获取供应商下所有花材ID (itemIds) $itemIdsInfo = ItemService::getGhsItemIds($sjId); //dd($itemInfoData); //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}] $data = ProductService::assembleData($classIds, $itemIdsInfo, $itemInfoData, $oftenItemIds, '', true); util::success($data); } catch (\Exception $e) { $transaction->rollBack(); util::fail(); } } public function actionDetail() { $id = Yii::$app->request->get('id', 0); $respond = ProductClass::getItemInfo($id); util::success($respond); } public function actionUpdate() { $post = Yii::$app->request->post(); ProductClass::updateProduct($post); 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)) { util::fail("参数错误"); } if (in_array($type, ['inTurn', 'addPrice', 'cost', 'weight', 'ratio'])) $data = json_decode($data, true); foreach ($data as $v) { $id = $v['id']; $val = $v[$type] ?? ''; $where = []; $where['id'] = $id; $where['shopId'] = $this->shopId; $where['sjId'] = $this->sjId; if (empty($val)) { util::fail("参数错误1"); } $data = [ $type => $val ]; ProductClass::updateByCondition($where, $data); ProductClass::autoPriceById($id); } util::complete(); } }