PersonController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * 用户端 设计师/项目经理
  4. */
  5. namespace api\modules\v1\controllers;
  6. use common\library\ZM_Geohash;
  7. use common\models\Building;
  8. use common\models\Designer;
  9. use common\models\ImageSource;
  10. use common\models\Manager;
  11. use yii\rest\ActiveController;
  12. use common\library\Apireturn;
  13. use yii\helpers\ArrayHelper;
  14. use yii\filters\auth\QueryParamAuth;
  15. use yii;
  16. class PersonController extends ActiveController
  17. {
  18. public $modelClass = 'common\models';
  19. const DISPLAY = 10;//显示条数
  20. public function behaviors()
  21. {
  22. return ArrayHelper::merge(parent::behaviors(), [
  23. 'authenticator' => [
  24. 'class' => QueryParamAuth::className(),
  25. 'tokenParam' => "token",//access-token修改为token
  26. 'optional' => [//不需要认证方法名 array
  27. ],
  28. ]
  29. ]);
  30. }
  31. /**
  32. * 设计师,项目经理信息
  33. */
  34. public function actionInfo()
  35. {
  36. $id =Yii::$app->request->post('id');
  37. $type = Yii::$app->request->post('type');
  38. if(empty($id))
  39. return Apireturn::sent(0,'缺少id');
  40. if($type == 1)//设计师
  41. {
  42. $data = Designer::find()->where(['id'=>$id])->select('id,realname,introduction')->asArray()->one();
  43. $image = ImageSource::find()->where(['type'=>ImageSource::TYPE_DESIGNER,'status'=>ImageSource::STATUS_YES,'topid'=>$id])->select('pic')->one();
  44. $data['type'] = 1;
  45. if(!empty($image))
  46. $data['pic'] =$image->pic;
  47. }else{
  48. $data = Manager::find()->where(['id'=>$id])->select('id,realname,introduction')->asArray()->one();
  49. $image = ImageSource::find()->where(['type'=>ImageSource::TYPE_MANAGER,'status'=>ImageSource::STATUS_YES,'topid'=>$id])->select('pic')->one();
  50. $data['type'] = 2;
  51. if(!empty($image))
  52. $data['pic'] =$image->pic;
  53. }
  54. return Apireturn::sent(1,'success',200,$data);
  55. }
  56. /**
  57. * 作品列表
  58. */
  59. public function actionWorkList()
  60. {
  61. $id = Yii::$app->request->post('id');
  62. $type = Yii::$app->request->post('type');
  63. $page = Yii::$app->request->post('page', 1);//分页页数
  64. $display = Yii::$app->request->post('display', self::DISPLAY);//分页页数
  65. $latitude = Yii::$app->request->post('latitude');
  66. $longitude = Yii::$app->request->post('longitude');
  67. $lists = array();
  68. if(empty($id))
  69. return Apireturn::sent(0,'缺少id');
  70. if($type == 1)
  71. {
  72. $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();
  73. if(!empty($list))
  74. {
  75. $geohash = new ZM_Geohash();
  76. foreach ($list as $key => $val)
  77. {
  78. foreach ($val->getOldAttributes() as $key2 =>$value2)
  79. {
  80. $lists[$key][$key2] = $value2;
  81. }
  82. $lists[$key]['pic'] = $val->all?$val->all->pic:"";
  83. if(!empty($val->latitude) && !empty($val->longitude) && !empty($latitude) && !empty($longitude))
  84. {
  85. $lists[$key]['distance'] = sprintf("%.1f",$geohash->getDistance($latitude,$longitude,$val->latitude,$val->longitude)/1000);
  86. }else{
  87. $lists[$key]['distance'] = "";
  88. }
  89. }
  90. }
  91. }else{
  92. $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();
  93. if(!empty($list))
  94. {
  95. $geohash = new ZM_Geohash();
  96. foreach ($list as $key => $val)
  97. {
  98. foreach ($val->getOldAttributes() as $key2 =>$value2)
  99. {
  100. $lists[$key][$key2] = $value2;
  101. }
  102. $lists[$key]['pic'] = $val->all?$val->all->pic:"";
  103. if(!empty($val->latitude) && !empty($val->longitude) && !empty($latitude) && !empty($longitude))
  104. {
  105. $lists[$key]['distance'] = sprintf("%.1f",$geohash->getDistance($latitude,$longitude,$val->latitude,$val->longitude)/1000);
  106. }else{
  107. $lists[$key]['distance'] = "";
  108. }
  109. }
  110. }
  111. }
  112. return Apireturn::sent(1,'success',200,$lists);
  113. }
  114. }