DictionarybController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/12
  6. * Time: 下午9:21
  7. */
  8. namespace backend\controllers;
  9. // 开发商,房产顾问,视频分类
  10. use backend\base\CommonController;
  11. use common\models\CategoryAdviser;
  12. use common\models\Developers;
  13. use common\models\CategoryVideo;
  14. use backend\server\UploadFile;
  15. use Yii;
  16. use backend\base\Help;
  17. class DictionarybController extends CommonController
  18. {
  19. /*
  20. * 开发商显示页面
  21. * */
  22. public function actionDeveloper()
  23. {
  24. return $this->render('developer');
  25. }
  26. /*
  27. * 获取开发商数据
  28. * */
  29. public function actionDeveloperform()
  30. {
  31. $model = new Developers();
  32. $rows = $model->getList(Yii::$app->request->post());
  33. if($rows != null)
  34. {
  35. foreach ($rows as &$val)
  36. {
  37. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  38. $val['update_at'] = date('Y-m-d H:i',$val['update_at']);
  39. $val['allow'] = Yii::$app->params['RecommendedState'][$val['allow']];
  40. $val['logo'] = Yii::$app->params['httpImg']['host'].Yii::$app->params['httpImg']['developers'].$val['logo'];
  41. }
  42. return Help::JsonData(0,'成功',$model->Total(Yii::$app->request->post()),$rows);
  43. }
  44. }
  45. /*
  46. * 添加开发商页面
  47. * */
  48. public function actionDeveloperadd()
  49. {
  50. return $this->render('developeradd');
  51. }
  52. /*
  53. * 添加开发商数据
  54. * */
  55. public function actionDeveloperaddform()
  56. {
  57. $model = new Developers();
  58. $model->scenario = 'add';
  59. $model->load(Yii::$app->request->post(),'');
  60. $url = Yii::$app->params['img_url']['developers'];
  61. $img = UploadFile::InstanceImgName('img',$url);
  62. $model->logo = $img;
  63. if($model->validate() && $model->insert())return Help::JsonCode(Help::SUCCESS,'添加成功');
  64. return Help::JsonCode(Help::ERROR,'添加失败',$model->errors);
  65. }
  66. /*
  67. * 添加和修改图片
  68. * */
  69. public function actionDeveloperimg()
  70. {
  71. $id = Yii::$app->request->post('id');
  72. $img = UploadFile::InstanceImgName('img',Yii::$app->params['img_url']['developers']);
  73. if(is_numeric($id) && !empty($img))
  74. {
  75. $model = new Developers();
  76. $row = $model->FindById($id);
  77. if($row != null)
  78. {
  79. UploadFile::delImg(Yii::$app->params['img_url']['developers'],$row->logo);
  80. $row->logo = $img;
  81. if($row->update() == true) return Help::JsonCode(Help::SUCCESS,'成功',$img);
  82. }
  83. }
  84. if($img != false) return Help::JsonCode(Help::SUCCESS,'成功',$img);
  85. return Help::JsonCode(Help::ERROR,'失败');
  86. }
  87. /*
  88. * 删除图片
  89. * */
  90. public function actionDeveloperunimg()
  91. {
  92. UploadFile::delImg(Yii::$app->params['img_url']['developers'],Yii::$app->request->post('imgname'));
  93. }
  94. /*
  95. * 修改图片
  96. * */
  97. public function actionDeveloperuneditimg()
  98. {
  99. // p($_POST);
  100. }
  101. /*
  102. * 修改开发商页面
  103. * */
  104. public function actionDeveloperedit()
  105. {
  106. // p($_PO)
  107. $model = new Developers();
  108. $row = $model->FindById(Yii::$app->request->get('id'));
  109. if($row != null)
  110. {
  111. $row['logo'] = Yii::$app->params['httpImg']['host']. Yii::$app->params['httpImg']['developers'].$row['logo'];
  112. return $this->render('developeredit',['model'=>$row]);
  113. }
  114. }
  115. /*
  116. * 修改开发商数据
  117. * */
  118. public function actionDevelopereditform()
  119. {
  120. $model = new Developers();
  121. $input = Yii::$app->request->post();
  122. $row = $model->FindById($input['id']);
  123. if($row)
  124. {
  125. $url = Yii::$app->params['img_url']['developers'];
  126. $img = UploadFile::InstanceImgName('img',$url);
  127. if(is_string($img))
  128. {
  129. UploadFile::delImg($url,$row->logo);
  130. $input['logo'] = $img;
  131. }
  132. $row->load($input,'');
  133. if($row->save()) return Help::JsonCode(Help::SUCCESS,'修改成功');
  134. return Help::JsonCode(Help::ERROR,'修改失败',$row->errors);
  135. }
  136. return Help::JsonCode(Help::ERROR,'修改失败');
  137. }
  138. /*
  139. * 删除开发商
  140. * */
  141. public function actionDeveloperdel()
  142. {
  143. $model = new Developers();
  144. $row = $model->FindById(Yii::$app->request->post('id'));
  145. if($row != null)
  146. {
  147. UploadFile::delImg(Yii::$app->params['img_url']['developers'],$row->logo);
  148. if($row->delete() == true) return Help::JsonCode(Help::SUCCESS,'删除成功');
  149. }
  150. return Help::JsonCode(Help::ERROR,'删除失败',$model->errors);
  151. }
  152. //======================================房产顾问========================================
  153. /*
  154. * 房产顾问显示页面
  155. * */
  156. public function actionAdviser()
  157. {
  158. return $this->render('adviser');
  159. }
  160. /*
  161. * 获取房产顾问数据
  162. * */
  163. public function actionAdviserform()
  164. {
  165. $model = new CategoryAdviser();
  166. $rows = $model->getList(Yii::$app->request->post());
  167. if($rows != null)
  168. {
  169. foreach ($rows as &$val)
  170. {
  171. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  172. $val['photo'] = Yii::$app->params['httpImg']['host'].Yii::$app->params['httpImg']['adviser'].$val['photo'];
  173. }
  174. return Help::JsonData(0,'成功',$model->Total(),$rows);
  175. }
  176. }
  177. /*
  178. * 添加房产顾问页面
  179. * */
  180. public function actionAdviseradd()
  181. {
  182. return $this->render('adviseradd');
  183. }
  184. /*
  185. * 添加房产顾问数据
  186. * */
  187. public function actionAdviseraddform()
  188. {
  189. $model = new CategoryAdviser();
  190. $model->Authenticator(Yii::$app->request->post('data'));
  191. if($model->validate() && $model->save()) return Help::JsonCode(Help::SUCCESS,'添加成功');
  192. return Help::JsonCode(Help::SUCCESS,'添加失败',$model->errors);
  193. }
  194. /*
  195. * 添加和修改图片
  196. * */
  197. public function actionAdviserimg()
  198. {
  199. $id = Yii::$app->request->post('id');
  200. $img = UploadFile::InstanceImgName('img',Yii::$app->params['img_url']['adviser']);
  201. if(is_numeric($id) && !empty($img))
  202. {
  203. $model = new CategoryAdviser();
  204. $row = $model->FindById($id);
  205. if($row != null)
  206. {
  207. UploadFile::delImg(Yii::$app->params['img_url']['adviser'],$row->photo);
  208. $row->photo = $img;
  209. if($row->update() == true) return Help::JsonCode(Help::SUCCESS,'成功',$img);
  210. }
  211. }
  212. if($img != false) return Help::JsonCode(Help::SUCCESS,'成功',$img);
  213. return Help::JsonCode(Help::ERROR,'失败');
  214. }
  215. /*
  216. * 修改房产顾问页面
  217. * */
  218. public function actionAdviseredit()
  219. {
  220. $model = new CategoryAdviser();
  221. $row = $model->FindById(Yii::$app->request->get('id'));
  222. if($row != null)
  223. {
  224. $row['photo'] = Yii::$app->params['httpImg']['host']. Yii::$app->params['httpImg']['adviser'].$row['photo'];
  225. return $this->render('adviseredit',['model'=>$row]);
  226. }
  227. }
  228. /*
  229. * 修改房产顾问数据
  230. * */
  231. public function actionAdvisereditform()
  232. {
  233. $model = new CategoryAdviser();
  234. $result = $model->Authenticator(Yii::$app->request->post('data'));
  235. if(is_object($result))
  236. {
  237. $row = $model->FindById(Yii::$app->request->post('data')['id']);
  238. $row = Help::SetAttr(Yii::$app->request->post('data'),$result,$row);
  239. if($row->update() == true) return Help::JsonCode(Help::SUCCESS,'修改成功');
  240. }
  241. return Help::JsonCode(Help::ERROR,'修改失败',$result);
  242. }
  243. /*
  244. * 删除图片
  245. * */
  246. public function actionAdviserunimg()
  247. {
  248. UploadFile::delImg(Yii::$app->params['img_url']['adviser'],Yii::$app->request->post('imgname'));
  249. }
  250. /*
  251. * 删除房产顾问
  252. * */
  253. public function actionAdviserdel()
  254. {
  255. $model = new CategoryAdviser();
  256. $row = $model->FindById(Yii::$app->request->post('id'));
  257. if($row != null)
  258. {
  259. $row->del = 2;
  260. if($row->update() == true) return Help::JsonCode(Help::SUCCESS,'删除成功');
  261. }
  262. return Help::JsonCode(Help::ERROR,'删除失败');
  263. }
  264. //======================================视频分类========================================
  265. /*
  266. * 视频分类-显示页面
  267. * */
  268. public function actionVideohome()
  269. {
  270. return $this->render('videohome');
  271. }
  272. /*
  273. * 视频分类-获取显示数据
  274. * */
  275. public function actionVideohomeform()
  276. {
  277. $model = new CategoryVideo();
  278. $rows = $model->getList(Yii::$app->request->post());
  279. if($rows != null)
  280. {
  281. foreach($rows as &$val)
  282. {
  283. $val['create_at'] = date('Y-m-d',$val['create_at']);
  284. $val['is_recommend'] =Yii::$app->params['RecommendedState'][$val['is_recommend']];
  285. }
  286. return Help::JsonData(0,'成功',$model->Total(),$rows);
  287. }
  288. }
  289. /*
  290. * 视频分类-修改显示页面
  291. * */
  292. public function actionVideoedit()
  293. {
  294. $model = new CategoryVideo();
  295. $row = $model->FindById(Yii::$app->request->get('id'));
  296. if($row != null)
  297. {
  298. return $this->render('videoedit',['model'=>$row]);
  299. }
  300. }
  301. /*
  302. * 视频分类-修改数据
  303. * */
  304. public function actionVideoeditform()
  305. {
  306. $model = new CategoryVideo();
  307. $input = Yii::$app->request->post('data');
  308. $authModel = $model->Authenticator($input);
  309. if(is_object($authModel))
  310. {
  311. $row = $model->FindById($input['id']);
  312. if($row != null)
  313. {
  314. $row = Help::SetAttr($input,$authModel,$row);
  315. if($row->save() == true) return Help::JsonCode(Help::SUCCESS,'修改成功');
  316. }
  317. }
  318. return Help::JsonCode(Help::ERROR,'修改失败',$authModel);
  319. }
  320. /*
  321. * 视频分类-添加页面
  322. * */
  323. public function actionVideoadd()
  324. {
  325. return $this->render('videoadd');
  326. }
  327. /*
  328. * 视频分类-添加数据
  329. * */
  330. public function actionVideoaddform()
  331. {
  332. $model = new CategoryVideo();
  333. $videoModel = $model->Authenticator(Yii::$app->request->post('data'));
  334. if(is_object($videoModel))
  335. {
  336. if($videoModel->insert() == true) return Help::JsonCode(Help::SUCCESS,'添加成功');
  337. }
  338. return Help::JsonCode(Help::ERROR,'添加失败',$videoModel);
  339. }
  340. /*
  341. *视频分类-删除视频
  342. * */
  343. public function actionVideodel()
  344. {
  345. $model = new CategoryVideo();
  346. $input = Yii::$app->request->post();
  347. $row = $model->FindById($input['id']);
  348. if($row != null)
  349. {
  350. $row->del = 2;
  351. if($row->save() == true) return Help::JsonCode(Help::SUCCESS,'删除成功');
  352. }
  353. return Help::JsonCode(Help::SUCCESS,'删除失败');
  354. }
  355. }