ListnavServer.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/5
  6. * Time: 下午5:24
  7. */
  8. namespace backend\server;
  9. use common\models\CategoryNews;
  10. use Yii;
  11. use common\models\ListNav;
  12. class ListnavServer
  13. {
  14. /*
  15. * 列表数据状态设置
  16. * */
  17. public function setList()
  18. {
  19. $input = Yii::$app->request->post();
  20. if (!empty($input['id'])) {
  21. $model = ListNav::findOne($input['id']);
  22. switch ($input['code']) {
  23. case 'del':
  24. if ($model->delete()) return ['code' => 200, 'msg' => '删除完成'];
  25. break;
  26. case 'state':
  27. $model->state = $input['val'];
  28. if ($model->save()) return ['code' => 200, 'msg' => '状态设置完成'];
  29. break;
  30. case 'sort':
  31. $model->sort = $input['val'];
  32. if ($model->save()) return ['code' => 200, 'msg' => '排序设置完成'];
  33. break;
  34. }
  35. return ['code' => 300, 'msg' => '执行失败'];
  36. }
  37. }
  38. //============================推动区域信息==========================================================================
  39. //推送给区域类型数据添加
  40. public function addListCity()
  41. {
  42. $input = Yii::$app->request->post();
  43. $data = [];
  44. if (isset($input['informationInfo']) && is_array($input['informationInfo'])) {
  45. $data['information'] = json_encode($input['informationInfo'], JSON_UNESCAPED_UNICODE);
  46. }
  47. if (empty($input['list_id'])) {
  48. return ['code' => 300, 'msg' => '数据错误'];
  49. }
  50. $data['list_id'] = $input['list_id'];
  51. if (ListNav::find()->where(['list_id' => $data['list_id'], 'city' => $input['city_id']])->exists()) {
  52. return ['code' => 300, 'msg' => '该区域已存在'];
  53. }
  54. $data['city'] = $input['city_id'];
  55. $model = new ListNav();
  56. $model->load($data, '');
  57. if ($model->validate() && $model->save()) {
  58. return ['code' => 200, 'msg' => '添加成功'];
  59. } else {
  60. return ['code' => 300, 'msg' => '添加失败'];
  61. }
  62. }
  63. //获取区域推送类型列表数据
  64. public function getListCity()
  65. {
  66. $input = Yii::$app->request->post();
  67. if (empty($input['list_id']) && !is_numeric($input['list_id'])) {
  68. return ['code' => 300, 'msg' => '信息错误'];
  69. }
  70. $model = new ListNav();
  71. return $model->getListCity($input);
  72. }
  73. //============================推送资讯信息==========================================================================
  74. //获取资讯栏目列表
  75. public function getNewsList()
  76. {
  77. $data = (new CategoryNews())->getList([], ['id', 'news_name']);
  78. return $data;
  79. }
  80. public function addListNews()
  81. {
  82. $input = Yii::$app->request->post();
  83. $data = [];
  84. if (isset($input['informationInfo']) && is_array($input['informationInfo'])) {
  85. $data['information'] = json_encode($input['informationInfo'], JSON_UNESCAPED_UNICODE);
  86. }
  87. if (empty($input['list_id'])) {
  88. return ['code' => 300, 'msg' => '数据错误'];
  89. }
  90. $data['list_id'] = $input['list_id'];
  91. if (ListNav::find()->where(['list_id' => $data['list_id'], 'news' => $input['news']])->exists()) {
  92. return ['code' => 300, 'msg' => '该资讯已存在'];
  93. }
  94. $data['news'] = $input['news'];
  95. $model = new ListNav();
  96. $model->load($data, '');
  97. if ($model->validate() && $model->save()) {
  98. return ['code' => 200, 'msg' => '添加成功'];
  99. } else {
  100. return ['code' => 300, 'msg' => '添加失败'];
  101. }
  102. }
  103. public function getListNews()
  104. {
  105. $input = Yii::$app->request->post();
  106. if (empty($input['list_id']) && !is_numeric($input['list_id'])) {
  107. return ['code' => 300, 'msg' => '信息错误'];
  108. }
  109. $model = new ListNav();
  110. return $model->getListNews($input);
  111. }
  112. //==============================自定义推送导航类目信息==============================================================\
  113. public function addListTitle()
  114. {
  115. $input = Yii::$app->request->post();
  116. $data = [];
  117. if (isset($input['informationInfo']) && is_array($input['informationInfo'])) {
  118. $data['information'] = json_encode($input['informationInfo'], JSON_UNESCAPED_UNICODE);
  119. }
  120. if (empty($input['list_id'])) {
  121. return ['code' => 300, 'msg' => '数据错误'];
  122. }
  123. $data['list_id'] = $input['list_id'];
  124. if (ListNav::find()->where(['list_id' => $data['list_id'], 'title' => $input['title']])->exists()) {
  125. return ['code' => 300, 'msg' => '该资讯已存在'];
  126. }
  127. $data['title'] = $input['title'];
  128. $data['url'] = $input['url'];
  129. $model = new ListNav();
  130. $model->load($data, '');
  131. if ($model->validate() && $model->save()) {
  132. return ['code' => 200, 'msg' => '添加成功'];
  133. } else {
  134. return ['code' => 300, 'msg' => '添加失败'];
  135. }
  136. }
  137. public function getListTitle()
  138. {
  139. $input = Yii::$app->request->post();
  140. if (empty($input['list_id']) && !is_numeric($input['list_id'])) {
  141. return ['code' => 300, 'msg' => '信息错误'];
  142. }
  143. $model = new ListNav();
  144. return $model->getListTitle($input);
  145. }
  146. }