CatController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\modules\admin\controllers\q_and_a;
  3. use app\models\QAndACat;
  4. use app\modules\admin\controllers\BaseController;
  5. use app\modules\admin\models\q_and_a\CatForm;
  6. class CatController extends BaseController
  7. {
  8. /**
  9. * 列表
  10. */
  11. public function actionList()
  12. {
  13. $param = get_params();
  14. $form = new CatForm();
  15. $form->attributes = $param;
  16. $form->store_id = get_store_id();
  17. return $this->asJson($form->search());
  18. }
  19. /**
  20. * 获取详情
  21. */
  22. public function actionInfo($id = null)
  23. {
  24. return $this->asJson([
  25. 'code' => 0,
  26. 'data' => [
  27. 'model' => QAndACat::findOne($id)
  28. ]
  29. ]);
  30. }
  31. /**
  32. * 保存
  33. */
  34. public function actionSave()
  35. {
  36. $form = new CatForm();
  37. $form->attributes = post_params();
  38. return $this->asJson($form->save());
  39. }
  40. public function actionState($id = null, $state = 1)
  41. {
  42. $id = json_decode($id, true);
  43. foreach ($id as $v) {
  44. $model = QAndACat::findOne($v);
  45. if (!$model) {
  46. return $this->asJson([
  47. 'code' => 1,
  48. 'msg' => '请刷新重试'
  49. ]);
  50. }
  51. $model->state = $state;
  52. $model->save();
  53. }
  54. return $this->asJson([
  55. 'code' => 0,
  56. 'msg' => '成功'
  57. ]);
  58. }
  59. /**
  60. * 删除
  61. * @param $id
  62. */
  63. public function actionDel($id)
  64. {
  65. $model = QAndACat::findOne($id);
  66. if (empty($model)) {
  67. $res = ['code' => 1, 'msg' => '参数错误'];
  68. } else {
  69. $model->is_delete = 1;
  70. $res = $model->save() ? ['code' => 0, 'msg' => '保存成功'] : ['code' => 1, 'msg' => '保存失败'];
  71. }
  72. return $this->asJson($res);
  73. }
  74. }