PublicController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/2/26/026
  6. * Time: 11:15
  7. */
  8. namespace backend\controllers;
  9. use yii\filters\HttpCache;
  10. use yii\web\Controller;
  11. use Yii;
  12. use backend\server\User;
  13. use backend\base\Help;
  14. use yii\captcha\Captcha;
  15. use yii\log\FileTarget;
  16. class PublicController extends Controller
  17. {
  18. public $enableCsrfValidation = false;
  19. public $layout = false;
  20. public function actionAa()
  21. {
  22. phpinfo();
  23. }
  24. /*
  25. * 对比楼盘接口
  26. */
  27. public function actionAllhouse()
  28. {
  29. $model = \common\models\House::find()->select(['name'])->andWhere(['del' => 1])->asArray()->all();
  30. if (!empty($model)) {
  31. return Help::JsonCode(Help::SUCCESS, 'ch', $model);
  32. }
  33. }
  34. public function actionCes()
  35. {
  36. $model = \common\models\House::find()->select(['name', 'id'])->andWhere(['del' => 1])->andWhere(['like', 'name', ' '])->asArray()->all();
  37. $m = new \common\models\House();
  38. foreach ($model as $val) {
  39. $_m = clone $m;
  40. $a = $_m::findOne($val['id']);
  41. if (!empty($a)) {
  42. $a->name = trim($val['name'], " ");
  43. $a->save(false);
  44. }
  45. }
  46. }
  47. public function actionHouse()
  48. {
  49. // ini_set('memory_limit','502M');
  50. // ini_set("max_execution_time", "0");
  51. // $name = json_decode(file_get_contents(Yii::$app->basePath . '/runtime/house.json'),true);
  52. $model = \common\models\House::find()->select(['pfg_house.*', 'pfg_house_detail.*'])->leftJoin('pfg_house_detail', 'pfg_house.id=pfg_house_detail.hid')->andWhere(['pfg_house.del' => 1])->asArray()->all();
  53. return Help::JsonCode(Help::SUCCESS, 'ch', $model);
  54. }
  55. public function actionSs()
  56. {
  57. $name = Yii::$app->request->post('name');
  58. $val = \common\models\House::find()->select(['pfg_house.*', 'pfg_house_detail.*'])->leftJoin('pfg_house_detail', 'pfg_house.id=pfg_house_detail.hid')->andWhere(['pfg_house.del' => 1])->andWhere(['pfg_house.name' => $name])->asArray()->one();
  59. //
  60. // foreach ($model as &$val)
  61. // {
  62. if (!empty($val['characteristic'])) {
  63. $val['characteristic'] = array_column(\common\models\Characteristic::find()->select(['name'])->andWhere(['id' => json_decode($val['characteristic'], true)])->asArray()->all(), 'name');
  64. }
  65. // //1
  66. if (!empty($val['type'])) {
  67. $val['type'] = array_column(\common\models\CategoryLabel::find()->select(['name'])->andWhere(['type' => 1])->andWhere(['id' => json_decode($val['type'], true)])->asArray()->all(), 'name');
  68. }
  69. // //2
  70. if (!empty($val['architecture_type'])) {
  71. $val['architecture_type'] = array_column(\common\models\CategoryLabel::find()->select(['name'])->andWhere(['type' => 2])->andWhere(['id' => json_decode($val['architecture_type'], true)])->asArray()->all(), 'name');
  72. }
  73. // //3
  74. if (!empty($val['property_tag'])) {
  75. $val['property_tag'] = array_column(\common\models\CategoryLabel::find()->select(['name'])->andWhere(['type' => 3])->andWhere(['id' => json_decode($val['property_tag'], true)])->asArray()->all(), 'name');
  76. }
  77. $val['city'] = \common\models\CategoryCity::find()->select(['city_name'])->andWhere(['del' => 1])->andWhere(['id' => $val['city']])->asArray()->one()['city_name'];
  78. //
  79. $val['houstalbum'] = \common\models\HouseAlbum::find()->select(['pfg_house_album.title', 'pfg_house_album.img', 'pfg_category_album.name as album_name'])->leftJoin('pfg_category_album', 'pfg_house_album.album_id=pfg_category_album.id')->andWhere(['pfg_house_album.hid' => $val['id']])->andWhere(['pfg_house_album.del' => 1])->asArray()->all();
  80. $val['housetype'] = \common\models\HouseType::find()->select(['pfg_house_type.title', 'pfg_house_type.img', 'pfg_house_type.area', 'pfg_house_type.indoor_info', 'pfg_category_housetype.huxing_name as type_name'])->leftJoin('pfg_category_housetype', 'pfg_house_type.type_id=pfg_category_housetype.id')->andWhere(['pfg_house_type.hid' => $val['id']])->andWhere(['pfg_house_type.del' => 1])->asArray()->all();
  81. $val['housepeitao'] = \common\models\HouseFacilities::find()->select(['pfg_category_facilities.name as peitao_name', 'pfg_house_facilities.distance', 'pfg_house_facilities.latitude_longitude', 'pfg_house_facilities.name'])->leftJoin('pfg_category_facilities', 'pfg_house_facilities.fid=pfg_category_facilities.id')->andWhere(['pfg_house_facilities.hid' => $val['id']])->andWhere(['pfg_house_facilities.del' => 1])->asArray()->all();
  82. $val['housepermit'] = \common\models\HousePermit::find()->select(['permit', 'time', 'building_num'])->andWhere(['hid' => $val['id']])->andWhere(['del' => 1])->asArray()->all();
  83. $val['houseprice'] = \common\models\HousePriceRecord::find()->select(['price', 'create_time', 'min_price', 'explain'])->andWhere(['hid' => $val['id']])->andWhere(['del' => 1])->asArray()->all();
  84. // }
  85. return Help::JsonCode(Help::SUCCESS, 'ch', $val);
  86. //
  87. }
  88. public function actionAaa()
  89. {
  90. $model = new \common\models\Demo();
  91. $model->data = $_POST['data'];
  92. $model->save();
  93. // $log = new FileTarget();
  94. // $log->logFile = Yii::getAlias('@common').'/log/sync'.date('Ymd').'.log';
  95. // $log->messages[] = [json_encode(),1,'application',microtime(true)];
  96. // $log->export();
  97. }
  98. // public function behaviors()
  99. // {
  100. // return [
  101. // [
  102. // 'class' => 'yii\filters\HttpCache',
  103. // 'only' => ['login'],
  104. // // 'lastModified' => function ($action, $params) {
  105. // // return 1521815690;
  106. // // },
  107. // 'etagSeed'=>function($action,$params){
  108. // return serialize(['ass']);
  109. // }
  110. // ],
  111. // ];
  112. // }
  113. //注册
  114. public function actionSignup()
  115. {
  116. $this->VerifySkip();
  117. return $this->render('signup');
  118. }
  119. //注册提交数据
  120. public function actionSignupfrom()
  121. {
  122. $model = $this->UserModel();
  123. $row = $model->Signup();
  124. if ($row === true) {
  125. Help::JsonCode(200, '注册成功');
  126. }
  127. Help::JsonCode(100, '注册失败', $row);
  128. }
  129. //登录
  130. public function actionLogin()
  131. {
  132. if (empty(Yii::$app->session['user_info'])) {
  133. if (Yii::$app->request->isPost) {
  134. $model = new \backend\server\LoginFrom();
  135. $row = $model->loginVerification();
  136. if ($row === true) {
  137. return Help::JsonCode(Help::SUCCESS, '登录成功');
  138. }
  139. return Help::JsonCode(Help::ERROR, '登录失败', $row);
  140. }
  141. return $this->render('login');
  142. }
  143. $this->redirect(['/index/index']);
  144. }
  145. //登录提交数据
  146. public function actionLoginfrom()
  147. {
  148. $model = $this->UserModel();
  149. $result = $model->Login();
  150. if ($result === true) {
  151. Help::JsonCode(200, '登录成功');
  152. }
  153. Help::JsonCode(300, $result);
  154. }
  155. public function actionLogout()
  156. {
  157. unset(Yii::$app->session['user_info']);
  158. Yii::$app->session->close();
  159. $this->redirect(['/public/login']);
  160. }
  161. public function actionResourceclear()
  162. {
  163. $name = Yii::$app->cache;
  164. if ($name->set(Yii::$app->params['resourceCacheKey']['backend'], time())) {
  165. return Help::JsonCode(Help::SUCCESS, '缓存清理成功');
  166. }
  167. return Help::JsonCode(Help::ERROR, '缓存清理失败');
  168. }
  169. public function actions()
  170. {
  171. return [
  172. 'captcha' => [
  173. 'class' => 'yii\captcha\CaptchaAction',
  174. 'maxLength' => 4,
  175. 'minLength' => 4,
  176. 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
  177. 'testLimit' => 999,
  178. ],
  179. ];
  180. }
  181. //同步楼盘接口
  182. public function actionSynchouse()
  183. {
  184. $input = Yii::$app->request->post('data');
  185. $model = new \backend\server\SyncHouse();
  186. $result = $model->HouseOpe(json_decode($input, true));
  187. if ($result === true) return Help::JsonCode(Help::SUCCESS, $result);
  188. return Help::JsonCode(Help::ERROR, $result);
  189. }
  190. protected function UserModel()
  191. {
  192. return new User();
  193. }
  194. protected function VerifySkip()
  195. {
  196. if (!empty(Yii::$app->session['user_info'])) $this->goHome();
  197. }
  198. /*
  199. * 返回当天报名去重复的数据
  200. */
  201. public function actionThensignup()
  202. {
  203. $input = Yii::$app->request->post();
  204. if (isset($input['start']) && isset($input['end']) && is_numeric($input['start']) && is_numeric($input['end'])) {
  205. $model = \common\models\Enroll::find();
  206. $model->andWhere(['del' => 1]);
  207. $model->andWhere(['>=', 'create_at', $input['start']]);
  208. $model->andWhere(['<=', 'create_at', $input['end']]);
  209. $data = $model->groupBy('mobile')->count();
  210. if (!empty($data)) {
  211. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'get_success'), ['count' => $data]);
  212. }
  213. }
  214. return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
  215. }
  216. //接收淘房同步资讯
  217. public function actionTfsyncnews()
  218. {
  219. try {
  220. $input = Yii::$app->request->post('data');
  221. $model = new \backend\server\news\Tfsync();
  222. if ($model->getData($input) == true) {
  223. return Help::JsonCode(Help::SUCCESS, '成功');
  224. }
  225. } catch (\Exception $e) {
  226. return Help::JsonCode(Help::ERROR, $e->getMessage());
  227. }
  228. return Help::JsonCode(Help::ERROR, '添加失败');
  229. }
  230. /**
  231. * 直播同步接受api
  232. * */
  233. public function actionSynclive()
  234. {
  235. $input = Yii::$app->request->post();
  236. $model = new \backend\server\SyncLive();
  237. $result = $model->LiveOpe($input);
  238. if ($result === true) return Help::JsonCode(Help::SUCCESS, $result);
  239. return Help::JsonCode(Help::ERROR, $result);
  240. }
  241. /**
  242. * 敏感词库同步接收
  243. * */
  244. public function actionSyncword()
  245. {
  246. $input = Yii::$app->request->post();
  247. $model = new \backend\server\SyncWord();
  248. $result = $model->LiveOpe($input);
  249. if ($result === true) return Help::JsonCode(Help::SUCCESS, $result);
  250. return Help::JsonCode(Help::ERROR, $result);
  251. }
  252. /**
  253. * 资讯同步接收
  254. * */
  255. public function actionSynchronizationnews()
  256. {
  257. $input = Yii::$app->request->post();
  258. $model = new \backend\server\SyncNews();
  259. $result = $model->newsOpe($input);
  260. if ($result === true) return Help::JsonCode(Help::SUCCESS, $result);
  261. return Help::JsonCode(Help::ERROR, $result);
  262. }
  263. /**
  264. * 用户同步接收
  265. * */
  266. public function actionSyncuser()
  267. {
  268. $input = Yii::$app->request->post();
  269. $model = new \backend\server\SyncUser();
  270. $result = $model->userOpe($input);
  271. if ($result === true) return Help::JsonCode(Help::SUCCESS, $result);
  272. return Help::JsonCode(Help::ERROR, $result);
  273. }
  274. /**
  275. * VR同步接收
  276. * */
  277. public function actionVrsync()
  278. {
  279. $input = Yii::$app->request->post();
  280. $model = new \backend\server\SyncVr();
  281. $result = $model->userOpe($input);
  282. if ($result === true) return Help::JsonCode(Help::SUCCESS, $result);
  283. return Help::JsonCode(Help::ERROR, $result);
  284. }
  285. }