123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 |
- <?php
- namespace frontend\controllers;
- use api\modules\v1\controllers\ImageUploadController;
- use common\library\LMUploadFile;
- use common\library\Sms;
- use common\library\ZM_Geohash;
- use common\models\ActivityReceive;
- use common\models\Appointment;
- use common\models\Building;
- use common\models\Comment;
- use common\models\Designer;
- use common\models\ImageSource;
- use common\models\Manager;
- use common\models\User;
- use common\models\UserInfo;
- use Yii;
- use yii\db\Connection;
- use yii\web\Cookie;
- use yii\web\UploadedFile;
- class BuildingController extends BasewechatController
- {
- public $imgtype = array('bmp','jpg','png','gif','jpeg');
- public function actionIndex()
- {
- return $this->render('index');
- }
- //工地与样板房详情
- public function actionDetail()
- {
- $type = Yii::$app->request->get('type');//用户分享,有值显示返回图标
- $cookie = Yii::$app->request->cookies;
- $userid = YII::$app->user->id;
- $user = User::find()->select('tel')->where('id=:id and status=:status',[':id'=>$userid,':status'=>User::STATUS_ACTIVE])->one();
- $usertel = '';
- if(!empty($user)){
- $usertel = $user->tel;
- }
- $latitude = "";
- $longitude = "";
- if($cookie->has('localtion'))
- {
- $lcookie = $cookie->getValue('localtion');
- $latitude=$lcookie['lat'];
- $longitude=$lcookie['lng'];
- }
- $id = \Yii::$app->request->get('id');
- $datas = Building::find()->where('id=:id and posted=:posted',[':id'=>$id,'posted'=>Building::POSTED_YES])->one();
- if(!empty($datas)){
- $geohash = new ZM_Geohash();
- $distance="";
- $nearlist =[];
- if(!empty($latitude)&&!empty($longitude))
- {
- if(!empty($datas->latitude)&&!empty($datas->longitude)){
- $distance = $geohash->getDistance($latitude,$longitude,$datas->latitude,$datas->longitude);
- }
- $nearlist = Building::findBySql("select id,name,layout,acreage,get_Distance(latitude,longitude,:latitude,:longitude) as distance from bd_building where posted=1 and opening_begin < :time and opening_end > :time AND id != :id HAVING distance < :distance ORDER BY distance ASC LIMIT 0,2", [':latitude' => $latitude, ':longitude' => $longitude, ':time' => time(), ':distance' => 10000,':id'=>$id])->joinWith('image')->asArray()->all();
- if(!empty($nearlist)){
- for($i=0;$i<count($nearlist);$i++) {
- $buildid = $nearlist[$i]['id'];
- $images = ImageSource::find()->select('pic')->where('topid=:id and status=:status', [':id' => $buildid, ':status' => ImageSource::STATUS_YES])->andWhere(['type' => [20,30,40,50]])->asArray()->all();
- $nearlist[$i]['image'] = $images;
- }
- }
- }
- $comments = Comment::find()->where('pid=:pid and status=:status',[':pid'=>$id,':status'=>Comment::STATUS_ACTIVE])->orderBy('created_at DESC')->all();
- $arr = Appointment::find()->where('uid=:uid and pid=:pid and status=:status',[':uid'=>$userid,':pid'=>$id,':status'=>Appointment::STATUS_DEAL])->andWhere(['>', 'booking_time', time()])->orderBy('updated_at desc')->one();
- $datas->view += 1;
- $datas->save();
- $wechat = new \common\library\WeChat();
- $ticket = $wechat->getTicket();
- $jssdk = new \common\library\Jssdk(Yii::$app->params['wechat']['appID'],Yii::$app->params['wechat']['appsecret'],$ticket);
- $signPackage = $jssdk->getSignPackage();
- return $this->render('site',['datas'=>$datas,'arr'=>$arr,'comments'=>$comments,'distance'=>$distance,'nearlist'=>$nearlist,'usertel'=>$usertel,'signPackage'=>$signPackage,'type'=>$type]);
- }else{
- var_dump('该房子未通过审核');exit;
- Yii::$app->getSession()->setFlash('error', '该房子未通过审核!');
- return $this->render('index');
- }
- }
- //设计师详情
- public function actionDesigner()
- {
- $cookie = Yii::$app->request->cookies;
- $latitude = "";
- $longitude = "";
- if($cookie->has('localtion'))
- {
- $lcookie = $cookie->getValue('localtion');
- $latitude=$lcookie['lat'];
- $longitude=$lcookie['lng'];
- }
- $id = \Yii::$app->request->get('id');
- $data = Designer::find()->where('id=:id and status=:status',[':id'=>$id,':status'=>Designer::STATUS_YES])->one();
- // $arrs = Building::findBySql("SELECT *,get_Distance(latitude,longitude,:latitude,:longitude) as distance FROM {{%building}} WHERE designer_id = :designer_id AND posted = :posted ORDER BY created_at desc", [':designer_id'=>$id,':latitude' => $latitude, ':longitude' => $longitude,':posted'=>Building::POSTED_YES])->asArray()->all();
- $arrs = Building::find()->where("designer_id = :designer_id AND posted = :posted",[':designer_id'=>$id,':posted'=>Building::POSTED_YES])->orderBy('created_at DESC')->all();
- $geohash = new ZM_Geohash();
- foreach ($arrs as $list)
- {
- if(!empty($latitude)&&!empty($longitude)&&!empty($list->latitude)&&!empty($list->longitude))
- {
- $distance = $geohash->getDistance($latitude,$longitude,$list->latitude,$list->longitude);
- $list->distance = $distance;
- }
- }
- //
- return $this->render('designer',['data'=>$data,'arrs'=>$arrs]);
- }
- //项目经理详情
- public function actionManager()
- {
- $cookie = Yii::$app->request->cookies;
- $latitude = "";
- $longitude = "";
- if($cookie->has('localtion'))
- {
- $lcookie = $cookie->getValue('localtion');
- $latitude=$lcookie['lat'];
- $longitude=$lcookie['lng'];
- }
- $id = \Yii::$app->request->get('id');
- $data = Manager::find()->where('id=:id and status=:status',[':id'=>$id,':status'=>Manager::STATUS_YES])->one();
- // $arrs = Building::findBySql("SELECT *,get_Distance(latitude,longitude,:latitude,:longitude) as distance FROM {{%building}} WHERE manager_id = :manager_id AND posted = :posted ORDER BY created_at desc", [':manager_id'=>$id,':latitude' => $latitude, ':longitude' => $longitude,':posted'=>Building::POSTED_YES])->asArray()->all();
- $arrs = Building::find()->where("manager_id = :manager_id AND posted = :posted",[':manager_id'=>$id,':posted'=>Building::POSTED_YES])->orderBy('created_at DESC')->all();
- $geohash = new ZM_Geohash();
- foreach ($arrs as $list)
- {
- if(!empty($latitude)&&!empty($longitude)&&!empty($list->latitude)&&!empty($list->longitude))
- {
- $distance = $geohash->getDistance($latitude,$longitude,$list->latitude,$list->longitude);
- $list->distance = $distance;
- }
- }
- return $this->render('manager',['data'=>$data,'arrs'=>$arrs]);
- }
- //评价页面
- public function actionEvaluate()
- {
- $id = \Yii::$app->request->get('id');
- $type= \Yii::$app->request->get('type');
- $userid = YII::$app->user->id;
- $data = UserInfo::find()->where('uid=:uid',[':uid'=>$userid])->one();
- $picture_form = new LMUploadFile();
- return $this->render('evaluate',['data'=>$data,'pid'=>$id,'type'=>$type,"picture_form" => $picture_form]);
- }
- //评价
- public function actionEvaluate1()
- {
- $star = Yii::$app->request->post('star');
- $content = Yii::$app->request->post('content');
- $pid = Yii::$app->request->post('pid');
- $type = Yii::$app->request->post('type');
- if(!empty($pid)){
- if(!empty($star)&&!empty($content)){
- $data = new Comment();
- $data->pid = $pid;
- $data->type = $type;
- $data->star = $star;
- $data->content = $content;
- $data->uid = Yii::$app->user->id;
- $data->created_at = time();
- $data->updated_at = time();
- $data->status = Comment::STATUS_ACTIVE;
- if($data->validate() && $data->save()){
- $imgs =json_decode(Yii::$app->request->post('imgs'),true);//上传的评论图片
- if(!empty($imgs))
- {
- foreach ($imgs as $key=>$val)
- {
- $imageSource = new ImageSource();
- $imageSource->type = ImageSource::TYPE_COMMENT;
- $imageSource->topid = $data->id;
- $imageSource->pic = $val;
- $imageSource->created_at = time();
- $imageSource->status = ImageSource::STATUS_YES;
- $imageSource->updated_at = time();
- $imageSource->save();
- }
- }
- $result=['sign'=>1,'msg'=>'评论成功'];
- }else{
- $result=['sign'=>0,'msg'=>'提交失败,请重新提交'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'评价内容和评星不能为空'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'房产pid数据有误'];
- }
- return json_encode($result);
- }
- /**
- * 上传评论图片
- * @return string
- */
- public function actionEvaluateimg()
- {
- if (Yii::$app->request->isPost) {
- $arr = array('pic'=>"","sign"=>1,"error"=>"");
- $file = $_FILES['mypic'] ;
- $files['name']=$file['name'];
- $files['type']=$file['type'];
- $files['tmp_name']=$file['tmp_name'];
- $files['error']=$file['error'];
- $files['size']=$file['size'];
- $folder = "/evaluate/".date("Ym")."/".date("d")."/";
- $file_path=\Yii::getAlias('@common/allupload').$folder;
- $result = $this->uploadFile($files,$file_path,2*1024*1024,$this->imgtype);
- if(!empty($result['dest']))
- $arr['pic']= $folder.$result['dest'];
- else
- $arr = ['sign'=>0,'error'=>$result['mes']];
- return json_encode($arr);
- }
- }
- /**
- * 上传图片
- * @param $file
- * @param string $path
- * @param $max_size
- * @param $allowExt
- * @return mixed
- */
- public function uploadFile($file,$path='./uploads',$max_size,$allowExt){
- $filename=$file['name'];
- $type=$file['type'];
- $temp_name=$file['tmp_name'];
- $error=$file['error'];
- $size=$file['size'];
- if ($error==UPLOAD_ERR_OK) {
- if ($size>$max_size) {
- $res['mes']=$filename."文件超过规定上传大小,最多2M";
- }
- $ext=$this->getExt($filename);
- if (!in_array($ext, $allowExt)) {
- $res['mes']=$filename.'文件名不合乎规范';
- }
- // if (!is_uploaded_file($temp_name)) {
- // $res['mes']=$filename."文件不是通过HTTP POST 方法上传上传过来的";
- // }
- if (@$res) {
- return $res;
- }
- if (!file_exists($path)) {
- mkdir($path,0777,true);
- chmod($path, 0777);
- }
- $fname=$this->getUniName();
- $url =$fname.'.'.$ext;
- $destination=$path.'/'.$fname.'.'.$ext;
- if (move_uploaded_file($temp_name, $destination)) {
- $res['mes']=$filename.'上传成功';
- $res['dest']=$url;
- }else{
- $res['mes']=$filename."文件上传失败";
- }
- }else{
- switch ($error) {
- case '1':
- $res['mes']="超过了配置文件上传文件的大小";
- break;
- case '2':
- $res['mes']="超过表单设置上传文件文件的大小";
- break;
- case '3':
- $res['mes']="文件部分被上传";
- break;
- case '4':
- $res['mes']="没有文件被上传";
- break;
- case '6':
- $res['mes']="没有找到临时目录";
- break;
- case '7':
- $res['mes']="文件不可写";
- break;
- default:
- $res['mes']="上传文件失败";
- break;
- }
- }
- return $res;
- }
- public function getExt($filename){
- $arr=explode('.', basename($filename));
- return end($arr);
- }
- public function getUniName(){
- return md5(uniqid(microtime(true),true));
- }
- //添加预约时间
- public function actionAppointment()
- {
- $userid = YII::$app->user->id;
- $time = Yii::$app->request->post('time');
- $pid = Yii::$app->request->post('pid');
- $type = Yii::$app->request->post('type');
- if(!empty($time)&&!empty($pid)){
- $model = new Appointment();
- $model->uid = Yii::$app->user->id;
- $arr = Appointment::find()->where('uid=:uid and pid=:pid and status=:status',[':uid'=>$userid,':pid'=>$pid,':status'=>Appointment::STATUS_DEAL])->andWhere(['>', 'updated_at', time()])->orderBy('updated_at desc')->one();
- if(empty($arr)){
- $user = User::find()->where('id=:id',[':id'=>$userid])->one();
- $userinfo = UserInfo::find()->where('uid=:uid',[':uid'=>$userid])->one();
- if(!empty($userinfo)&&!empty($user)){
- $model->pid = $pid;
- $model->type = $type;
- $model->applicant_tel = $user->tel;
- $model->applicant_name = $userinfo->nickname;
- $model->created_at = time();
- $model->booking_time = intval($time+60);
- $model->updated_at = intval($time+60);
- $model->status = Appointment::STATUS_DEAL;
- $model->state = Appointment::STATE_YTAY;
- if($model->validate() && $model->save()){
- //发送短信
- $this->appSms($pid);
- //红包发放
- $activiModel = new ActivityReceive();
- $activiModel->sentRed($pid);
- $result=['sign'=>1,'msg'=>'预约成功'];
- }else{
- $result=['sign'=>0,'msg'=>'预约失败'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'用户详细信息有误'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'您已经有预约'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'时间或房屋id不能为空'];
- }
- return json_encode($result);
- }
- //取消预约
- public function actionCancelappointment()
- {
- $userid = YII::$app->user->id;
- $pid = Yii::$app->request->post('pid');
- $model = Appointment::find()->where('uid=:uid and pid=:pid and status=:status',[':uid'=>$userid,':pid'=>$pid,':status'=>Appointment::STATUS_DEAL])->orderBy('booking_time desc')->one();
- if(!empty($model)){
- $model->status = Appointment::STATUS_DELETE;
- $model->updated_at = time();
- if($model->validate() && $model->save()){
- $result=['sign'=>1,'msg'=>'已取消'];
- }else{
- $result=['sign'=>0,'msg'=>'取消失败'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'不存在预约'];
- }
- return json_encode($result);
- }
- public function actionBuildingposition()
- {
- $lat = Yii::$app->request->get('lat');
- $lng = Yii::$app->request->get('lng');
- $type = Yii::$app->request->get('type');
- return $this->render('buildingPosition',['lat'=>$lat,'lng'=>$lng,'type'=>$type]);
- }
- //预约发送短信
- public function appSms($id)
- {
- $data = Building::findBySql("SELECT a.address,a.type,b.tel FROM {{%building}} AS a LEFT JOIN {{%user_company}} AS b ON a.uid = b.uid WHERE a.id = :id",[':id'=>$id])->asArray()->one();
- if(!empty($data)){
- $sms = new Sms();
- //用户
- if(!empty(Yii::$app->user->identity->tel)){
- if($data['type']==Building::TYPE_HOUSE)//样板房
- {
- $content = "业主您好!您已成功预约".$data['address']."的房子进行参观,具体参观的时间请联络平台客服热线400-0592-018!";
- }else{
- $content = "您已成功预约".$data['address'].",有问题请及时联系我们的客服400-0592-018";
- }
- $sms->SendMessage(Yii::$app->user->identity->tel,$content,false);
- }
- //装修公司
- if(!empty($data['tel']))
- {
- $content = "您好,你的".$data['address'].",有业主预约参观,请保持好现场形象管理,业主的信息请在".Yii::$app->params['sitetitle']."后台查看。";
- $sms->SendMessage($data['tel'],$content,false);
- }
- }
- }
- }
|