ProductController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. //获取所有当前供应商的分类 (全部、常用)
  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. $shopId = $get['shopId'] ?? 0;
  98. $connection = Yii::$app->db;//事务处理
  99. $transaction = $connection->beginTransaction();
  100. try {
  101. if (empty($id)) {
  102. if (!empty($this->shopId)) {
  103. $ghs = GhsClass::build($shopId, $this->shopId, $this->sjId);
  104. $sjId = $ghs['sjId'] ?? 0;
  105. } else {
  106. $shop = ShopClass::getShopInfo($shopId);
  107. $sjId = $shop['merchantId'] ?? 0;
  108. }
  109. } else {
  110. $ghs = GhsClass::getGhsInfo($id);
  111. $sjId = $ghs['sjId'] ?? 0;
  112. $shopId = $ghs['shopId'] ?? 0;
  113. }
  114. $transaction->commit();
  115. //获取所有当前供应商的分类 (全部、常用)
  116. //根据分类组装分类下的花材信息
  117. $classIds = ItemClassClass::getGhsItemClassAll($sjId);
  118. $where['merchantId'] = $sjId;
  119. $where['shopId'] = $shopId;
  120. $itemInfoData = ProductClass::getAllByCondition($where, null, "*");
  121. $itemInfoData = ProductClass::groupProductInfo($itemInfoData);
  122. //常用的itemIds
  123. $oftenItemIds = ProductClass::getOftenItemIds($shopId);
  124. //获取供应商下所有花材ID (itemIds)
  125. $itemIdsInfo = ItemService::getGhsItemIds($this->sjId);
  126. //dd($itemInfoData);
  127. //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
  128. $data = ProductService::assembleData($classIds, $itemIdsInfo, $itemInfoData, $oftenItemIds, '');
  129. util::success($data);
  130. } catch (Exception $e) {
  131. $transaction->rollBack();
  132. util::fail();
  133. }
  134. }
  135. }