diff --git a/app/common/model/User.php b/app/common/model/User.php index 2f5a4662..93f04e45 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -13,6 +13,7 @@ declare (strict_types=1); namespace app\common\model; use app\common\enum\user\UserTypeEnum; +use app\common\model\invite\InviteLog; use app\common\model\user\PointsLog as PointsLogModel; use cores\BaseModel; use think\model\relation\BelongsTo; @@ -71,6 +72,15 @@ class User extends BaseModel ->bind(['avatar_url' => 'preview_url']); } + /** + * 关联邀请 + * @return HasOne + */ + public function invite(): HasOne + { + return $this->hasOne(InviteLog::class, 'invitee_user_id', 'user_id'); + } + /** * 关联会员等级表 * @return BelongsTo diff --git a/app/store/controller/User.php b/app/store/controller/User.php index 3a2d2296..408b290d 100644 --- a/app/store/controller/User.php +++ b/app/store/controller/User.php @@ -12,6 +12,7 @@ declare (strict_types=1); namespace app\store\controller; +use app\store\model\UploadFile; use app\store\model\User as UserModel; use think\db\exception\DbException; use think\response\Json; @@ -33,6 +34,21 @@ class User extends Controller // 用户列表 $model = new UserModel; $list = $model->getList($this->request->param()); + if ($list->total() > 0) { + $list->each(function ($item) { + //邀请 + $item->invite_user = []; + if (!empty($item->invite->user)) { + if (!empty($item->invite->user->avatar_id)) { + $file = UploadFile::detail($item->invite->user->avatar_id); + $item->invite->user->avatar_url = !empty($file->preview_url) ? $file->preview_url : ''; + } + $item->invite_user = $item->invite->user; + } + unset($item->invite); + }); + } + return $this->renderSuccess(compact('list')); } diff --git a/app/store/model/User.php b/app/store/model/User.php index c74f2e2d..3f5c0530 100644 --- a/app/store/model/User.php +++ b/app/store/model/User.php @@ -91,7 +91,7 @@ class User extends UserModel ->where('is_delete', '=', '0') ->order(['create_time' => 'desc']) ->paginate(15); - return static::preload($userList, ['avatar', 'grade']); + return static::preload($userList, ['avatar', 'grade', 'invite.user']); } /**