wang hou sheng 7 months ago
parent c7633e7828
commit e5ebce9ffc
  1. 10
      app/common/model/User.php
  2. 16
      app/store/controller/User.php
  3. 2
      app/store/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

@ -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'));
}

@ -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']);
}
/**

Loading…
Cancel
Save