shopAdmin; if (isset($staff->identity) && $staff->identity == 2) { util::fail('不能操作'); } $get = Yii::$app->request->get(); $productId = $get['itemId'] ?? 0; $bookItemCustomId = $get['bookItemCustomId'] ?? 0; $num = $get['num'] ?? 0; if ($num <= 0) { util::fail('请填写要减的数量'); } $shop = $this->shop; $staff = $this->shopAdmin; $bookItemCustomRes = BookItemCustomClass::getById($bookItemCustomId, true); if (empty($bookItemCustomRes)) { util::fail('没有预订相关的信息呢'); } if ($bookItemCustomRes->mainId != $this->mainId) { util::fail('不是你的预订信息'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { CheckOrderClass::bookToDelStock($productId, $num, $shop, $staff); $transaction->commit(); util::complete('操作成功'); } catch (\Exception $e) { Yii::info("操作失败原因:" . $e->getMessage()); $transaction->rollBack(); util::fail('操作失败'); } } //预订中增加库存 public function actionBookAddStock() { $staff = $this->shopAdmin; if (isset($staff->identity) && $staff->identity == 2) { util::fail('不能操作'); } $get = Yii::$app->request->get(); $productId = $get['itemId'] ?? 0; $bookItemCustomId = $get['bookItemCustomId'] ?? 0; $num = $get['num'] ?? 0; if ($num <= 0) { util::fail('请填写要加的数量'); } $shop = $this->shop; $staff = $this->shopAdmin; $bookItemCustomRes = BookItemCustomClass::getById($bookItemCustomId, true); if (empty($bookItemCustomRes)) { util::fail('没有预订相关的信息呢...'); } if ($bookItemCustomRes->mainId != $this->mainId) { util::fail('不是你的预订信息..'); } $needCgNum = $bookItemCustomRes->needCgNum ?? 0; if ($num > $needCgNum) { util::fail("最多只需要加" . $needCgNum . "份"); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { CheckOrderClass::bookToAddStock($productId, $num, $shop, $staff, $bookItemCustomRes); $transaction->commit(); util::complete('操作成功'); } catch (\Exception $e) { Yii::info("操作失败原因:" . $e->getMessage()); $transaction->rollBack(); util::fail('操作失败'); } } //借库存 ssh 20240720 public function actionLoan() { $staff = $this->shopAdmin; if (isset($staff->identity) && $staff->identity == 2) { util::fail('不能操作'); } $get = Yii::$app->request->get(); $inId = $get['inId'] ?? 0; $outId = $get['outId'] ?? 0; $bookItemCustomId = $get['bookItemCustomId'] ?? 0; $num = $get['num'] ?? 0; if ($num <= 0) { util::fail('请填写要借的数量'); } $shop = $this->shop; $staff = $this->shopAdmin; $bookItemCustomRes = BookItemCustomClass::getById($bookItemCustomId, true); if (empty($bookItemCustomRes)) { util::fail('没有预订相关的信息呢'); } if ($bookItemCustomRes->mainId != $this->mainId) { util::fail('不是你的预订信息'); } $needCgNum = $bookItemCustomRes->needCgNum ?? 0; if ($num > $needCgNum) { util::fail("最多只需要借" . $needCgNum . "份"); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { CheckOrderClass::loanStock($inId, $outId, $num, $shop, $staff, $bookItemCustomRes); $transaction->commit(); util::complete('操作成功'); } catch (\Exception $e) { Yii::info("操作失败原因:" . $e->getMessage()); $transaction->rollBack(); util::fail('操作失败'); } } //订单列表 ssh 2021.1.14 public function actionList() { $get = Yii::$app->request->get(); $orderStatus = isset($get['status']) ? $get['status'] : ''; $where = []; $where['shopId'] = $this->shopId; if (!empty($orderStatus)) { $where['status'] = $orderStatus; } $list = CheckOrderClass::getOrderList($where); util::success($list); } //订单详情 2021.1.22 lqh public function actionDetail() { $orderSn = Yii::$app->request->get('orderSn', ''); $orderData = CheckOrderClass::getOrderDetail($orderSn, $this->shopId); util::success($orderData); } //分配库存 ssh 20230720 public function actionSendStock() { $shopAdmin = $this->shopAdmin; if (!isset($shopAdmin->super) || $shopAdmin->super != 1) { util::fail('超管才能盘点'); } $post = Yii::$app->request->post(); $motherId = $post['motherId'] ?? 0; $mother = ProductClass::getById($motherId, true); if (empty($mother) || $mother->mainId != $this->mainId) { util::fail('无法操作'); } $motherName = $mother->name ?? ''; $ghsItemInfo = $post['itemInfo'] ?? ''; if (empty($ghsItemInfo)) { util::fail('请选择花材3'); } $itemList = json_decode($ghsItemInfo, true); if (empty($itemList)) { util::fail('没有花材'); } $totalNum = 0; foreach ($itemList as $key => $item) { $currentNum = $item['bigNum'] ?? 0; $totalNum = bcadd($totalNum, $currentNum, 2); } if ($totalNum > $mother->stock) { util::fail($motherName . "不足{$totalNum}扎"); } $motherBigNum = bcsub($mother->stock, $totalNum, 2); $motherBigNum = floatval($motherBigNum); $ids = array_column($itemList, 'productId'); $infoList = ProductClass::getByIds($ids, null, 'id'); if (!empty($infoList)) { foreach ($itemList as $itemKey => $itemVal) { $productId = $itemVal['productId'] ?? 0; $bigNum = $itemVal['bigNum'] ?? 0; $addBigNum = $infoList[$productId]['stock'] ?? 0; $newBigNum = bcadd($bigNum, $addBigNum, 2); $itemList[$itemKey]['bigNum'] = $newBigNum; } } $itemList[] = ['productId' => $motherId, 'bigNum' => $motherBigNum, 'smallNum' => 0]; $newJson = json_encode($itemList); $post['itemInfo'] = $newJson; $post['sjId'] = $this->sjId; $post['shopId'] = $this->shopId; $post['adminId'] = $this->adminId; $post['mainId'] = $this->mainId; $staff = $this->shopAdmin; $post['staffName'] = $staff->name ?? ''; $order = $this->saveOrder($post, false, false, ['motherId' => $motherId]); util::success($order); } //盘点确认 lqh 2021.1.22 public function actionCreateOrder() { $shopAdmin = $this->shopAdmin; if (!isset($shopAdmin->super) || $shopAdmin->super != 1) { util::fail('超管才能盘点'); } $post = Yii::$app->request->post(); $post['sjId'] = $this->sjId; $post['shopId'] = $this->shopId; $post['adminId'] = $this->adminId; $post['mainId'] = $this->mainId; $staff = $this->shopAdmin; $post['staffName'] = $staff->name ?? ''; $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $order = $this->saveOrder($post, false, false); $transaction->commit(); util::success($order); } catch (\Exception $e) { Yii::info("操作失败:" . $e->getMessage()); $transaction->rollBack(); util::fail('操作失败'); } } //盘点存草稿 lqh 2021.1.22 public function actionCreateDraft() { $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('超管才能操作'); } $post = Yii::$app->request->post(); $post['sjId'] = $this->sjId; $post['shopId'] = $this->shopId; $post['adminId'] = $this->adminId; //ssh 20210827 util::fail('草稿功能取消'); $order = $this->saveOrder($post, true, false); util::success($order); } //编辑草稿 ,继续保存草稿 public function actionUpdateDraft() { $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('超管才能操作'); } $post = Yii::$app->request->post(); $post['sjId'] = $this->sjId; $post['shopId'] = $this->shopId; $post['adminId'] = $this->adminId; $staff = $this->shopAdmin; $post['staffName'] = $staff->name ?? ''; $orderSn = $post['orderSn'] ?? ''; $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId); if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) { util::fail("订单不存在"); } $order = $this->saveOrder($post, true, true); util::success($order); } //编辑草稿, 确认 public function actionUpdateOrder() { $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('超管才能操作'); } $post = Yii::$app->request->post(); $post['sjId'] = $this->sjId; $post['shopId'] = $this->shopId; $post['mainId'] = $this->mainId; $post['adminId'] = $this->adminId; $staff = $this->shopAdmin; $post['staffName'] = $staff->name ?? ''; $orderSn = $post['orderSn'] ?? ''; $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId); if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) { util::fail("订单不存在"); } $order = $this->saveOrder($post, false, true); util::success($order); } protected function saveOrder($post, $draft = false, $update = false, $params = []) { $shopAdmin = $this->shopAdmin; if (!isset($shopAdmin->super) || $shopAdmin->super != 1) { util::fail('超管才能操作'); } $ghsItemInfo = $post['itemInfo'] ?? ''; if (empty($ghsItemInfo)) { util::fail('请选择花材4'); } //数据格式 [{productId:0,bigNum:1,smallNum:0}] $ghsItemInfo = json_decode($ghsItemInfo, true); if (!is_array($ghsItemInfo)) { util::fail('花材格式不正确'); } //判断花材格式,是否属于当前门店 ProductClass::valid($ghsItemInfo, $this->mainId); foreach ($ghsItemInfo as $key => $item) { //如果盘点数是99999则转为0 if (isset($item['bigNum']) && $item['bigNum'] == 99999) { $ghsItemInfo[$key]['bigNum'] = 0; } } $post['itemInfo'] = $ghsItemInfo; if ($update === true) { $order = CheckOrderClass::opOrder($post, $draft, $update, true, $params); } else { $order = CheckOrderClass::opOrder($post, $draft, $update, true, $params); } return $order; } //清空库存 ssh 20231224 public function actionClearStock() { ini_set('memory_limit', '2045M'); set_time_limit(0); $staff = $this->shopAdmin; $could = $staff->mobile == '15280215347' ? true : false; $mainId = $this->mainId; if (getenv('YII_ENV') == 'production') { //源花汇小周、小吴、小吕可以清花材 if ($mainId == 10536) { if (in_array($this->adminId, [11648, 11961, 11976])) { $could = true; } } //花瀚鲜花供应链 if ($mainId == 14499) { if (in_array($this->adminId, [11961, 11976])) { $could = true; } } //徐记花卉 if ($mainId == 10866) { if (in_array($this->adminId, [11964])) { $could = true; } } //小蔡鲜花苏南店 if ($mainId == 28944) { if (in_array($this->adminId, [29264])) { $could = true; } } //镜中 if ($mainId == 33447) { if (in_array($this->adminId, [33513])) { $could = true; } } //花语鲜花批发 if($mainId == 85727){ if (in_array($this->adminId, [82699])) { $could = true; } } } else { $could = $staff->mobile == '17187822038' ? true : false; if ($mainId == 812) { if (in_array($this->adminId, [1091])) { $could = true; } } $could = $staff->mobile == '15280215347' ? true : false; } if ($could == false) { util::fail('无法清空库存'); } $mainId = $this->mainId ?? 0; $adminId = $this->adminId ?? 0; $shopId = $this->shopId ?? 0; $sjId = $this->sjId ?? 0; $list = ProductClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0, 'stock>' => 0,], null, '*', null, true); $productList = []; if (!empty($list)) { foreach ($list as $key => $info) { $id = $info->id ?? 0; if ($info->virtualStock == 0) { $productList[] = ['productId' => $id, 'bigNum' => 0, 'smallNum' => 0]; } } } if (empty($productList)) { util::fail('没有花材需要清空'); } $modifyData = [ 'remark' => '清空库存', 'sjId' => $sjId, 'shopId' => $shopId, 'adminId' => $adminId, 'mainId' => $mainId, 'itemInfo' => $productList, ]; $draft = false; $update = false; CheckOrderClass::opOrder($modifyData, $draft, $update); util::complete('清除成功'); } }