CompanyBuildingController.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  1. <?php
  2. namespace api\modules\v1\controllers;
  3. use common\library\ZM_Geohash;
  4. use common\models\Appointment;
  5. use common\models\Area;
  6. use common\models\Building;
  7. use common\models\Comment;
  8. use common\models\Designer;
  9. use common\models\ImageSource;
  10. use common\models\Manager;
  11. use common\models\Reply;
  12. use common\models\UserCompany;
  13. use common\models\UserInfo;
  14. use yii\rest\ActiveController;
  15. use common\library\Apireturn;
  16. use yii\helpers\ArrayHelper;
  17. use yii\filters\auth\QueryParamAuth;
  18. use yii;
  19. class CompanyBuildingController extends ActiveController
  20. {
  21. public static $stage_arr = array('开工大吉','拆改','水电','泥水','木工','油漆','验收');
  22. public static $layout_arr = array('一房','二房','三房','四房','五房','复式','楼中楼','别墅','办公室','店面','单身公寓','自建房','跃层式');
  23. public static $style_arr =array('北欧','欧式','现代简约','中式','新中式','美式乡村','田园','地中海','东南亚','时尚混搭','简欧','新古典','雅致主义','日韩式','工业风','港式');
  24. public static $pattern_arr = array('清包','半包','全包');
  25. public $modelClass = 'common\models';
  26. const DISPLAY = 10;//显示条数
  27. public function behaviors()
  28. {
  29. return ArrayHelper::merge(parent::behaviors(), [
  30. 'authenticator' => [
  31. 'class' => QueryParamAuth::className(),
  32. 'tokenParam' => "token",//access-token修改为token
  33. 'optional' => [//不需要认证方法名 array
  34. ],
  35. ]
  36. ]);
  37. }
  38. /**
  39. * 添加样板房
  40. */
  41. public function actionAddRoom()
  42. {
  43. $post = Yii::$app->request->post();
  44. if(empty($post['name']) || empty($post['acreage']) || empty($post['budget']) || empty($post['opening_begin']) || empty($post['opening_end']) || empty($post['layout']) || empty($post['style']))
  45. return Apireturn::sent(0,'请填写完整信息',200);
  46. $str_opening_begin = strtotime($post['opening_begin']);
  47. $str_opening_end = strtotime($post['opening_end']);
  48. if($str_opening_begin > $str_opening_end)
  49. return Apireturn::sent(0,'可约时间不能大于结束时间',200);
  50. if(empty($post['designer_id']) || empty($post['manager_id']))
  51. return Apireturn::sent(0,'请选择设计师和项目经理',200);
  52. if(empty($post['province']) || empty($post['city']) || empty($post['district']) )
  53. return Apireturn::sent(0,'请选择地区',200);
  54. if(empty($post['address']))
  55. return Apireturn::sent(0,'请输入详细地址',200);
  56. if(empty($post['longitude']) || empty($post['latitude']))
  57. return Apireturn::sent(0,'缺少经纬度',200);
  58. $model = new Building();
  59. $model->uid = Yii::$app->user->id;
  60. $model->name = $post['name'];
  61. $model->type = Building::TYPE_HOUSE;
  62. $model->latitude = $post['latitude'];
  63. $model->longitude = $post['longitude'];
  64. if(!empty($model->longitude)&&!empty($model->latitude)) {
  65. $geohash = new ZM_Geohash();
  66. $geohash->init_codingMap();
  67. $model->hashcode = $geohash->encode($model->latitude, $model->longitude);
  68. }
  69. $model->province = $post['province'];
  70. $model->city = $post['city'];
  71. $model->district = $post['district'];
  72. $model->address = $post['address'];
  73. $model->created_at = time();
  74. $model->updated_at = time();
  75. $model->status = Building::STATUS_SUCCESS;
  76. $model->acreage = $post['acreage'];
  77. $model->budget = $post['budget'];
  78. $model->layout = $post['layout'];
  79. $model->style = $post['style'];
  80. $model->opening_begin =$str_opening_begin;
  81. $model->opening_end = $str_opening_end;
  82. $model->manager_id = $post['manager_id'];
  83. $model->designer_id = $post['designer_id'];
  84. $model->posted = Building::POSTED_YES;
  85. if($model->save())
  86. {
  87. $this->uploadBuildingImg($model->id,$post);
  88. return Apireturn::sent(1,'添加样板房成功',200);
  89. }else{
  90. return Apireturn::sent(0,'添加样板房失败',200);
  91. }
  92. }
  93. /**
  94. * 查看样板房
  95. */
  96. public function actionCheckRoom()
  97. {
  98. $id = Yii::$app->request->post('id');
  99. if(empty($id))
  100. return Apireturn::sent(0,'非法操作',200);
  101. $info = Building::find()->where(['id'=>$id,'uid'=>Yii::$app->user->id])->select("id,name,latitude,longitude,province,city,district,address,layout,acreage,opening_begin,opening_end,budget,style,manager_id,designer_id")->one();
  102. if(empty($info))
  103. return Apireturn::sent(0,'找不到该样板房',200);
  104. $arr = array();
  105. foreach ($info->getOldAttributes() as $key =>$value)
  106. {
  107. $arr[$key] = $value;
  108. }
  109. //设计师详情
  110. $data['designer'] = array();
  111. if(!empty($info->designer))
  112. {
  113. $arr['designer']['id'] = $info->designer->id;
  114. $arr['designer']['realname'] = $info->designer->realname;
  115. }
  116. //项目经理详情
  117. $data['manager'] = array();
  118. if(!empty($info->manager))
  119. {
  120. $arr['manager']['id'] = $info->manager->id;
  121. $arr['manager']['realname'] = $info->manager->realname;
  122. }
  123. $arr['living_room'] = $info->living ? $info->living->pic : "" ;
  124. $arr['master_bedroom'] = $info->master ? $info->master->pic : "" ;
  125. $arr['portion'] = $info->portion ? $info->portion->pic : "" ;
  126. $arr['portion2'] = $info->portion2 ? $info->portion2->pic : "" ;
  127. $arr['portion3'] = $info->portion3 ? $info->portion3->pic : "" ;
  128. $arr['portion4'] = $info->portion4 ? $info->portion4->pic : "" ;
  129. $arr['portion5'] = $info->portion5 ? $info->portion5->pic : "" ;
  130. $arr['flat'] = $info->flat ? $info->flat->pic : "" ;
  131. $arr['province_name'] = !empty($info->province) ? Area::queryCity($info->province) : "";
  132. $arr['city_name'] = !empty($info->city) ? Area::queryCity($info->city) : "";
  133. $arr['district_name'] = !empty($info->district) ? Area::queryCity($info->district) : "";
  134. return Apireturn::sent(1,'success',200,$arr);
  135. }
  136. /**
  137. * 编辑样板房
  138. */
  139. public function actionEditRoom()
  140. {
  141. $post = Yii::$app->request->post();
  142. if(empty($post['id']))
  143. return Apireturn::sent(0,'缺少id',200);
  144. $model = Building::find()->where(['id'=>$post['id'],'uid'=>Yii::$app->user->id])->one();
  145. if(empty($model))
  146. return Apireturn::sent(0,'找不到该样板房',200);
  147. if(empty($post['name']) || empty($post['acreage']) || empty($post['budget']) || empty($post['opening_begin']) || empty($post['opening_end']) || empty($post['layout']) || empty($post['style']))
  148. return Apireturn::sent(0,'请填写完整信息',200);
  149. $str_opening_begin = strtotime($post['opening_begin']);
  150. $str_opening_end = strtotime($post['opening_end']);
  151. if($str_opening_begin > $str_opening_end)
  152. return Apireturn::sent(0,'可约时间不能大于结束时间',200);
  153. if(empty($post['designer_id']) || empty($post['manager_id']))
  154. return Apireturn::sent(0,'请选择设计师和项目经理',200);
  155. if(empty($post['province']) || empty($post['city']) || empty($post['district']) )
  156. return Apireturn::sent(0,'请选择地区',200);
  157. if(empty($post['address']))
  158. return Apireturn::sent(0,'请输入详细地址',200);
  159. if(empty($post['longitude']) || empty($post['latitude']))
  160. return Apireturn::sent(0,'缺少经纬度',200);
  161. if(!empty($model->longitude)&&!empty($model->latitude)) {
  162. $geohash = new ZM_Geohash();
  163. $geohash->init_codingMap();
  164. $model->hashcode = $geohash->encode($model->latitude, $model->longitude);
  165. }
  166. $model->name = $post['name'];
  167. $model->latitude = $post['latitude'];
  168. $model->longitude = $post['longitude'];
  169. $model->province = $post['province'];
  170. $model->city = $post['city'];
  171. $model->district = $post['district'];
  172. $model->address = $post['address'];
  173. $model->updated_at = time();
  174. $model->acreage = $post['acreage'];
  175. $model->budget = $post['budget'];
  176. $model->layout = $post['layout'];
  177. $model->style = $post['style'];
  178. $model->opening_begin =$str_opening_begin;
  179. $model->opening_end = $str_opening_end;
  180. $model->manager_id = $post['manager_id'];
  181. $model->designer_id = $post['designer_id'];
  182. if($model->save())
  183. {
  184. $this->uploadBuildingImg($model->id,$post,'edit');
  185. return Apireturn::sent(1,'修改样板房成功',200);
  186. }else{
  187. return Apireturn::sent(0,'修改样板房失败',200);
  188. }
  189. }
  190. /**
  191. * 添加工地
  192. */
  193. public function actionAddWork()
  194. {
  195. $post = Yii::$app->request->post();
  196. if(empty($post['name']) || empty($post['acreage']) || empty($post['budget']) || empty($post['opening_begin']) || empty($post['opening_end']) || empty($post['layout']) || empty($post['style']) || empty($post['stage']) || empty($post['pattern']) )
  197. return Apireturn::sent(0,'请填写完整信息',200);
  198. $str_opening_begin = strtotime($post['opening_begin']);
  199. $str_opening_end = strtotime($post['opening_end']);
  200. if($str_opening_begin > $str_opening_end)
  201. return Apireturn::sent(0,'可约时间不能大于结束时间',200);
  202. if(empty($post['designer_id']) || empty($post['manager_id']))
  203. return Apireturn::sent(0,'请选择设计师和项目经理',200);
  204. if(empty($post['province']) || empty($post['city']) || empty($post['district']) )
  205. return Apireturn::sent(0,'请选择地区',200);
  206. if(empty($post['address']))
  207. return Apireturn::sent(0,'请输入详细地址',200);
  208. if(empty($post['longitude']) || empty($post['latitude']))
  209. return Apireturn::sent(0,'缺少经纬度',200);
  210. $model = new Building();
  211. $model->uid = Yii::$app->user->id;
  212. $model->name = $post['name'];
  213. $model->type = Building::TYPE_SITE;
  214. $model->latitude = $post['latitude'];
  215. $model->longitude = $post['longitude'];
  216. if(!empty($model->longitude)&&!empty($model->latitude)) {
  217. $geohash = new ZM_Geohash();
  218. $geohash->init_codingMap();
  219. $model->hashcode = $geohash->encode($model->latitude, $model->longitude);
  220. }
  221. $model->stage = $post['stage'];
  222. $model->pattern = $post['pattern'];
  223. $model->province = $post['province'];
  224. $model->city = $post['city'];
  225. $model->district = $post['district'];
  226. $model->address = $post['address'];
  227. $model->created_at = time();
  228. $model->updated_at = time();
  229. $model->status = Building::STATUS_SUCCESS;
  230. $model->acreage = $post['acreage'];
  231. $model->budget = $post['budget'];
  232. $model->layout = $post['layout'];
  233. $model->style = $post['style'];
  234. $model->opening_begin =$str_opening_begin;
  235. $model->opening_end = $str_opening_end;
  236. $model->manager_id = $post['manager_id'];
  237. $model->designer_id = $post['designer_id'];
  238. $model->posted = Building::POSTED_YES;
  239. if($model->save())
  240. {
  241. $this->uploadBuildingImg($model->id,$post);
  242. return Apireturn::sent(1,'添加样板房成功',200);
  243. }else{
  244. return Apireturn::sent(0,'添加样板房失败',200);
  245. }
  246. }
  247. /**
  248. * 查看工地
  249. */
  250. public function actionCheckWork()
  251. {
  252. $id = Yii::$app->request->post('id');
  253. if(empty($id))
  254. return Apireturn::sent(0,'非法操作',200);
  255. $info = Building::find()->where(['id'=>$id,'uid'=>Yii::$app->user->id])->select("id,name,latitude,longitude,province,city,district,address,layout,stage,pattern,acreage,opening_begin,opening_end,budget,style,manager_id,designer_id")->one();
  256. if(empty($info))
  257. return Apireturn::sent(0,'找不到该工地',200);
  258. $arr = array();
  259. foreach ($info->getOldAttributes() as $key =>$value)
  260. {
  261. $arr[$key] = $value;
  262. }
  263. //设计师详情
  264. $data['designer'] = array();
  265. if(!empty($info->designer))
  266. {
  267. $arr['designer']['id'] = $info->designer->id;
  268. $arr['designer']['realname'] = $info->designer->realname;
  269. }
  270. //项目经理详情
  271. $data['manager'] = array();
  272. if(!empty($info->manager))
  273. {
  274. $arr['manager']['id'] = $info->manager->id;
  275. $arr['manager']['realname'] = $info->manager->realname;
  276. }
  277. $arr['living_room'] = $info->living ? $info->living->pic : "" ;
  278. $arr['master_bedroom'] = $info->master ? $info->master->pic : "" ;
  279. $arr['portion'] = $info->portion ? $info->portion->pic : "" ;
  280. $arr['build'] = $info->build ? $info->build->pic : "" ;
  281. $arr['build2'] = $info->build2 ? $info->build2->pic : "" ;
  282. $arr['flat'] = $info->flat ? $info->flat->pic : "" ;
  283. $arr['province_name'] = !empty($info->province) ? Area::queryCity($info->province) : "";
  284. $arr['city_name'] = !empty($info->city) ? Area::queryCity($info->city) : "";
  285. $arr['district_name'] = !empty($info->district) ? Area::queryCity($info->district) : "";
  286. return Apireturn::sent(1,'success',200,$arr);
  287. }
  288. /**
  289. * 工地详情
  290. */
  291. public function actionWorkInfo()
  292. {
  293. $id = Yii::$app->request->post('id');
  294. $model = Building::find()->where(['id'=>$id,'uid'=>Yii::$app->user->id,'type'=>Building::TYPE_SITE])->select('id,name,latitude,longitude,layout,budget,stage,style,acreage,pattern,address,opening_begin,opening_end,manager_id,designer_id,view')->one();
  295. if(empty($model))
  296. return Apireturn::sent(0,'找不到该工地',200);
  297. $data = array();
  298. foreach ($model->getOldAttributes() as $key => $value)
  299. {
  300. $data[$key] = $value;
  301. }
  302. /*公司名称
  303. $data['companyName'] = "";
  304. $userCompany = UserCompany::find()->select('company')->where(['uid'=>Yii::$app->user->id])->one();
  305. if(!empty($userCompany))
  306. $data['companyName'] = $userCompany->company;*/
  307. //户型图
  308. $data['flat']="";
  309. if(!empty($model->flat->pic))
  310. $data['flat'] = $model->flat->pic;
  311. //设计师详情
  312. $data['designer'] = array();
  313. if(!empty($model->designer))
  314. {
  315. $data['designer']['id'] = $model->designer->id;
  316. $data['designer']['pic'] = !empty($model->designer->image->pic) ? $model->designer->image->pic : "";
  317. $data['designer']['realname'] = $model->designer->realname;
  318. }
  319. //项目经理详情
  320. $data['manager'] = array();
  321. if(!empty($model->manager))
  322. {
  323. $data['manager']['id'] = $model->manager->id;
  324. $data['manager']['pic'] = !empty($model->manager->image->pic) ? $model->manager->image->pic : "";
  325. $data['manager']['realname'] = $model->manager->realname;
  326. }
  327. //轮播图列表
  328. $data['imgs'] = array();
  329. if(!empty($model->allimg))
  330. {
  331. foreach ($model->allimg as $img_val)
  332. {
  333. $data['imgs'][] = $img_val->pic;
  334. }
  335. }
  336. //预约人列表
  337. $data['appoints'] = array();
  338. if(!empty($model->appointment))
  339. {
  340. foreach ($model->appointment as $user)
  341. {
  342. $data['appoints'][] = !empty($user->user->userinfo->portrait) ? UserInfo::imagesUrl($user->user->userinfo->portrait):"";
  343. }
  344. }
  345. //所有评论
  346. $comment = Comment::find()->select("id,star,uid,content,created_at")->where('pid=:id and status = :status',[':id'=>$id,':status'=>Comment::STATUS_ACTIVE])->orderBy("created_at DESC")->all();
  347. $data['comments'] = array();
  348. if(!empty($comment))
  349. {
  350. foreach ($comment as $com_key => $com_val)
  351. {
  352. $data['comments'][$com_key]['id'] = $com_val->id;
  353. $data['comments'][$com_key]['star'] = $com_val->star;
  354. $data['comments'][$com_key]['content'] = $com_val->content;
  355. $data['comments'][$com_key]['created_at'] = Comment::time_tran($com_val->created_at);
  356. $data['comments'][$com_key]['imgs'] = ImageSource::find()->select('pic')->where(['topid'=>$com_val->id,'type'=>ImageSource::TYPE_COMMENT,'status'=>ImageSource::STATUS_YES])->asArray()->all();
  357. if(!empty($com_val->userinfo))
  358. {
  359. $data['comments'][$com_key]['portrait'] = !empty($com_val->userinfo->portrait) ? UserInfo::imagesUrl($com_val->userinfo->portrait):"";;
  360. $data['comments'][$com_key]['nickname'] = $com_val->userinfo->nickname;
  361. }
  362. $data['comments'][$com_key]['replys'] = array();
  363. $replys = Reply::find()->where(['cid'=>$com_val->id,'status'=>Reply::STATUS_ACTIVE])->select('id,from_userid,to_userid,content')->orderBy('created_at ASC')->all();
  364. if(!empty($replys))
  365. {
  366. foreach ($replys as $rep_key => $rep_val)
  367. {
  368. $data['comments'][$com_key]['replys'][$rep_key]['own'] = $rep_val->from_userid == Yii::$app->user->id ? 1 : 0 ;
  369. $data['comments'][$com_key]['replys'][$rep_key]['content'] = $rep_val->content;
  370. }
  371. }
  372. }
  373. }
  374. return Apireturn::sent(1,'success',200,$data);
  375. }
  376. /**
  377. * 编辑工地
  378. */
  379. public function actionEditWork()
  380. {
  381. $post = Yii::$app->request->post();
  382. if(empty($post['id']))
  383. return Apireturn::sent(0,'缺少id',200);
  384. $model = Building::find()->where(['id'=>$post['id'],'uid'=>Yii::$app->user->id])->one();
  385. if(empty($model))
  386. return Apireturn::sent(0,'找不到该样板房',200);
  387. if(empty($post['name']) || empty($post['acreage']) || empty($post['budget']) || empty($post['opening_begin']) || empty($post['opening_end']) || empty($post['layout']) || empty($post['style']) || empty($post['stage']) || empty($post['pattern']) )
  388. return Apireturn::sent(0,'请填写完整信息',200);
  389. $str_opening_begin = strtotime($post['opening_begin']);
  390. $str_opening_end = strtotime($post['opening_end']);
  391. if($str_opening_begin > $str_opening_end)
  392. return Apireturn::sent(0,'可约时间不能大于结束时间',200);
  393. if(empty($post['designer_id']) || empty($post['manager_id']))
  394. return Apireturn::sent(0,'请选择设计师和项目经理',200);
  395. if(empty($post['province']) || empty($post['city']) || empty($post['district']) )
  396. return Apireturn::sent(0,'请选择地区',200);
  397. if(empty($post['address']))
  398. return Apireturn::sent(0,'请输入详细地址',200);
  399. if(empty($post['longitude']) || empty($post['latitude']))
  400. return Apireturn::sent(0,'缺少经纬度',200);
  401. $model->name = $post['name'];
  402. $model->latitude = $post['latitude'];
  403. $model->longitude = $post['longitude'];
  404. if(!empty($model->longitude)&&!empty($model->latitude)) {
  405. $geohash = new ZM_Geohash();
  406. $geohash->init_codingMap();
  407. $model->hashcode = $geohash->encode($model->latitude, $model->longitude);
  408. }
  409. $model->stage = $post['stage'];
  410. $model->pattern = $post['pattern'];
  411. $model->province = $post['province'];
  412. $model->city = $post['city'];
  413. $model->district = $post['district'];
  414. $model->address = $post['address'];
  415. $model->updated_at = time();
  416. $model->acreage = $post['acreage'];
  417. $model->budget = $post['budget'];
  418. $model->layout = $post['layout'];
  419. $model->style = $post['style'];
  420. $model->opening_begin =$str_opening_begin;
  421. $model->opening_end = $str_opening_end;
  422. $model->manager_id = $post['manager_id'];
  423. $model->designer_id = $post['designer_id'];
  424. if($model->save())
  425. {
  426. $this->uploadBuildingImg($model->id,$post,'edit');
  427. return Apireturn::sent(1,'修改成功',200);
  428. }else{
  429. return Apireturn::sent(0,'修改失败',200);
  430. }
  431. }
  432. /**
  433. * 更改样板房/工地发布状态
  434. */
  435. public function actionUpdatePosted()
  436. {
  437. $post = Yii::$app->request->post();
  438. if(empty($post['id']))
  439. return Apireturn::sent(0,'非法操作');
  440. $model = Building::find()->where(['id'=>$post['id'],'uid'=>Yii::$app->user->id])->one();
  441. if(empty($model))
  442. return Apireturn::sent(0,'找不到记录');
  443. if(!in_array($post['posted'],array(Building::POSTED_YES,Building::POSTED_NO)))
  444. return Apireturn::sent(0,'参数错误');
  445. $posted = $post['posted'];
  446. $model->posted = $posted;
  447. if($model->save())
  448. return Apireturn::sent(1,'操作成功');
  449. else
  450. return Apireturn::sent(0,'操作失败');
  451. }
  452. /**
  453. * 获取设计师
  454. */
  455. public function actionDesigner()
  456. {
  457. $list = Designer::find()->where(['company'=>Yii::$app->user->id,'status'=>Designer::STATUS_YES])->select('id,realname,introduction')->orderBy('id DESC')->all();
  458. $arr =array();
  459. if(!empty($list)){
  460. foreach ($list as $value)
  461. {
  462. $arr[] = array('id'=>$value->id,'realname'=>$value->realname,'introduction'=>$value->introduction,'pic'=>$value->image?$value->image->pic:"");
  463. }
  464. }
  465. return Apireturn::sent(1,'success',200,$arr);
  466. }
  467. /**
  468. * 获取项目经理
  469. */
  470. public function actionManager()
  471. {
  472. $list = Manager::find()->where(['company'=>Yii::$app->user->id,'status'=>Manager::STATUS_YES])->select('id,realname,introduction')->orderBy('id DESC')->all();
  473. $arr =array();
  474. if(!empty($list)){
  475. foreach ($list as $value)
  476. {
  477. $arr[] = array('id'=>$value->id,'realname'=>$value->realname,'introduction'=>$value->introduction,'pic'=>$value->image?$value->image->pic:"");
  478. }
  479. }
  480. return Apireturn::sent(1,'success',200,$arr);
  481. }
  482. /**
  483. * 我的工地列表
  484. */
  485. public function actionWorkList()
  486. {
  487. $page = Yii::$app->request->POST('page', 1);//分页页数
  488. $display = Yii::$app->request->POST('display', self::DISPLAY);//分页页数
  489. $list = Building::findBySql("SELECT id,name,layout,acreage,style,designer_id,posted FROM {{%building}} WHERE uid = :uid AND type = :type AND (posted = :posted OR posted = :posted2) ORDER BY id DESC limit " . ($page - 1) * $display . "," . $display,[':uid'=>Yii::$app->user->id,':posted'=>Building::POSTED_YES,':posted2'=>Building::POSTED_NO,':type'=>Building::TYPE_SITE])->all();
  490. $count = Building::find()->where('uid = :uid AND type = :type AND (posted = :posted OR posted = :posted2)',[':uid'=>Yii::$app->user->id,':posted'=>Building::POSTED_YES,':posted2'=>Building::POSTED_NO,':type'=>Building::TYPE_SITE])->count();
  491. $arr = array();
  492. if(!empty($list)){
  493. foreach ($list as $key => $value)
  494. {
  495. foreach ($value->getOldAttributes() as $key2 =>$value2)
  496. {
  497. $arr[$key][$key2] = $value2;
  498. }
  499. $arr[$key]['design_name'] = $value->designer?$value->designer->realname:"";
  500. $arr[$key]['pic'] = $value->all?$value->all->pic:"";
  501. }
  502. }
  503. return Apireturn::sent(1,'success',200,array('count'=>$count,'list'=>$arr));
  504. }
  505. /**
  506. * 我的样板房列表
  507. */
  508. public function actionRoomList()
  509. {
  510. $page = Yii::$app->request->POST('page', 1);//分页页数
  511. $display = Yii::$app->request->POST('display', self::DISPLAY);//分页页数
  512. $list = Building::findBySql("SELECT id,name,layout,acreage,style,designer_id,posted FROM {{%building}} WHERE uid = :uid AND type = :type AND (posted = :posted OR posted = :posted2) ORDER BY id DESC limit " . ($page - 1) * $display . "," . $display,[':uid'=>Yii::$app->user->id,':posted'=>Building::POSTED_YES,':posted2'=>Building::POSTED_NO,':type'=>Building::TYPE_HOUSE])->all();
  513. $count = Building::find()->where('uid = :uid AND type = :type AND (posted = :posted OR posted = :posted2)',[':uid'=>Yii::$app->user->id,':posted'=>Building::POSTED_YES,':posted2'=>Building::POSTED_NO,':type'=>Building::TYPE_HOUSE])->count();
  514. $arr = array();
  515. if(!empty($list)){
  516. foreach ($list as $key => $value)
  517. {
  518. foreach ($value->getOldAttributes() as $key2 =>$value2)
  519. {
  520. $arr[$key][$key2] = $value2;
  521. }
  522. $arr[$key]['design_name'] = $value->designer?$value->designer->realname:"";
  523. $arr[$key]['pic'] = $value->all?$value->all->pic:"";
  524. }
  525. }
  526. return Apireturn::sent(1,'success',200,array('count'=>$count,'list'=>$arr));
  527. }
  528. /**
  529. * 样板房详情
  530. */
  531. public function actionRoomInfo()
  532. {
  533. $id = Yii::$app->request->post('id');
  534. $model = Building::find()->where(['id'=>$id,'uid'=>Yii::$app->user->id,'type'=>Building::TYPE_HOUSE])->select('id,name,latitude,longitude,layout,budget,style,acreage,address,opening_begin,opening_end,manager_id,designer_id,view')->one();
  535. if(empty($model))
  536. return Apireturn::sent(0,'找不到该工地',200);
  537. $data = array();
  538. foreach ($model->getOldAttributes() as $key => $value)
  539. {
  540. $data[$key] = $value;
  541. }
  542. /*公司名称
  543. $data['companyName'] = "";
  544. $userCompany = UserCompany::find()->select('company')->where(['uid'=>Yii::$app->user->id])->one();
  545. if(!empty($userCompany))
  546. $data['companyName'] = $userCompany->company;*/
  547. //户型图
  548. $data['flat']="";
  549. if(!empty($model->flat->pic))
  550. $data['flat'] = $model->flat->pic;
  551. //设计师详情
  552. $data['designer'] = array();
  553. if(!empty($model->designer))
  554. {
  555. $data['designer']['id'] = $model->designer->id;
  556. $data['designer']['pic'] = !empty($model->designer->image->pic) ? $model->designer->image->pic : "";
  557. $data['designer']['realname'] = $model->designer->realname;
  558. }
  559. //项目经理详情
  560. $data['manager'] = array();
  561. if(!empty($model->manager))
  562. {
  563. $data['manager']['id'] = $model->manager->id;
  564. $data['manager']['pic'] = !empty($model->manager->image->pic) ? $model->manager->image->pic : "";
  565. $data['manager']['realname'] = $model->manager->realname;
  566. }
  567. //轮播图列表
  568. $data['imgs'] = array();
  569. if(!empty($model->allimg))
  570. {
  571. foreach ($model->allimg as $img_val)
  572. {
  573. $data['imgs'][] = $img_val->pic;
  574. }
  575. }
  576. //预约人列表
  577. $data['appoints'] = array();
  578. if(!empty($model->appointment))
  579. {
  580. foreach ($model->appointment as $user)
  581. {
  582. $data['appoints'][] = !empty($user->user->userinfo->portrait) ? UserInfo::imagesUrl($user->user->userinfo->portrait):"";
  583. }
  584. }
  585. //所有评论
  586. $comment = Comment::find()->select("id,star,uid,content,created_at")->where('pid=:id and status = :status',[':id'=>$id,':status'=>Comment::STATUS_ACTIVE])->orderBy("created_at DESC")->all();
  587. $data['comments'] = array();
  588. if(!empty($comment))
  589. {
  590. foreach ($comment as $com_key => $com_val)
  591. {
  592. $data['comments'][$com_key]['id'] = $com_val->id;
  593. $data['comments'][$com_key]['star'] = $com_val->star;
  594. $data['comments'][$com_key]['content'] = $com_val->content;
  595. $data['comments'][$com_key]['created_at'] = Comment::time_tran($com_val->created_at);
  596. $data['comments'][$com_key]['imgs'] = ImageSource::find()->select('pic')->where(['topid'=>$com_val->id,'type'=>ImageSource::TYPE_COMMENT,'status'=>ImageSource::STATUS_YES])->asArray()->all();
  597. if(!empty($com_val->userinfo))
  598. {
  599. $data['comments'][$com_key]['portrait'] =!empty($com_val->userinfo->portrait) ? UserInfo::imagesUrl($com_val->userinfo->portrait):"";;
  600. $data['comments'][$com_key]['nickname'] = $com_val->userinfo->nickname;
  601. }
  602. $data['comments'][$com_key]['replys'] = array();
  603. $replys = Reply::find()->where(['cid'=>$com_val->id,'status'=>Reply::STATUS_ACTIVE])->select('id,from_userid,to_userid,content')->orderBy('created_at ASC')->all();
  604. if(!empty($replys))
  605. {
  606. foreach ($replys as $rep_key => $rep_val)
  607. {
  608. $data['comments'][$com_key]['replys'][$rep_key]['own'] = $rep_val->from_userid == Yii::$app->user->id ? 1 : 0 ;
  609. $data['comments'][$com_key]['replys'][$rep_key]['content'] = $rep_val->content;
  610. }
  611. }
  612. }
  613. }
  614. return Apireturn::sent(1,'success',200,$data);
  615. }
  616. /**
  617. * 添加更新工地图片
  618. */
  619. public function uploadBuildingImg($id,$post,$type = 'add')
  620. {
  621. //客厅照片,开工大吉
  622. if(!empty($post['living_room']))
  623. {
  624. if($type != 'add'){//编辑
  625. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_LIVING_ROOM])->one();
  626. if(empty($model))
  627. {
  628. $model = new ImageSource();
  629. $model->topid = $id;
  630. $model->created_at = time();
  631. $model->status = ImageSource::STATUS_YES;
  632. $model->type = ImageSource::TYPE_LIVING_ROOM;
  633. }
  634. }else{//添加
  635. $model = new ImageSource();
  636. $model->topid = $id;
  637. $model->created_at = time();
  638. $model->status = ImageSource::STATUS_YES;
  639. $model->type = ImageSource::TYPE_LIVING_ROOM;
  640. }
  641. $model->pic = $post['living_room'];
  642. $model->updated_at = time();
  643. $model->save();
  644. unset($model);
  645. }elseif (empty($post['living_room']) && $type == 'edit')
  646. {
  647. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_LIVING_ROOM])->one();
  648. if(!empty($model))
  649. {
  650. $model->status = ImageSource::STATUS_NO;
  651. $model->updated_at = time();
  652. $model->save();
  653. }
  654. }
  655. //主卧照片,现场施工
  656. if(!empty($post['master_bedroom']))
  657. {
  658. if($type != 'add'){//编辑
  659. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_MASTER_BEDROOM])->one();
  660. if(empty($model))
  661. {
  662. $model = new ImageSource();
  663. $model->topid = $id;
  664. $model->created_at = time();
  665. $model->status = ImageSource::STATUS_YES;
  666. $model->type = ImageSource::TYPE_MASTER_BEDROOM;
  667. }
  668. }else{//添加
  669. $model = new ImageSource();
  670. $model->topid = $id;
  671. $model->created_at = time();
  672. $model->status = ImageSource::STATUS_YES;
  673. $model->type = ImageSource::TYPE_MASTER_BEDROOM;
  674. }
  675. $model->pic = $post['master_bedroom'];
  676. $model->updated_at = time();
  677. $model->save();
  678. unset($model);
  679. }elseif (empty($post['master_bedroom']) && $type == 'edit')
  680. {
  681. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_MASTER_BEDROOM])->one();
  682. if(!empty($model))
  683. {
  684. $model->status = ImageSource::STATUS_NO;
  685. $model->updated_at = time();
  686. $model->save();
  687. }
  688. }
  689. //局部美照,现场施工
  690. if(!empty($post['portion']))
  691. {
  692. if($type != 'add'){//编辑
  693. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION])->one();
  694. if(empty($model))
  695. {
  696. $model = new ImageSource();
  697. $model->topid = $id;
  698. $model->created_at = time();
  699. $model->status = ImageSource::STATUS_YES;
  700. $model->type = ImageSource::TYPE_PORTION;
  701. }
  702. }else{//添加
  703. $model = new ImageSource();
  704. $model->topid = $id;
  705. $model->created_at = time();
  706. $model->status = ImageSource::STATUS_YES;
  707. $model->type = ImageSource::TYPE_PORTION;
  708. }
  709. $model->pic = $post['portion'];
  710. $model->updated_at = time();
  711. $model->save();
  712. unset($model);
  713. }elseif (empty($post['portion']) && $type == 'edit')
  714. {
  715. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION])->one();
  716. if(!empty($model))
  717. {
  718. $model->status = ImageSource::STATUS_NO;
  719. $model->updated_at = time();
  720. $model->save();
  721. }
  722. }
  723. //现场施工照片2
  724. if(!empty($post['build']))
  725. {
  726. if($type != 'add'){//编辑
  727. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_BUILD])->one();
  728. if(empty($model))
  729. {
  730. $model = new ImageSource();
  731. $model->topid = $id;
  732. $model->created_at = time();
  733. $model->status = ImageSource::STATUS_YES;
  734. $model->type = ImageSource::TYPE_BUILD;
  735. }
  736. }else{//添加
  737. $model = new ImageSource();
  738. $model->topid = $id;
  739. $model->created_at = time();
  740. $model->status = ImageSource::STATUS_YES;
  741. $model->type = ImageSource::TYPE_BUILD;
  742. }
  743. $model->pic = $post['build'];
  744. $model->updated_at = time();
  745. $model->save();
  746. unset($model);
  747. }elseif (empty($post['build']) && $type == 'edit')
  748. {
  749. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_BUILD])->one();
  750. if(!empty($model))
  751. {
  752. $model->status = ImageSource::STATUS_NO;
  753. $model->updated_at = time();
  754. $model->save();
  755. }
  756. }
  757. //现场施工照片3
  758. if(!empty($post['build2']))
  759. {
  760. if($type != 'add'){//编辑
  761. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_BUILD2])->one();
  762. if(empty($model))
  763. {
  764. $model = new ImageSource();
  765. $model->topid = $id;
  766. $model->created_at = time();
  767. $model->status = ImageSource::STATUS_YES;
  768. $model->type = ImageSource::TYPE_BUILD2;
  769. }
  770. }else{//添加
  771. $model = new ImageSource();
  772. $model->topid = $id;
  773. $model->created_at = time();
  774. $model->status = ImageSource::STATUS_YES;
  775. $model->type = ImageSource::TYPE_BUILD2;
  776. }
  777. $model->pic = $post['build2'];
  778. $model->updated_at = time();
  779. $model->save();
  780. unset($model);
  781. }elseif (empty($post['build2']) && $type == 'edit')
  782. {
  783. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_BUILD2])->one();
  784. if(!empty($model))
  785. {
  786. $model->status = ImageSource::STATUS_NO;
  787. $model->updated_at = time();
  788. $model->save();
  789. }
  790. }
  791. //局部美照2
  792. if(!empty($post['portion2']))
  793. {
  794. if($type != 'add'){//编辑
  795. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION2])->one();
  796. if(empty($model))
  797. {
  798. $model = new ImageSource();
  799. $model->topid = $id;
  800. $model->created_at = time();
  801. $model->status = ImageSource::STATUS_YES;
  802. $model->type = ImageSource::TYPE_PORTION2;
  803. }
  804. }else{//添加
  805. $model = new ImageSource();
  806. $model->topid = $id;
  807. $model->created_at = time();
  808. $model->status = ImageSource::STATUS_YES;
  809. $model->type = ImageSource::TYPE_PORTION2;
  810. }
  811. $model->pic = $post['portion2'];
  812. $model->updated_at = time();
  813. $model->save();
  814. unset($model);
  815. }elseif (empty($post['portion2']) && $type == 'edit')
  816. {
  817. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION2])->one();
  818. if(!empty($model))
  819. {
  820. $model->status = ImageSource::STATUS_NO;
  821. $model->updated_at = time();
  822. $model->save();
  823. }
  824. }
  825. //局部美照3
  826. if(!empty($post['portion3']))
  827. {
  828. if($type != 'add'){//编辑
  829. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION3])->one();
  830. if(empty($model))
  831. {
  832. $model = new ImageSource();
  833. $model->topid = $id;
  834. $model->created_at = time();
  835. $model->status = ImageSource::STATUS_YES;
  836. $model->type = ImageSource::TYPE_PORTION3;
  837. }
  838. }else{//添加
  839. $model = new ImageSource();
  840. $model->topid = $id;
  841. $model->created_at = time();
  842. $model->status = ImageSource::STATUS_YES;
  843. $model->type = ImageSource::TYPE_PORTION3;
  844. }
  845. $model->pic = $post['portion3'];
  846. $model->updated_at = time();
  847. $model->save();
  848. unset($model);
  849. }elseif (empty($post['portion3']) && $type == 'edit')
  850. {
  851. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION3])->one();
  852. if(!empty($model))
  853. {
  854. $model->status = ImageSource::STATUS_NO;
  855. $model->updated_at = time();
  856. $model->save();
  857. }
  858. }
  859. //局部美照4
  860. if(!empty($post['portion4']))
  861. {
  862. if($type != 'add'){//编辑
  863. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION4])->one();
  864. if(empty($model))
  865. {
  866. $model = new ImageSource();
  867. $model->topid = $id;
  868. $model->created_at = time();
  869. $model->status = ImageSource::STATUS_YES;
  870. $model->type = ImageSource::TYPE_PORTION4;
  871. }
  872. }else{//添加
  873. $model = new ImageSource();
  874. $model->topid = $id;
  875. $model->created_at = time();
  876. $model->status = ImageSource::STATUS_YES;
  877. $model->type = ImageSource::TYPE_PORTION4;
  878. }
  879. $model->pic = $post['portion4'];
  880. $model->updated_at = time();
  881. $model->save();
  882. unset($model);
  883. }elseif (empty($post['portion4']) && $type == 'edit')
  884. {
  885. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION4])->one();
  886. if(!empty($model))
  887. {
  888. $model->status = ImageSource::STATUS_NO;
  889. $model->updated_at = time();
  890. $model->save();
  891. }
  892. }
  893. //局部美照5
  894. if(!empty($post['portion5']))
  895. {
  896. if($type != 'add'){//编辑
  897. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION5])->one();
  898. if(empty($model))
  899. {
  900. $model = new ImageSource();
  901. $model->topid = $id;
  902. $model->created_at = time();
  903. $model->status = ImageSource::STATUS_YES;
  904. $model->type = ImageSource::TYPE_PORTION5;
  905. }
  906. }else{//添加
  907. $model = new ImageSource();
  908. $model->topid = $id;
  909. $model->created_at = time();
  910. $model->status = ImageSource::STATUS_YES;
  911. $model->type = ImageSource::TYPE_PORTION5;
  912. }
  913. $model->pic = $post['portion5'];
  914. $model->updated_at = time();
  915. $model->save();
  916. unset($model);
  917. }elseif (empty($post['portion5']) && $type == 'edit')
  918. {
  919. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION5])->one();
  920. if(!empty($model))
  921. {
  922. $model->status = ImageSource::STATUS_NO;
  923. $model->updated_at = time();
  924. $model->save();
  925. }
  926. }
  927. //户型平面图
  928. if(!empty($post['flat']))
  929. {
  930. if($type != 'add'){//编辑
  931. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_FLAT])->one();
  932. if(empty($model))
  933. {
  934. $model = new ImageSource();
  935. $model->topid = $id;
  936. $model->created_at = time();
  937. $model->status = ImageSource::STATUS_YES;
  938. $model->type = ImageSource::TYPE_FLAT;
  939. }
  940. }else{//添加
  941. $model = new ImageSource();
  942. $model->topid = $id;
  943. $model->created_at = time();
  944. $model->status = ImageSource::STATUS_YES;
  945. $model->type = ImageSource::TYPE_FLAT;
  946. }
  947. $model->pic = $post['flat'];
  948. $model->updated_at = time();
  949. $model->save();
  950. unset($model);
  951. }elseif (empty($post['flat']) && $type == 'edit')
  952. {
  953. $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_FLAT])->one();
  954. if(!empty($model))
  955. {
  956. $model->status = ImageSource::STATUS_NO;
  957. $model->updated_at = time();
  958. $model->save();
  959. }
  960. }
  961. }
  962. /**
  963. * 工地/样板房预约列表
  964. */
  965. public function actionAppointments()
  966. {
  967. $page = Yii::$app->request->post('page', 1);//分页页数
  968. $display = Yii::$app->request->post('display', self::DISPLAY);//分页页数
  969. $id = Yii::$app->request->post('id');//工地,样板房id
  970. $list = Appointment::findBySql("SELECT a.applicant_name,a.applicant_tel,a.state,a.booking_time,b.portrait FROM {{%appointment}} a LEFT JOIN {{%user_info}} b ON a.uid = b.uid WHERE a.pid = :id AND a.status = :status ORDER BY a.id DESC LIMIT ".($page-1) * $display.",".$display,[':id'=>$id,':status'=>Appointment::STATE_YES])->asArray()->all();
  971. if(!empty($list))
  972. {
  973. foreach ($list as $key => $value)
  974. {
  975. $list[$key]['portrait'] = empty($value['portrait']) ? "":UserInfo::imagesUrl($value['portrait']);
  976. //$list[$key]['applicant_tel'] = empty($value['applicant_tel']) ? "":Appointment::telPreg($value['applicant_tel']);
  977. $building = Building::find()->where(['id'=>$id])->select('name')->one();
  978. if(!empty($building))
  979. $list[$key]['name'] = $building->name;
  980. else
  981. $list[$key]['name'] = "";
  982. }
  983. }
  984. $userCompany = UserCompany::find()->where(['uid'=>Yii::$app->user->id])->select('member')->one();
  985. $member = 0;
  986. if(!empty($userCompany))
  987. $member = $userCompany->member;
  988. return Apireturn::sent(1,'success',200,array('member'=>$member,'list'=>$list));
  989. }
  990. /**
  991. * 装修进度,户型,装修方式,装修风格
  992. * @return array
  993. */
  994. public function actionData()
  995. {
  996. $array = array('stage'=>self::$stage_arr,'layout'=>self::$layout_arr,'style'=>self::$style_arr,'pattern'=>self::$pattern_arr);
  997. return Apireturn::sent(1,'success',200,$array);
  998. }
  999. }