XjController.php 5.1 KB

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