ListnewsServer.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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\ListNews;
  12. class ListnewsServer
  13. {
  14. //=============================一般性设置获取数据===================================================================
  15. //获取推送列表
  16. public function getListNews()
  17. {
  18. $input = Yii::$app->request->post();
  19. $listnewsModel = new ListNews();
  20. return $listnewsModel->getList($input);
  21. }
  22. //添加listnews信息
  23. public function addListNews()
  24. {
  25. $input = Yii::$app->request->post();
  26. $data = [];
  27. if (!empty($input['nid']) && !empty($input['list_id'])) {
  28. $data['nid'] = $input['nid'];
  29. $data['list_id'] = $input['list_id'];
  30. } else {
  31. return ['code' => '300', 'msg' => '信息不全'];
  32. }
  33. $listnewsModel = new ListNews();
  34. if ($listnewsModel->listExists(['list_id' => $data['list_id'], 'nid' => $data['nid']])) {
  35. return ['code' => '300', 'msg' => '该资讯讯息已存在'];
  36. }
  37. if (isset($input['informationInfo']) && is_array($input['informationInfo'])) {
  38. $data['information'] = json_encode($input['informationInfo'], JSON_UNESCAPED_UNICODE);
  39. }
  40. $listnewsModel->load($data, '');
  41. if ($listnewsModel->validate() && $listnewsModel->save()) {
  42. return ['code' => '200', 'msg' => '新增完成'];
  43. } else {
  44. return ['code' => '300', 'msg' => '新增失败'];
  45. }
  46. }
  47. //执行修改
  48. public function editListNews()
  49. {
  50. $input = Yii::$app->request->post();
  51. if (isset($input['informationInfo']) && is_array($input['informationInfo'])) {
  52. $input['information'] = json_encode($input['informationInfo'], JSON_UNESCAPED_UNICODE);
  53. unset($input['informationInfo']);
  54. }
  55. $rows = ListNews::findOne($input['id']);
  56. unset($input['id']);
  57. $rows->load($input, '');
  58. if ($rows->update()) {
  59. return ['code' => '200', 'msg' => '修改完成'];
  60. } else {
  61. return ['code' => '200', 'msg' => '修改失败'];
  62. }
  63. }
  64. /*
  65. * 列表数据状态设置
  66. * */
  67. public function setList()
  68. {
  69. $input = Yii::$app->request->post();
  70. if (!empty($input['id'])) {
  71. $model = ListNews::findOne($input['id']);
  72. switch ($input['code']) {
  73. case 'del':
  74. if ($model->delete()) return ['code' => 200, 'msg' => '删除完成'];
  75. break;
  76. case 'state':
  77. $model->state = $input['val'];
  78. if ($model->save()) return ['code' => 200, 'msg' => '状态设置完成'];
  79. break;
  80. case 'sort':
  81. $model->sort = $input['val'];
  82. if ($model->save()) return ['code' => 200, 'msg' => '排序设置完成'];
  83. break;
  84. }
  85. return ['code' => 300, 'msg' => '执行失败'];
  86. }
  87. }
  88. //数据添加验证
  89. public function varcherListInfo()
  90. {
  91. // $input = Yii::$app->request->post();
  92. // switch ($input['list_id']){
  93. //
  94. // }
  95. return ['code'=>200,'msg'=>'信息符合'];
  96. }
  97. //======================================================================================================================
  98. }