User.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: NODELOG
  5. * DateTime: 2017/3/8 16:32
  6. * Description:
  7. */
  8. namespace api\common\models;
  9. use api\modules\v1\models\Circle;
  10. use api\modules\v1\models\Clock;
  11. use api\modules\v1\models\ClockLike;
  12. use api\modules\v1\models\Comment;
  13. use api\modules\v1\models\UserCar;
  14. use common\models\Article;
  15. use common\models\Footprint;
  16. use common\models\Friend;
  17. use common\models\SearchRecord;
  18. use common\models\Suggest;
  19. use yii\helpers\Url;
  20. class User extends \common\modules\user\models\User
  21. {
  22. /**
  23. * 默认属性
  24. * @return array|false
  25. * @author nodelog
  26. */
  27. public function fields()
  28. {
  29. return [
  30. 'nickname',
  31. 'tel',
  32. 'avatar' => function ($model) {
  33. return Url::to($model->getAvatar(), true);
  34. },
  35. 'profile',
  36. 'count',
  37. ];
  38. }
  39. /**
  40. * 扩展属性
  41. * 请求时接口url加参数,如:?expand=profile
  42. * @return array|false
  43. * @author nodelog
  44. */
  45. public function extraFields()
  46. {
  47. return [
  48. 'profile',
  49. 'count',
  50. ];
  51. }
  52. /**
  53. * 数据统计
  54. * @author nodelog
  55. */
  56. public function getCount()
  57. {
  58. $data = [];
  59. $where = ['user_id' => \Yii::$app->user->id];
  60. $searchCount = SearchRecord::find()->where($where)->andWhere(['del' => 0])->sum('count');
  61. if (empty($searchCount)) {
  62. $searchCount = 0;
  63. }
  64. $pagePathList = \Yii::$app->config->get('page_path_list');
  65. $data[] = [
  66. 'title' => '搜索',
  67. 'count' => $searchCount,
  68. 'link' => $pagePathList['search_page'],
  69. 'link_type' => 1
  70. ];
  71. $data[] = [
  72. 'title' => '足迹',
  73. 'count' => Footprint::find()->my()->count(),
  74. 'link' => $pagePathList['footprint_page'],
  75. 'link_type' => 1
  76. ];
  77. $data[] = [
  78. 'title' => '企业反馈',
  79. 'count' => Article::find()->my()->count(),
  80. 'link' => $pagePathList['company_page'],
  81. 'link_type' => 1
  82. ];
  83. $data[] = [
  84. 'title' => '意见反馈',
  85. 'count' => Suggest::find()->where($where)->count(),
  86. 'link' => $pagePathList['feedback_page'],
  87. 'link_type' => 1
  88. ];
  89. return $data;
  90. }
  91. /**
  92. * 获取用户信息
  93. * @return \yii\db\ActiveQuery
  94. * @author nodelog
  95. */
  96. public function getProfile()
  97. {
  98. return $this->hasOne(Profile::className(), ['user_id' => 'id']);
  99. }
  100. }