Houses.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/4
  6. * Time: 下午2:20
  7. */
  8. //处理楼盘业务
  9. namespace backend\server;
  10. use backend\base\Help;
  11. use common\models\House;
  12. use common\models\HouseDetail;
  13. use common\models\UserHouse;
  14. use Yii;
  15. class Houses extends \yii\base\Component
  16. {
  17. const EVENT_COMPRESS = 'compress_img'; //压缩图片
  18. public function GroupList($input)
  19. {
  20. $model = new House();
  21. if(!empty($input['city']))
  22. {
  23. $city = new \common\models\CategoryCity();
  24. $pro = $city->FindById($input['city']);
  25. if($pro['pid'] == 0)
  26. {
  27. // $input['city'] =$pro['id']; //20190223 注释
  28. $r = $city->GetAllSon($input['city'],['city_name','id']);
  29. if(!empty($r))
  30. {
  31. $input['city'] = array_column($r,'id');
  32. }
  33. }
  34. }
  35. $list = $model->getList($input);
  36. if($list != null)
  37. {
  38. $arr = [];
  39. //资讯
  40. $id = array_column($list,'id');
  41. $houseNews = new \common\models\HouseNews();
  42. //相册
  43. $houseAlbum = new \common\models\HouseAlbum();
  44. $houseAlbum->hid = $id;
  45. $albumList = $houseAlbum->HidTotal();
  46. if($albumList != null)
  47. {
  48. $Albumcolumn = array_column($albumList,'num','hid');
  49. }
  50. //户型
  51. $houseType = new \common\models\HouseType();
  52. $houseType->hid = $id;
  53. $typeList = $houseType->HidTotal();
  54. if($typeList != null)
  55. {
  56. $typeColumn = array_column($typeList,'num','hid');
  57. }
  58. //周边配套
  59. $peitao = new \common\models\HouseFacilities();
  60. $peitao->hid = $id;
  61. $peitaoList = $peitao->HidTotal();
  62. if($peitaoList != null)
  63. {
  64. $peitaoColumn = array_column($peitaoList,'num','hid');
  65. }
  66. $yushou = new \common\models\HousePermit();
  67. $yushow = $yushou->HidTotal(['hid'=>$id]);
  68. if($yushow != null)
  69. {
  70. $PermitColumn = array_column($yushow,'num','hid');
  71. }
  72. $videoModel = new \common\models\Video();
  73. $videoModel->hid = $id;
  74. $videoModel->HidList();
  75. if(!empty($videoModel))
  76. {
  77. $video = array_column($yushow,'video_url','hid');
  78. }
  79. foreach ($list as &$val)
  80. {
  81. $_houseNews = clone $houseNews;
  82. $val['album_num'] = 0;
  83. $val['type_num'] = 0;
  84. $val['peitao_num'] = 0;
  85. $val['permit'] = 0;
  86. $val['video'] = 0;
  87. $val['news_num'] = $_houseNews::find()->andWhere(['hid'=>$val['id']])->andWhere(['del'=>1])->count();
  88. if(!empty($Albumcolumn[$val['id']]))
  89. {
  90. $val['album_num'] = $Albumcolumn[$val['id']];
  91. }
  92. if(!empty($typeColumn[$val['id']]))
  93. {
  94. $val['type_num'] = $typeColumn[$val['id']];
  95. }
  96. if(!empty($peitaoColumn[$val['id']])){
  97. $val['peitao_num'] = $peitaoColumn[$val['id']];
  98. }
  99. if(!empty($PermitColumn[$val['id']]))
  100. {
  101. $val['permit'] = $PermitColumn[$val['id']];
  102. }
  103. if(!empty($video[$val['id']]))
  104. {
  105. $val['video'] = 1;
  106. }
  107. $val['create_at'] = date('Y-m-d H:i',$val['create_at']);
  108. }
  109. $arr['data'] = $list;
  110. $arr['count'] = $model->getListTotal($input);
  111. return $arr;
  112. }
  113. }
  114. public function HouseRelation()
  115. {
  116. $arr = [];
  117. //价格区间
  118. $price = new \common\models\HousesPrice();
  119. $arr['priceList'] = $price->getList([]);
  120. //特色楼盘
  121. $tese = new \common\models\Characteristic();
  122. $arr['teseList'] = $tese->getList([]);
  123. //区域
  124. $city = new \common\models\CategoryCity();
  125. // $city->pid = 0;
  126. $arr['city'] = $city->SortgetList([]);
  127. //楼盘标签
  128. $label = new \common\models\CategoryLabel();
  129. $label->type=1;
  130. $arr['label'] = $label->getList([]);
  131. $label->type=2;
  132. $arr['Architecture'] = $label->getList([]);
  133. $label->type=3;
  134. $arr['housetag'] = $label->getList([]);
  135. //户型划分
  136. // $type = new \common\models\HouseType();
  137. // $arr['type'] = $type->getList([]);
  138. //开发商
  139. $developers = new \common\models\Developers();
  140. $arr['developers'] = $developers->getList([]);
  141. return $arr;
  142. }
  143. public function add($form)
  144. {
  145. $model = new House();
  146. $model->scenario = 'add';
  147. $modelDetails = new HouseDetail();
  148. $imgUrl = Yii::$app->params['img_url']['house'];
  149. $model->thumb = UploadFile::InstanceImgName('img',$imgUrl);
  150. if($model->thumb != false)
  151. {
  152. //压缩图片
  153. // $compressParams = [];
  154. // $compressParams['data']['imgname'] = $model->thumb;;
  155. // $compressParams['data']['url'] = $imgUrl;
  156. // $compressParams['data']['source'] = '楼盘缩略图@添加';
  157. // $this->onCompress($compressParams);
  158. }
  159. else
  160. {
  161. $model->thumb = ''; //图片不存在时返回false字段验证 的时候会报错
  162. }
  163. $houseModel = $model->Authenticator($form);
  164. if(is_array($houseModel))
  165. {
  166. return $houseModel;
  167. }
  168. $Details = $modelDetails->Authenticator($form);
  169. if(is_array($Details))
  170. {
  171. return $Details;
  172. }
  173. $transaction = Yii::$app->db->beginTransaction();
  174. $UserHouseModel = new UserHouse();
  175. if(!empty($form['characteristic']))
  176. {
  177. $houseModel->characteristic = json_encode(array_values($form['characteristic']));
  178. }
  179. if(!empty($form['type']))
  180. {
  181. $houseModel->type = json_encode(array_values($form['type']));
  182. }
  183. if(!empty($form['architecture_type']))
  184. {
  185. $houseModel->architecture_type = json_encode(array_values($form['architecture_type']));
  186. }
  187. if(!empty($form['property_tag']))
  188. {
  189. $Details->property_tag = json_encode(array_values($form['property_tag']));
  190. }
  191. if(!empty($form['evaluating']))
  192. {
  193. $Details->evaluating = json_encode($form['evaluating']);
  194. }
  195. // if(!empty($form['fit']))
  196. // {
  197. // $Details->fit = implode(',',$form['fit']);
  198. // }
  199. $houseModel->insert(false);
  200. // exit;
  201. $Details->hid = $houseModel->attributes['id'];
  202. $UserHouseModel->uid = Yii::$app->session['user_info']['uid'];
  203. $UserHouseModel->hid = $Details->hid;
  204. if($Details->insert(false) == true && is_numeric($houseModel->attributes['id']) && $UserHouseModel->insert() == true)
  205. {
  206. $transaction->commit();
  207. //水印
  208. //水印处理
  209. if(!empty($form['watermark']))
  210. {
  211. // if( $form['watermark'] == 1 && $model->thumb != false)
  212. // {
  213. // $ImgSet = new SetUploadImg();
  214. // $ImgSet->SetImgWatermark($model->thumb,$imgUrl);
  215. // }
  216. }
  217. // if($form['watermark'] == 1 && $model->thumb != false)
  218. // {
  219. // \backend\server\SetUploadImg::Watermark($imgUrl.$model->thumb,
  220. // Yii::$app->params['watermark_img']['url']. Yii::$app->params['watermark_img']['module1'],5);
  221. // }
  222. return true;
  223. }
  224. $transaction->rollBack();
  225. //数据库添加不成功删除上传的图片
  226. if($model->thumb != false)
  227. {
  228. UploadFile::delImg($imgUrl,$model->thumb);
  229. }
  230. return false;
  231. }
  232. public function Edit($input)
  233. {
  234. $model = new House();
  235. $imgUrl = Yii::$app->params['img_url']['house'];
  236. $house = $model->FindById($input['id']);
  237. $house->scenario = 'edit';
  238. $modelHouse = $house->Authenticator($input);
  239. if(is_array($modelHouse))
  240. {
  241. return $modelHouse;
  242. }
  243. $modelDetails = new HouseDetail();
  244. $HouseDetails = $modelDetails->Authenticator($input);
  245. if(is_array($HouseDetails))
  246. {
  247. return $HouseDetails;
  248. }
  249. // $house = $model->FindById($input['id']);
  250. $delImg = $house->thumb;
  251. $houseUpdate = \backend\base\Help::SetAttr($input,$modelHouse,$house);
  252. if(!empty($input['characteristic']))
  253. {
  254. $houseUpdate->characteristic = json_encode(array_values($input['characteristic']));
  255. }
  256. else
  257. {
  258. $houseUpdate->characteristic = '';
  259. }
  260. if(!empty($input['type']))
  261. {
  262. $houseUpdate->type = json_encode(array_values($input['type']));
  263. }
  264. else
  265. {
  266. $houseUpdate->type = '';
  267. }
  268. if(!empty($input['architecture_type']))
  269. {
  270. $houseUpdate->architecture_type = json_encode(array_values($input['architecture_type']));
  271. }
  272. else
  273. {
  274. $houseUpdate->architecture_type = '';
  275. }
  276. if(!empty($input['property_tag']))
  277. {
  278. $HouseDetails->property_tag = json_encode(array_values($input['property_tag']));
  279. }
  280. else
  281. {
  282. $HouseDetails->property_tag = '';
  283. }
  284. if(!empty($input['evaluating']))
  285. {
  286. $HouseDetails->evaluating = json_encode($input['evaluating']);
  287. }
  288. else
  289. {
  290. $HouseDetails->evaluating = '';
  291. }
  292. // if(!empty($input['fit']))
  293. // {
  294. // $HouseDetails->fit = implode(',',$input['fit']);
  295. // }
  296. $img = UploadFile::InstanceImgName('img',$imgUrl);
  297. if($img != false)
  298. {
  299. $houseUpdate->thumb = $img;
  300. UploadFile::delImg($imgUrl,$delImg);
  301. //水印处理
  302. if(!empty($input['watermark'])){
  303. // if($input['watermark'] == 1 )
  304. // {
  305. // $ImgSet = new SetUploadImg();
  306. // $ImgSet->SetImgWatermark($houseUpdate->thumb,$imgUrl);
  307. // }
  308. }
  309. //压缩图片
  310. // $compressParams = [];
  311. // $compressParams['data']['imgname'] = $img;;
  312. // $compressParams['data']['url'] = $imgUrl;
  313. // $compressParams['data']['source'] = '楼盘缩略图@修改';
  314. // $this->onCompress($compressParams);
  315. }
  316. $detailsHouse = $modelDetails->FindById($input['id']);
  317. $Update = $houseUpdate->update(false);
  318. $detailsHouse = \backend\base\Help::SetAttr($input,$HouseDetails,$detailsHouse);
  319. $UpdateDetails = $detailsHouse->update(false);
  320. if($UpdateDetails == true || $Update == true) return true;
  321. }
  322. public function HouseAndNews()
  323. {
  324. $query = new \common\models\News();
  325. $query->hid = Yii::$app->request->post('hid');
  326. $rows['data'] = $query->HouseNewsList(Yii::$app->request->post());
  327. $rows['count'] = $query->HouseNewsTotal();
  328. if(!empty($rows['data']))
  329. {
  330. return $rows;
  331. }
  332. return false;
  333. }
  334. //后期再修改一下 SQL语句这样写不行
  335. public function RelationNewsRecord()
  336. {
  337. $model = new \common\models\HouseNews();
  338. $nid = Yii::$app->request->post('nid');
  339. $insert = false;
  340. foreach ($nid as $val)
  341. {
  342. $_model = clone $model;
  343. $row = $_model::find()->andWhere(['nid'=>$val])->andWhere(['hid'=>Yii::$app->request->post('hid')])->one();
  344. if($row == null)
  345. {
  346. $_model->nid = $val;
  347. $_model->hid = Yii::$app->request->post('hid');
  348. $_model->uid = Yii::$app->session['user_info']['uid'];
  349. $insert = $_model->insert();
  350. }
  351. else
  352. {
  353. $row->del = 1;
  354. $row->uid = Yii::$app->session['user_info']['uid'];
  355. $insert = $row->update();
  356. }
  357. }
  358. if($insert == true) return true;
  359. }
  360. public function FilterNews()
  361. {
  362. $model = new \common\models\HouseNews();
  363. $model->hid = Yii::$app->request->post('hid');
  364. $houseNewsInfo = $model->getHidList();
  365. $nids = array_column($houseNewsInfo,'nid');
  366. $nid_hid = array_column($houseNewsInfo,'hnid','nid');
  367. $newsModel = new \common\models\News();
  368. $newsModel->hid = Yii::$app->request->post('hid');
  369. $arr['data'] = $newsModel->getNewsListHouse($nids);
  370. // $arr['data'] = $model->getNewsList(Yii::$app->request->post());
  371. if($arr['data'] != null)
  372. {
  373. foreach ($arr['data'] as $key=>$val)
  374. {
  375. if(!empty($val['state']))
  376. {
  377. // $arr['data'][$key]['is_view'] = Yii::$app->params['newsStatus'][$val['is_view']];
  378. $arr['data'][$key]['create_at'] = date('Y-m-d',$val['create_at']);
  379. if(isset($nid_hid[$val['id']]) && !empty($nid_hid[$val['id']])){
  380. $arr['data'][$key]['hnid'] = $nid_hid[$val['id']];
  381. }else{
  382. $arr['data'][$key]['hnid'] = 'news';
  383. }
  384. }
  385. else
  386. {
  387. unset($arr['data'][$key]); //删除文章的时候
  388. }
  389. }
  390. $arr['count'] = $model->Total(Yii::$app->request->post());
  391. return $arr;
  392. }
  393. }
  394. /*
  395. * 点击加载资讯时,过滤已经关联的资讯
  396. * */
  397. public function FilterLoadNews()
  398. {
  399. $model = new \common\models\News();
  400. $model->id = Yii::$app->request->post('id');
  401. $model->subject = Yii::$app->request->post('name');
  402. $model->category = Yii::$app->request->post('news');
  403. $result = $model->getList(Yii::$app->request->post());
  404. $HouseNewsModel = new \common\models\HouseNews();
  405. $HouseNewsModel->hid = Yii::$app->request->post('hid');
  406. $HidArr = $HouseNewsModel->getHidList();
  407. if($HidArr != null)
  408. {
  409. $arr = [];
  410. foreach ($HidArr as $key=>$val)
  411. {
  412. if($val['del'] != 2)
  413. {
  414. $arr[$val['nid']] = $val;
  415. }
  416. }
  417. }
  418. $brr = [];
  419. if($result != null)
  420. {
  421. foreach ($result as $key=>$val)
  422. {
  423. if(empty($arr[$val['id']])){
  424. $brr[$key]['id'] = $val['id'];
  425. $brr[$key]['subject'] = $val['subject'];
  426. $brr[$key]['clicks'] = $val['clicks'];
  427. $brr[$key]['city_name'] = $val['city_name'];
  428. $brr[$key]['create_at'] = date('Y-m-d H:i',$val['create_at']);
  429. $brr[$key]['state'] = Yii::$app->params['newsStatus'][$val['state']];
  430. }
  431. }
  432. $rows['count'] = count($brr);
  433. $rows['data'] = $brr;
  434. return $rows;
  435. }
  436. return false;
  437. }
  438. //添加楼盘相册逻辑
  439. public function HouseAibumCreate()
  440. {
  441. $model = new \common\models\HouseAlbum();
  442. $row = $model->Authenticator(Yii::$app->request->post());
  443. return true;
  444. if(is_array($row)) return $row;
  445. $url = Yii::$app->params['img_url']['housealbum'];
  446. $inputArr = UploadFile::InstancesImgName('img',$url);
  447. if(is_array($inputArr))
  448. {
  449. //水印处理
  450. // if(Yii::$app->request->post('thumb_watermark') == 1)
  451. // {
  452. // $ImgSet = new SetUploadImg();
  453. // $ImgSet->SetImgWatermark($inputArr,$url);
  454. // }
  455. //压缩图片
  456. // $compressParams = [];
  457. // $compressParams['data']['imgname'] = $inputArr;;
  458. // $compressParams['data']['url'] = $url;
  459. // $compressParams['data']['source'] = $row->album_id.'-楼盘相册@添加';
  460. // $this->onCompress($compressParams);
  461. $arrData = [];
  462. foreach($inputArr as $key=>$val)
  463. {
  464. $arrData[$key]['hid'] = $row->hid;
  465. $arrData[$key]['album_id'] = $row->album_id;
  466. $arrData[$key]['img'] = $val;
  467. $arrData[$key]['title'] = Yii::$app->request->post('imginput')[$key];
  468. $arrData[$key]['zhu'] = Yii::$app->request->post('editzhux')[$key];
  469. $arrData[$key]['create_at'] = $_SERVER['REQUEST_TIME'];
  470. $arrData[$key]['update_at'] = $_SERVER['REQUEST_TIME'];
  471. }
  472. $result = Yii::$app->db->createCommand()->batchInsert($model::tableName(),['hid','album_id','img','title','zhu','create_at','update_at'],$arrData)->execute();
  473. if($result > 0)
  474. {
  475. return true;
  476. }
  477. }
  478. else
  479. {
  480. if($row->insert() == true) return true;
  481. }
  482. }
  483. public function HouseAlbumSave()
  484. {
  485. $post = Yii::$app->request->post();
  486. $model = new \common\models\HouseAlbum();
  487. $row = $model->Authenticator($post);
  488. if(is_array($row)) return $row;
  489. $arreditDefault = 0;
  490. //处理删除的信息
  491. if(!empty($post['delimg']))
  492. {
  493. $arreditDefault = \common\models\HouseAlbum::updateAll(['del'=>2,'update_at'=>$_SERVER['REQUEST_TIME']],['id'=>$post['delimg']]);
  494. }
  495. //处理修改的信息
  496. if(!empty($post['edittitle']))
  497. {
  498. $editContent = [];
  499. foreach ($post['editid'] as $key=>$val)
  500. {
  501. if(is_numeric($val))
  502. {
  503. $editContent[$val]['title'] = $post['edittitle'][$key];
  504. $editContent[$val]['zhu'] = $post['editzhuj'][$key];
  505. }
  506. }
  507. foreach($editContent as $key=>$val)
  508. {
  509. if(!empty($val))
  510. {
  511. $_model = clone $model;
  512. $findone = $_model::findOne($key);
  513. if($findone != null)
  514. {
  515. $findone->title =$val['title'];
  516. $findone->zhu =$val['zhu'];
  517. $arreditDefault = $findone->update();
  518. }
  519. }
  520. }
  521. }
  522. //处理添加的信息
  523. if(!empty($_FILES['img']))
  524. {
  525. $inputArr = UploadFile::InstancesImgName('img',Yii::$app->params['img_url']['housealbum']);
  526. if(is_array($inputArr))
  527. {
  528. //水印处理
  529. // if(Yii::$app->request->post('thumb_watermark') == 1)
  530. // {
  531. // $ImgSet = new SetUploadImg();
  532. // $ImgSet->SetImgWatermark($inputArr,Yii::$app->params['img_url']['housealbum']);
  533. // }
  534. //压缩图片
  535. // $compressParams = [];
  536. // $compressParams['data']['imgname'] = $inputArr;;
  537. // $compressParams['data']['url'] = Yii::$app->params['img_url']['housealbum'];
  538. // $compressParams['data']['source'] =$row->album_id.'-楼盘相册@修改';
  539. // $this->onCompress($compressParams);
  540. $arrData = [];
  541. foreach($inputArr as $key=>$val)
  542. {
  543. $arrData[$key]['hid'] = $row->hid;
  544. $arrData[$key]['album_id'] = $row->album_id;
  545. $arrData[$key]['img'] = $val;
  546. $arrData[$key]['title'] = Yii::$app->request->post('imginput')[$key];
  547. $arrData[$key]['zhu'] = Yii::$app->request->post('editzhux')[$key];
  548. $arrData[$key]['create_at'] = $_SERVER['REQUEST_TIME'];
  549. $arrData[$key]['update_at'] = $_SERVER['REQUEST_TIME'];
  550. }
  551. $arreditDefault = Yii::$app->db->createCommand()->batchInsert($model::tableName(),['hid','album_id','img','title','zhu','create_at','update_at'],$arrData)->execute();
  552. }
  553. }
  554. if($post['album_idxxxx'] != $post['album_id'])
  555. {
  556. $arreditDefault = \common\models\HouseAlbum::updateAll(['album_id'=>$post['album_idxxxx'],'update_at'=>$_SERVER['REQUEST_TIME']],['hid'=>$post['hid'],'album_id'=>$post['album_id']]);
  557. }
  558. if($arreditDefault > 0) return true;
  559. return true;
  560. }
  561. public function AlbumStateSave($type)
  562. {
  563. $input = Yii::$app->request->post();
  564. switch ($type)
  565. {
  566. case '1':
  567. switch ($input['state'])
  568. {
  569. case 'Y':
  570. $arr = ['state'=>2,'update_at'=>$_SERVER['REQUEST_TIME']];
  571. break;
  572. case 'N':
  573. $arr = ['state'=>1,'update_at'=>$_SERVER['REQUEST_TIME']];
  574. break;
  575. default:
  576. return false;
  577. break;
  578. }
  579. break;
  580. case '2':
  581. $arr = ['del'=>2,'update_at'=>$_SERVER['REQUEST_TIME']];
  582. break;
  583. }
  584. $result = \common\models\HouseAlbum::updateAll($arr,['album_id'=>$input['album_id'],'hid'=>$input['hid'],'del'=>1]);
  585. if($result > 0) return true;
  586. }
  587. //添加楼盘户型逻辑
  588. public function HouseTypeCreate()
  589. {
  590. $model = new \common\models\HouseType();
  591. $input = Yii::$app->request->post();
  592. $row = $model->Authenticator($input);
  593. if (is_array($row)) return $row;
  594. $inputArr = UploadFile::InstancesImgName('img', Yii::$app->params['img_url']['housetype']);
  595. if (is_array($inputArr)) {
  596. //判断是否水印
  597. // if(!empty($input['thumb_watermark']) && $input['thumb_watermark'] == 1)
  598. // {
  599. // $ImgSet = new SetUploadImg();
  600. // $ImgSet->SetImgWatermark($inputArr, Yii::$app->params['img_url']['housetype']);
  601. // }
  602. //压缩图片
  603. // $compressParams = [];
  604. // $compressParams['data']['imgname'] = $inputArr;
  605. // $compressParams['data']['url'] = Yii::$app->params['img_url']['housetype'];
  606. // $compressParams['data']['source'] = $row->type_id.'-楼盘户型@添加';
  607. // $this->onCompress($compressParams);
  608. $arrData = [];
  609. foreach ($inputArr as $key => $val) {
  610. $arrData[$key]['hid'] = $row->hid;
  611. $arrData[$key]['type_id'] = $row->type_id;
  612. $arrData[$key]['img'] = $val;
  613. if(isset($input['title'][$key])) $arrData[$key]['title'] = $input['title'][$key];
  614. if(isset($input['area'][$key])) $arrData[$key]['area'] = $input['area'][$key];
  615. if(isset($input['indoor_info'][$key])) $arrData[$key]['indoor_info'] = $input['indoor_info'][$key];
  616. $arrData[$key]['create_at'] = $_SERVER['REQUEST_TIME'];
  617. $arrData[$key]['update_at'] = $_SERVER['REQUEST_TIME'];
  618. // $arrData[$key]['hot'] = $row->hot;
  619. }
  620. $result = Yii::$app->db->createCommand()->batchInsert($model::tableName(), ['hid', 'type_id', 'img', 'title','area','indoor_info', 'create_at', 'update_at'], $arrData)->execute();
  621. if ($result > 0) {
  622. return true;
  623. }
  624. }
  625. else
  626. {
  627. if($row->insert() == true) return true;
  628. }
  629. }
  630. public function HouseTypeSave()
  631. {
  632. $post = Yii::$app->request->post();
  633. $model = new \common\models\HouseType();
  634. $row = $model->Authenticator($post);
  635. if(is_array($row)) return $row;
  636. $arreditDefault = false;
  637. //处理删除的信息
  638. if(!empty($post['delimg']))
  639. {
  640. $result = \common\models\HouseType::updateAll(['del'=>2,'update_at'=>$_SERVER['REQUEST_TIME']],['id'=>$post['delimg']]);
  641. }
  642. //处理修改的信息
  643. if(!empty($post['editid']))
  644. {
  645. // p($post['editid']);
  646. $imgSaveArr = [];
  647. foreach ($post['editid'] as $key=>$val)
  648. {
  649. if($val == 'undefined')
  650. {
  651. $imgSaveArr['title'][] = $post['title'][$key];
  652. $imgSaveArr['indoor_info'][] = $post['indoor_info'][$key];
  653. $imgSaveArr['area'][] = $post['area'][$key];
  654. }else{
  655. $_model = clone $model;
  656. $findRow = $_model::findOne($val);
  657. if($findRow != null)
  658. {
  659. $findRow->title = $post['title'][$key];
  660. $findRow->indoor_info = $post['indoor_info'][$key];
  661. $findRow->area = $post['area'][$key];
  662. $result = $findRow->update(false);
  663. }
  664. }
  665. }
  666. }
  667. //处理添加的信息
  668. if(!empty($_FILES['img']))
  669. {
  670. $imgUrl = Yii::$app->params['img_url']['housetype'];
  671. $inputArr = UploadFile::InstancesImgName('img',$imgUrl);
  672. if(is_array($inputArr))
  673. {
  674. // if(!empty($post['thumb_watermark']) && $post['thumb_watermark'] == 1)
  675. // {
  676. // $ImgSet = new SetUploadImg();
  677. // $ImgSet->SetImgWatermark($inputArr,$imgUrl);
  678. // }
  679. //压缩图片
  680. // $compressParams = [];
  681. // $compressParams['data']['imgname'] = $inputArr;
  682. // $compressParams['data']['url'] = $imgUrl;
  683. // $compressParams['data']['source'] = $row->type_id.'-楼盘户型@修改';
  684. // $this->onCompress($compressParams);
  685. $arrData = [];
  686. foreach($inputArr as $key=>$val)
  687. {
  688. $arrData[$key]['hid'] = $row->hid;
  689. $arrData[$key]['type_id'] = $row->type_id;
  690. $arrData[$key]['img'] = $val;
  691. $arrData[$key]['title'] = $imgSaveArr['title'][$key];
  692. $arrData[$key]['area'] = $imgSaveArr['area'][$key];
  693. $arrData[$key]['indoor_info'] = $imgSaveArr['indoor_info'][$key];
  694. $arrData[$key]['create_at'] = $_SERVER['REQUEST_TIME'];
  695. $arrData[$key]['update_at'] = $_SERVER['REQUEST_TIME'];
  696. }
  697. $result = Yii::$app->db->createCommand()->batchInsert($model::tableName(), ['hid', 'type_id', 'img', 'title','area','indoor_info', 'create_at', 'update_at'], $arrData)->execute();
  698. }
  699. }
  700. if($post['huxing_id'] != $post['type_id'])
  701. {
  702. $result = \common\models\HouseType::updateAll(['type_id'=>$post['huxing_id'],'update_at'=>$_SERVER['REQUEST_TIME']],['type_id'=> $post['type_id'],'hid'=>$post['hid']]);
  703. }
  704. if($result > 0) return true;
  705. return true;
  706. }
  707. //楼盘户型的上架下架
  708. public function HouseTypeStateSave($type)
  709. {
  710. $input = Yii::$app->request->post();
  711. switch ($type)
  712. {
  713. case '1':
  714. switch ($input['state'])
  715. {
  716. case 'Y':
  717. $arr = ['state'=>2,'update_at'=>$_SERVER['REQUEST_TIME']];
  718. break;
  719. case 'N':
  720. $arr = ['state'=>1,'update_at'=>$_SERVER['REQUEST_TIME']];
  721. break;
  722. default:
  723. return false;
  724. break;
  725. }
  726. break;
  727. case '2':
  728. $arr = ['del'=>2,'update_at'=>$_SERVER['REQUEST_TIME']];
  729. break;
  730. default:
  731. return false;
  732. break;
  733. }
  734. $result = \common\models\HouseType::updateAll($arr,['type_id'=>$input['type_id'],'hid'=>$input['hid'],'del'=>1]);
  735. if($result > 0) return true;
  736. }
  737. public function HousePriceRecordadd($input)
  738. {
  739. $model = new \common\models\HousePriceRecord();
  740. $priceModel = $model->Authenticator($input);
  741. if(is_array($priceModel)) return $priceModel;
  742. $housemodel = new \common\models\House();
  743. $houserRow = $housemodel->FindById($priceModel->hid);
  744. $Transaction = Yii::$app->db->beginTransaction();
  745. $houserRow->sale_price = $priceModel->price;
  746. $houserRow->update_at = $_SERVER['REQUEST_TIME'];
  747. $add = $priceModel->insert();
  748. $save = $houserRow->update(false);
  749. if($add == true && $save == true)
  750. {
  751. $Transaction->commit();
  752. return true;
  753. }
  754. $Transaction->rollBack();
  755. }
  756. public function HousePriceRecordSave($input)
  757. {
  758. $model = new \common\models\HousePriceRecord();
  759. $priceModel = $model->Authenticator($input);
  760. if(is_array($priceModel)) return $priceModel;
  761. $row = $model->FindById($input['id']);
  762. if($row != null)
  763. {
  764. $save = \backend\base\Help::SetAttr($input,$priceModel,$row);
  765. if($save->update() == true) return true;
  766. }
  767. }
  768. public function HousePriceDelete($input)
  769. {
  770. // $model = new \common\models\HousePriceRecord();
  771. foreach ($input['id'] as $val)
  772. {
  773. if(!is_numeric($val)) return false;
  774. }
  775. $del = \common\models\HousePriceRecord::updateAll(['del'=>2,'update_at'=>$_SERVER['REQUEST_TIME']],['id'=>$input['id']]);
  776. if($del > 0) return true;
  777. }
  778. //压缩图片
  779. private function onCompress($data)
  780. {
  781. $model = new \backend\event\TinifyEvent();
  782. $model->CompressImg($data);
  783. }
  784. }