XjController.php 5.5 KB

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