XjController.php 5.4 KB

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