| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?php
- /**
- * User: admin
- * Date Time: 2021/1/15 20:36
- */
- namespace ghs\controllers;
- use bizGhs\admin\classes\AdminClass;
- use bizGhs\item\classes\ItemClass;
- use bizGhs\item\classes\ItemClassClass;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\product\services\ProductService;
- use bizGhs\item\services\ItemService;
- use common\components\noticeUtil;
- use common\components\util;
- use Yii;
- class ProductController extends BaseController
- {
- public $guestAccess = ['index'];
- //开单时获取所有的分类花材信息
- //库存预警
- public function actionIndex()
- {
- $py = Yii::$app->request->get('py', '');
- $type = Yii::$app->request->get('type', '');
- //访问店铺时用户增加最近访问的店铺 ssh 2021.3.1
- AdminClass::addRecentShop($this->lookShopId, $this->admin);
- //获取所有当前供应商的分类 (全部、常用)
- //根据分类组装分类下的花材信息
- $classIds = ItemClassClass::getGhsItemClassAll($this->sjId);
- $where['merchantId'] = $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;
- $itemInfoData = ProductClass::getAllByCondition($where, null, "*");
- $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
- //常用的itemIds
- $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);
- $pyName = Yii::$app->request->get('py', '');
- // $itemInfo = ItemClass::getGhsItemAll($this->sjId);
- // $itemIds = array_column($itemInfo, 'itemId');
- $where['merchantId'] = $this->sjId;
- if ($pyName) {
- // $pyNameItemIds = ItemClass::getItemIdsByPyName($pyName);
- // $itemIds = array_intersect($itemIds, $pyNameItemIds);
- $pyName = strtolower($pyName);
- $where['py'] = $pyName;
- }
- $shopId = Yii::$app->request->get('shopId', 0);
- if (!$shopId) {
- $shopId = $this->shopId;
- }
- $where['shopId'] = $shopId;
- $type = Yii::$app->request->get('type', '');
- $showPage = Yii::$app->request->get('showPage', 0);
- if ($showPage) {
- $respond = ProductClass::getList("*", $where, "inTurn desc");
- $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 actionChangePrice()
- {
- $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()
- {
- $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']))
- $data = json_decode($data, true);
- foreach ($data as $v) {
- $id = $v['id'];
- $val = $v[$type] ?? '';
- $where = [];
- $where['id'] = $id;
- $where['shopId'] = $this->shopId;
- $where['merchantId'] = $this->sjId;
- if (empty($val)) {
- util::fail("参数错误1");
- }
- $data = [
- $type => $val
- ];
- ProductClass::updateByCondition($where, $data);
- ProductClass::autoPriceById($id);
- }
- util::complete();
- }
- public function actionUpdate()
- {
- $post = Yii::$app->request->post();
- ProductClass::updateProduct($post);
- util::complete();
- }
- }
|