ProductController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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\ItemClass;
  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\noticeUtil;
  15. use common\components\util;
  16. use Yii;
  17. class ProductController extends BaseController
  18. {
  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. $ghs = GhsClass::getGhsInfo($id);
  100. if(empty($ghs)){
  101. util::fail('供货商无效');
  102. }
  103. $shopId = $ghs['ghsShopId']??0;
  104. $sjId = $ghs['ghsSjId']??0;
  105. AdminClass::addRecentShop($shopId,$this->admin);
  106. //获取所有当前供应商的分类 (全部、常用)
  107. //根据分类组装分类下的花材信息
  108. $classIds = ItemClassClass::getGhsItemClassAll($sjId);
  109. $where['merchantId'] = $sjId;
  110. $where['shopId'] = $shopId;
  111. $itemInfoData = ProductClass::getAllByCondition($where,null,"*");
  112. $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
  113. //常用的itemIds
  114. $oftenItemIds = ProductClass::getOftenItemIds($shopId);
  115. //获取供应商下所有花材ID (itemIds)
  116. $itemIdsInfo = ItemService::getGhsItemIds($this->sjId);
  117. //dd($itemInfoData);
  118. //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
  119. $data = ProductService::assembleData($classIds, $itemIdsInfo,$itemInfoData, $oftenItemIds, '');
  120. util::success($data);
  121. }
  122. }