IntelligentMatchController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers;
  8. use app\models\IntelligentMatchCat;
  9. use app\models\IntelligentScene;
  10. use app\modules\admin\models\IntelligentGoodsForm;
  11. use app\modules\admin\models\IntelligentMatchForm;
  12. use app\modules\admin\models\IntelligentSceneForm;
  13. class IntelligentMatchController extends BaseController
  14. {
  15. /**
  16. * 保存分类
  17. * @return \yii\web\Response
  18. */
  19. public function actionCatSave()
  20. {
  21. $data = post_params();
  22. $form = new IntelligentMatchForm();
  23. $cat = $data['id'] ? (IntelligentMatchCat::findOne($data['id']) ?: new IntelligentMatchCat()) : new IntelligentMatchCat();
  24. $form->model = $cat;
  25. $form->attributes = $data;
  26. $form->store_id = get_store_id();
  27. return $this->asJson($form->save());
  28. }
  29. /**
  30. * 获取分类列表
  31. * @return \yii\web\Response
  32. */
  33. public function actionCatList()
  34. {
  35. $is_show = get_params('is_show',IntelligentMatchCat::IS_SHOW_TRUE);
  36. $list = IntelligentMatchCat::getCatList(get_store_id(), $is_show);
  37. return $this->asJson([
  38. 'code' => 0,
  39. 'data' => [
  40. 'list' => $list
  41. ]
  42. ]);
  43. }
  44. /**
  45. * 批量修改分类状态
  46. * @return \yii\web\Response
  47. */
  48. public function actionCatStatus()
  49. {
  50. $status = get_params('status',1);
  51. $attributes = $status == 0 || $status == 1 ? ['is_show' => $status] : ['is_delete' => 1];
  52. $res = IntelligentMatchCat::updateAll($attributes, ['id' => get_params('id',[])]);
  53. return $this->asJson([
  54. 'code' => 0,
  55. 'data' => [
  56. 'updateCount' => $res
  57. ]
  58. ]);
  59. }
  60. /**
  61. * 批量修改分类状态
  62. * @return \yii\web\Response
  63. */
  64. public function actionCatChange()
  65. {
  66. $id = get_params('id');
  67. $parent_id = get_params('parent_id');
  68. $res = IntelligentMatchCat::updateAll(['parent_id' => $parent_id], ['id' => $id]);
  69. return $this->asJson([
  70. 'code' => 0,
  71. 'data' => [
  72. 'updateCount' => $res
  73. ]
  74. ]);
  75. }
  76. /**
  77. * 删除分类
  78. * @return \yii\web\Response
  79. */
  80. public function actionCatDel()
  81. {
  82. $cat = IntelligentMatchCat::findOne(get_params('id'));
  83. if (empty($cat)) {
  84. return $this->asJson([
  85. 'code' => 1,
  86. 'msg' => '查无此分类'
  87. ]);
  88. }
  89. $cat->is_delete = 1;
  90. if ($cat->save()) {
  91. return $this->asJson([
  92. 'code' => 0,
  93. 'msg' => '删除成功'
  94. ]);
  95. }else {
  96. return $this->asJson([
  97. 'code' => 1,
  98. 'msg' => '删除失败'
  99. ]);
  100. }
  101. }
  102. /**
  103. * 获取场景列表信息
  104. * @return \yii\web\Response
  105. * User: hankaige
  106. * DATE TIME: 2023/1/28 09:36
  107. */
  108. public function actionIntelligentScene(){
  109. $form = new IntelligentSceneForm();
  110. $form->keyword = get_params('search_key','');
  111. $form->cat_id = get_params('cat_id',0);
  112. $result = $form->list();
  113. return $this->asJson($result);
  114. }
  115. /**
  116. * 获取场景信息
  117. * @param $id
  118. * @return \yii\web\Response
  119. * User: hankaige
  120. * DATE TIME: 2023/1/28 09:47
  121. */
  122. /*public function actionIntelligentSceneItem($id = 0){
  123. if($id > 0){
  124. $model = IntelligentScene::findOne($id);
  125. }else{
  126. $model = new IntelligentScene();
  127. }
  128. return $this->asJson($model);
  129. }*/
  130. /**
  131. * 保存场景信息
  132. * @return \yii\web\Response
  133. * User: hankaige
  134. * DATE TIME: 2023/1/28 09:47
  135. */
  136. public function actionIntelligentSceneSave(){
  137. $data = post_params();
  138. $form = new IntelligentSceneForm();
  139. $form->model = $data['id'] ? (IntelligentScene::findOne($data['id']) ?: new IntelligentScene()) : new IntelligentScene();
  140. $form->attributes = $data;
  141. $result = $form->save();
  142. return $this->asJson($result);
  143. }
  144. /**
  145. * 删除场景
  146. * @return \yii\web\Response
  147. * User: hankaige
  148. * DATE TIME: 2023/1/28 09:47
  149. */
  150. public function actionIntelligentSceneDel(){
  151. IntelligentScene::updateAll(['is_delete'=>1],['store_id'=>get_store_id(),'id'=>get_params('id')]);
  152. return $this->asJson(['code'=>0,'msg'=>'删除成功']);
  153. }
  154. /**
  155. * 修改场景状态
  156. * @return \yii\web\Response
  157. * User: hankaige
  158. * DATE TIME: 2023/1/28 09:47
  159. */
  160. public function actionIntelligentSceneStatus(){
  161. IntelligentScene::updateAll(['status'=>!get_params('status')],['store_id'=>get_store_id(),'id'=>get_params('id')]);
  162. return $this->asJson(['code'=>0,'msg'=>'修改成功']);
  163. }
  164. /**
  165. * 设置默认场景
  166. * @return \yii\web\Response
  167. * User: hankaige
  168. * DATE TIME: 2023/1/30 14:07
  169. */
  170. public function actionIntelligentSceneDefault(){
  171. $id = get_params('id');
  172. $item = IntelligentScene::findOne($id);
  173. if($item->is_default == 0){
  174. // 要设置为默认
  175. IntelligentScene::updateAll(['is_default' => 0],['store_id'=>get_store_id(),'is_default'=>1]);
  176. }
  177. $item->is_default = $item->is_default ? 0 : 1;
  178. if($item->save()){
  179. return $this->asJson(['code'=>0,'msg'=>'修改成功']);
  180. }else{
  181. return $this->asJson(['code'=>1,'msg'=>'修改失败','data'=>$item->getErrors()]);
  182. }
  183. }
  184. /*
  185. * 获取智配商品的图片
  186. */
  187. public function actionIntelligentGoodsList() {
  188. $form = new IntelligentGoodsForm();
  189. $form->attributes = get_params();
  190. $form->store_id = get_store_id();
  191. return $this->asJson($form->list());
  192. }
  193. /*
  194. * 保存智配商品的图片
  195. */
  196. public function actionIntelligentGoodsSave() {
  197. $form = new IntelligentGoodsForm();
  198. $form->attributes = post_params();
  199. $form->store_id = get_store_id();
  200. return $this->asJson($form->save());
  201. }
  202. }