request->get(); $id = $get['id'] ?? 0; $num = $get['num'] ?? 1; $info = ProductClass::getById($id, true); if (empty($info)) { util::fail('没有找到花材'); } $name = $info->name ?? ''; $ptItemId = $info->itemId ?? 0; $ext = $this->shopExt; $printLabelSn = $ext->printLabelSn ?? ''; if (empty($printLabelSn)) { util::fail('请设置标签打印机'); } $p = new printUtil($printLabelSn); $unit = $info->ratio . $info->smallUnit . '/' . $info->bigUnit; $p->times = $num; $content = '' . $name . ''; $content .= '' . $ptItemId . ''; $content .= '' . $unit . ''; $p->printLabelMsg($content); util::complete(); } //按分类列出所有花材 public function actionIndex() { $py = Yii::$app->request->get('py', ''); $requestType = Yii::$app->request->get('requestType', 'common'); //默认显示上架商品 $status = Yii::$app->request->get('status', 1); //默认显示未删除商品 $delStatus = Yii::$app->request->get('delStatus', 0); //获取所有当前供应商的分类 (全部、常用) //根据分类组装分类下的花材信息 //中央ID $classIds = ItemClassClass::getGhsItemClassAll($this->mainId); $where['mainId'] = $this->mainId; if ($py) { $pyName = strtolower($py); $where['py'] = $pyName; } if ($requestType == 'hasStock') { //改价只显示库存大于0的 $where['stock>'] = 0; } if (!empty($status)) { $where['status'] = $status; } $where['delStatus'] = $delStatus; //客户等级 $customId = Yii::$app->request->get('customId', 0); $level = 1; if (!empty($customId)) { $custom = CustomClass::getById($customId, true); $level = $custom->level ?? 1; } $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], "*"); $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level); $data = ProductService::assembleData($classIds, $itemInfoData, true); util::success($data); } //所有花材分页和不分页 public function actionList() { $where = []; $classId = Yii::$app->request->get('classId', 0); if (!empty($classId)) { $where['classId'] = $classId; } $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]; } } $status = Yii::$app->request->get('status', 0); if (!empty($status)) { $where['status'] = $status; } $delStatus = Yii::$app->request->get('delStatus', 0); if ($delStatus != 2) { $where['delStatus'] = $delStatus; } $where['mainId'] = $this->mainId; $productIds = Yii::$app->request->get('ids', ''); if (!empty($productIds)) { $productIdArr = explode(',', $productIds); if (!empty($productIdArr)) { $where['id'] = ['in', $productIdArr]; } } //输出标准会员价,即花店价,默认显示的是花店价 $level = 1; $type = Yii::$app->request->get('type', ''); $showPage = Yii::$app->request->get('showPage', 0); if ($showPage) { if ($type == 'waring') { $pro = Product::find()->where("mainId={$this->mainId}")->andWhere('`stock`<`stockWarning`')->select('id')->asArray()->all(); $lackIds = array_column($pro, 'id'); if (empty($lackIds)) { util::success([]); } $lackIds = array_filter(array_unique($lackIds)); $where['id'] = ['in', $lackIds]; $respond = ProductClass::getList("*", $where, "actualSold desc"); } else { $respond = ProductClass::getList("*", $where, "inTurn desc"); } $respond['list'] = ProductClass::groupProductInfo($respond['list'], $level); $respond['list'] = ProductClass::groupClassName($this->sjId, $respond['list']); util::success($respond); } else { if ($type == 'waring') { //库存预警 按库存从小到大排序 $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*"); } else { if (!empty($productIds)) { //优先按 $productIds 排序 "FIELD(`id`,4,5,6)"=>true $data = ProductClass::getAllByCondition($where, ["FIELD(`id`,$productIds)" => true, 'inTurn' => SORT_DESC], "*"); } else { $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*"); } } $data = ProductClass::groupProductInfo($data, $level); $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 actionAll() { $where = []; $where['mainId'] = $this->mainId; $classId = Yii::$app->request->get('classId', 0); if (!empty($classId)) { $where['classId'] = $classId; } $status = Yii::$app->request->get('status', 0); if (!empty($status)) { $where['status'] = $status; } $delStatus = Yii::$app->request->get('delStatus', 0); if ($delStatus != 2) { $where['delStatus'] = $delStatus; } //输出标准会员价,即花店价,默认显示的是花店价 $level = 1; $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*"); $data = ProductClass::groupProductInfo($data, $level); util::success(['list' => $data]); } //批量改价 public function actionBatchChangePrice() { $shop = $this->shop; $join = $shop->join ?? 0; $default = $shop->default ?? 0; if ($join == 0 && $default == 0) { util::fail('请在总店操作'); } $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('超管才能修改'); } $shop = $this->shop; $default = $shop->default ?? 0; $data = Yii::$app->request->post('data', ''); if (empty($data)) { util::fail('没有修改'); } $arr = json_decode($data, true); if (empty($arr)) { util::fail('没有修改哦'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $ids = array_column($arr, 'id'); $ids = array_unique(array_filter($ids)); if (empty($ids)) { util::fail('请选择花材'); } $sjId = $shop->sjId ?? 0; $chainShopList = []; if ($default == 1) { $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true); } $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true); foreach ($arr as $product) { $productId = $product['id']; $productInfo = $productList[$productId] ?? []; if (empty($productInfo)) { util::fail('没有找到花材'); } $productName = $productInfo->name ?? ''; if (isset($product['id']) == false) { util::fail('没有花材'); } if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) { util::fail('请填写' . $productName . '的花店价'); } $price = $product['price']; if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) { util::fail('请填写' . $productName . '的散客价'); } $skPrice = $product['skPrice']; if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) { util::fail('没有权限访问'); } if (empty($price)) { continue; } $ptItemId = $productInfo->itemId; ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice); //在首店修改需要同步到所有直营店 if ($default == 1) { foreach ($chainShopList as $chain) { if ($chain->id == $shop->id) { continue; } ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice); } } } $mainId = $shop->mainId ?? 0; if (!empty($mainId)) { //提醒零售收银台界面要刷新 $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true); if (!empty($staffList)) { foreach ($staffList as $staff) { $staffId = $staff->id ?? 0; Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']); } } } $transaction->commit(); util::complete('修改成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("修改失败原因:" . $e->getMessage()); util::fail('修改失败'); } } //改价 public function actionChangePrice() { $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('超管才能修改'); } $productId = Yii::$app->request->post('productId', 0); $productInfo = ProductClass::getById($productId, true); if (empty($productInfo)) { util::fail("花材不存在"); } if ($productInfo->mainId != $this->mainId) { util::fail('没有权限'); } $price = Yii::$app->request->post('price', ''); if (is_numeric($price) && $price > 0) { ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE); } else { $price = bcadd($productInfo->cost, $productInfo->addPrice, 2); ProductClass::changeSinglePrice($productInfo, $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("花材不存在"); } //2021.04.06改为用product中的成本价+加价 $price = bcadd($productData['cost'], $productData['addPrice'], 2); ProductClass::changeSinglePrice($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->mainId); if (!$productData) { util::fail("花材不存在"); } ProductClass::changeAddPrice($productId, $addPrice); util::complete(); } //批量修改更多,包括排序、重量和保质期 ssh 20211211 public function actionBatchChangeMore() { $shop = $this->shop; $join = $shop->join ?? 0; $default = $shop->default ?? 0; if ($join == 0 && $default == 0) { util::fail('请在总店操作'); } $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('超管才能操作'); } $addData = Yii::$app->request->post('addData', ''); if (empty($addData)) { util::fail('没有花材'); } $itemData = json_decode($addData, true); if (is_array($itemData) == false) { util::fail('没有花材...'); } $ids = array_column($itemData, 'id'); $infoList = ProductClass::getByIds($ids); if (empty($infoList)) { util::fail('没有花材'); } foreach ($infoList as $info) { if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) { util::fail('非常访问,不是你的花材不能修改'); } } foreach ($itemData as $key => $data) { $id = $data['id'] ?? 0; ProductClass::updateById($id, $data); } util::complete('修改成功'); } //批量修改加价 ssh 20211211 public function actionBatchChangeAddPrice() { $shop = $this->shop; $join = $shop->join ?? 0; $default = $shop->default ?? 0; if ($join == 0 && $default == 0) { util::fail('请在总店操作'); } $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('超管才能操作'); } $addData = Yii::$app->request->post('addData', ''); if (empty($addData)) { util::fail('没有花材'); } $itemData = json_decode($addData, true); if (is_array($itemData) == false) { util::fail('没有花材...'); } $ids = array_column($itemData, 'id'); $infoList = ProductClass::getByIds($ids, null, 'id'); if (empty($infoList)) { util::fail('没有花材'); } foreach ($infoList as $info) { if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) { util::fail('不能修改别人的花材'); } } //首店修改同步到所有直营店 $sjId = $shop->sjId ?? 0; $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true); foreach ($itemData as $key => $data) { $id = $data['id'] ?? 0; unset($data['id']); ProductClass::updateById($id, $data); $ptItemId = $infoList[$id]['itemId'] ?? 0; if (empty($ptItemId)) { continue; } if (isset($shop->default) && $shop->default == 1) { foreach ($chainShopList as $chainShop) { if (isset($chainShop->join) && $chainShop->join == 1) { continue; } $currentMainId = $chainShop->mainId ?? 0; if ($currentMainId == $shop->mainId) { //前面已经修改过了,不需要重复修改 continue; } ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data); } } } util::complete('修改成功'); } public function actionUpdate() { $shop = $this->shop; $join = $shop->join ?? 0; $default = $shop->default ?? 0; if ($join == 0 && $default == 0) { //util::fail('请在总店操作'); } $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('超管才能操作'); } $post = Yii::$app->request->post(); $post['adminId'] = $this->adminId; $post['staffName'] = $this->shopAdmin->name; ProductClass::updateProduct($post, $this->shop); util::complete(); } //上下架状态控制 ssh 20210713 public function actionStatusUpdate() { $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; $status = $post['status'] ?? 1; $product = ProductClass::getById($id, true); if ($product->mainId != $this->mainId) { util::fail('没有权限操作'); } $product->status = $status; if ($status == 2) { $product->discountPrice = 0; } $product->save(); util::complete(); } //花材展示状态控制 ssh 20210804 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->mainId != $this->mainId) { 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); $ptItemId = $respond['itemId'] ?? 0; $ptItemInfo = PtItemClass::getById($ptItemId); $respond['ptItemInfo'] = $ptItemInfo; util::success($respond); } //新增花材 2021.6.21 public function actionAdd() { $post = Yii::$app->request->post(); $shop = $this->shop; $join = $shop->join ?? 0; $default = $shop->default ?? 0; if ($join == 0 && $default == 0) { util::fail('请在总店操作'); } $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('管理员才能添加花材'); } $post['sjId'] = $this->sjId; $post['adminId'] = $this->adminId; $post['mainId'] = $this->mainId; $price = $post['price'] ?? 0; $addPrice = $post['addPrice'] ?? 0; if ($addPrice > $price) { util::fail('加价不能大于售价'); } $cost = bcsub($price, $addPrice, 2); $post['cost'] = $cost; $post['staffName'] = $shopAdmin->name ?? ''; ProductClass::addProduct($post, $this->shop); util::complete('添加成功'); } //获取拼音缩写 ssh 20210707 public function actionPy() { $name = Yii::$app->request->get('name'); $py = stringUtil::py($name); util::success(['py' => $py]); } //(客户端-批发商)复制花材 public function actionClone() { $post = Yii::$app->request->post(); $shop = $this->shop; $join = $shop->join ?? 0; $default = $shop->default ?? 0; if ($join == 0 && $default == 0) { util::fail('请在总店操作'); } $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('管理员才能添加花材'); } $shop = $this->shop; $default = $shop->default ?? 0; if ($default != 1) { util::fail('请在总店添加'); } $post['sjId'] = $this->sjId; $post['adminId'] = $this->adminId; $post['mainId'] = $this->mainId; $post['staffName'] = $shopAdmin->name ?? ''; $price = $post['price'] ?? 0; $addPrice = $post['addPrice'] ?? 0; if ($addPrice > $price) { util::fail('加价不能大于售价'); } $cost = bcsub($price, $addPrice, 2); $post['cost'] = $cost; $post['copy'] = 1; //复制标识 //去除无用的字段 unset($post['viewNum']); unset($post['actualSold']); unset($post['itemId']); unset($post['id']); unset($post['delStatus']); ProductClass::addProduct($post, $this->shop); util::complete('复制成功'); } //下载价格表 ssh 20210922 public function actionGeneratePriceTable() { $level = Yii::$app->request->get('level', 0); $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId); $file = $respond['file'] ?? ''; $shortFile = $respond['shortFile'] ?? ''; $fileUrl = Yii::$app->params['ghsHost'] . $file; util::success(['file' => $fileUrl, 'shortFile' => $shortFile]); } //下载条形码 lqh 20211227 public function actionGenerateBarcodeTable() { $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId); $file = $respond['file'] ?? ''; $shortFile = $respond['shortFile'] ?? ''; $fileUrl = Yii::$app->params['ghsHost'] . $file; util::success(['file' => $fileUrl, 'shortFile' => $shortFile]); } }