XjController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\product\classes\XjClass;
  4. use bizGhs\item\classes\ItemClass;
  5. use common\components\imgUtil;
  6. use common\components\util;
  7. use Yii;
  8. class XjController extends BaseController
  9. {
  10. //取出所有小菊 ssh 20210904
  11. public function actionGetAllXj()
  12. {
  13. $where = [];
  14. $where['shopId'] = $this->shopId;
  15. $where['status'] = 1;
  16. $list = XjClass::getShopXj($this->shopId);
  17. util::success(['list' => $list]);
  18. }
  19. //取出商家上架的小菊 ssh 20210904
  20. public function actionGetSjXj()
  21. {
  22. $get = Yii::$app->request->get();
  23. $itemId = $get['itemId'] ?? 0;
  24. $product = ItemClass::getById($itemId, true);
  25. if ($product->mainId != $this->mainId) {
  26. util::fail('不是您的花材');
  27. }
  28. $list = XjClass::getAllByCondition(['itemId' => $itemId, 'delStatus' => 0, 'status' => 1], null, '*');
  29. if (!empty($list)) {
  30. foreach ($list as $key => $val) {
  31. $shortCover = $val['cover'] ?? '';
  32. $cover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  33. $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  34. $list[$key]['cover'] = $cover;
  35. $list[$key]['bigCover'] = $bigCover;
  36. $list[$key]['shortCover'] = $shortCover;
  37. }
  38. }
  39. util::success(['list' => $list]);
  40. }
  41. //取出商家所有小菊 ssh 20210904
  42. public function actionGetFilterXj()
  43. {
  44. $get = Yii::$app->request->get();
  45. $itemId = $get['itemId'] ?? 0;
  46. $product = ItemClass::getById($itemId, true);
  47. if ($product->mainId != $this->mainId) {
  48. util::fail('不是您的花材');
  49. }
  50. $list = XjClass::getAllByCondition(['itemId' => $itemId, 'delStatus' => 0], null, '*');
  51. if (!empty($list)) {
  52. foreach ($list as $key => $val) {
  53. $shortCover = $val['cover'] ?? '';
  54. $cover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  55. $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  56. $list[$key]['cover'] = $cover;
  57. $list[$key]['bigCover'] = $bigCover;
  58. $list[$key]['shortCover'] = $shortCover;
  59. }
  60. }
  61. util::success(['list' => $list]);
  62. }
  63. //保存所有数量 ssh 20221030
  64. public function actionSaveAllNum()
  65. {
  66. $post = Yii::$app->request->post();
  67. $itemId = $post['itemId'] ?? 0;
  68. $product = ItemClass::getById($itemId, true);
  69. if ($product->mainId != $this->mainId) {
  70. util::fail('不是您的花材');
  71. }
  72. $data = $post['data'] ?? '';
  73. $arr = json_decode($data, true);
  74. if (empty($arr)) {
  75. util::fail('没有找到花材列表');
  76. }
  77. foreach ($arr as $item) {
  78. $id = $item['id'] ?? 0;
  79. $stock = $item['stock'] ?? -1;
  80. $xj = XjClass::getById($id, true);
  81. if (empty($xj)) {
  82. continue;
  83. }
  84. if ($xj->itemId != $itemId) {
  85. continue;
  86. }
  87. $xj->stock = $stock;
  88. //有库存则上架,没库存则下架
  89. $status = $stock == 0 ? 2 : 1;
  90. $xj->status = $status;
  91. $xj->save();
  92. }
  93. util::complete('保存成功');
  94. }
  95. //清除全部小菊 lqh 2021.12.8
  96. public function actionClearAll()
  97. {
  98. $get = Yii::$app->request->get();
  99. $itemId = $get['itemId'] ?? 0;
  100. $product = ItemClass::getById($itemId, true);
  101. if ($product->mainId != $this->mainId) {
  102. util::fail('不是您的花材');
  103. }
  104. XjClass::clearAll($itemId);
  105. util::complete('已删除');
  106. }
  107. //新增小菊 lqh 2021.12.8
  108. public function actionBatchAdd()
  109. {
  110. $post = Yii::$app->request->post();
  111. $itemId = $post['itemId'] ?? 0;
  112. $product = ItemClass::getById($itemId, true);
  113. if ($product->mainId != $this->mainId) {
  114. util::fail('不是您的花材');
  115. }
  116. $xjData = $post['xjData'] ?? '';
  117. if (empty($xjData)) {
  118. util::fail('请上传图片');
  119. }
  120. $arr = json_decode($xjData, true);
  121. if (is_array($arr) == false) {
  122. util::fail('请上传图片...');
  123. }
  124. XjClass::batchAddXj($arr, $this->shop, $product);
  125. util::complete('添加成功');
  126. }
  127. }