PushmnewsController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/5/29
  6. * Time: 上午11:35
  7. */
  8. namespace backend\controllers;
  9. use backend\base\CommonController;
  10. use backend\base\Help;
  11. use Yii;
  12. use common\models\PushmNews;
  13. use common\models\PushmNewscolumn;
  14. use backend\server\UploadFile;
  15. class PushmnewsController extends CommonController
  16. {
  17. /*
  18. * 首页-资讯
  19. * */
  20. public function actionPone()
  21. {
  22. return $this->render('pone',['type'=>1]);
  23. }
  24. /*
  25. * 首页-资讯 数据
  26. * */
  27. public function actionPoneform()
  28. {
  29. $model = new PushmNews();
  30. $model->type = Yii::$app->request->post('type');
  31. $rows = $model->getList(Yii::$app->request->post());
  32. if(!empty($rows))
  33. {
  34. foreach($rows as &$val)
  35. {
  36. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  37. $val['img'] = Yii::$app->params['httpImg']['host'].Yii::$app->params['httpImg']['pushnews'].$val['img'];
  38. }
  39. return Help::JsonData(0,Yii::t('app','get_success'),$model->Total(),$rows);
  40. }
  41. }
  42. public function actionPoneadd()
  43. {
  44. return $this->render('poneadd',['type'=>Yii::$app->request->get('type')]);
  45. }
  46. /*
  47. * 首页-资讯 数据添加
  48. * */
  49. public function actionPoneaddform()
  50. {
  51. $model = new PushmNews();
  52. $model->scenario = 'add';
  53. $auth = $model->Authenticator(Yii::$app->request->post());
  54. if(is_object($auth))
  55. {
  56. $img = UploadFile::InstanceImgName('img',Yii::$app->params['img_url']['pushnews']);
  57. if(is_string($img))
  58. {
  59. $auth->img = $img;
  60. }
  61. if($auth->save()) return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
  62. }
  63. return Help::JsonCode(Help::ERROR,Yii::t('app','add_error'),$auth);
  64. }
  65. /*
  66. * 资讯首页 - 头部
  67. * */
  68. public function actionPtwo()
  69. {
  70. return $this->render('ptwo',['type'=>2]);
  71. }
  72. /*
  73. * 资讯推送 - 资讯首页底部 热门专题
  74. * */
  75. // public function actionPthree()
  76. // {
  77. // return $this->render('pthree',['type'=>3]);
  78. // }
  79. /*
  80. * 禁用 and 删除
  81. * */
  82. public function actionNewsdelandshow()
  83. {
  84. $model = new PushmNews();
  85. $input = Yii::$app->request->post();
  86. $row = $model->FindById($input['id']);
  87. if($row != null)
  88. {
  89. switch ($input['type'])
  90. {
  91. case 'show':
  92. if($row->is_show == 1)
  93. {
  94. $row->is_show = 2;
  95. }
  96. else if($row->is_show == 2)
  97. {
  98. $row->is_show = 1;
  99. }
  100. break;
  101. case 'del':
  102. $row->del = 2;
  103. break;
  104. case 'sort':
  105. $row->sort = $input['sort'];
  106. break;
  107. }
  108. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  109. }
  110. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  111. }
  112. /*
  113. * 首页 - 资讯 栏目
  114. * */
  115. public function actionHomenewscolumn()
  116. {
  117. return $this->render('homenewscolumn');
  118. }
  119. /*
  120. * 首页 - 资讯 栏目
  121. * */
  122. public function actionHomenewscolumnform()
  123. {
  124. $model = new PushmNewscolumn();
  125. $rows = $model->getList(Yii::$app->request->post());
  126. if(!empty($rows))
  127. {
  128. foreach ($rows as &$val)
  129. {
  130. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  131. }
  132. return Help::JsonData(0,Yii::t('app','get_success'),$model->Total(),$rows);
  133. }
  134. }
  135. /*
  136. * 首页 - 资讯 栏目 添加
  137. * */
  138. public function actionNewscolumnadd()
  139. {
  140. return $this->render('newscolumnadd');
  141. }
  142. /*
  143. * 首页 - 资讯 栏目 添加
  144. * */
  145. public function actionNewscolumnaddform()
  146. {
  147. $model = new PushmNewscolumn();
  148. $model->scenario = 'add';
  149. $model->cid = Yii::$app->request->post('nid');
  150. $auth = $model->Authenticator(Yii::$app->request->post());
  151. if(is_object($auth))
  152. {
  153. if($auth->save()) return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
  154. }
  155. return Help::JsonCode(Help::ERROR,Yii::t('app','add_error'),$auth);
  156. }
  157. /*
  158. * 首页 - 资讯 栏目 修改 页面
  159. * */
  160. public function actionNewscolumnedit()
  161. {
  162. $model = new PushmNewscolumn();
  163. $row = $model->FindById(Yii::$app->request->get('id'));
  164. if(!empty($row))
  165. {
  166. return $this->render('newscolumnedit',['model'=>$row,'name'=>Yii::$app->request->get('name')]);
  167. }
  168. }
  169. /*
  170. * 首页 - 资讯 栏目 修改 数据
  171. * */
  172. public function actionNewscolumnaeditform()
  173. {
  174. $model = new PushmNewscolumn();
  175. $input = Yii::$app->request->post();
  176. $row = $model->FindById($input['id']);
  177. if(!empty($row))
  178. {
  179. $row->cid = $input['nid'];
  180. $row->short = $input['short'];
  181. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  182. }
  183. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  184. }
  185. /*
  186. * 首页 - 资讯 栏目 添加
  187. * */
  188. public function actionNewscolumndelandshow()
  189. {
  190. $model = new PushmNewscolumn();
  191. $input = Yii::$app->request->post();
  192. $row = $model->FindById($input['id']);
  193. if($row != null)
  194. {
  195. switch ($input['type'])
  196. {
  197. case 'show':
  198. if($row->is_show == 1)
  199. {
  200. $row->is_show = 2;
  201. }
  202. else if($row->is_show == 2)
  203. {
  204. $row->is_show = 1;
  205. }
  206. break;
  207. case 'del':
  208. $row->del = 2;
  209. break;
  210. case 'sort':
  211. $row->sort = $input['sort'];
  212. break;
  213. }
  214. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  215. }
  216. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  217. }
  218. /*
  219. * 首页 - 资讯 栏目所属内容 页面
  220. * */
  221. public function actionNewcontent()
  222. {
  223. return $this->render('newcontent',['cid'=>Yii::$app->request->get('cid')]);
  224. }
  225. /*
  226. * 首页 - 资讯 栏目所属内容 数据
  227. * */
  228. public function actionNewcontentform()
  229. {
  230. $model = new PushmNews();
  231. $model->type = Yii::$app->request->post('type');
  232. $model->cid = Yii::$app->request->post('cid');
  233. $rows = $model->getList(Yii::$app->request->post());
  234. if(!empty($rows))
  235. {
  236. foreach($rows as &$val)
  237. {
  238. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  239. $val['img'] = Yii::$app->params['httpImg']['host'].Yii::$app->params['httpImg']['PushmNews'].$val['img'];
  240. }
  241. return Help::JsonData(0,Yii::t('app','get_success'),$model->Total(),$rows);
  242. }
  243. }
  244. /*
  245. * 首页 - 资讯 添加跟栏目相关的内容 页面
  246. * */
  247. public function actionNewcontentadd()
  248. {
  249. return $this->render('newcontentadd',['cid'=>Yii::$app->request->get('type')]);
  250. }
  251. /*
  252. * 首页 - 资讯 添加跟栏目相关的内容 数据
  253. * */
  254. public function actionNewcontentaddform()
  255. {
  256. $model = new PushmNews();
  257. $row = $model->Authenticator(Yii::$app->request->post());
  258. if(is_object($row))
  259. {
  260. if($row->save()) return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
  261. }
  262. return Help::JsonCode(Help::ERROR,Yii::t('app','add_error'),$row);
  263. }
  264. public function actionNewcontentdelandshow()
  265. {
  266. $model = new PushmNews();
  267. $input = Yii::$app->request->post();
  268. $row = $model->FindById($input['id']);
  269. if($row != null)
  270. {
  271. switch ($input['type'])
  272. {
  273. case 'show':
  274. if($row->is_show == 1)
  275. {
  276. $row->is_show = 2;
  277. }
  278. else if($row->is_show == 2)
  279. {
  280. $row->is_show = 1;
  281. }
  282. break;
  283. case 'del':
  284. $row->del = 2;
  285. break;
  286. case 'sort':
  287. $row->sort = $input['sort'];
  288. break;
  289. }
  290. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  291. }
  292. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  293. }
  294. }