ProductController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. //当前门店所有花材分类
  54. public function actionList()
  55. {
  56. //$classId = Yii::$app->request->get('classId',0);
  57. $pyName = Yii::$app->request->get('py', '');
  58. // $itemInfo = ItemClass::getGhsItemAll($this->sjId);
  59. // $itemIds = array_column($itemInfo, 'itemId');
  60. $where['merchantId'] = $this->sjId;
  61. if ($pyName) {
  62. // $pyNameItemIds = ItemClass::getItemIdsByPyName($pyName);
  63. // $itemIds = array_intersect($itemIds, $pyNameItemIds);
  64. $pyName = strtolower($pyName);
  65. $where['py'] = $pyName;
  66. }
  67. $shopId = Yii::$app->request->get('shopId', 0);
  68. if (!$shopId) {
  69. $shopId = $this->shopId;
  70. }
  71. $where['shopId'] = $shopId;
  72. $type = Yii::$app->request->get('type', '');
  73. $showPage = Yii::$app->request->get('showPage',0);
  74. if($showPage){
  75. $res = ProductClass::getList("*",$where,"inTurn desc");
  76. $data = $res['list'];
  77. }else{
  78. $data = ProductClass::getAllByCondition($where,"inTurn desc","*");
  79. }
  80. $data = ProductClass::groupProductInfo($data);
  81. if ($type == 'waring') {
  82. //库存预警
  83. $newData = [];
  84. foreach ($data as $v){
  85. if($v['stock'] <= $v['stockWarning']) {
  86. $newData[] = $v;
  87. }
  88. }
  89. util::success(['list' => $newData]);
  90. }
  91. if($showPage){
  92. $res['list'] = $data;
  93. util::success(['list' => $res]);
  94. }else{
  95. util::success(['list' => $data]);
  96. }
  97. }
  98. }