CompanyPersonController.php 4.7 KB

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