User.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. 'type',
  38. 'chain',
  39. ];
  40. }
  41. /**
  42. * 扩展属性
  43. * 请求时接口url加参数,如:?expand=profile
  44. * @return array|false
  45. * @author nodelog
  46. */
  47. public function extraFields()
  48. {
  49. return [
  50. 'profile',
  51. 'count',
  52. ];
  53. }
  54. /**
  55. * 数据统计
  56. * @author nodelog
  57. */
  58. public function getCount()
  59. {
  60. $data = [];
  61. $where = ['user_id' => \Yii::$app->user->id];
  62. $searchCount = SearchRecord::find()->where($where)->andWhere(['del' => 0])->sum('count');
  63. if (empty($searchCount)) {
  64. $searchCount = 0;
  65. }
  66. $pagePathList = \Yii::$app->config->get('page_path_list');
  67. $data[] = [
  68. 'title' => '搜索',
  69. 'count' => $searchCount,
  70. 'link' => $pagePathList['search_page'],
  71. 'link_type' => 1
  72. ];
  73. $data[] = [
  74. 'title' => '足迹',
  75. 'count' => Footprint::find()->my()->count(),
  76. 'link' => $pagePathList['footprint_page'],
  77. 'link_type' => 1
  78. ];
  79. $data[] = [
  80. 'title' => '企业反馈',
  81. 'count' => Article::find()->my()->count(),
  82. 'link' => $pagePathList['company_page'],
  83. 'link_type' => 1
  84. ];
  85. $data[] = [
  86. 'title' => '意见反馈',
  87. 'count' => Suggest::find()->where($where)->count(),
  88. 'link' => $pagePathList['feedback_page'],
  89. 'link_type' => 1
  90. ];
  91. return $data;
  92. }
  93. /**
  94. * 获取用户信息
  95. * @return \yii\db\ActiveQuery
  96. * @author nodelog
  97. */
  98. public function getProfile()
  99. {
  100. return $this->hasOne(Profile::className(), ['user_id' => 'id']);
  101. }
  102. }