| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace app\modules\admin\controllers\q_and_a;
- use app\models\QAndACat;
- use app\modules\admin\controllers\BaseController;
- use app\modules\admin\models\q_and_a\CatForm;
- class CatController extends BaseController
- {
- /**
- * 列表
- */
- public function actionList()
- {
- $param = get_params();
- $form = new CatForm();
- $form->attributes = $param;
- $form->store_id = get_store_id();
- return $this->asJson($form->search());
- }
- /**
- * 获取详情
- */
- public function actionInfo($id = null)
- {
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'model' => QAndACat::findOne($id)
- ]
- ]);
- }
- /**
- * 保存
- */
- public function actionSave()
- {
- $form = new CatForm();
- $form->attributes = post_params();
- return $this->asJson($form->save());
- }
- public function actionState($id = null, $state = 1)
- {
- $id = json_decode($id, true);
- foreach ($id as $v) {
- $model = QAndACat::findOne($v);
- if (!$model) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请刷新重试'
- ]);
- }
- $model->state = $state;
- $model->save();
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '成功'
- ]);
- }
- /**
- * 删除
- * @param $id
- */
- public function actionDel($id)
- {
- $model = QAndACat::findOne($id);
- if (empty($model)) {
- $res = ['code' => 1, 'msg' => '参数错误'];
- } else {
- $model->is_delete = 1;
- $res = $model->save() ? ['code' => 0, 'msg' => '保存成功'] : ['code' => 1, 'msg' => '保存失败'];
- }
- return $this->asJson($res);
- }
- }
|