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; $shopId = $this->shopId; $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true); $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(); } //新增花材 2021.6.21 public function actionAdd() { $post = Yii::$app->request->post(); $shop = $this->shop ?? []; $pfShopId = $shop->pfShopId ?? 0; if (!empty($pfShopId)) { 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; ItemClass::addItem($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 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 = 0; $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*"); $data = ProductClass::groupProductInfo($data, $level); util::success(['list' => $data]); } public function actionIndex() { $py = Yii::$app->request->get('py', ''); //默认显示上架商品 $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 (!empty($status)) { $where['status'] = $status; } $where['delStatus'] = $delStatus; $level = 0; $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() { $classId = Yii::$app->request->get('classId', 0); $pyName = Yii::$app->request->get('py', ''); if ($pyName) { $pyName = strtolower($pyName); $where['py'] = $pyName; } $where['mainId'] = $this->mainId; 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]); } //批量改价 public function actionBatchChangePrice() { $shop = $this->shop ?? []; $pfShopId = $shop->pfShopId ?? 0; if (!empty($pfShopId)) { util::fail('请在批发端操作'); } $default = $shop->default ?? 0; $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('超管才能修改'); } $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) { if (isset($product['price']) == false) { util::fail('没有价格'); } if (isset($product['id']) == false) { util::fail('没有花材'); } $price = $product['price']; $productId = $product['id']; $product = $productList[$productId] ?? []; if (empty($product)) { util::fail('没有找到花材'); } if (isset($product->mainId) == false || $product->mainId != $this->mainId) { util::fail('没有权限访问'); } if (empty($price)) { continue; } $ptItemId = $product->itemId; ItemClass::changeSinglePrice($shop, $ptItemId, $price); //在首店修改需要同步到所有直营店 if ($default == 1) { foreach ($chainShopList as $chain) { if ($chain->id == $shop->id) { continue; } ItemClass::changeSinglePrice($chain, $ptItemId, $price); } } } $transaction->commit(); util::complete('修改成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("失败原因:" . $e->getMessage()); util::fail('修改失败'); } } //从零售端采购入库,查看供应商的某个门店的product public function actionGhsItem() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $ghs = GhsClass::getGhsInfo($id); if (empty($ghs)) { util::fail('没有找到供应商'); } $shopId = $ghs['shopId'] ?? 0; $black = $ghs['black'] ?? 2; if ($black == 2) { util::fail('您已被列入黑名单'); } $connection = Yii::$app->db;//事务处理 $transaction = $connection->beginTransaction(); try { //获取所有当前供应商的分类 (全部、常用) //根据分类组装分类下的花材信息 $shop = ShopClass::getById($shopId, true); $mainId = $shop->mainId ?? 0; $classIds = ItemClassClass::getGhsItemClassAll($mainId); $where['mainId'] = $mainId; $where['delStatus'] = 0; $where['status'] = 1; $level = $ghs['giveLevel'] ?? 0; $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], "*"); $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level); $data = ProductService::assembleData($classIds, $itemInfoData, 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); $ptItemId = $respond['itemId'] ?? 0; $ptItemInfo = PtItemClass::getById($ptItemId); $respond['ptItemInfo'] = $ptItemInfo; util::success($respond); } public function actionUpdate() { $shop = $this->shop ?? []; $pfShopId = $shop->pfShopId ?? 0; if (!empty($pfShopId)) { util::fail('请在批发端操作'); } $post = Yii::$app->request->post(); $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('超管才能修改'); } $post['adminId'] = $this->adminId; $post['staffName'] = $this->shopAdmin->name; ItemClass::updateProduct($post, $this->shop); util::complete(); } //批量修改product 排序,成本价,加价 public function actionBatchUpdate() { //data = [{id:1,inTurn:10,addPrice:2,cost:10}] $data = Yii::$app->request->post('data', ''); $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(); } //供应商产品的详情 ssh 20210903 public function actionGhsProductDetail() { $id = Yii::$app->request->get('id', 0); $ghsId = Yii::$app->request->get('ghsId', 0); $ghs = GhsClass::getById($ghsId, true); GhsClass::valid($ghs, $this->shopId); $mainId = $ghs->mainId ?? 0; $product = ProductClass::getItemInfo($id, $ghs); if (isset($product['mainId']) == false || $product['mainId'] != $mainId) { Yii::info(json_encode($product)); Yii::info('mainId: ' . $mainId); util::fail('没有权限访问'); } $original = ProductClass::getById($id); if (isset($original['discountPrice']) && $original['discountPrice'] > 0) { $discountPrice = $original['discountPrice']; $original['price'] = floatval($discountPrice); $skAddPrice = $original['skAddPrice'] ?? 0; $addPrice = $original['addPrice'] ?? 0; $hjAddPrice = $original['hjAddPrice'] ?? 0; $zsAddPrice = $original['zsAddPrice'] ?? 0; $sk = bcsub($addPrice, $skAddPrice, 2); $hj = bcsub($addPrice, $hjAddPrice, 2); $zs = bcsub($addPrice, $zsAddPrice, 2); $original['skPrice'] = floatval(bcsub($discountPrice, $sk, 2)); $original['hjPrice'] = floatval(bcsub($discountPrice, $hj, 2)); $original['zsPrice'] = floatval(bcsub($discountPrice, $zs, 2)); } $product['originalInfo'] = $original; util::success($product); } //批量修改加价 ssh 20211211 public function actionBatchChangeAddPrice() { $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('超管才能操作'); } $shop = $this->shop; $pfShopId = $shop->pfShopId ?? 0; if (!empty($pfShopId)) { 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('修改成功'); } }