123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?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\ListNav;
- class ListnavServer
- {
- /*
- * 列表数据状态设置
- * */
- public function setList()
- {
- $input = Yii::$app->request->post();
- if (!empty($input['id'])) {
- $model = ListNav::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 addListCity()
- {
- $input = Yii::$app->request->post();
- $data = [];
- if (isset($input['informationInfo']) && is_array($input['informationInfo'])) {
- $data['information'] = json_encode($input['informationInfo'], JSON_UNESCAPED_UNICODE);
- }
- if (empty($input['list_id'])) {
- return ['code' => 300, 'msg' => '数据错误'];
- }
- $data['list_id'] = $input['list_id'];
- if (ListNav::find()->where(['list_id' => $data['list_id'], 'city' => $input['city_id']])->exists()) {
- return ['code' => 300, 'msg' => '该区域已存在'];
- }
- $data['city'] = $input['city_id'];
- $model = new ListNav();
- $model->load($data, '');
- if ($model->validate() && $model->save()) {
- return ['code' => 200, 'msg' => '添加成功'];
- } else {
- return ['code' => 300, 'msg' => '添加失败'];
- }
- }
- //获取区域推送类型列表数据
- public function getListCity()
- {
- $input = Yii::$app->request->post();
- if (empty($input['list_id']) && !is_numeric($input['list_id'])) {
- return ['code' => 300, 'msg' => '信息错误'];
- }
- $model = new ListNav();
- return $model->getListCity($input);
- }
- //============================推送资讯信息==========================================================================
- //获取资讯栏目列表
- public function getNewsList()
- {
- $data = (new CategoryNews())->getList([], ['id', 'news_name']);
- return $data;
- }
- public function addListNews()
- {
- $input = Yii::$app->request->post();
- $data = [];
- if (isset($input['informationInfo']) && is_array($input['informationInfo'])) {
- $data['information'] = json_encode($input['informationInfo'], JSON_UNESCAPED_UNICODE);
- }
- if (empty($input['list_id'])) {
- return ['code' => 300, 'msg' => '数据错误'];
- }
- $data['list_id'] = $input['list_id'];
- if (ListNav::find()->where(['list_id' => $data['list_id'], 'news' => $input['news']])->exists()) {
- return ['code' => 300, 'msg' => '该资讯已存在'];
- }
- $data['news'] = $input['news'];
- $model = new ListNav();
- $model->load($data, '');
- if ($model->validate() && $model->save()) {
- return ['code' => 200, 'msg' => '添加成功'];
- } else {
- return ['code' => 300, 'msg' => '添加失败'];
- }
- }
- public function getListNews()
- {
- $input = Yii::$app->request->post();
- if (empty($input['list_id']) && !is_numeric($input['list_id'])) {
- return ['code' => 300, 'msg' => '信息错误'];
- }
- $model = new ListNav();
- return $model->getListNews($input);
- }
- //==============================自定义推送导航类目信息==============================================================\
- public function addListTitle()
- {
- $input = Yii::$app->request->post();
- $data = [];
- if (isset($input['informationInfo']) && is_array($input['informationInfo'])) {
- $data['information'] = json_encode($input['informationInfo'], JSON_UNESCAPED_UNICODE);
- }
- if (empty($input['list_id'])) {
- return ['code' => 300, 'msg' => '数据错误'];
- }
- $data['list_id'] = $input['list_id'];
- if (ListNav::find()->where(['list_id' => $data['list_id'], 'title' => $input['title']])->exists()) {
- return ['code' => 300, 'msg' => '该资讯已存在'];
- }
- $data['title'] = $input['title'];
- $data['url'] = $input['url'];
- $model = new ListNav();
- $model->load($data, '');
- if ($model->validate() && $model->save()) {
- return ['code' => 200, 'msg' => '添加成功'];
- } else {
- return ['code' => 300, 'msg' => '添加失败'];
- }
- }
- public function getListTitle()
- {
- $input = Yii::$app->request->post();
- if (empty($input['list_id']) && !is_numeric($input['list_id'])) {
- return ['code' => 300, 'msg' => '信息错误'];
- }
- $model = new ListNav();
- return $model->getListTitle($input);
- }
- }
|