RoutinedecorationController.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <?php
  2. /*
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/7/10
  6. * Time: 上午9:44
  7. * 装修品鉴
  8. **/
  9. namespace backend\controllers;
  10. use backend\base\CommonController;
  11. use backend\base\Help;
  12. use common\models\NewsRenovationcontent;
  13. use Yii;
  14. use backend\server\UploadFile;
  15. use common\models\NewsRenovation;
  16. class RoutinedecorationController extends CommonController{
  17. /*
  18. * 常规管理 - 装修品鉴 - 页面
  19. **/
  20. public function actionHome()
  21. {
  22. return $this->render('home');
  23. }
  24. /*
  25. *常规管理 - 装修品鉴 - 数据
  26. ***/
  27. public function actionHomeform()
  28. {
  29. $model = new NewsRenovation();
  30. $model->title = Yii::$app->request->post('title');
  31. $result = $model->getList(Yii::$app->request->post());
  32. if(!empty($result))
  33. {
  34. $content = new \common\models\NewsRenovationcontent();
  35. foreach ($result as &$val)
  36. {
  37. $content->nid = $val['id'];
  38. $val['count'] = $content->Total();
  39. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  40. }
  41. return Help::JsonData(0,Yii::t('app','get_success'),$model->getListTotal(),$result);
  42. }
  43. return Help::JsonCode(Help::ERROR,Yii::t('app','get_error'));
  44. }
  45. /*
  46. *常规管理 - 装修品鉴 - 添加页面
  47. **/
  48. public function actionHomeadd()
  49. {
  50. $label = new \common\models\CategoryLabel();
  51. $label->type = 4;
  52. $labelList = $label->getList([]);
  53. return $this->render('homeadd',['label'=>$labelList]);
  54. }
  55. /*
  56. * 常规管理 - 装修品鉴 - 添加数据
  57. **/
  58. public function actionHomeaddform()
  59. {
  60. $model = new \common\models\NewsRenovation();
  61. $auth = $model->Authenticator(Yii::$app->request->post());
  62. if(is_object($auth))
  63. {
  64. $img = UploadFile::InstanceImgName('img',Yii::$app->params['img_url']['pj']);
  65. if(is_string($img))
  66. {
  67. $auth->img = $img;
  68. }
  69. if($auth->save())
  70. {
  71. return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
  72. }
  73. UploadFile::delImg(Yii::$app->params['img_url']['pj'],$img);
  74. }
  75. return Help::JsonCode(Help::ERROR,Yii::t('app','add_error'),$auth);
  76. }
  77. /*
  78. * 常规管理 - 装修品鉴 - 修改页面
  79. **/
  80. public function actionHomeedit()
  81. {
  82. $model = new NewsRenovation();
  83. $row = $model->FindById(Yii::$app->request->get('id'));
  84. if(!empty($row))
  85. {
  86. $row['img'] = Yii::$app->params['httpImg']['host'].Yii::$app->params['httpImg']['pj'].$row['img'];
  87. return $this->render('homeedit',['model'=>$row,'housename'=>Yii::$app->request->get('name')]);
  88. }
  89. }
  90. /*
  91. * 常规管理 - 装修品鉴 - 修改数据
  92. **/
  93. public function actionHomeeditform()
  94. {
  95. $model = new NewsRenovation();
  96. $input = Yii::$app->request->post();
  97. $row = $model->Authenticator($input);
  98. if(is_object($row))
  99. {
  100. $row = $model->FindById($input['id']);
  101. if(!empty($row))
  102. {
  103. $row = Help::SetAttr($input,$model,$row);
  104. if(!empty($_FILES['img']))
  105. {
  106. $url = Yii::$app->params['img_url']['pj'];
  107. $img = UploadFile::InstanceImgName('img',$url);
  108. if(is_string($img))
  109. {
  110. UploadFile::delImg($url,$row->img);
  111. $row->img = $img;
  112. }
  113. }
  114. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  115. }
  116. }
  117. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'),$row);
  118. }
  119. /*
  120. * 常规管理 - 装修品鉴 - 批量删除
  121. **/
  122. public function actionHomedel()
  123. {
  124. $id = Yii::$app->request->post('id');
  125. if(is_array($id))
  126. {
  127. $model = NewsRenovation::updateAll(['del'=>2,'update_at'=>$_SERVER['REQUEST_TIME']],['id'=>$id]);
  128. if($model >0)
  129. {
  130. return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  131. }
  132. }
  133. return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_error'));
  134. }
  135. /*
  136. * 常规管理 - 装修品鉴 - 隐藏和显示
  137. **/
  138. public function actionHomeshow()
  139. {
  140. $model = new NewsRenovation();
  141. $row = $model->FindById(Yii::$app->request->post('id'));
  142. $input = Yii::$app->request->post();
  143. if(!empty($row))
  144. {
  145. switch ($input['type'])
  146. {
  147. case 'clicks':
  148. $row->click = $input['clicks'];
  149. break;
  150. case 'show':
  151. if($row->is_show == 1)
  152. {
  153. $row->is_show = 2;
  154. }
  155. else
  156. {
  157. $row->is_show = 1;
  158. }
  159. break;
  160. }
  161. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  162. }
  163. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  164. }
  165. /*
  166. * 常规管理 - 装修品鉴 - 内容页面
  167. **/
  168. public function actionCont()
  169. {
  170. return $this->render('cont',['post'=>Yii::$app->request->get()]);
  171. }
  172. /*
  173. * 常规管理 - 装修品鉴 - 内容数据
  174. **/
  175. public function actionContform()
  176. {
  177. $model = new NewsRenovationcontent();
  178. $model->nid = Yii::$app->request->post('nid');
  179. $rows = $model->getList(Yii::$app->request->post());
  180. if(!empty($rows))
  181. {
  182. foreach ($rows as &$val)
  183. {
  184. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  185. }
  186. return Help::JsonData(0,Yii::t('app','get_success'),$model->getListTotal(),$rows);
  187. }
  188. }
  189. /*
  190. *
  191. **/
  192. public function actionContadd()
  193. {
  194. $model = new \common\models\CategoryLabel();
  195. $model->type = 4;
  196. $rows = $model->getList([]);
  197. return $this->render('contadd',['post'=>Yii::$app->request->get(),'model'=>$rows]);
  198. }
  199. /*
  200. *
  201. **/
  202. public function actionContaddform()
  203. {
  204. $model = new NewsRenovationcontent();
  205. $model->scenario = 'add';
  206. $auth = $model->Authenticator(Yii::$app->request->post());
  207. if(is_object($auth) && $auth->save())
  208. {
  209. return Help::JsonCode(Help::SUCCESS,Yii::t('app','add_success'));
  210. }
  211. return Help::JsonCode(Help::ERROR,Yii::t('app','add_error'),$auth);
  212. }
  213. /*
  214. *常规管理 - 装修品鉴 - 内容排序
  215. **/
  216. public function actionConteditsort()
  217. {
  218. $model = new NewsRenovationcontent();
  219. $input = Yii::$app->request->post();
  220. $rows = $model->FindById($input['id']);
  221. if(!empty($rows))
  222. {
  223. if(!empty($input['sort']))
  224. {
  225. $rows->sort = $input['sort'];
  226. }
  227. if($input['is_show'] == 1)
  228. {
  229. if( $rows->is_show == 1)
  230. {
  231. $rows->is_show =2;
  232. }
  233. else
  234. {
  235. $rows->is_show = 1;
  236. }
  237. }
  238. if($rows->save()) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  239. }
  240. return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'));
  241. }
  242. /*
  243. *
  244. **/
  245. public function actionContedit()
  246. {
  247. $model = new NewsRenovationcontent();
  248. $rows = $model->FindById(Yii::$app->request->get('id'));
  249. if(!empty($rows))
  250. {
  251. $label = new \common\models\CategoryLabel();
  252. $label->type = 4;
  253. $labelList = $label->getList([]);
  254. return $this->render('contedit',['model'=>$rows,'label'=>$labelList,'post'=>Yii::$app->request->get()]);
  255. }
  256. }
  257. /*
  258. *
  259. **/
  260. public function actionConteditform()
  261. {
  262. $model = new NewsRenovationcontent();
  263. $row = $model->FindById(Yii::$app->request->post('id'));
  264. if (!empty($row))
  265. {
  266. $row->content = Yii::$app->request->post('content');
  267. if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
  268. }
  269. return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_error'));
  270. }
  271. }