ProductController.php 4.9 KB

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