WebconfigController.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <?php
  2. namespace backend\controllers;
  3. use backend\models\AdminUser;
  4. use common\library\LMUploadFile;
  5. use common\models\Aboutwe;
  6. use common\models\Advert;
  7. use common\models\HotSearch;
  8. use common\models\Information;
  9. use common\models\Notice;
  10. use yii\web\UploadedFile;
  11. //use common\models\Aboutwe;
  12. //use common\models\HelpTopic;
  13. use yii;
  14. use yii\data\Pagination;
  15. /**
  16. * 轮播图,公告,内容,热门管理
  17. * @package backend\controllers
  18. */
  19. class WebconfigController extends BaseController
  20. {
  21. public $layout = 'iframe';
  22. const PAGESIZE =20;
  23. // const HELP_SUBMIT = 0; //问题提交带审核
  24. // const HELP_AUDITING = 1; //问题已审核状态
  25. // const HELP_DEL = 2; //问题删除状态
  26. //
  27. //
  28. // const ISSHOW_SHOW = 1;//问题显示
  29. // const ISSHOW_NOT = 0;//问题不显示
  30. /**
  31. * 编辑框里图片上传
  32. * @return string
  33. */
  34. public function actionUploadsummernote(){
  35. $file= $_FILES;
  36. $picture_name=time().rand(0,10000000);
  37. $fileName = $file['file']['name'];
  38. $file_ext = strtolower(substr($fileName, strrpos($fileName, '.') + 1));
  39. $picture_name .= '.'.$file_ext;
  40. $type = Yii::$app->request->post('type');
  41. if($type=='information'){
  42. $folder = "/"."information"."/".date("Ym")."/".date("d")."/";
  43. }elseif($type=='aboutwe'){
  44. $folder = "/"."aboutwe"."/".date("Ym")."/".date("d")."/";
  45. }
  46. $file_path=\Yii::getAlias('@common/allupload').$folder;
  47. $file_path_rel = "/".date("Ym")."/".date("d")."/";
  48. $url =$file_path.$picture_name;
  49. if(!is_dir($file_path)){
  50. mkdir($file_path,0777,true);
  51. }
  52. if(move_uploaded_file($file['file']['tmp_name'],$file_path.$picture_name)){//上传到服务器
  53. return $folder.$picture_name;
  54. }
  55. }
  56. /**
  57. * 公告管理列表
  58. */
  59. public function actionNotice()
  60. {
  61. $datas = Notice::find()->where('status=:status',[':status'=>Notice::STATUS_ACTIVE])->orderBy('updated_at DESC');
  62. $pages=new Pagination(["totalCount"=>$datas->count(),"pageSize"=>self::PAGESIZE]);
  63. $datas=$datas->offset($pages->offset)->limit($pages->limit)->all();
  64. return $this->render('notice',['datas'=>$datas,'pages'=>$pages]);
  65. }
  66. /**
  67. * 添加公告界面
  68. */
  69. public function actionAddnotice()
  70. {
  71. $id=Yii::$app->request->get('id');
  72. $datas = Information::find()->select('title')->where(['status'=>Information::STATUS_ACTIVE])->all();
  73. if(!empty($id)){
  74. $model = Notice::find()->where('id = :id',[':id'=>$id])->one();
  75. return $this->render('add_notice',['model'=>$model,'datas'=>$datas]);
  76. }else{
  77. return $this->render('add_notice',['datas'=>$datas]);
  78. }
  79. }
  80. /**
  81. * 检查内容sid
  82. */
  83. public function actionChecksid()
  84. {
  85. $title = Yii::$app->request->post('title');
  86. $model = Information::find()->where('title=:title and status=:status',[':title'=>$title,'status'=>Information::STATUS_ACTIVE])->one();
  87. if(!empty($model)){
  88. $id = $model->id;
  89. $data = Notice::find()->where('sid=:sid and status=:status',[':sid'=>$id,'status'=>Notice::STATUS_ACTIVE])->one();
  90. if(!empty($data)){
  91. return json_encode('该内容标题已被安排');
  92. }
  93. return json_encode('该内容标题可用');
  94. }
  95. return json_encode('该内容标题不存在');
  96. }
  97. /**
  98. * 检查内容sid
  99. */
  100. public function actionChecktitle()
  101. {
  102. $title = Yii::$app->request->post('title');
  103. $model = Information::find()->where('title=:title and status=:status',[':title'=>$title,'status'=>Information::STATUS_ACTIVE])->one();
  104. if(empty($model)){
  105. return json_encode('该内容标题可用');
  106. }
  107. return json_encode('该内容标题已存在');
  108. }
  109. /**
  110. * 添加公告
  111. */
  112. public function actionAdd_notice()
  113. {
  114. $model =new Notice();
  115. $over_time = Yii::$app->request->post('end');
  116. $start = Yii::$app->request->post('start');
  117. $title = Yii::$app->request->post('title');
  118. $datas = Information::find()->select('title')->where(['status'=>Information::STATUS_ACTIVE])->all();
  119. if($title!='请选择标题'){
  120. $data = Information::find()->where('title=:title',[':title'=>$title])->one();
  121. if(!empty($data)){
  122. $model->sid = $data->id;
  123. if(empty($over_time)){
  124. $model->over_time = strtotime('2038-1-19');
  125. }else{
  126. $model->over_time = strtotime($over_time);
  127. }
  128. if(empty($start)){
  129. $model->release_time = time();
  130. }else{
  131. $model->release_time = strtotime($start);
  132. }
  133. $model->created_at = time();
  134. $model->updated_at = time();
  135. $model->status =Notice::STATUS_ACTIVE;
  136. if($model->validate() && $model->save()){
  137. Yii::$app->getSession()->setFlash('success', '添加成功!');
  138. return $this->redirect(['webconfig/notice']);
  139. }else{
  140. Yii::$app->getSession()->setFlash('error', '添加失败');
  141. return $this->render('add_notice',['datas'=>$datas]);
  142. }
  143. }else{
  144. Yii::$app->getSession()->setFlash('error', '添加失败,该标题不存在');
  145. return $this->render('add_notice',['datas'=>$datas]);
  146. }
  147. }else{
  148. Yii::$app->getSession()->setFlash('error', '请选择标题');
  149. return $this->render('add_notice',['datas'=>$datas]);
  150. }
  151. }
  152. /**
  153. * 修改公告
  154. * @return \yii\web\Response
  155. */
  156. public function actionEdit_notice(){
  157. $id = Yii::$app->request->post('id');
  158. $over_time = Yii::$app->request->post('end');
  159. $start = Yii::$app->request->post('start');
  160. $title = Yii::$app->request->post('title');
  161. $datas = Information::find()->select('title')->where(['status'=>Information::STATUS_ACTIVE])->all();
  162. if($title!='请选择标题') {
  163. $model = Notice::find()->where('id=:id',[':id'=>$id])->one();
  164. if (!empty($model)) {
  165. if (empty($over_time)) {
  166. $model->over_time = strtotime('2038-1-19');
  167. } else {
  168. $model->over_time = strtotime($over_time);
  169. }
  170. if (empty($start)) {
  171. $model->release_time = time();
  172. } else {
  173. $model->release_time = strtotime($start);
  174. }
  175. $model->updated_at = time();
  176. if ($model->validate() && $model->save()) {
  177. Yii::$app->getSession()->setFlash('success', '修改成功!');
  178. return $this->redirect(['webconfig/notice']);
  179. } else {
  180. Yii::$app->getSession()->setFlash('error', '修改失败');
  181. return $this->render('add_notice', ['model' => $model,'datas'=>$datas]);
  182. }
  183. } else {
  184. Yii::$app->getSession()->setFlash('error', '修改失败,该公告不存在');
  185. return $this->render('add_notice', ['model' => $model,'datas'=>$datas]);
  186. }
  187. }
  188. }
  189. /**
  190. * 删除公告
  191. * @return string
  192. */
  193. public function actionDel_notice(){
  194. $result=['sign'=>1,'msg'=>'ok'];
  195. $id = Yii::$app->request->post('id');
  196. $model = Notice::find()->where('id=:id',[':id'=>$id])->one();
  197. if(!empty($model)){
  198. $model->status = Notice::STATUS_DELETED;
  199. $model->updated_at = time();
  200. if($model->validate() && $model->save()){
  201. $result=['sign'=>1,'msg'=>'ok'];
  202. }else{
  203. // var_dump($model->getErrors());exit;
  204. $result=['sign'=>0,'msg'=>'error'];
  205. }
  206. }else{
  207. $result=['sign'=>0,'msg'=>'找不到该规格'];
  208. }
  209. return json_encode($result);
  210. }
  211. /**
  212. * 内容管理列表
  213. */
  214. public function actionInformation()
  215. {
  216. $datas = Information::find()->where('status=:status',[':status'=>Notice::STATUS_ACTIVE])->orderBy('updated_at DESC');
  217. $pages=new Pagination(["totalCount"=>$datas->count(),"pageSize"=>self::PAGESIZE]);
  218. $datas=$datas->offset($pages->offset)->limit($pages->limit)->all();
  219. return $this->render('information',['datas'=>$datas,'pages'=>$pages]);
  220. }
  221. /**
  222. * 添加内容界面
  223. */
  224. public function actionAddinformation()
  225. {
  226. $id=Yii::$app->request->get('id');
  227. if(!empty($id)){
  228. $model = Information::find()->where('id = :id',[':id'=>$id])->one();
  229. $picture_form = new LMUploadFile();
  230. return $this->render('add_information',['model'=>$model,'picture_form' => $picture_form]);
  231. }else{
  232. $picture_form = new LMUploadFile();
  233. return $this->render('add_information',["picture_form" => $picture_form]);
  234. }
  235. }
  236. /**
  237. * 添加内容
  238. */
  239. public function actionAdd_information()
  240. {
  241. $model =new Information();
  242. $picture_form = new LMUploadFile();
  243. if($model->load(Yii::$app->request->post())){
  244. $title = $_POST['Information']['title'];
  245. if(!empty($title)){
  246. $data = Information::find()->where('title=:title and status=:status',[':title'=>$title,':status'=>Information::STATUS_ACTIVE])->one();
  247. if(empty($data)){
  248. $model->created_at = time();
  249. $model->updated_at = time();
  250. $model->status =Information::STATUS_ACTIVE;
  251. if($model->validate() && $model->save()){
  252. Yii::$app->getSession()->setFlash('success', '添加成功!');
  253. return $this->redirect(['webconfig/information']);
  254. }else{
  255. return $this->render('add_information',["picture_form" => $picture_form]);
  256. }
  257. }else{
  258. Yii::$app->getSession()->setFlash('error', '标题已被使用,请使用别的标题');
  259. return $this->render('add_information',["picture_form" => $picture_form]);
  260. }
  261. }else{
  262. Yii::$app->getSession()->setFlash('error', '标题不能为空');
  263. return $this->render('add_information',["picture_form" => $picture_form]);
  264. }
  265. }else{
  266. Yii::$app->getSession()->setFlash('error', '修改失败');
  267. return $this->render('add_information',["picture_form" => $picture_form]);
  268. }
  269. }
  270. /**
  271. * 编辑内容
  272. * @return \yii\web\Response
  273. */
  274. public function actionEdit_information(){
  275. $id = Yii::$app->request->post('id');
  276. $model = Information::find()->where('id=:id',[':id'=>$id])->one();
  277. $picture_form = new LMUploadFile();
  278. if($model->load(Yii::$app->request->post())){
  279. $model->updated_at = time();
  280. if($model->validate() && $model->save()){
  281. Yii::$app->getSession()->setFlash('success', '修改成功!');
  282. return $this->redirect(['webconfig/information']);
  283. }else{
  284. Yii::$app->getSession()->setFlash('error', '修改失败');
  285. return $this->render('add_information',['model'=>$model,'picture_form' => $picture_form]);
  286. }
  287. }else{
  288. Yii::$app->getSession()->setFlash('error', '修改失败');
  289. return $this->render('add_information',['model'=>$model,'picture_form' => $picture_form]);
  290. }
  291. }
  292. /**
  293. * 删除内容
  294. * @return string
  295. */
  296. public function actionDel_information(){
  297. $result=['sign'=>1,'msg'=>'ok'];
  298. $id = Yii::$app->request->post('id');
  299. $model = Information::find()->where('id=:id',[':id'=>$id])->one();
  300. if(!empty($model)){
  301. $model->status = Information::STATUS_DELETED;
  302. $model->updated_at = time();
  303. if($model->validate() && $model->save()){
  304. $result=['sign'=>1,'msg'=>'ok'];
  305. }else{
  306. // var_dump($model->getErrors());exit;
  307. $result=['sign'=>0,'msg'=>'error'];
  308. }
  309. }else{
  310. $result=['sign'=>0,'msg'=>'找不到该规格'];
  311. }
  312. return json_encode($result);
  313. }
  314. /**
  315. * 热门搜索列表
  316. * @return string
  317. */
  318. public function actionHotsearch(){
  319. $datas = HotSearch::find()->where('status =:status',[':status'=>HotSearch::HOT_SEARCH_COMMON])->all();
  320. return $this->render('hot_search',['datas'=>$datas]);
  321. }
  322. /**
  323. * 添加热门搜索
  324. * @return string
  325. */
  326. public function actionAddhotsearch(){
  327. $result = '';
  328. $keyword = Yii::$app->request->post('keyword');
  329. if(!empty($keyword)){
  330. $model = HotSearch::find()->where('keyword=:keyword', [':keyword' => $keyword])->one();
  331. if(empty($model)){
  332. $dates = new HotSearch();
  333. $dates->keyword = $keyword;
  334. $dates->create_at = time();
  335. $dates->updated_at = time();
  336. $dates->status = HotSearch::HOT_SEARCH_COMMON;
  337. if($dates->validate() && $dates->save()){
  338. $result = ['sign'=>1,'msg'=>'添加成功','id'=>$dates->id];
  339. }else{
  340. $result=['sign'=>0,'msg'=>'添加失败'];
  341. }
  342. }else{
  343. $result=['sign'=>0,'msg'=>'该搜索词已存在'];
  344. }
  345. }else{
  346. $result=['sign'=>0,'msg'=>'搜索词不能为空'];
  347. }
  348. return json_encode($result);
  349. }
  350. /**
  351. *编辑热门搜索
  352. * @return string
  353. */
  354. public function actionEdithotsearch(){
  355. $id = Yii::$app->request->post('id');
  356. $keyword = Yii::$app->request->post('keyword');
  357. $model = HotSearch::find()->where('id=:id', [':id' => $id])->one();
  358. if(!empty($keyword)){
  359. if(!empty($model)){
  360. $model->keyword = $keyword;
  361. $model->updated_at = time();
  362. if($model->validate() && $model->save()){
  363. $result = ['sign'=>1,'msg'=>'修改成功'];
  364. }else{
  365. $result=['sign'=>0,'msg'=>'修改失败'];
  366. }
  367. }else{
  368. $result=['sign'=>0,'msg'=>'id不存在'];
  369. }
  370. }else{
  371. $result=['sign'=>0,'msg'=>'搜索词不能为空'];
  372. }
  373. return json_encode($result);
  374. }
  375. /**
  376. * 删除热门搜索
  377. * @return string
  378. */
  379. public function actionDelhotsearch(){
  380. $id = Yii::$app->request->post('id');
  381. $model = HotSearch::find()->where('id=:id', [':id' => $id])->one();
  382. if(!empty($model)){
  383. $model->status = HotSearch::HOT_SEARCH_DEL;
  384. $model->updated_at = time();
  385. if($model->validate() && $model->save()){
  386. $result = ['sign'=>1,'msg'=>'删除成功'];
  387. }else{
  388. $result=['sign'=>0,'msg'=>'删除失败'];
  389. }
  390. }else{
  391. $result=['sign'=>0,'msg'=>'删除失败'];
  392. }
  393. return json_encode($result);
  394. }
  395. /**
  396. * 内容管理上传封面
  397. * @return string
  398. */
  399. public function actionAdvertimgurl()
  400. {
  401. $type = Yii::$app->request->post('type');
  402. if (Yii::$app->request->isPost) {
  403. $picture_form = new LMUploadFile();
  404. $picture_form->imageFile = UploadedFile::getInstance($picture_form, 'imageFile');
  405. if($type=='advert'){
  406. if ($picture_form->upload('advert_picture',false,160,160)) {
  407. return "<script language='JavaScript'>window.parent.callback('上传成功!',1,'" . $picture_form->filepath . "');</script>";
  408. } else {
  409. if(isset($picture_form->getErrors()['imageFile'][0])){
  410. $error = $picture_form->getErrors()['imageFile'][0];
  411. }else{
  412. $error = '图片上传失败';
  413. }
  414. return "<script language='JavaScript'>window.parent.callback('上传失败!',0,'" . $error . "');</script>";
  415. }
  416. }else if($type=='covers'){
  417. if ($picture_form->upload('covers_picture',false,160,160)) {
  418. return "<script language='JavaScript'>window.parent.callback('上传成功!',1,'" . $picture_form->filepath . "');</script>";
  419. } else {
  420. if(isset($picture_form->getErrors()['imageFile'][0])){
  421. $error = $picture_form->getErrors()['imageFile'][0];
  422. }else{
  423. $error = '图片上传失败';
  424. }
  425. return "<script language='JavaScript'>window.parent.callback('上传失败!',0,'" . $error . "');</script>";
  426. }
  427. }
  428. }
  429. }
  430. }