| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632 |
- <?php
- namespace hd\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\item\classes\PtItemClass;
- use biz\shop\classes\ShopClass;
- use biz\shop\classes\ShopExtClass;
- use bizGhs\item\classes\ItemClassClass;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\product\services\ProductService;
- use bizHd\admin\classes\ShopAdminClass;
- use bizHd\item\classes\ItemClass;
- use bizHd\purchase\classes\PurchaseClass;
- use common\components\noticeUtil;
- use common\components\printUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class ProductController extends BaseController
- {
- public $guestAccess = ['ghs-item', 'ghs-product-detail'];
- //打印花材的标签 ssh 20220602
- public function actionPrint()
- {
- $get = Yii::$app->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;
- if (isset($info->ratioType) && $info->ratioType == 1) {
- $unit = '若干' . $info->smallUnit . '/' . $info->bigUnit;
- }
- $p->times = $num;
- $content = '<TEXT x="360" y="30" font="12" w="2" h="2" r="90">' . $name . '</TEXT>';
- $content .= '<BC128 x="260" y="30" h="70" s="1" r="90" n="4" w="11">' . $ptItemId . '</BC128>';
- $content .= '<TEXT x="60" y="30" font="12" w="2" h="2" r="90">' . $unit . '</TEXT>';
- $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;
- if ($price <= 0) {
- util::fail('请填写价格');
- }
- $addPrice = $post['addPrice'] ?? 0;
- if ($addPrice > $price) {
- util::fail('加价不能大于售价');
- }
- $post['skPrice'] = $price;
- $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;
- $field = 'id,cover,name,cost,itemId,classId,property,skPrice,skMore,addPrice,variety,price,discountPrice,skDiscountPrice,stock,stockWarning,presell,ratioType,smallRatio,smallUnit,bigUnit,ratio,actualSold';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
- $respond = ProductService::assembleData($classIds, $itemInfoData, true);
- $classItem = $respond['classItem'] ?? [];
- util::success($classItem);
- }
- //当前门店所有花材分类
- 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 ?? [];
- $shopId = $shop->id ?? 0;
- $default = $shop->default ?? 0;
- $join = $shop->join ?? 0;
- $shopAdmin = $this->shopAdmin;
- $adminId = $this->adminId ?? 0;
- //normal常规改价,cg采购改价
- $changeType = Yii::$app->request->post('changeType', 'normal');
- $doType = Yii::$app->request->post('doType', 0);
- if ($changeType == 'cg' && $doType == 0) {
- if (getenv('YII_ENV') == 'production') {
- //小蔡鲜花的几个分店的零售店不能修改体系
- if (in_array($shopId, [29153, 29155, 29157, 29162, 29164])) {
- util::fail('本店无法改价');
- }
- } else {
- if (in_array($shopId, [36545])) {
- util::fail('本店无法改价哦');
- }
- }
- }
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能修改');
- }
- if ($join == 0 && $default == 0) {
- util::fail('当前直营分店,只能回总店修改价格');
- }
- $targetId = Yii::$app->request->post('targetId', 0);
- $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
- $post = Yii::$app->request->post();
- $data = $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 {
- if ($doType == 0 || $doType == 1) {
- $cg = PurchaseClass::getLockById($targetId);
- if (!empty($cg)) {
- if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
- util::fail('不是您的采购单');
- }
- if ($cg->status == PurchaseClass::STATUS_UN_SEND && $cg->book == 1) {
- util::fail('预订单只有发货后,才能确认收货');
- }
- //没有发货则先发货
- if ($cg->status == PurchaseClass::STATUS_UN_SEND) {
- $cg = PurchaseClass::orderSend($cg, [], true);
- }
- //确认收货并入库
- if ($cg->status == PurchaseClass::STATUS_SENDING) {
- PurchaseClass::takeToPutIn($cg);
- if ($doType == 1) {
- $transaction->commit();
- util::complete('入库成功');
- }
- } else {
- util::fail('订单不是待入库状态');
- }
- } else {
- if ($doType == 1) {
- util::fail('入库失败,没有找到采购单');
- }
- }
- }
- $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'];
- $productInfo = $productList[$productId] ?? [];
- if (empty($productInfo)) {
- util::fail('没有找到花材');
- }
- $productName = $productInfo->name ?? '';
- if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
- util::fail('请填写' . $productName . '的批发价');
- }
- if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
- util::fail('请填写' . $productName . '的零售价');
- }
- $skPrice = $product['skPrice'];
- if (isset($product['hjPrice']) == false || is_numeric($product['hjPrice']) == false || $product['hjPrice'] < 0) {
- util::fail('请填写' . $productName . '的会员价');
- }
- $hjPrice = $product['hjPrice'] ?? 0;
- if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
- util::fail('无法访问');
- }
- if ($hjPrice > $price) {
- util::fail($productName . ' 批发价要大于会员价');
- }
- if ($price > $skPrice) {
- util::fail($productName . ' 零售价要大于批发价');
- }
- $ptItemId = $productInfo->itemId;
- ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
- //在首店修改需要同步到所有直营店
- if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
- foreach ($chainShopList as $chain) {
- if ($chain->id == $shop->id) {
- continue;
- }
- $chainMainId = $chain->mainId ?? 0;
- $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
- $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
- ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
- }
- }
- }
- $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']);
- Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
- }
- }
- }
- $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;
- //是否显示全部花材,包括下架的
- $showAll = $get['showAll'] ?? 0;
- if ($showAll == 0) {
- $where['status'] = 1;
- }
- $where['frontHide'] = 0;
- $level = $ghs['giveLevel'] ?? 1;
- $field = 'id,py,cover,name,ratio,classId,itemId,weight,smallUnit,bigUnit,smallUnit,smallRatio,ratioType,variety,price,skPrice,skDiscountPrice,hjPrice,hjDiscountPrice,actualSold,stock,stockWarning,discountPrice,presell,presellDate,reachNum,reachNumDiscount,limitBuy';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::hdCgGroup($itemInfoData, $level);
- $myProduct = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], null, 'id,stock,onStock,stockWarning,itemId', 'itemId');
- if (!empty($itemInfoData)) {
- $myShop = $this->shop;
- $myDisplay = isset($myShop->pfShopId) && $myShop->pfShopId > 0 ? 1 : 0;
- foreach ($itemInfoData as $key => $val) {
- $ptItemId = $val['itemId'] ?? 0;
- $myStock = $myProduct[$ptItemId]['stock'] ?? 0;
- $myStock = floatval($myStock);
- $myOnStock = $myProduct[$ptItemId]['onStock'] ?? 0;
- $myStockWarning = $myProduct[$ptItemId]['stockWarning'] ?? 5;
- $myLack = bcadd($myStock, $myOnStock, 2) > $myStockWarning ? 0 : 1;
- $itemInfoData[$key]['myStock'] = $myStock;
- $itemInfoData[$key]['myOnStock'] = $myOnStock;
- $itemInfoData[$key]['myStockWarning'] = $myStockWarning;
- $itemInfoData[$key]['myLack'] = $myLack;
- $itemInfoData[$key]['myDisplay'] = $myDisplay;
- }
- }
- $respond = ProductService::assembleData($classIds, $itemInfoData, true);
- $classItem = $respond['classItem'] ?? [];
- util::success($classItem);
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("报错内容:" . $e->getMessage());
- util::fail();
- }
- }
- public function actionGhsItemV2()
- {
- $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;
- //是否显示全部花材,包括下架的
- $showAll = $get['showAll'] ?? 0;
- if ($showAll == 0) {
- $where['status'] = 1;
- }
- $where['frontHide'] = 0;
- $level = $ghs['giveLevel'] ?? 1;
- $field = 'id,py,cover,name,ratio,classId,itemId,weight,smallUnit,bigUnit,smallUnit,smallRatio,ratioType,variety,price,skPrice,skDiscountPrice,hjPrice,hjDiscountPrice,actualSold,stock,stockWarning,discountPrice,presell,presellDate,reachNum,reachNumDiscount,limitBuy';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::hdCgGroup($itemInfoData, $level);
- $myProduct = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], null, 'id,stock,onStock,stockWarning,itemId', 'itemId');
- if (!empty($itemInfoData)) {
- $myShop = $this->shop;
- $myDisplay = isset($myShop->pfShopId) && $myShop->pfShopId > 0 ? 1 : 0;
- foreach ($itemInfoData as $key => $val) {
- $ptItemId = $val['itemId'] ?? 0;
- $myStock = $myProduct[$ptItemId]['stock'] ?? 0;
- $myStock = floatval($myStock);
- $myOnStock = $myProduct[$ptItemId]['onStock'] ?? 0;
- $myStockWarning = $myProduct[$ptItemId]['stockWarning'] ?? 5;
- $myLack = bcadd($myStock, $myOnStock, 2) > $myStockWarning ? 0 : 1;
- $itemInfoData[$key]['myStock'] = $myStock;
- $itemInfoData[$key]['myOnStock'] = $myOnStock;
- $itemInfoData[$key]['myStockWarning'] = $myStockWarning;
- $itemInfoData[$key]['myLack'] = $myLack;
- $itemInfoData[$key]['myDisplay'] = $myDisplay;
- }
- }
- $respond = ProductService::assembleData($classIds, $itemInfoData, true);
- if ($showAll == 1) {
- if (isset($respond['classItem']) && !empty($respond['classItem'])) {
- foreach ($respond['classItem'] as $bigKey => $bigVal) {
- if (isset($bigVal['child']) && !empty($bigVal['child'])) {
- foreach ($bigVal['child'] as $key => $val) {
- unset($bigVal['child'][$key]['cover']);
- unset($bigVal['child'][$key]['actualSold']);
- unset($bigVal['child'][$key]['defaultGradePrice']);
- unset($bigVal['child'][$key]['discountPrice']);
- unset($bigVal['child'][$key]['hjDiscountPrice']);
- unset($bigVal['child'][$key]['hjPrice']);
- unset($bigVal['child'][$key]['presellDateShow']);
- unset($bigVal['child'][$key]['prePrice']);
- unset($bigVal['child'][$key]['print']);
- unset($bigVal['child'][$key]['reachNum']);
- unset($bigVal['child'][$key]['reachNumDiscount']);
- unset($bigVal['child'][$key]['reachPrice']);
- unset($bigVal['child'][$key]['skDiscountPrice']);
- unset($bigVal['child'][$key]['skPrice']);
- unset($bigVal['child'][$key]['bigUnit']);
- unset($bigVal['child'][$key]['weight']);
- unset($bigVal['child'][$key]['stockWarning']);
- //unset($bigVal['child'][$key]['smallPrice']);
- //unset($bigVal['child'][$key]['smallRatio']);
- }
- $respond['classItem'][$bigKey]['child'] = $bigVal['child'];
- }
- }
- }
- }
- util::success($respond);
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("报错内容:" . $e->getMessage());
- 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 20230111
- public function actionGhsProductDetail()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $ghsId = $get['ghsId'] ?? 0;
- $product = ProductClass::getById($id);
- if (empty($product)) {
- util::fail('没有花材信息');
- }
- $ghsInfo = GhsClass::getById($ghsId, true);
- $level = isset($ghsInfo->giveLevel) ? $ghsInfo->giveLevel : 1;
- $list = ProductClass::groupProductInfo([$product], $level);
- $product = current($list);
- 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('修改成功');
- }
- }
|