ProductController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * User: admin
  4. * Date Time: 2021/3/2 14:34
  5. */
  6. namespace hd\controllers;
  7. use biz\ghs\classes\GhsClass;
  8. use bizGhs\admin\classes\AdminClass;
  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\util;
  14. use Yii;
  15. class ProductController extends BaseController
  16. {
  17. public $guestAccess = ['ghs-item'];
  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. //需要显示分页
  75. if ($showPage) {
  76. $respond = ProductClass::getList("*", $where, "inTurn desc");
  77. util::success($respond);
  78. }
  79. $data = ProductClass::getAllByCondition($where, "inTurn desc", "*");
  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. util::success(['list' => $data]);
  92. }
  93. //从零售端采购入库,查看供货商的某个门店的product
  94. public function actionGhsItem()
  95. {
  96. $get = Yii::$app->request->get();
  97. $id = $get['id'] ?? 0;
  98. $ghsShopId = $get['shopId'] ?? 0;
  99. if (empty($id)) {
  100. $ghs = GhsClass::build($ghsShopId, $this->shopId, $this->sjId);
  101. } else {
  102. $ghs = GhsClass::getGhsInfo($id);
  103. }
  104. if (empty($ghs)) {
  105. util::fail('供货商无效');
  106. }
  107. $shopId = $ghs['ghsShopId'] ?? 0;
  108. $sjId = $ghs['ghsSjId'] ?? 0;
  109. AdminClass::addRecentShop($shopId, $this->admin);
  110. //获取所有当前供应商的分类 (全部、常用)
  111. //根据分类组装分类下的花材信息
  112. $classIds = ItemClassClass::getGhsItemClassAll($sjId);
  113. $where['merchantId'] = $sjId;
  114. $where['shopId'] = $shopId;
  115. $itemInfoData = ProductClass::getAllByCondition($where, null, "*");
  116. $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
  117. //常用的itemIds
  118. $oftenItemIds = ProductClass::getOftenItemIds($shopId);
  119. //获取供应商下所有花材ID (itemIds)
  120. $itemIdsInfo = ItemService::getGhsItemIds($this->sjId);
  121. //dd($itemInfoData);
  122. //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
  123. $data = ProductService::assembleData($classIds, $itemIdsInfo, $itemInfoData, $oftenItemIds, '');
  124. util::success($data);
  125. }
  126. }