1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- /**
- * 建材商
- */
- namespace api\modules\v1\controllers;
- use common\library\ZM_Geohash;
- use common\models\UserMater;
- use yii\rest\ActiveController;
- use common\library\Apireturn;
- use yii\helpers\ArrayHelper;
- use yii\filters\auth\QueryParamAuth;
- use yii;
- class MaterController extends ActiveController
- {
- public $modelClass = 'common\models';
- public function behaviors()
- {
- return ArrayHelper::merge(parent::behaviors(), [
- 'authenticator' => [
- 'class' => QueryParamAuth::className(),
- 'tokenParam' => "token",//access-token修改为token
- 'optional' => [//不需要认证方法名 array
- ],
- ]
- ]);
- }
- /**
- * 用户查看建材商详情
- * @return array
- */
- public function actionInfo()
- {
- $id = Yii::$app->request->post('id');
- $latitude = Yii::$app->request->post('latitude');
- $longitude = Yii::$app->request->post('longitude');
- $info = UserMater::find()->select('id,uid,backpic,company,name,tel,position,age,intro,type_id,latitude,longitude,address')->where(['id'=>$id,'member'=>UserMater::MEMBER_YES])->one();
- if(empty($info))
- return Apireturn::sent(0,'找不到记录',200);
- $data = array();
- foreach ($info->getOldAttributes() as $key => $val)
- {
- $data[$key] = $val;
- }
- $data['type'] = !empty($info->type) ? $info->type->name : "";
- //距离
- $data['distance'] = "";
- if(!empty($latitude)&&!empty($longitude)) {
- $geohash = new ZM_Geohash();
- if (!empty($info->latitude) && !empty($info->longitude)) {
- $data['distance'] = sprintf("%.1f", $geohash->getDistance($latitude, $longitude, $info->latitude, $info->longitude) / 1000);
- }
- }
- $data['imgs'] = array();
- if(!empty($info->images))
- {
- foreach ($info->images as $img_val)
- $data['imgs'][] = $img_val->pic;
- }
- return Apireturn::sent(1,'success',200,$data);
- }
- }
|