BuildingController.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2017/7/24
  6. * Time: 11:37
  7. */
  8. namespace company\controllers;
  9. use common\library\ZM_Geohash;
  10. use yii\base\Controller;
  11. use yii;
  12. use yii\filters\AccessControl;
  13. use common\models\Building;
  14. use yii\data\Pagination;
  15. use common\models\Manager;
  16. use common\models\Designer;
  17. use common\library\LMUploadFile;
  18. use yii\web\UploadedFile;
  19. use common\models\ImageSource;
  20. use common\models\Appointment;
  21. class BuildingController extends Controller{
  22. public function behaviors()
  23. {
  24. return [
  25. 'access' => [
  26. 'class' => AccessControl::className(),
  27. 'rules' => [
  28. [
  29. 'actions' => [],
  30. 'allow' => true,
  31. 'roles' => ['@'],
  32. ],
  33. ],
  34. ],
  35. ];
  36. }
  37. //新加板样房、 工地
  38. public static function add_building(){
  39. $model = new Building();
  40. if($model->load(Yii::$app->request->get())){
  41. $opening_begin = strtotime(Yii::$app->request->get('opening_begin'));
  42. $opening_end = strtotime(Yii::$app->request->get('opening_end'));
  43. if(!is_numeric($opening_begin)&&!is_numeric($opening_end)){
  44. $opening_begin = strtotime($opening_begin);
  45. $opening_end = strtotime($opening_end);
  46. }
  47. $pickup_address_coordinate = Yii::$app->request->get('pickup_address_coordinate');//地址坐标
  48. $url ="http://restapi.amap.com/v3/geocode/regeo?key=9176f3987ffff3aaadfe2af13a2fccdb&location={$pickup_address_coordinate}&poitype=&radius=&extensions=base&batch=false&roadlevel=";
  49. $ch = curl_init();
  50. $timeout = 5;
  51. curl_setopt($ch, CURLOPT_URL, $url);
  52. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  53. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  54. $html = curl_exec($ch);
  55. curl_close($ch);
  56. $html = json_decode($html);
  57. if($html->info == "OK")
  58. {
  59. if($html->regeocode->addressComponent->adcode != Yii::$app->request->get("Building")['district'] && $html->regeocode->addressComponent->adcode !=Yii::$app->request->get("Building")['city']){
  60. $result=['sign'=>1,'msg'=>"您选择的地区和地图的坐标地点不符合"];
  61. return json_encode($result);
  62. }
  63. }
  64. $arr = explode(',',$pickup_address_coordinate);
  65. $living_room = Yii::$app->request->get('living_room');//客厅照片
  66. $master_bedroom = Yii::$app->request->get('master_bedroom');//主卧照片
  67. $portion = Yii::$app->request->get('portion');//局部美图
  68. $portion2 = Yii::$app->request->get('portion2');//局部美图2
  69. $portion3 = Yii::$app->request->get('portion3');//局部美图3
  70. $portion4 = Yii::$app->request->get('portion4');//局部美图4
  71. $portion5 = Yii::$app->request->get('portion5');//局部美图5
  72. $build = Yii::$app->request->get('build');//施工图
  73. $build2 = Yii::$app->request->get('build2');//施工图
  74. $flat = Yii::$app->request->get('flat');//平面图
  75. $model->longitude = isset($arr[0])?$arr[0]:"";
  76. $model->latitude = isset($arr[1])?$arr[1]:"";
  77. if(!empty($model->longitude)&&!empty($model->latitude))
  78. {
  79. $geohash = new ZM_Geohash();
  80. $geohash->init_codingMap();
  81. $model->hashcode =$geohash->encode($model->latitude,$model->longitude);
  82. }
  83. $model->uid = Yii::$app->user->id;
  84. $model->opening_begin = $opening_begin;
  85. $model->opening_end = $opening_end;
  86. $model->created_at = time();
  87. $model->updated_at = time();
  88. $model->status = Building::STATUS_REVIEW;
  89. //客厅照片
  90. if($model->validate()&&$model->save()){
  91. if(!empty($living_room)){
  92. $living_room_image = new ImageSource();
  93. $living_room_image->topid = $model->id;
  94. $living_room_image->type = ImageSource::TYPE_LIVING_ROOM;
  95. $living_room_image->pic = isset($living_room)?$living_room:"";
  96. $living_room_image->status = ImageSource::STATUS_YES;
  97. $living_room_image->created_at = time();
  98. $living_room_image->updated_at = time();
  99. if($living_room_image->validate()&&$living_room_image->save()){
  100. $result=['sign'=>0,'msg'=>'成功'];
  101. }else{
  102. $result=['sign'=>4000,'msg'=>'失败,客厅照片'];
  103. return json_encode($result);
  104. }
  105. }
  106. //主卧照片
  107. if(!empty($master_bedroom)){
  108. $master_bedroom_image = new ImageSource();
  109. $master_bedroom_image->topid = $model->id;;
  110. $master_bedroom_image->type = ImageSource::TYPE_MASTER_BEDROOM;
  111. $master_bedroom_image->pic = isset($master_bedroom)?$master_bedroom:"";
  112. $master_bedroom_image->status = ImageSource::STATUS_YES;
  113. $master_bedroom_image->created_at = time();
  114. $master_bedroom_image->updated_at = time();
  115. if($master_bedroom_image->validate()&&$master_bedroom_image->save()){
  116. $result=['sign'=>0,'msg'=>'成功'];
  117. }else{
  118. $result=['sign'=>4000,'msg'=>'失败,主卧照片'];
  119. return json_encode($result);
  120. }
  121. }
  122. //局部美图
  123. if(!empty($portion)){
  124. $portion_image = new ImageSource();
  125. $portion_image->topid = $model->id;;
  126. $portion_image->type = ImageSource::TYPE_PORTION;
  127. $portion_image->pic = isset($portion)?$portion:"";
  128. $portion_image->status = ImageSource::STATUS_YES;
  129. $portion_image->created_at = time();
  130. $portion_image->updated_at = time();
  131. if($portion_image->validate()&&$portion_image->save()){
  132. $result=['sign'=>0,'msg'=>'成功'];
  133. }else{
  134. $result=['sign'=>4000,'msg'=>'失败,局部美图'];
  135. return json_encode($result);
  136. }
  137. }
  138. //局部美图2
  139. if(!empty($portion2)){
  140. $portion2_image = new ImageSource();
  141. $portion2_image->topid = $model->id;;
  142. $portion2_image->type = ImageSource::TYPE_PORTION2;
  143. $portion2_image->pic = isset($portion2)?$portion2:"";
  144. $portion2_image->status = ImageSource::STATUS_YES;
  145. $portion2_image->created_at = time();
  146. $portion2_image->updated_at = time();
  147. if($portion2_image->validate()&&$portion2_image->save()){
  148. $result=['sign'=>0,'msg'=>'成功'];
  149. }else{
  150. $result=['sign'=>4000,'msg'=>'失败,局部美图'];
  151. return json_encode($result);
  152. }
  153. }
  154. //局部美图3
  155. if(!empty($portion3)){
  156. $portion3_image = new ImageSource();
  157. $portion3_image->topid = $model->id;;
  158. $portion3_image->type = ImageSource::TYPE_PORTION3;
  159. $portion3_image->pic = isset($portion3)?$portion3:"";
  160. $portion3_image->status = ImageSource::STATUS_YES;
  161. $portion3_image->created_at = time();
  162. $portion3_image->updated_at = time();
  163. if($portion3_image->validate()&&$portion3_image->save()){
  164. $result=['sign'=>0,'msg'=>'成功'];
  165. }else{
  166. $result=['sign'=>4000,'msg'=>'失败,局部美图'];
  167. return json_encode($result);
  168. }
  169. }
  170. //局部美图4
  171. if(!empty($portion4)){
  172. $portion4_image = new ImageSource();
  173. $portion4_image->topid = $model->id;;
  174. $portion4_image->type = ImageSource::TYPE_PORTION4;
  175. $portion4_image->pic = isset($portion4)?$portion4:"";
  176. $portion4_image->status = ImageSource::STATUS_YES;
  177. $portion4_image->created_at = time();
  178. $portion4_image->updated_at = time();
  179. if($portion4_image->validate()&&$portion4_image->save()){
  180. $result=['sign'=>0,'msg'=>'成功'];
  181. }else{
  182. $result=['sign'=>4000,'msg'=>'失败,局部美图'];
  183. return json_encode($result);
  184. }
  185. }
  186. //局部美图5
  187. if(!empty($portion5)){
  188. $portion5_image = new ImageSource();
  189. $portion5_image->topid = $model->id;;
  190. $portion5_image->type = ImageSource::TYPE_PORTION5;
  191. $portion5_image->pic = isset($portion5)?$portion5:"";
  192. $portion5_image->status = ImageSource::STATUS_YES;
  193. $portion5_image->created_at = time();
  194. $portion5_image->updated_at = time();
  195. if($portion5_image->validate()&&$portion5_image->save()){
  196. $result=['sign'=>0,'msg'=>'成功'];
  197. }else{
  198. $result=['sign'=>4000,'msg'=>'失败,局部美图'];
  199. return json_encode($result);
  200. }
  201. }
  202. //施工图1
  203. if(!empty($build)){
  204. $build_image = new ImageSource();
  205. $build_image->topid = $model->id;;
  206. $build_image->type = ImageSource::TYPE_BUILD;
  207. $build_image->pic = isset($build)?$build:"";
  208. $build_image->status = ImageSource::STATUS_YES;
  209. $build_image->created_at = time();
  210. $build_image->updated_at = time();
  211. if($build_image->validate()&&$build_image->save()){
  212. $result=['sign'=>0,'msg'=>'成功'];
  213. }else{
  214. $result=['sign'=>4000,'msg'=>'失败,施工图'];
  215. return json_encode($result);
  216. }
  217. }
  218. //施工图2
  219. if(!empty($build2)){
  220. $build2_image = new ImageSource();
  221. $build2_image->topid = $model->id;;
  222. $build2_image->type = ImageSource::TYPE_BUILD2;
  223. $build2_image->pic = isset($build2)?$build2:"";
  224. $build2_image->status = ImageSource::STATUS_YES;
  225. $build2_image->created_at = time();
  226. $build2_image->updated_at = time();
  227. if($build2_image->validate()&&$build2_image->save()){
  228. $result=['sign'=>0,'msg'=>'成功'];
  229. }else{
  230. $result=['sign'=>4000,'msg'=>'失败,施工图'];
  231. return json_encode($result);
  232. }
  233. }
  234. //平面图
  235. if(!empty($flat)){
  236. $flat_image = new ImageSource();
  237. $flat_image->topid = $model->id;;
  238. $flat_image->type = ImageSource::TYPE_FLAT;
  239. $flat_image->pic = isset($flat)?$flat:"";
  240. $flat_image->status = ImageSource::STATUS_YES;
  241. $flat_image->created_at = time();
  242. $flat_image->updated_at = time();
  243. if($flat_image->validate()&&$flat_image->save()){
  244. $result=['sign'=>0,'msg'=>'成功'];
  245. }else{
  246. $result=['sign'=>4000,'msg'=>'失败,平面图'];
  247. return json_encode($result);
  248. }
  249. }
  250. $result=['sign'=>0,'msg'=>'发布成功'];
  251. return json_encode($result);
  252. }else{
  253. $result=['sign'=>4000,'msg'=>'添加失败'];
  254. return json_encode($result);
  255. }
  256. }else{
  257. $result=['sign'=>4000,'msg'=>'数据有误'];
  258. return json_encode($result);
  259. }
  260. }
  261. //更新板样房、 工地
  262. public static function update_building($id){
  263. if(empty($id)){
  264. $id = Yii::$app->request->get('topid');
  265. }
  266. $model = Building::find()->where('id=:id',[':id'=>$id])->one();
  267. if($model->load(Yii::$app->request->get())){
  268. $opening_begin = strtotime(Yii::$app->request->get('opening_begin'));
  269. $opening_end = strtotime(Yii::$app->request->get('opening_end'));
  270. $pickup_address_coordinate = Yii::$app->request->get('pickup_address_coordinate');//地址坐标
  271. $url ="http://restapi.amap.com/v3/geocode/regeo?key=9176f3987ffff3aaadfe2af13a2fccdb&location={$pickup_address_coordinate}&poitype=&radius=&extensions=base&batch=false&roadlevel=";
  272. $ch = curl_init();
  273. $timeout = 5;
  274. curl_setopt($ch, CURLOPT_URL, $url);
  275. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  276. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  277. $html = curl_exec($ch);
  278. curl_close($ch);
  279. $html = json_decode($html);
  280. if($html->info == "OK")
  281. {
  282. if($html->regeocode->addressComponent->adcode != Yii::$app->request->get("Building")['district'] && $html->regeocode->addressComponent->adcode !=Yii::$app->request->get("Building")['city']){
  283. $result=['sign'=>1,'msg'=>"您选择的地区和地图的坐标地点不符合"];
  284. return json_encode($result);
  285. }
  286. }
  287. $arr = explode(',',$pickup_address_coordinate);
  288. $model->latitude = isset($arr[1])?$arr[1]:"";
  289. $model->longitude = isset($arr[0])?$arr[0]:"";
  290. if(!empty($model->longitude)&&!empty($model->latitude))
  291. {
  292. $geohash = new ZM_Geohash();
  293. $geohash->init_codingMap();
  294. $model->hashcode =$geohash->encode($model->latitude,$model->longitude);
  295. }
  296. $living_room = Yii::$app->request->get('living_room');//客厅照片
  297. $master_bedroom = Yii::$app->request->get('master_bedroom');//主卧照片
  298. $portion = Yii::$app->request->get('portion');//局部美图
  299. $portion2 = Yii::$app->request->get('portion2');//局部美图2
  300. $portion3 = Yii::$app->request->get('portion3');//局部美图3
  301. $portion4 = Yii::$app->request->get('portion4');//局部美图4
  302. $portion5 = Yii::$app->request->get('portion5');//局部美图5
  303. $build = Yii::$app->request->get('build');//施工图
  304. $build2 = Yii::$app->request->get('build2');//施工图2
  305. $flat = Yii::$app->request->get('flat');//平面图
  306. $living_room_delete = Yii::$app->request->get('living_room_delete');
  307. $master_bedroom_delete = Yii::$app->request->get('master_bedroom_delete');
  308. $portion_delete = Yii::$app->request->get('portion_delete');
  309. $portion2_delete = Yii::$app->request->get('portion2_delete');
  310. $portion3_delete = Yii::$app->request->get('portion3_delete');
  311. $portion4_delete = Yii::$app->request->get('portion4_delete');
  312. $portion5_delete = Yii::$app->request->get('portion5_delete');
  313. $build_delete = Yii::$app->request->get('build_delete');
  314. $build2_delete = Yii::$app->request->get('build2_delete');
  315. $flat_delete = Yii::$app->request->get('flat_delete');
  316. $model->uid = Yii::$app->user->id;
  317. $model->opening_begin = $opening_begin;
  318. $model->opening_end = $opening_end;
  319. $model->created_at = time();
  320. $model->updated_at = time();
  321. $model->status = Building::STATUS_REVIEW;
  322. //客厅照片
  323. if($model->validate()&&$model->save()){
  324. if($living_room_delete == -1)
  325. {
  326. $living_room_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_LIVING_ROOM,':status'=>ImageSource::STATUS_YES])->one();
  327. $living_room_image->status = ImageSource::STATUS_NO;
  328. $living_room_image->updated_at = time();
  329. $living_room_image->save();
  330. }
  331. if(!empty($living_room)){
  332. $living_room_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_LIVING_ROOM,':status'=>ImageSource::STATUS_YES])->one();
  333. if(empty($living_room_image)){
  334. $living_room_image = new ImageSource();
  335. $living_room_image->created_at = time();
  336. }
  337. $living_room_image->topid = $model->id;
  338. $living_room_image->type = ImageSource::TYPE_LIVING_ROOM;
  339. $living_room_image->pic = isset($living_room)?$living_room:"";
  340. $living_room_image->status = ImageSource::STATUS_YES;
  341. $living_room_image->updated_at = time();
  342. if($living_room_image->validate()&&$living_room_image->save()){
  343. $result=['sign'=>0,'msg'=>'成功'];
  344. }else{
  345. $result=['sign'=>1,'msg'=>'失败,客厅照片'];
  346. return json_encode($result);
  347. }
  348. }
  349. if($master_bedroom_delete == -1)
  350. {
  351. $master_bedroom_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_MASTER_BEDROOM,':status'=>ImageSource::STATUS_YES])->one();
  352. $master_bedroom_image->status = ImageSource::STATUS_NO;
  353. $master_bedroom_image->updated_at = time();
  354. $master_bedroom_image->save();
  355. }
  356. //主卧照片
  357. if(!empty($master_bedroom)){
  358. $master_bedroom_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_MASTER_BEDROOM,':status'=>ImageSource::STATUS_YES])->one();
  359. if(empty($master_bedroom_image)){
  360. $master_bedroom_image = new ImageSource();
  361. $master_bedroom_image->created_at = time();
  362. }
  363. $master_bedroom_image->topid = $model->id;;
  364. $master_bedroom_image->type = ImageSource::TYPE_MASTER_BEDROOM;
  365. $master_bedroom_image->pic = isset($master_bedroom)?$master_bedroom:"";
  366. $master_bedroom_image->status = ImageSource::STATUS_YES;
  367. $master_bedroom_image->updated_at = time();
  368. if($master_bedroom_image->validate()&&$master_bedroom_image->save()){
  369. $result=['sign'=>0,'msg'=>'成功'];
  370. }else{
  371. $result=['sign'=>1,'msg'=>'失败,主卧照片'];
  372. return json_encode($result);
  373. }
  374. }
  375. if($portion_delete == -1)
  376. {
  377. $portion_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION,':status'=>ImageSource::STATUS_YES])->one();
  378. $portion_image->status = ImageSource::STATUS_NO;
  379. $portion_image->updated_at = time();
  380. $portion_image->save();
  381. }
  382. //局部美图
  383. if(!empty($portion)){
  384. $portion_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION,':status'=>ImageSource::STATUS_YES])->one();
  385. if(empty($portion_image)){
  386. $portion_image = new ImageSource();
  387. $portion_image->created_at = time();
  388. }
  389. $portion_image->topid = $model->id;;
  390. $portion_image->type = ImageSource::TYPE_PORTION;
  391. $portion_image->pic = isset($portion)?$portion:"";
  392. $portion_image->status = ImageSource::STATUS_YES;
  393. $portion_image->updated_at = time();
  394. if($portion_image->validate()&&$portion_image->save()){
  395. $result=['sign'=>0,'msg'=>'成功'];
  396. }else{
  397. $result=['sign'=>1,'msg'=>'失败,局部美图'];
  398. return json_encode($result);
  399. }
  400. }
  401. if($portion2_delete == -1)
  402. {
  403. $portion2_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION2,':status'=>ImageSource::STATUS_YES])->one();
  404. $portion2_image->status = ImageSource::STATUS_NO;
  405. $portion2_image->updated_at = time();
  406. $portion2_image->save();
  407. }
  408. //局部美图2
  409. if(!empty($portion2)){
  410. $portion2_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION2,':status'=>ImageSource::STATUS_YES])->one();
  411. if(empty($portion2_image)){
  412. $portion2_image = new ImageSource();
  413. $portion2_image->created_at = time();
  414. }
  415. $portion2_image->topid = $model->id;;
  416. $portion2_image->type = ImageSource::TYPE_PORTION2;
  417. $portion2_image->pic = isset($portion2)?$portion2:"";
  418. $portion2_image->status = ImageSource::STATUS_YES;
  419. $portion2_image->updated_at = time();
  420. if($portion2_image->validate()&&$portion2_image->save()){
  421. $result=['sign'=>0,'msg'=>'成功'];
  422. }else{
  423. $result=['sign'=>1,'msg'=>'失败,局部美图'];
  424. return json_encode($result);
  425. }
  426. }
  427. if($portion3_delete == -1)
  428. {
  429. $portion3_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION3,':status'=>ImageSource::STATUS_YES])->one();
  430. $portion3_image->status = ImageSource::STATUS_NO;
  431. $portion3_image->updated_at = time();
  432. $portion3_image->save();
  433. }
  434. //局部美图3
  435. if(!empty($portion3)){
  436. $portion3_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION3,':status'=>ImageSource::STATUS_YES])->one();
  437. if(empty($portion3_image)){
  438. $portion3_image = new ImageSource();
  439. $portion3_image->created_at = time();
  440. }
  441. $portion3_image->topid = $model->id;;
  442. $portion3_image->type = ImageSource::TYPE_PORTION3;
  443. $portion3_image->pic = isset($portion3)?$portion3:"";
  444. $portion3_image->status = ImageSource::STATUS_YES;
  445. $portion3_image->updated_at = time();
  446. if($portion3_image->validate()&&$portion3_image->save()){
  447. $result=['sign'=>0,'msg'=>'成功'];
  448. }else{
  449. $result=['sign'=>1,'msg'=>'失败,局部美图'];
  450. return json_encode($result);
  451. }
  452. }
  453. if($portion4_delete == -1)
  454. {
  455. $portion4_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION4,':status'=>ImageSource::STATUS_YES])->one();
  456. $portion4_image->status = ImageSource::STATUS_NO;
  457. $portion4_image->updated_at = time();
  458. $portion4_image->save();
  459. }
  460. //局部美图4
  461. if(!empty($portion4)){
  462. $portion4_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION4,':status'=>ImageSource::STATUS_YES])->one();
  463. if(empty($portion4_image)){
  464. $portion4_image = new ImageSource();
  465. $portion4_image->created_at = time();
  466. }
  467. $portion4_image->topid = $model->id;;
  468. $portion4_image->type = ImageSource::TYPE_PORTION4;
  469. $portion4_image->pic = isset($portion4)?$portion4:"";
  470. $portion4_image->status = ImageSource::STATUS_YES;
  471. $portion4_image->updated_at = time();
  472. if($portion4_image->validate()&&$portion4_image->save()){
  473. $result=['sign'=>0,'msg'=>'成功'];
  474. }else{
  475. $result=['sign'=>1,'msg'=>'失败,局部美图'];
  476. return json_encode($result);
  477. }
  478. }
  479. if($portion5_delete == -1)
  480. {
  481. $portion5_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION5,':status'=>ImageSource::STATUS_YES])->one();
  482. $portion5_image->status = ImageSource::STATUS_NO;
  483. $portion5_image->updated_at = time();
  484. $portion5_image->save();
  485. }
  486. //局部美图5
  487. if(!empty($portion5)){
  488. $portion5_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION5,':status'=>ImageSource::STATUS_YES])->one();
  489. if(empty($portion5_image)){
  490. $portion5_image = new ImageSource();
  491. $portion5_image->created_at = time();
  492. }
  493. $portion5_image->topid = $model->id;;
  494. $portion5_image->type = ImageSource::TYPE_PORTION5;
  495. $portion5_image->pic = isset($portion5)?$portion5:"";
  496. $portion5_image->status = ImageSource::STATUS_YES;
  497. $portion5_image->updated_at = time();
  498. if($portion5_image->validate()&&$portion5_image->save()){
  499. $result=['sign'=>0,'msg'=>'成功'];
  500. }else{
  501. $result=['sign'=>1,'msg'=>'失败,局部美图'];
  502. return json_encode($result);
  503. }
  504. }
  505. if($build_delete == -1)
  506. {
  507. $build_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_BUILD,':status'=>ImageSource::STATUS_YES])->one();
  508. $build_image->status = ImageSource::STATUS_NO;
  509. $build_image->updated_at = time();
  510. $build_image->save();
  511. }
  512. //施工图
  513. if(!empty($build)){
  514. $build_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_BUILD,':status'=>ImageSource::STATUS_YES])->one();
  515. if(empty($build_image)){
  516. $build_image = new ImageSource();
  517. $build_image->created_at = time();
  518. }
  519. $build_image->topid = $model->id;;
  520. $build_image->type = ImageSource::TYPE_BUILD;
  521. $build_image->pic = isset($build)?$build:"";
  522. $build_image->status = ImageSource::STATUS_YES;
  523. $build_image->updated_at = time();
  524. if($build_image->validate()&&$build_image->save()){
  525. $result=['sign'=>0,'msg'=>'成功'];
  526. }else{
  527. $result=['sign'=>1,'msg'=>'失败,施工图'];
  528. return json_encode($result);
  529. }
  530. }
  531. if($build2_delete == -1)
  532. {
  533. $build2_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_BUILD2,':status'=>ImageSource::STATUS_YES])->one();
  534. $build2_image->status = ImageSource::STATUS_NO;
  535. $build2_image->updated_at = time();
  536. $build2_image->save();
  537. }
  538. //施工图2
  539. if(!empty($build2)){
  540. $build2_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_BUILD2,':status'=>ImageSource::STATUS_YES])->one();
  541. if(empty($build2_image)){
  542. $build2_image = new ImageSource();
  543. $build2_image->created_at = time();
  544. }
  545. $build2_image->topid = $model->id;;
  546. $build2_image->type = ImageSource::TYPE_BUILD2;
  547. $build2_image->pic = isset($build2)?$build2:"";
  548. $build2_image->status = ImageSource::STATUS_YES;
  549. $build2_image->updated_at = time();
  550. if($build2_image->validate()&&$build2_image->save()){
  551. $result=['sign'=>0,'msg'=>'成功'];
  552. }else{
  553. $result=['sign'=>1,'msg'=>'失败,施工图2'];
  554. return json_encode($result);
  555. }
  556. }
  557. if($flat_delete == -1)
  558. {
  559. $flat_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_FLAT,':status'=>ImageSource::STATUS_YES])->one();
  560. $flat_image->status = ImageSource::STATUS_NO;
  561. $flat_image->updated_at = time();
  562. $flat_image->save();
  563. }
  564. //平面图
  565. if(!empty($flat)){
  566. $flat_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_FLAT,':status'=>ImageSource::STATUS_YES])->one();
  567. if(empty($flat_image)){
  568. $flat_image = new ImageSource();
  569. $flat_image->created_at = time();
  570. }
  571. $flat_image->topid = $model->id;;
  572. $flat_image->type = ImageSource::TYPE_FLAT;
  573. $flat_image->pic = isset($flat)?$flat:"";
  574. $flat_image->status = ImageSource::STATUS_YES;
  575. $flat_image->updated_at = time();
  576. if($flat_image->validate()&&$flat_image->save()){
  577. $result=['sign'=>0,'msg'=>'成功'];
  578. }else{
  579. $result=['sign'=>1,'msg'=>'失败,平面图'];
  580. return json_encode($result);
  581. }
  582. }
  583. $result=['sign'=>0,'msg'=>'成功'];
  584. return json_encode($result);
  585. }else{
  586. $result=['sign'=>4000,'msg'=>'有问题'];
  587. return json_encode($result);
  588. }
  589. }else{
  590. $result=['sign'=>4000,'msg'=>'数据有误'];
  591. return json_encode($result); }
  592. }
  593. //删除板样房、 工地
  594. public static function delede_building($id){
  595. $model = Building::find()->where('id=:id',[':id'=>$id])->one();
  596. // if(!empty($model)){
  597. // $image_model = ImageSource::find()
  598. // ->where('topid=:topid and (type=:type1 or type=:type2 or type=:type3 or type=:type4)',
  599. // [
  600. // ':topid'=>$model->id,
  601. // ':type1'=>ImageSource::TYPE_LIVING_ROOM,
  602. // ':type1'=>ImageSource::TYPE_MASTER_BEDROOM,
  603. // ':type1'=>ImageSource::TYPE_PORTION,
  604. // ':type1'=>ImageSource::TYPE_FLAT,
  605. // ])->all();
  606. // }
  607. $model->posted = Building::POSTED_DELETE;
  608. $model->updated_at = time();
  609. if($model->validate()&&$model->save()){
  610. $result=['sign'=>1,'msg'=>'删除成功'];
  611. }else{
  612. var_dump($model->getErrors());
  613. $result=['sign'=>4000,'msg'=>'数据有误'];
  614. }
  615. return json_encode($result);
  616. }
  617. //发布板样房、 工地
  618. public static function delede_posted($id){
  619. $model = Building::find()->where('id=:id and posted=:posted',[':id'=>$id,':posted'=>Building::POSTED_NO])->one();
  620. $model->posted = Building::POSTED_YES;
  621. $model->updated_at = time();
  622. if($model->validate()&&$model->save()){
  623. $result=['sign'=>1,'msg'=>'发布成功'];
  624. }else{
  625. var_dump($model->getErrors());
  626. $result=['sign'=>4000,'msg'=>'数据有误'];
  627. }
  628. return json_encode($result);
  629. }
  630. //停止板样房、 工地
  631. public static function stop_posted($id){
  632. $model = Building::find()->where('id=:id and posted=:posted',[':id'=>$id,':posted'=>Building::POSTED_YES])->one();
  633. $model->posted = Building::POSTED_NO;
  634. $model->updated_at = time();
  635. if($model->validate()&&$model->save()){
  636. $result=['sign'=>1,'msg'=>'停止成功'];
  637. }else{
  638. var_dump($model->getErrors());
  639. $result=['sign'=>4000,'msg'=>'数据有误'];
  640. }
  641. return json_encode($result);
  642. }
  643. }