XjController.php 5.0 KB

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