| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- /**
- * User: admin
- * Date Time: 2021/3/2 14:34
- */
- namespace hd\controllers;
- use biz\ghs\classes\GhsClass;
- use bizGhs\admin\classes\AdminClass;
- use bizGhs\item\classes\ItemClassClass;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\product\services\ProductService;
- use bizGhs\item\services\ItemService;
- use common\components\util;
- use Yii;
- class ProductController extends BaseController
- {
- public $guestAccess = ['ghs-item'];
- public function actionIndex()
- {
- $py = Yii::$app->request->get('py', '');
- $type = Yii::$app->request->get('type', '');
- //访问店铺时用户增加最近访问的店铺 ssh 2021.3.1
- AdminClass::addRecentShop($this->shopId, $this->admin);
- //获取所有当前供应商的分类 (全部、常用)
- //根据分类组装分类下的花材信息
- $classIds = ItemClassClass::getGhsItemClassAll($this->sjId);
- $where['merchantId'] = $this->sjId;
- if ($py) {
- $pyName = strtolower($py);
- $where['py'] = $pyName;
- }
- $shopId = $this->shopId;
- //库存预警
- 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");
- 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]);
- }
- //从零售端采购入库,查看供货商的某个门店的product
- public function actionGhsItem()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $ghsShopId = $get['shopId'] ?? 0;
- if (empty($id)) {
- $ghs = GhsClass::build($ghsShopId, $this->shopId, $this->sjId);
- } else {
- $ghs = GhsClass::getGhsInfo($id);
- }
- if (empty($ghs)) {
- util::fail('供货商无效');
- }
- $shopId = $ghs['ghsShopId'] ?? 0;
- $sjId = $ghs['ghsSjId'] ?? 0;
- AdminClass::addRecentShop($shopId, $this->admin);
- //获取所有当前供应商的分类 (全部、常用)
- //根据分类组装分类下的花材信息
- $classIds = ItemClassClass::getGhsItemClassAll($sjId);
- $where['merchantId'] = $sjId;
- $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, '');
- util::success($data);
- }
- }
|