XjController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 actionBatchAdd()
  114. {
  115. $post = Yii::$app->request->post();
  116. $itemId = $post['itemId'] ?? 0;
  117. $product = ItemClass::getById($itemId, true);
  118. if ($product->mainId != $this->mainId) {
  119. util::fail('不是您的花材');
  120. }
  121. $xjData = $post['xjData'] ?? '';
  122. if (empty($xjData)) {
  123. util::fail('请上传图片');
  124. }
  125. $arr = json_decode($xjData, true);
  126. if (is_array($arr) == false) {
  127. util::fail('请上传图片...');
  128. }
  129. XjClass::batchAddXj($arr, $this->shop, $product);
  130. util::complete('添加成功');
  131. }
  132. //删除选项 ssh 20230728
  133. public function actionDelItem()
  134. {
  135. $get = Yii::$app->request->get();
  136. $id = $get['id'] ?? 0;
  137. $xj = XjClass::getById($id, true);
  138. if (empty($xj) || $xj->mainId != $this->mainId) {
  139. util::fail('删除失败');
  140. }
  141. $xj->delStatus = 1;
  142. $xj->status = 2;
  143. $xj->save();
  144. $itemId = $xj->itemId ?? 0;
  145. $delList = XjClass::getAllByCondition(['itemId' => $itemId, 'delStatus' => 1], null, '*', null, true);
  146. //超过2个月,多颜色订单就不能售后,超过3个月多颜色的花材就要删除掉,多处要同步修改,关键词 xj_global_change ssh 20251230
  147. if(!empty($delList)){
  148. $threeMonthsAgo = time() - (90 * 24 * 60 * 60); // 3个月前的时间戳
  149. foreach ($delList as $item) {
  150. $updateTime = strtotime($item->updateTime); // 将时间转换为时间戳
  151. // 判断 updateTime 是否超过 3 个月
  152. if ($updateTime < $threeMonthsAgo) {
  153. //$item->delete();
  154. }
  155. }
  156. }
  157. util::complete();
  158. }
  159. //清除全部小菊 lqh 2021.12.8
  160. public function actionClearAll()
  161. {
  162. $get = Yii::$app->request->get();
  163. $itemId = $get['itemId'] ?? 0;
  164. $product = ItemClass::getById($itemId, true);
  165. if ($product->mainId != $this->mainId) {
  166. util::fail('不是您的花材');
  167. }
  168. XjClass::updateByCondition(['itemId' => $itemId], ['status' => 2, 'delStatus' => 1]);
  169. $delList = XjClass::getAllByCondition(['itemId' => $itemId, 'delStatus' => 1], null, '*', null, true);
  170. //超过2个月,多颜色订单就不能售后,超过3个月多颜色的花材就要删除掉,多处要同步修改,关键词 xj_global_change ssh 20251230
  171. if(!empty($delList)){
  172. $threeMonthsAgo = time() - (90 * 24 * 60 * 60); // 3个月前的时间戳
  173. foreach ($delList as $item) {
  174. $updateTime = strtotime($item->updateTime); // 将时间转换为时间戳
  175. // 判断 updateTime 是否超过 3 个月
  176. if ($updateTime < $threeMonthsAgo) {
  177. //$item->delete();
  178. }
  179. }
  180. }
  181. util::complete('已删除');
  182. }
  183. }