ProductController.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * User: admin
  4. * Date Time: 2021/3/2 14:34
  5. */
  6. namespace hd\controllers;
  7. use bizGhs\admin\classes\AdminClass;
  8. use bizGhs\item\classes\ItemClass;
  9. use bizGhs\item\classes\ItemClassClass;
  10. use bizGhs\product\classes\ProductClass;
  11. use bizGhs\product\services\ProductService;
  12. use bizGhs\item\services\ItemService;
  13. use common\components\noticeUtil;
  14. use common\components\util;
  15. use Yii;
  16. class ProductController extends BaseController
  17. {
  18. public function actionIndex()
  19. {
  20. $py = Yii::$app->request->get('py', '');
  21. $type = Yii::$app->request->get('type', '');
  22. //访问店铺时用户增加最近访问的店铺 ssh 2021.3.1
  23. AdminClass::addRecentShop($this->shopId, $this->admin);
  24. //获取所有当前供应商的分类 (全部、常用)
  25. //根据分类组装分类下的花材信息
  26. $classIds = ItemClassClass::getGhsItemClassAll($this->sjId);
  27. $where['merchantId'] = $this->sjId;
  28. if ($py) {
  29. $pyName = strtolower($py);
  30. $where['py'] = $pyName;
  31. }
  32. $shopId = $this->shopId;
  33. //库存预警
  34. if ($type == 'waring') {
  35. //shopId 改为可以前端传,默认是当前shopId linqh 2021.1.26
  36. $shopId = Yii::$app->request->get('shopId', 0);
  37. if (!$shopId) {
  38. $shopId = $this->shopId;
  39. }
  40. }
  41. $where['shopId'] = $shopId;
  42. $itemInfoData = ProductClass::getAllByCondition($where,null,"*");
  43. $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
  44. //常用的itemIds
  45. $oftenItemIds = ProductClass::getOftenItemIds($shopId);
  46. //获取供应商下所有花材ID (itemIds)
  47. $itemIdsInfo = ItemService::getGhsItemIds($this->sjId);
  48. //dd($itemInfoData);
  49. //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
  50. $data = ProductService::assembleData($classIds, $itemIdsInfo,$itemInfoData, $oftenItemIds, $type);
  51. util::success($data);
  52. }
  53. }