request->get('py', ''); $type = Yii::$app->request->get('type', ''); $delStatus = Yii::$app->request->get('delStatus', 0); //获取所有当前供应商的分类 (全部、常用) //根据分类组装分类下的花材信息 $classIds = ItemClassClass::getGhsItemClassAll($this->sjId); $where['sjId'] = $this->sjId; if ($py) { $pyName = strtolower($py); $where['py'] = $pyName; } $shopId = $this->shopId; //兼容客户根据门店下单 if ($this->lookShopId) { $shopId = $this->lookShopId; } //库存预警 if ($type == 'waring') { //shopId 改为可以前端传,默认是当前shopId linqh 2021.1.26 $shopId = Yii::$app->request->get('shopId', 0); if (!$shopId) { $shopId = $this->shopId; } } $where['shopId'] = $shopId; // delStatus = 2 表示取出上下架的花材 shish 20210713 if ($delStatus != 2) { $where['delStatus'] = $delStatus; } $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], "*"); $itemInfoData = ProductClass::groupProductInfo($itemInfoData); //常用的itemIds $oftenItemIds = []; //$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); // $itemInfo = ItemClass::getGhsItemAll($this->sjId); // $itemIds = array_column($itemInfo, 'itemId'); $where['sjId'] = $this->sjId; $name = Yii::$app->request->get('name', ''); if (empty($name)) { $py = Yii::$app->request->get('py', ''); $name = !empty($py) ? $py : ''; } if (!empty($name)) { if (stringUtil::isLetter($name)) { $where['py'] = ['like', $name]; } else { $where['name'] = ['like', $name]; } } if ($classId) { //获取itemIds //$itemIds = ItemClass::getItemIdsByClassId($this->sjId, $classId); //$where['itemId'] = ['in', $itemIds]; $where['classId'] = $classId; } $shopId = Yii::$app->request->get('shopId', 0); if (!$shopId) { $shopId = $this->shopId; } $where['shopId'] = $shopId; $productIds = Yii::$app->request->get('ids', ''); if (!empty($productIds)) { $productIdArr = explode(',', $productIds); if (!empty($productIdArr)) { $where['id'] = ['in', $productIdArr]; } } $type = Yii::$app->request->get('type', ''); $showPage = Yii::$app->request->get('showPage', 0); if ($showPage) { if ($type == 'waring') { $respond = ProductClass::getList("*", $where, "stock asc"); } else { $respond = ProductClass::getList("*", $where, "inTurn desc"); } $respond['list'] = ProductClass::groupProductInfo($respond['list']); $respond['list'] = ProductClass::groupClassName($this->sjId, $respond['list']); util::success($respond); } if ($type == 'waring') { //库存预警 按库存从小到大排序 $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*"); } else { $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*"); } $data = ProductClass::groupProductInfo($data); $data = ProductClass::groupClassName($this->sjId, $data); if ($type == 'waring') { //库存预警 $newData = []; foreach ($data as $v) { if ($v['stock'] <= $v['stockWarning']) { $newData[] = $v; } } util::success(['list' => $newData]); } util::success(['list' => $data]); } //改价 public function actionChangePrice() { $shop = $this->shop; $default = $shop->default ?? 0; if ($default != 1) { util::fail('请在首店修改'); } $shopAdmin = $this->shopAdmin; $roleId = $shopAdmin['roleId'] ?? 0; $role = AdminRoleClass::getById($roleId); $roleName = $role['roleName'] ?? ''; if ($roleName == '员工') { util::fail('没有权限操作哦'); } $productId = Yii::$app->request->post('productId', 0); $price = Yii::$app->request->post('price', ''); if (is_numeric($price) && $price > 0) { //改价 //判断是否有效 $productData = ProductClass::getProductData($productId, $this->shopId); if (!$productData) { util::fail("花材不存在"); } ProductClass::changePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_CHANGE); } else { //自动调价 $productData = ProductClass::getById($productId); if (!$productData) { util::fail("花材不存在"); } $itemId = $productData['itemId']; //获取该花材的每扎成本价和每扎加价 //自动调价=每扎成本价+每扎加价 $itemData = ItemClass::getItemData($itemId, $this->sjId); // if (!$itemData) { // util::fail("出错拉"); // } // $price = bcadd($itemData['cost'], $itemData['addPrice'], 2); $price = bcadd($productData['cost'], $productData['addPrice'], 2); ProductClass::changePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO); } util::success(['price' => $price]); } //恢复自动调价 public function actionAutoPrice() { $productId = Yii::$app->request->post('productId', 0); $productData = ProductClass::getById($productId); if (!$productData) { util::fail("花材不存在"); } //$itemId = $productData['itemId']; //获取该花材的每扎成本价和每扎加价 //自动调价=每扎成本价+每扎加价 // $itemData = ItemClass::getItemData($itemId, $this->sjId); // if (!$itemData) { // util::fail("出错拉"); // } //2021.04.06改为用product中的成本价+加价 $price = bcadd($productData['cost'], $productData['addPrice'], 2); ProductClass::changePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO); util::complete("操作成功"); } //修改加价 public function actionChangeAddPrice() { $productId = Yii::$app->request->post('productId', 0); $addPrice = Yii::$app->request->post('addPrice', ''); if ($addPrice < 0) { util::fail("加价不能小于0"); } $productData = ProductClass::getProductData($productId, $this->shopId); if (!$productData) { util::fail("花材不存在"); } ProductClass::changeAddPrice($productId, $addPrice); util::complete(); } //批量修改product 排序,成本价,加价 public function actionBatchUpdate() { $shop = $this->shop; $default = $shop->default ?? 0; if ($default != 1) { util::fail('请在首店修改'); } $shopAdmin = $this->shopAdmin; $roleId = $shopAdmin['roleId'] ?? 0; $role = AdminRoleClass::getById($roleId); $roleName = $role['roleName'] ?? ''; if ($roleName == '员工') { util::fail('没有权限操作哦'); } $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', 'delStatus', 'ratio', 'price', 'stockWarning', 'shelfLife'])) { $data = json_decode($data, true); } else { util::fail('不允许的类型'); } foreach ($data as $v) { if ($type == 'delStatus') { $val = $v[$type] ?? ''; if (!in_array($val, [0, 1])) { util::fail("参数错误"); } } } foreach ($data as $v) { $id = $v['id']; $val = $v[$type] ?? ''; //shish 20210703 if ($type == 'ratio') { if (preg_match("/^[1-9][0-9]*$/", $val) == false || $val <= 0) { util::fail('单位比请填写整数,并且要大于0'); } } //修改售价 shish 20210703 if ($type == 'price') { $product = ProductClass::getLockById($id); if (empty($product)) { continue; } $currentItemId = $product->itemId ?? 0; if (empty($currentItemId)) { continue; } //留空恢复自动调价 //所有门店同步调整 if (empty($val)) { $currentPrice = bcadd($product->cost, $product->addPrice, 2); $upData = ['priceLabel' => ProductClass::PRICE_LABEL_AUTO, 'price' => $currentPrice]; } else { $upData = ['priceLabel' => ProductClass::PRICE_LABEL_CHANGE, 'price' => $val]; } $shopAll = ShopClass::getAllShop($this->sjId); if (!empty($shopAll)) { foreach ($shopAll as $currentShop) { $currentShopId = $currentShop['id'] ?? 0; if (empty($currentShopId)) { continue; } ProductClass::updateByCondition(['shopId' => $currentShopId, 'itemId' => $currentItemId], $upData); } } continue; } $where = []; $where['id'] = $id; $where['shopId'] = $this->shopId; $where['sjId'] = $this->sjId; if (empty($val)) { util::fail("参数错误!"); } $data = [ $type => $val ]; ProductClass::updateByCondition($where, $data); ProductClass::autoPriceById($id); //2021.7.6 linqh 如果是首店,则更新全部分店 ProductClass::updateSyncProduct($id, $this->shopId, $data); } util::complete(); } public function actionUpdate() { $post = Yii::$app->request->post(); $shop = $this->shop; $default = $shop->default ?? 0; if ($default != 1) { //除了上下架其它只能在首店修改 if (isset($post['delStatus']) == false) { util::fail('请在首店修改'); } } $shopAdmin = $this->shopAdmin; $roleId = $shopAdmin['roleId'] ?? 0; $role = AdminRoleClass::getById($roleId); $roleName = $role['roleName'] ?? ''; if ($roleName == '员工') { util::fail('没有权限操作哦'); } ProductClass::updateProduct($post); util::complete(); } //上下架状态控制 shish 20210713 public function actionDelStatusUpdate() { $post = Yii::$app->request->post(); $shopAdmin = $this->shopAdmin; $roleId = $shopAdmin['roleId'] ?? 0; $role = AdminRoleClass::getById($roleId); $roleName = $role['roleName'] ?? ''; if ($roleName == '员工') { util::fail('没有权限操作哦'); } $id = $post['id'] ?? 0; $delStatus = $post['delStatus'] ?? 0; $product = ProductClass::getById($id, true); if ($product->shopId != $this->shopId) { util::fail('没有权限操作'); } $product->delStatus = $delStatus; $product->save(); util::complete(); } //详情 ruidian 2021.5.3 public function actionDetail() { $id = Yii::$app->request->get('id', 0); $respond = ProductClass::getItemInfo($id); util::success($respond); } //新增花材 2021.6.21 public function actionAdd() { $post = Yii::$app->request->post(); $shop = $this->shop; $default = $shop->default ?? 0; if ($default != 1) { util::fail('请在首店添加'); } $shopAdmin = $this->shopAdmin; $roleId = $shopAdmin['roleId'] ?? 0; $role = AdminRoleClass::getById($roleId); $roleName = $role['roleName'] ?? ''; if ($roleName == '员工') { util::fail('没有权限操作哦'); } $post['sjId'] = $this->sjId; $post['adminId'] = $this->adminId; $post['shopId'] = $this->shopId; ProductClass::addProduct($post); util::complete('添加成功'); } //获取拼音缩写 shish 20210707 public function actionPy() { $name = Yii::$app->request->get('name'); $py = stringUtil::py($name); util::success(['py' => $py]); } }