123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- /**
- * 用户端 设计师/项目经理
- */
- namespace api\modules\v1\controllers;
- use common\library\ZM_Geohash;
- use common\models\Building;
- use common\models\Designer;
- use common\models\ImageSource;
- use common\models\Manager;
- use yii\rest\ActiveController;
- use common\library\Apireturn;
- use yii\helpers\ArrayHelper;
- use yii\filters\auth\QueryParamAuth;
- use yii;
- class PersonController extends ActiveController
- {
- public $modelClass = 'common\models';
- const DISPLAY = 10;//显示条数
- public function behaviors()
- {
- return ArrayHelper::merge(parent::behaviors(), [
- 'authenticator' => [
- 'class' => QueryParamAuth::className(),
- 'tokenParam' => "token",//access-token修改为token
- 'optional' => [//不需要认证方法名 array
- ],
- ]
- ]);
- }
- /**
- * 设计师,项目经理信息
- */
- public function actionInfo()
- {
- $id =Yii::$app->request->post('id');
- $type = Yii::$app->request->post('type');
- if(empty($id))
- return Apireturn::sent(0,'缺少id');
- if($type == 1)//设计师
- {
- $data = Designer::find()->where(['id'=>$id])->select('id,realname,introduction')->asArray()->one();
- $image = ImageSource::find()->where(['type'=>ImageSource::TYPE_DESIGNER,'status'=>ImageSource::STATUS_YES,'topid'=>$id])->select('pic')->one();
- $data['type'] = 1;
- if(!empty($image))
- $data['pic'] =$image->pic;
- }else{
- $data = Manager::find()->where(['id'=>$id])->select('id,realname,introduction')->asArray()->one();
- $image = ImageSource::find()->where(['type'=>ImageSource::TYPE_MANAGER,'status'=>ImageSource::STATUS_YES,'topid'=>$id])->select('pic')->one();
- $data['type'] = 2;
- if(!empty($image))
- $data['pic'] =$image->pic;
- }
- return Apireturn::sent(1,'success',200,$data);
- }
- /**
- * 作品列表
- */
- public function actionWorkList()
- {
- $id = Yii::$app->request->post('id');
- $type = Yii::$app->request->post('type');
- $page = Yii::$app->request->post('page', 1);//分页页数
- $display = Yii::$app->request->post('display', self::DISPLAY);//分页页数
- $latitude = Yii::$app->request->post('latitude');
- $longitude = Yii::$app->request->post('longitude');
- $lists = array();
- if(empty($id))
- return Apireturn::sent(0,'缺少id');
- if($type == 1)
- {
- $list= Building::find()->select('id,type,address,latitude,longitude,layout,style,acreage')->where(['designer_id'=>$id,'posted'=>Building::POSTED_YES])->offset(($page - 1) * $display)->limit($display)->orderBy('id DESC')->all();
- if(!empty($list))
- {
- $geohash = new ZM_Geohash();
- foreach ($list as $key => $val)
- {
- foreach ($val->getOldAttributes() as $key2 =>$value2)
- {
- $lists[$key][$key2] = $value2;
- }
- $lists[$key]['pic'] = $val->all?$val->all->pic:"";
- if(!empty($val->latitude) && !empty($val->longitude) && !empty($latitude) && !empty($longitude))
- {
- $lists[$key]['distance'] = sprintf("%.1f",$geohash->getDistance($latitude,$longitude,$val->latitude,$val->longitude)/1000);
- }else{
- $lists[$key]['distance'] = "";
- }
- }
- }
- }else{
- $list= Building::find()->select('id,type,address,latitude,longitude,layout,style,acreage')->where(['manager_id'=>$id,'posted'=>Building::POSTED_YES])->offset(($page - 1) * $display)->limit($display)->orderBy('id DESC')->all();
- if(!empty($list))
- {
- $geohash = new ZM_Geohash();
- foreach ($list as $key => $val)
- {
- foreach ($val->getOldAttributes() as $key2 =>$value2)
- {
- $lists[$key][$key2] = $value2;
- }
- $lists[$key]['pic'] = $val->all?$val->all->pic:"";
- if(!empty($val->latitude) && !empty($val->longitude) && !empty($latitude) && !empty($longitude))
- {
- $lists[$key]['distance'] = sprintf("%.1f",$geohash->getDistance($latitude,$longitude,$val->latitude,$val->longitude)/1000);
- }else{
- $lists[$key]['distance'] = "";
- }
- }
- }
- }
- return Apireturn::sent(1,'success',200,$lists);
- }
- }
|