request->post(); $listnewsModel = new ListNews(); return $listnewsModel->getList($input); } //添加listnews信息 public function addListNews() { $input = Yii::$app->request->post(); $data = []; if (!empty($input['nid']) && !empty($input['list_id'])) { $data['nid'] = $input['nid']; $data['list_id'] = $input['list_id']; } else { return ['code' => '300', 'msg' => '信息不全']; } $listnewsModel = new ListNews(); if ($listnewsModel->listExists(['list_id' => $data['list_id'], 'nid' => $data['nid']])) { return ['code' => '300', 'msg' => '该资讯讯息已存在']; } if (isset($input['informationInfo']) && is_array($input['informationInfo'])) { $data['information'] = json_encode($input['informationInfo'], JSON_UNESCAPED_UNICODE); } $listnewsModel->load($data, ''); if ($listnewsModel->validate() && $listnewsModel->save()) { return ['code' => '200', 'msg' => '新增完成']; } else { return ['code' => '300', 'msg' => '新增失败']; } } //执行修改 public function editListNews() { $input = Yii::$app->request->post(); if (isset($input['informationInfo']) && is_array($input['informationInfo'])) { $input['information'] = json_encode($input['informationInfo'], JSON_UNESCAPED_UNICODE); unset($input['informationInfo']); } $rows = ListNews::findOne($input['id']); unset($input['id']); $rows->load($input, ''); if ($rows->update()) { return ['code' => '200', 'msg' => '修改完成']; } else { return ['code' => '200', 'msg' => '修改失败']; } } /* * 列表数据状态设置 * */ public function setList() { $input = Yii::$app->request->post(); if (!empty($input['id'])) { $model = ListNews::findOne($input['id']); switch ($input['code']) { case 'del': if ($model->delete()) return ['code' => 200, 'msg' => '删除完成']; break; case 'state': $model->state = $input['val']; if ($model->save()) return ['code' => 200, 'msg' => '状态设置完成']; break; case 'sort': $model->sort = $input['val']; if ($model->save()) return ['code' => 200, 'msg' => '排序设置完成']; break; } return ['code' => 300, 'msg' => '执行失败']; } } //数据添加验证 public function varcherListInfo() { // $input = Yii::$app->request->post(); // switch ($input['list_id']){ // // } return ['code'=>200,'msg'=>'信息符合']; } //====================================================================================================================== }