function ($model) { return Url::to($model->getAvatar(), true); }, 'profile', 'count', 'type', 'chain'=> function ($model) { return Category::find()->where(['id' => $model->chain])->one(); }, ]; } /** * 扩展属性 * 请求时接口url加参数,如:?expand=profile * @return array|false * @author nodelog */ public function extraFields() { return [ 'profile', 'count', ]; } /** * 数据统计 * @author nodelog */ public function getCount() { $data = []; $where = ['user_id' => \Yii::$app->user->id]; $searchCount = SearchRecord::find()->where($where)->andWhere(['del' => 0])->sum('count'); if (empty($searchCount)) { $searchCount = 0; } $pagePathList = \Yii::$app->config->get('page_path_list'); $data[] = [ 'title' => '搜索', 'count' => $searchCount, 'link' => $pagePathList['search_page'], 'link_type' => 1 ]; $data[] = [ 'title' => '足迹', 'count' => Footprint::find()->my()->count(), 'link' => $pagePathList['footprint_page'], 'link_type' => 1 ]; $data[] = [ 'title' => '企业反馈', 'count' => Article::find()->my()->count(), 'link' => $pagePathList['company_page'], 'link_type' => 1 ]; $data[] = [ 'title' => '意见反馈', 'count' => Suggest::find()->where($where)->count(), 'link' => $pagePathList['feedback_page'], 'link_type' => 1 ]; return $data; } /** * 获取用户信息 * @return \yii\db\ActiveQuery * @author nodelog */ public function getProfile() { return $this->hasOne(Profile::className(), ['user_id' => 'id']); } }