PushnewsController.php 11 KB

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