ProductController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 biz\shop\classes\ShopClass;
  9. use bizGhs\admin\classes\AdminClass;
  10. use bizGhs\item\classes\ItemClassClass;
  11. use bizGhs\product\classes\ProductClass;
  12. use bizGhs\product\services\ProductService;
  13. use bizGhs\item\services\ItemService;
  14. use common\components\util;
  15. use Yii;
  16. class ProductController extends BaseController
  17. {
  18. public $guestAccess = ['ghs-item'];
  19. public function actionIndex()
  20. {
  21. $py = Yii::$app->request->get('py', '');
  22. $type = Yii::$app->request->get('type', '');
  23. //访问店铺时用户增加最近访问的店铺 ssh 2021.3.1
  24. AdminClass::addRecentShop($this->shopId, $this->admin);
  25. //获取所有当前供应商的分类 (全部、常用)
  26. //根据分类组装分类下的花材信息
  27. $classIds = ItemClassClass::getGhsItemClassAll($this->sjId);
  28. $where['merchantId'] = $this->sjId;
  29. if ($py) {
  30. $pyName = strtolower($py);
  31. $where['py'] = $pyName;
  32. }
  33. $shopId = $this->shopId;
  34. //库存预警
  35. if ($type == 'waring') {
  36. //shopId 改为可以前端传,默认是当前shopId linqh 2021.1.26
  37. $shopId = Yii::$app->request->get('shopId', 0);
  38. if (!$shopId) {
  39. $shopId = $this->shopId;
  40. }
  41. }
  42. $where['shopId'] = $shopId;
  43. $itemInfoData = ProductClass::getAllByCondition($where, null, "*");
  44. $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
  45. //常用的itemIds
  46. $oftenItemIds = ProductClass::getOftenItemIds($shopId);
  47. //获取供应商下所有花材ID (itemIds)
  48. $itemIdsInfo = ItemService::getGhsItemIds($this->sjId);
  49. //dd($itemInfoData);
  50. //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
  51. $data = ProductService::assembleData($classIds, $itemIdsInfo, $itemInfoData, $oftenItemIds, $type);
  52. util::success($data);
  53. }
  54. //当前门店所有花材分类
  55. public function actionList()
  56. {
  57. //$classId = Yii::$app->request->get('classId',0);
  58. $pyName = Yii::$app->request->get('py', '');
  59. // $itemInfo = ItemClass::getGhsItemAll($this->sjId);
  60. // $itemIds = array_column($itemInfo, 'itemId');
  61. $where['merchantId'] = $this->sjId;
  62. if ($pyName) {
  63. // $pyNameItemIds = ItemClass::getItemIdsByPyName($pyName);
  64. // $itemIds = array_intersect($itemIds, $pyNameItemIds);
  65. $pyName = strtolower($pyName);
  66. $where['py'] = $pyName;
  67. }
  68. $shopId = Yii::$app->request->get('shopId', 0);
  69. if (!$shopId) {
  70. $shopId = $this->shopId;
  71. }
  72. $where['shopId'] = $shopId;
  73. $type = Yii::$app->request->get('type', '');
  74. $showPage = Yii::$app->request->get('showPage', 0);
  75. //需要显示分页
  76. if ($showPage) {
  77. $respond = ProductClass::getList("*", $where, "inTurn desc");
  78. util::success($respond);
  79. }
  80. $data = ProductClass::getAllByCondition($where, "inTurn desc", "*");
  81. $data = ProductClass::groupProductInfo($data);
  82. if ($type == 'waring') {
  83. //库存预警
  84. $newData = [];
  85. foreach ($data as $v) {
  86. if ($v['stock'] <= $v['stockWarning']) {
  87. $newData[] = $v;
  88. }
  89. }
  90. util::success(['list' => $newData]);
  91. }
  92. util::success(['list' => $data]);
  93. }
  94. //从零售端采购入库,查看供货商的某个门店的product
  95. public function actionGhsItem()
  96. {
  97. $get = Yii::$app->request->get();
  98. $id = $get['id'] ?? 0;
  99. $shopId = $get['shopId'] ?? 0;
  100. $ghsShopAdminId = isset($get['ghsShopAdminId']) && !empty($get['ghsShopAdminId']) ?? 0;
  101. if (!empty($ghsShopAdminId)) {
  102. } else {
  103. if (empty($id)) {
  104. if (!empty($this->shopId)) {
  105. $ghs = GhsClass::build($shopId, $this->shopId, $this->sjId);
  106. $sjId = $ghs['ghsSjId'] ?? 0;
  107. } else {
  108. $shop = ShopClass::getShopInfo($shopId);
  109. $sjId = $shop['merchantId'] ?? 0;
  110. }
  111. } else {
  112. $ghs = GhsClass::getGhsInfo($id);
  113. $sjId = $ghs['ghsSjId'] ?? 0;
  114. }
  115. }
  116. //获取所有当前供应商的分类 (全部、常用)
  117. //根据分类组装分类下的花材信息
  118. $classIds = ItemClassClass::getGhsItemClassAll($sjId);
  119. $where['merchantId'] = $sjId;
  120. $where['shopId'] = $shopId;
  121. $itemInfoData = ProductClass::getAllByCondition($where, null, "*");
  122. $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
  123. //常用的itemIds
  124. $oftenItemIds = ProductClass::getOftenItemIds($shopId);
  125. //获取供应商下所有花材ID (itemIds)
  126. $itemIdsInfo = ItemService::getGhsItemIds($this->sjId);
  127. //dd($itemInfoData);
  128. //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
  129. $data = ProductService::assembleData($classIds, $itemIdsInfo, $itemInfoData, $oftenItemIds, '');
  130. util::success($data);
  131. }
  132. }