123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/5
- * Time: 下午5:24
- */
- namespace backend\server;
- use common\models\CategoryNews;
- use Yii;
- use common\models\ListNews;
- class ListnewsServer
- {
- //=============================一般性设置获取数据===================================================================
- //获取推送列表
- public function getListNews()
- {
- $input = Yii::$app->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'=>'信息符合'];
- }
- //======================================================================================================================
- }
|