PushController.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/13
  6. * Time: 上午8:46
  7. */
  8. namespace backend\controllers;
  9. use backend\base\CommonController;
  10. use backend\base\Help;
  11. use backend\server\NewsInformation;
  12. use common\models\CategoryCity;
  13. use common\models\HomeDiscount;
  14. use common\models\PushBottom;
  15. use common\models\PushCityprice;
  16. use common\models\PushSojourncity;
  17. use Yii;
  18. use common\models\PushRotation;
  19. use common\models\PushActivity;
  20. use common\models\PushChoice;
  21. use common\models\PushHousesale;
  22. use common\models\PushCity;
  23. use common\models\PushCharacteristic;
  24. use backend\server\UploadFile;
  25. class PushController extends CommonController
  26. {
  27. /*
  28. * 推送首页轮播
  29. * */
  30. public function actionRotation()
  31. {
  32. $cityModel = $this->City();
  33. return $this->render('rotation', ['city' => $cityModel]);
  34. }
  35. /*
  36. * 推送首页轮播数据
  37. * */
  38. public function actionRotationforms()
  39. {
  40. $model = new PushRotation();
  41. $rows = $model->getList(Yii::$app->request->post());
  42. if ($rows != null) {
  43. $imgUrl = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['push_lb'];
  44. foreach ($rows as &$val) {
  45. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  46. $val['img'] = $imgUrl . $val['img'];
  47. }
  48. return Help::JsonData(0, Yii::t('app', 'get_success'), $model->Total(Yii::$app->request->post()), $rows);
  49. }
  50. return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
  51. }
  52. /*
  53. * 推送首页轮播 - 添加页面
  54. */
  55. public function actionRotationadd()
  56. {
  57. $cityModel = $this->City();
  58. return $this->render('rotationadd', ['city' => $cityModel]);
  59. }
  60. /*
  61. * 推送首页轮播 - 添加数据
  62. */
  63. public function actionRotationform()
  64. {
  65. $model = new PushRotation();
  66. $input = Yii::$app->request->post();
  67. $model = $model->Authenticator($input);
  68. if (is_object($model)) {
  69. $url = Yii::$app->params['img_url']['push_lb'];
  70. $img = UploadFile::InstanceImgName('img', $url);
  71. if (is_string($img)) {
  72. $model->img = $img;
  73. //压缩图片
  74. $compressParams = [];
  75. $compressParams['data']['imgname'] = $img;;
  76. $compressParams['data']['url'] = $url;
  77. $compressParams['data']['source'] = '推送位,首页轮播图@添加';
  78. $ya = new \backend\event\TinifyEvent();
  79. $ya->CompressImg($compressParams);
  80. }
  81. if ($model->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
  82. }
  83. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_error'), $model);
  84. }
  85. /*
  86. * 推送首页轮播 - 修改
  87. */
  88. public function actionRotationedit()
  89. {
  90. $model = new PushRotation();
  91. $input = Yii::$app->request->get();
  92. $row = $model->FindById($input['id']);
  93. if ($row != null) {
  94. $imgUrl = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['push_lb'];
  95. $row['img'] = $imgUrl . $row['img'];
  96. $cityModel = $this->City();
  97. foreach ($cityModel as &$val) {
  98. $val['checked'] = '';
  99. if ($val['id'] == $row['city']) {
  100. $val['checked'] = 'selected';
  101. }
  102. }
  103. return $this->render('rotationedit', ['model' => $row, 'city' => $cityModel]);
  104. }
  105. }
  106. /*
  107. * 推送首页轮播图 - 公用轮播图设定
  108. * */
  109. public function actionRotationuniversal()
  110. {
  111. $input = Yii::$app->request->post();
  112. $rows = PushRotation::findOne($input['id']);
  113. $rows->universal = $input['universal'];
  114. if ($rows->update(false)) return Help::JsonCode(Help::SUCCESS, '设置完成');
  115. return Help::JsonCode(Help::SUCCESS, '设置失败');
  116. }
  117. /*
  118. * 推送首页轮播 - 修改数据
  119. * */
  120. public function actionRotationeditform()
  121. {
  122. $model = new PushRotation();
  123. $input = Yii::$app->request->post();
  124. $setAttribute = $model->Authenticator($input);
  125. if (is_object($setAttribute)) {
  126. $row = $model->FindById($input['id']);
  127. if ($row != null) {
  128. $row = Help::SetAttr($input, $model, $row);
  129. $url = Yii::$app->params['img_url']['push_lb'];
  130. $img = UploadFile::InstanceImgName('img', $url);
  131. if (is_string($img)) {
  132. UploadFile::delImg($url, $row->img);
  133. $row->img = $img;
  134. //压缩图片
  135. $compressParams = [];
  136. $compressParams['data']['imgname'] = $img;;
  137. $compressParams['data']['url'] = $url;
  138. $compressParams['data']['source'] = '推送位,首页轮播图@修改';
  139. $ya = new \backend\event\TinifyEvent();
  140. $ya->CompressImg($compressParams);
  141. }
  142. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  143. }
  144. }
  145. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'), $setAttribute);
  146. }
  147. /*
  148. * 推送首页轮播 - 删除 and 禁用
  149. * */
  150. public function actionImgdelshow()
  151. {
  152. $model = new PushRotation();
  153. $input = Yii::$app->request->post();
  154. $row = $model->FindById($input['id']);
  155. if ($row != null) {
  156. switch ($input['type']) {
  157. case 'show':
  158. if ($row->is_show == 1) {
  159. $row->is_show = 2;
  160. } else if ($row->is_show == 2) {
  161. $row->is_show = 1;
  162. }
  163. break;
  164. case 'sort':
  165. if (is_numeric($input['sort'])) {
  166. $row->sort = $input['sort'];
  167. }
  168. break;
  169. case 'del':
  170. $row->del = 2;
  171. break;
  172. case 'expiration':
  173. $row->expiration_date = $input['expiration'];
  174. break;
  175. }
  176. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  177. }
  178. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  179. }
  180. /*
  181. * 推送首页轮播 - 批量删除
  182. * */
  183. public function actionImgdelall()
  184. {
  185. $input = Yii::$app->request->post();
  186. $model = PushRotation::find()->where(['in', 'id', $input['id']])->all();
  187. $delall = PushRotation::deleteAll(['id' => $input['id']]);
  188. if ($delall) {
  189. foreach ($model as $value) {
  190. UploadFile::delImg(Yii::$app->params['img_url']['push_lb'], $value['img']);
  191. }
  192. return Help::JsonCode(Help::SUCCESS, '批量删除成功');
  193. }
  194. return Help::JsonCode(Help::ERROR, '批量删除失败');
  195. }
  196. /*
  197. * 首页-热门活动 -列表
  198. * */
  199. public function actionHotactivity()
  200. {
  201. $city = $this->City();
  202. return $this->render('hotactivity', ['city' => $city]);
  203. }
  204. public function actionHotactivityform()
  205. {
  206. $model = new PushActivity();
  207. $input = Yii::$app->request->post();
  208. $rows = $model->getList($input);
  209. if ($rows != null) {
  210. $url = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['hot_activity'];
  211. foreach ($rows as &$val) {
  212. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  213. $val['img'] = $url . $val['img'];
  214. }
  215. return Help::JsonData(0, Yii::t('app', 'get_success'), $model->Total($input), $rows);
  216. }
  217. return Help::JsonData(Help::ERROR, Yii::t('app', 'get_error'), 0);
  218. }
  219. /*
  220. * 首页-热门活动 - 添加页面
  221. */
  222. public function actionHotactivityadd()
  223. {
  224. $cityModel = $this->City();
  225. return $this->render('hotactivityadd', ['city' => $cityModel]);
  226. }
  227. /*
  228. * 首页-热门活动 - 添加数据
  229. * */
  230. public function actionHotactivityaddform()
  231. {
  232. $model = new PushActivity();
  233. $input = Yii::$app->request->post();
  234. $auth = $model->Authenticator($input);
  235. if (is_object($auth)) {
  236. $url = Yii::$app->params['img_url']['hot_activity'];
  237. $img = UploadFile::InstanceImgName('img', $url);
  238. if (is_string($img)) {
  239. $auth->img = $img;
  240. //压缩图片
  241. $compressParams = [];
  242. $compressParams['data']['imgname'] = $img;;
  243. $compressParams['data']['url'] = $url;
  244. $compressParams['data']['source'] = '推送位,首页热门活动@添加';
  245. $ya = new \backend\event\TinifyEvent();
  246. $ya->CompressImg($compressParams);
  247. }
  248. if ($auth->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
  249. }
  250. return Help::JsonCode(Help::ERROR, Yii::t('app', 'add_error'), $auth);
  251. }
  252. /*
  253. * 推送热门活动 - 修改页面
  254. */
  255. public function actionHotactivityedit()
  256. {
  257. $model = new PushActivity();
  258. $row = $model->FindById(Yii::$app->request->get('id'));
  259. if ($row != null) {
  260. $cityModel = $this->City();
  261. foreach ($cityModel as &$val) {
  262. $val['checked'] = '';
  263. if ($val['id'] == $row['city']) {
  264. $val['checked'] = 'selected';
  265. }
  266. }
  267. $row['img'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['hot_activity'] . $row['img'];
  268. return $this->render('hotactivityedit', ['model' => $row, 'city' => $cityModel]);
  269. }
  270. }
  271. /*
  272. * 推送热门活动 - 修改数据
  273. * */
  274. public function actionHotactivityeditform()
  275. {
  276. $model = new PushActivity();
  277. $input = Yii::$app->request->post();
  278. $setAttribute = $model->Authenticator($input);
  279. if (is_object($setAttribute)) {
  280. $row = $model->FindById($input['id']);
  281. if ($row != null) {
  282. $row = Help::SetAttr($input, $model, $row);
  283. $url = Yii::$app->params['img_url']['hot_activity'];
  284. $img = UploadFile::InstanceImgName('img', $url);
  285. if (is_string($img)) {
  286. UploadFile::delImg($url, $row->img);
  287. $row->img = $img;
  288. //压缩图片
  289. $compressParams = [];
  290. $compressParams['data']['imgname'] = $img;;
  291. $compressParams['data']['url'] = $url;
  292. $compressParams['data']['source'] = '推送位,首页热门活动@修改';
  293. $ya = new \backend\event\TinifyEvent();
  294. $ya->CompressImg($compressParams);
  295. }
  296. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  297. }
  298. }
  299. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'), $setAttribute);
  300. }
  301. /*
  302. * 推送首页轮播 - 删除 and 禁用
  303. * */
  304. public function actionHotactivitydelshow()
  305. {
  306. $model = new PushActivity();
  307. $input = Yii::$app->request->post();
  308. $row = $model->FindById($input['id']);
  309. if ($row != null) {
  310. switch ($input['type']) {
  311. case 'show':
  312. if ($row->is_show == 1) {
  313. $row->is_show = 2;
  314. } else if ($row->is_show == 2) {
  315. $row->is_show = 1;
  316. }
  317. break;
  318. case 'del':
  319. $row->del = 2;
  320. break;
  321. case 'expiration':
  322. $row->expiration_date = $input['expiration'];
  323. break;
  324. }
  325. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  326. }
  327. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  328. }
  329. /*
  330. * 首页-热门活动 - 批量删除
  331. * */
  332. public function actionHotactivitydelall()
  333. {
  334. $input = Yii::$app->request->post();
  335. $model = PushActivity::find()->where(['in', 'id', $input['id']])->all();
  336. $delall = PushActivity::deleteAll(['id' => $input['id']]);
  337. if ($delall) {
  338. foreach ($model as $value) {
  339. UploadFile::delImg(Yii::$app->params['img_url']['hot_activity'], $value['img']);
  340. }
  341. return Help::JsonCode(Help::SUCCESS, '批量删除成功');
  342. }
  343. return Help::JsonCode(Help::ERROR, '批量删除失败');
  344. }
  345. /*
  346. * 推送本周精选
  347. * */
  348. public function actionChoice()
  349. {
  350. $city = $this->City();
  351. return $this->render('choice', ['city' => $city]);
  352. }
  353. /*
  354. * 推送本周精选 数据列表
  355. * */
  356. public function actionChoiceform()
  357. {
  358. $model = new PushChoice();
  359. $input = Yii::$app->request->post();
  360. $rows = $model->getList($input);
  361. if ($rows != null) {
  362. $url = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['choice'];
  363. foreach ($rows as &$val) {
  364. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  365. $val['img'] = $url . $val['img'];
  366. }
  367. return Help::JsonData(0, Yii::t('app', 'get_success'), $model->Total($input), $rows);
  368. }
  369. return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
  370. }
  371. /*
  372. * 推送本周精选 - 添加
  373. */
  374. public function actionChoiceadd()
  375. {
  376. $cityModel = $this->City();
  377. return $this->render('choiceadd', ['city' => $cityModel]);
  378. }
  379. /*
  380. * 推送本周精选 - 添加数据
  381. */
  382. public function actionChoiceaddform()
  383. {
  384. $model = new PushChoice();
  385. $input = Yii::$app->request->post();
  386. $auth = $model->Authenticator($input);
  387. if (is_object($auth)) {
  388. $url = Yii::$app->params['img_url']['choice'];
  389. $img = UploadFile::InstanceImgName('img', $url);
  390. if (is_string($img)) {
  391. $auth->img = $img;
  392. //压缩图片
  393. $compressParams = [];
  394. $compressParams['data']['imgname'] = $img;;
  395. $compressParams['data']['url'] = $url;
  396. $compressParams['data']['source'] = '推送位,首页本周精选@添加';
  397. $ya = new \backend\event\TinifyEvent();
  398. $ya->CompressImg($compressParams);
  399. }
  400. if ($auth->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
  401. }
  402. return Help::JsonCode(Help::ERROR, Yii::t('app', 'add_error'), $auth);
  403. }
  404. /*
  405. * 推送本周精选 - 修改
  406. */
  407. public function actionChoiceedit()
  408. {
  409. $model = new PushChoice();
  410. $row = $model->FindById(Yii::$app->request->get('id'));
  411. if ($row != null) {
  412. $cityModel = $this->City();
  413. foreach ($cityModel as &$val) {
  414. $val['checked'] = '';
  415. if ($val['id'] == $row['city']) {
  416. $val['checked'] = 'selected';
  417. }
  418. }
  419. $row['img'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['choice'] . $row['img'];
  420. return $this->render('choiceedit', ['model' => $row, 'city' => $cityModel]);
  421. }
  422. }
  423. /*
  424. * 推送本周精选 - 修改
  425. */
  426. public function actionChoiceeditform()
  427. {
  428. $model = new PushChoice();
  429. $input = Yii::$app->request->post();
  430. $setAttribute = $model->Authenticator($input);
  431. if (is_object($setAttribute)) {
  432. $row = $model->FindById($input['id']);
  433. if ($row != null) {
  434. $row = Help::SetAttr($input, $model, $row);
  435. $url = Yii::$app->params['img_url']['choice'];
  436. $img = UploadFile::InstanceImgName('img', $url);
  437. if (is_string($img)) {
  438. UploadFile::delImg($url, $row->img);
  439. $row->img = $img;
  440. //压缩图片
  441. $compressParams = [];
  442. $compressParams['data']['imgname'] = $img;;
  443. $compressParams['data']['url'] = $url;
  444. $compressParams['data']['source'] = '推送位,首页本周精选@修改';
  445. $ya = new \backend\event\TinifyEvent();
  446. $ya->CompressImg($compressParams);
  447. }
  448. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  449. }
  450. }
  451. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'), $setAttribute);
  452. }
  453. /*
  454. * 首页-精选 - 删除 and 禁用
  455. * */
  456. public function actionChoicedelshow()
  457. {
  458. $model = new PushChoice();
  459. $input = Yii::$app->request->post();
  460. $row = $model->FindById($input['id']);
  461. if ($row != null) {
  462. switch ($input['type']) {
  463. case 'show':
  464. if ($row->is_show == 1) {
  465. $row->is_show = 2;
  466. } else if ($row->is_show == 2) {
  467. $row->is_show = 1;
  468. }
  469. break;
  470. case 'del':
  471. $row->del = 2;
  472. break;
  473. case 'expiration':
  474. $row->expiration_date = $input['expiration'];
  475. break;
  476. }
  477. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  478. }
  479. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  480. }
  481. /*
  482. * 首页-精选 - 批量删除
  483. * */
  484. public function actionChoicedelall()
  485. {
  486. $input = Yii::$app->request->post();
  487. $model = PushChoice::find()->where(['in', 'id', $input['id']])->all();
  488. $delall = PushChoice::deleteAll(['id' => $input['id']]);
  489. if ($delall) {
  490. foreach ($model as $value) {
  491. UploadFile::delImg(Yii::$app->params['img_url']['choice'], $value['img']);
  492. }
  493. return Help::JsonCode(Help::SUCCESS, '批量删除成功');
  494. }
  495. return Help::JsonCode(Help::ERROR, '批量删除失败');
  496. }
  497. /*
  498. * 推送热销楼盘 - 页面
  499. * */
  500. public function actionHotsale()
  501. {
  502. return $this->render('hotsale', ['type' => 1]);
  503. }
  504. /*
  505. * 推送热销楼盘 - 数据
  506. * */
  507. public function actionHotsaleform()
  508. {
  509. $model = new PushHousesale();
  510. $input = Yii::$app->request->post();
  511. $result = $model->getList($input);
  512. if ($result != null) {
  513. foreach ($result as &$val) {
  514. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  515. }
  516. return Help::JsonData(0, Yii::t('app', 'get_success'), $model->Total($input), $result);
  517. }
  518. return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
  519. }
  520. /*
  521. * 推送热销楼盘 - 添加
  522. */
  523. public function actionHotsaleadd()
  524. {
  525. return $this->render('hotsaleadd', ['type' => Yii::$app->request->get('type')]);
  526. }
  527. public function actionHotsaleaddform()
  528. {
  529. $input = Yii::$app->request->post();
  530. $model = new PushHousesale();
  531. $model->scenario = 'add';
  532. $validate = $model->Authenticator($input);
  533. if (is_object($validate)) {
  534. $validate->city = \common\models\House::find()->select(['pfg_category_city.pid'])->leftJoin('pfg_category_city', 'pfg_house.city = pfg_category_city.id')->andWhere(['pfg_house.id' => $input['hid']])->asArray()->one()['pid'];
  535. if ($validate->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
  536. }
  537. return Help::JsonCode(Help::ERROR, Yii::t('app', 'add_error'), $validate);
  538. }
  539. /*
  540. * 首页-热销楼盘 - 批量删除
  541. * */
  542. public function actionHotsaledelall()
  543. {
  544. $input = Yii::$app->request->post();
  545. $delall = PushHousesale::deleteAll(['id' => $input['hid']]);
  546. if ($delall) {
  547. return Help::JsonCode(Help::SUCCESS, '批量删除成功');
  548. }
  549. return Help::JsonCode(Help::ERROR, '批量删除失败');
  550. }
  551. /*
  552. * 首页-精选 - 删除 and 禁用
  553. * */
  554. public function actionSaledelshow()
  555. {
  556. $model = new PushHousesale();
  557. $input = Yii::$app->request->post();
  558. $row = $model->FindById($input['id']);
  559. if ($row != null) {
  560. switch ($input['type']) {
  561. case 'show':
  562. if ($row->is_show == 1) {
  563. $row->is_show = 2;
  564. } else if ($row->is_show == 2) {
  565. $row->is_show = 1;
  566. }
  567. break;
  568. case 'del':
  569. $row->del = 2;
  570. break;
  571. case 'sort':
  572. if (is_numeric($input['sort'])) {
  573. $row->sort = $input['sort'];
  574. }
  575. break;
  576. }
  577. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  578. }
  579. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  580. }
  581. /*
  582. *首页-热门区域
  583. * */
  584. public function actionHotcity()
  585. {
  586. return $this->render('hotcity');
  587. }
  588. /*
  589. * 首页-热门区域-数据列表
  590. * */
  591. public function actionHotcityform()
  592. {
  593. $model = new PushCity();
  594. $input = Yii::$app->request->post();
  595. $rows = $model->getList($input);
  596. if (!empty($rows)) {
  597. foreach ($rows as &$val) {
  598. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  599. }
  600. return Help::JsonData(0, '成功', $model->Total(), $rows);
  601. }
  602. }
  603. /*
  604. * 首页-热门区域-数据列表
  605. * */
  606. public function actionHotcityadd()
  607. {
  608. return $this->render('hotcityadd');
  609. }
  610. /*
  611. * 首页-热门区域-数据列表
  612. * */
  613. public function actionHotcityaddform()
  614. {
  615. $model = new PushCity();
  616. $input = Yii::$app->request->post();
  617. $auth = $model->Authenticator($input);
  618. if (is_object($auth)) {
  619. if (!empty($input)) {
  620. $arrData = [];
  621. $rows = $model->getList($input);
  622. if (!empty($rows)) {
  623. return Help::JsonCode(Help::ERROR, '请查看是否有重复添加的区域');
  624. }
  625. foreach ($input['city_id'] as $key => $val) {
  626. $arrData[$key]['city_id'] = $val;
  627. $arrData[$key]['sort'] = 0;
  628. $arrData[$key]['is_show'] = 1;
  629. $arrData[$key]['del'] = 1;
  630. $arrData[$key]['create_at'] = $_SERVER['REQUEST_TIME'];
  631. $arrData[$key]['update_at'] = $_SERVER['REQUEST_TIME'];
  632. }
  633. $result = Yii::$app->db->createCommand()->batchInsert($model::tableName(), ['city_id', 'sort', 'is_show', 'del', 'create_at', 'update_at'], $arrData)->execute();
  634. if ($result > 0) {
  635. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
  636. }
  637. }
  638. }
  639. return Help::JsonCode(Help::ERROR, Yii::t('app', 'add_error'), $auth);
  640. }
  641. /*
  642. * 首页-精选 - 删除 and 禁用
  643. * */
  644. public function actionCitydelshow()
  645. {
  646. $model = new PushCity();
  647. $input = Yii::$app->request->post();
  648. $row = $model->FindById($input['id']);
  649. if ($row != null) {
  650. switch ($input['type']) {
  651. case 'show':
  652. if ($row->is_show == 1) {
  653. $row->is_show = 2;
  654. } else if ($row->is_show == 2) {
  655. $row->is_show = 1;
  656. }
  657. break;
  658. case 'del':
  659. if ($row->delete()) {
  660. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  661. }
  662. break;
  663. case 'sort':
  664. if (!is_numeric($input['sort'])) {
  665. return Help::JsonCode(Help::ERROR, '请输入数字');
  666. }
  667. $row->sort = $input['sort'];
  668. break;
  669. }
  670. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  671. }
  672. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  673. }
  674. /*
  675. * 首页-特色类型 页面
  676. * */
  677. public function actionCharacteristic()
  678. {
  679. return $this->render('characteristic');
  680. }
  681. /*
  682. * 首页-特色类型 数据
  683. * */
  684. public function actionCharacteristicform()
  685. {
  686. $model = new PushCharacteristic();
  687. $input = Yii::$app->request->post();
  688. $rows = $model->getList($input);
  689. if (!empty($rows)) {
  690. $url = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['characteristic'];
  691. foreach ($rows as &$val) {
  692. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  693. $val['img'] = $url . $val['img'];
  694. }
  695. return Help::JsonData(0, Yii::t('app', 'get_success'), $model->Total(), $rows);
  696. }
  697. }
  698. /*
  699. * 首页-特色类型 添加页面
  700. * */
  701. public function actionCharacteristicadd()
  702. {
  703. return $this->render('characteristicadd');
  704. }
  705. /*
  706. * 首页-特色类型 添加页面
  707. * */
  708. public function actionCharacteristicaddform()
  709. {
  710. $model = new PushCharacteristic();
  711. $input = Yii::$app->request->post();
  712. $auth = $model->Authenticator($input);
  713. if (is_object($auth)) {
  714. $url = Yii::$app->params['img_url']['characteristic'];
  715. $imgStr = UploadFile::InstanceImgName('img', $url);
  716. if (is_string($imgStr)) {
  717. $auth->img = $imgStr;
  718. }
  719. if ($auth->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
  720. }
  721. return Help::JsonCode(Help::ERROR, Yii::t('app', 'add_error'), $auth);
  722. }
  723. /*
  724. * 首页-特色类型 修改页面
  725. * */
  726. public function actionCharacteristicedit()
  727. {
  728. $model = new PushCharacteristic();
  729. $row = $model->FindById(Yii::$app->request->get('id'));
  730. if ($row != null) {
  731. $row['img'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['characteristic'] . $row['img'];
  732. return $this->render('characteristicedit', ['model' => $row, 'get' => Yii::$app->request->get()]);
  733. }
  734. }
  735. /*
  736. * 首页-特色类型 修改页面
  737. * */
  738. public function actionCharacteristiceditform()
  739. {
  740. $model = new PushCharacteristic();
  741. $input = Yii::$app->request->post();
  742. $auth = $model->Authenticator($input);
  743. if (is_object($auth)) {
  744. $row = $model->FindById($input['id']);
  745. if (!empty($row)) {
  746. $url = Yii::$app->params['img_url']['characteristic'];
  747. $imgStr = UploadFile::InstanceImgName('img', $url);
  748. $result = Help::SetAttr($input, $auth, $row);
  749. if (is_string($imgStr)) {
  750. UploadFile::delImg($url, $row['img']);
  751. $result->img = $imgStr;
  752. }
  753. if ($result->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  754. }
  755. }
  756. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'), $auth);
  757. }
  758. /*
  759. * 首页-特色类型 - 删除 and 禁用
  760. * */
  761. public function actionCharacteristicdelshow()
  762. {
  763. $model = new PushCharacteristic();
  764. $input = Yii::$app->request->post();
  765. $row = $model->FindById($input['id']);
  766. if ($row != null) {
  767. switch ($input['type']) {
  768. case 'show':
  769. if ($row->is_show == 1) {
  770. $row->is_show = 2;
  771. } else if ($row->is_show == 2) {
  772. $row->is_show = 1;
  773. }
  774. break;
  775. case 'del':
  776. if (!empty($row->img)) {
  777. UploadFile::delImg(Yii::$app->params['img_url']['characteristic'], $row->img);
  778. }
  779. if ($row->delete()) {
  780. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  781. }
  782. break;
  783. case 'sort':
  784. if (!is_numeric($input['sort'])) {
  785. return Help::JsonCode(Help::ERROR, '请输入数字');
  786. }
  787. $row->sort = $input['sort'];
  788. break;
  789. }
  790. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  791. }
  792. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  793. }
  794. /**
  795. * 首页-旅居城市 页面
  796. */
  797. public function actionSojourncity()
  798. {
  799. return $this->render('sojourncity');
  800. }
  801. /**
  802. * 首页 - 旅居城市 数据
  803. */
  804. public function actionSojourncityform()
  805. {
  806. $model = new PushSojourncity();
  807. $rows = $model->getList(Yii::$app->request->post());
  808. if (!empty($rows)) {
  809. foreach ($rows as &$val) {
  810. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  811. }
  812. return Help::JsonData(0, Yii::t('app', 'get_success'), $model->Total(), $rows);
  813. }
  814. return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
  815. }
  816. /**
  817. * 首页 - 旅居城市 添加页面
  818. */
  819. public function actionSojourncityadd()
  820. {
  821. return $this->render('sojourncityadd');
  822. }
  823. /**
  824. * 首页 - 旅居城市 添加数据
  825. */
  826. public function actionSojourncityaddform()
  827. {
  828. $model = new PushSojourncity();
  829. $model->scenario = 'add';
  830. $auth = $model->Authenticator(Yii::$app->request->post());
  831. if (is_object($auth)) {
  832. if ($auth->save()) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
  833. }
  834. return Help::JsonCode(Help::ERROR, Yii::t('app', 'add_error'), $auth);
  835. }
  836. /**
  837. * 首页 - 旅居城市 删除AND 隐藏
  838. */
  839. public function actionSojourncitydelshow()
  840. {
  841. $model = new PushSojourncity();
  842. $input = Yii::$app->request->post();
  843. $row = $model->FindById($input['id']);
  844. if ($row != null) {
  845. switch ($input['type']) {
  846. case 'show':
  847. if ($row->is_show == 1) {
  848. $row->is_show = 2;
  849. } else if ($row->is_show == 2) {
  850. $row->is_show = 1;
  851. }
  852. break;
  853. case 'del':
  854. if ($row->delete()) {
  855. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  856. }
  857. break;
  858. case 'sort':
  859. if (!is_numeric($input['sort'])) {
  860. return Help::JsonCode(Help::ERROR, '请输入数字');
  861. }
  862. $row->sort = $input['sort'];
  863. break;
  864. }
  865. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  866. }
  867. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  868. }
  869. /**
  870. * 首页 - 旅居城市 批量删除
  871. */
  872. public function actionSojourncitydelall()
  873. {
  874. $input = Yii::$app->request->post();
  875. $delall = PushSojourncity::deleteAll(['id' => $input['id']]);
  876. if ($delall) {
  877. return Help::JsonCode(Help::SUCCESS, '批量删除成功');
  878. }
  879. return Help::JsonCode(Help::ERROR, '批量删除失败');
  880. }
  881. /*------------------------------------底部横幅-----------------------------------------------------*/
  882. //底部横幅页面
  883. public function actionBottom()
  884. {
  885. $city = $this->City();
  886. return $this->render('bottom', ['city' => $city]);
  887. }
  888. //底部横幅页面 - 数据
  889. public function actionBottomform()
  890. {
  891. $model = new PushBottom();
  892. $row = $model->getList(Yii::$app->request->post());
  893. if ($row != null) {
  894. foreach ($row as &$val) {
  895. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  896. $val['img'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['bottom'] . $val['img'];
  897. $val['img_small'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['bottom'] . $val['img_small'];
  898. }
  899. return Help::JsonData(0, Yii::t('app', 'get_success'), $model->Total(Yii::$app->request->post()), $row);
  900. }
  901. return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
  902. }
  903. //底部横幅 - 添加页面
  904. public function actionBottomadd()
  905. {
  906. $city = new CategoryCity();
  907. $pidcity = $this->City();
  908. $city->pid = 0;
  909. $soncity = $city->SortgetList([]);
  910. return $this->render('bottomadd', ['pidcity' => $pidcity, 'city' => $soncity]);
  911. }
  912. //底部横幅 - 添加数据
  913. public function actionBottomaddform()
  914. {
  915. $model = new PushBottom();
  916. $input = Yii::$app->request->post();
  917. $model = $model->Authenticator($input);
  918. if (is_object($model)) {
  919. $url = Yii::$app->params['img_url']['bottom'];
  920. $img = UploadFile::InstanceImgName('img', $url);
  921. if (is_string($img)) {
  922. $model->img = $img;
  923. }
  924. $img_small = UploadFile::InstanceImgName('img_small', $url);
  925. if (is_string($img_small)) {
  926. $model->img_small = $img_small;
  927. }
  928. if ($model->save(false)) return Help::JsonCode(Help::SUCCESS, '添加成功');
  929. }
  930. return Help::JsonCode(Help::ERROR, '添加失败');
  931. }
  932. //底部横幅 - 修改页面
  933. public function actionBottomedit()
  934. {
  935. $model = new PushBottom();
  936. $row = $model->FindById(Yii::$app->request->get('id'));
  937. if ($row != null) {
  938. $row['img'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['bottom'] . $row['img'];
  939. $row['img_small'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['bottom'] . $row['img_small'];
  940. $city = new CategoryCity();
  941. $pidcity = $this->City();
  942. $city->pid = 0;
  943. $soncity = $city->SortgetList([]);
  944. return $this->render('bottomedit', ['row' => $row, 'pidcity' => $pidcity, 'city' => $soncity]);
  945. }
  946. }
  947. //底部横幅 - 公共横幅设置
  948. public function actionBottomuniversal()
  949. {
  950. $input = Yii::$app->request->post();
  951. $rows = PushBottom::findOne($input['id']);
  952. $rows->universal = $input['universal'];
  953. if ($rows->update(false)) return Help::JsonCode(Help::SUCCESS, '设置完成');
  954. return Help::JsonCode(Help::SUCCESS, '设置失败');
  955. }
  956. //底部横幅 - 修改数据
  957. public function actionBottomeditform()
  958. {
  959. $model = new PushBottom();
  960. $row = $model->FindById(Yii::$app->request->post('id'));
  961. if ($row != null) {
  962. $url = Yii::$app->params['img_url']['bottom'];
  963. $img = UploadFile::InstanceImgName('img', $url);
  964. if (is_string($img)) {
  965. UploadFile::delImg($url, $row->img);
  966. $row->img = $img;
  967. }
  968. $img_small = UploadFile::InstanceImgName('img_small', $url);
  969. if (is_string($img_small)) {
  970. UploadFile::delImg($url, $row->img_small);
  971. $row->img_small = $img_small;
  972. }
  973. if ($row->load(Yii::$app->request->post(), '') && $row->update(false))
  974. return Help::JsonCode(Help::SUCCESS, '修改成功');
  975. }
  976. return Help::JsonCode(Help::ERROR, '修改失败');
  977. }
  978. //底部横幅 - 审核&排序&删除
  979. public function actionBottomdelshow()
  980. {
  981. $model = new PushBottom();
  982. $input = Yii::$app->request->post();
  983. $row = $model->FindById($input['id']);
  984. $rows = PushBottom::find()->select(['id', 'img_show'])->andWhere(['<>', 'id', $row['id']])->asArray()->all();
  985. if ($row != null) {
  986. switch ($input['type']) {
  987. case 'del':
  988. if (!empty($row->img)) {
  989. UploadFile::delImg(Yii::$app->params['img_url']['bottom'], $row->img);
  990. }
  991. if (!empty($row->img_small)) {
  992. UploadFile::delImg(Yii::$app->params['img_url']['bottom'], $row->img_small);
  993. }
  994. if ($row->delete()) {
  995. return Help::JsonCode(Help::SUCCESS, '删除成功');
  996. }
  997. break;
  998. case 'show':
  999. if ($row->is_show == 1) {
  1000. $row->is_show = 2;
  1001. } else {
  1002. $row->is_show = 1;
  1003. }
  1004. break;
  1005. case 'state':
  1006. if ($row->state == 1) {
  1007. $row->state = 2;
  1008. } else {
  1009. $row->state = 1;
  1010. }
  1011. break;
  1012. case 'img_show':
  1013. if ($row->img_show == 2) {
  1014. $row->img_show = 1;
  1015. foreach ($rows as $val) {
  1016. $query = PushBottom::findOne($val['id']);
  1017. if ($query) {
  1018. if ($query->img_show == 1) {
  1019. $query->img_show = 2;
  1020. $query->save(false);
  1021. }
  1022. }
  1023. }
  1024. } else {
  1025. $row->img_show = 2;
  1026. }
  1027. break;
  1028. case 'sort':
  1029. if (!is_numeric($input['sort'])) {
  1030. return Help::JsonCode(Help::ERROR, '请输入数字');
  1031. }
  1032. $row->sort = $input['sort'];
  1033. break;
  1034. }
  1035. if ($row->save()) return Help::JsonCode(Help::SUCCESS, '操作成功');
  1036. }
  1037. return Help::JsonCode(Help::ERROR, '操作失败');
  1038. }
  1039. //底部横幅 - 批量删除
  1040. public function actionBottomdelall()
  1041. {
  1042. $input = Yii::$app->request->post();
  1043. $model = PushBottom::find()->where(['IN', 'id', $input['id']])->asArray()->all();
  1044. $del = PushBottom::deleteAll(['id' => $input['id']]);
  1045. if ($del) {
  1046. foreach ($model as $val) {
  1047. UploadFile::delImg(Yii::$app->params['img_url']['bottom'], $val['img']);
  1048. UploadFile::delImg(Yii::$app->params['img_url']['bottom'], $val['img_small']);
  1049. }
  1050. return Help::JsonCode(Help::SUCCESS, '批量删除成功');
  1051. }
  1052. return Help::JsonCode(Help::ERROR, '批量删除失败');
  1053. }
  1054. /*------------------------------------楼盘首页优惠推荐-----------------------------------------------------*/
  1055. public function actionHomediscount()
  1056. {
  1057. return $this->render('homediscount');
  1058. }
  1059. public function actionHomediscountform()
  1060. {
  1061. $model = new HomeDiscount();
  1062. $rows = $model->getList(Yii::$app->request->post());
  1063. if ($rows != null) {
  1064. foreach ($rows as &$val) {
  1065. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  1066. }
  1067. return Help::JsonData(0, Yii::t('app', 'get_success'), $model->Total(Yii::$app->request->post()), $rows);
  1068. }
  1069. return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
  1070. }
  1071. public function actionHomediscountadd()
  1072. {
  1073. return $this->render('homediscountadd');
  1074. }
  1075. public function actionHomediscountaddform()
  1076. {
  1077. $model = new HomeDiscount();
  1078. $model->scenario = 'add';
  1079. $input = Yii::$app->request->post();
  1080. if (!empty($input)) {
  1081. if ($model->load($input, '') && $model->save()) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
  1082. }
  1083. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_error'), $model->errors);
  1084. }
  1085. public function actionHomediscountedit()
  1086. {
  1087. $model = new HomeDiscount();
  1088. $input = Yii::$app->request->get();
  1089. $row = $model->FindById($input['id']);
  1090. if ($row != null) {
  1091. return $this->render('homediscountedit', ['model' => $row]);
  1092. }
  1093. }
  1094. public function actionHomediscounteditform()
  1095. {
  1096. $model = new HomeDiscount();
  1097. $input = Yii::$app->request->post();
  1098. $row = $model->FindById($input['id']);
  1099. $row->scenario = 'edit';
  1100. if ($row != null) {
  1101. if ($row->load($input, '') && $row->save()) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  1102. }
  1103. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'), $row->errors);
  1104. }
  1105. public function actionSethomediscount()
  1106. {
  1107. $model = new HomeDiscount();
  1108. $input = Yii::$app->request->post();
  1109. $row = $model->FindById($input['id']);
  1110. if ($row != null) {
  1111. switch ($input['type']) {
  1112. case 'show':
  1113. if ($row->is_show == 1) {
  1114. $row->is_show = 2;
  1115. } else if ($row->is_show == 2) {
  1116. $row->is_show = 1;
  1117. }
  1118. break;
  1119. case 'sort':
  1120. if (is_numeric($input['sort'])) {
  1121. $row->sort = $input['sort'];
  1122. }
  1123. break;
  1124. case 'del':
  1125. if ($row->delete()) return Help::JsonCode(Help::SUCCESS, '删除成功');
  1126. break;
  1127. }
  1128. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  1129. }
  1130. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  1131. }
  1132. /*******************************************************************************************************/
  1133. private function City()
  1134. {
  1135. $city = new \common\models\CategoryCity();
  1136. $city->state = 1;
  1137. $city->pid = 0;
  1138. $cityModel = $city->getList([]);
  1139. return $cityModel;
  1140. }
  1141. }