// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\api\model\groupon; use app\common\model\groupon\TaskUsers as TaskUsersModel; /** * 拼团拼单成员模型 * Class TaskUsers * @package app\api\model\groupon */ class TaskUsers extends TaskUsersModel { /** * 隐藏字段 * @var array */ protected $hidden = [ 'order_id', 'robot_id', 'store_id', 'create_time', ]; /** * 获取指定拼单的成员列表 * @param int $taskId 拼单ID * @return TaskUsers[]|array|\think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getUserList(int $taskId) { $list = $this->where('task_id', '=', $taskId)->select(); if ($list->isEmpty()) { return $list; } $list = static::preload($list, ['user.avatar', 'robot.avatar'], true); $data = []; foreach ($list as $item) { $data[] = [ 'id' => $item['id'], 'task_id' => $item['task_id'], 'is_leader' => $item['is_leader'], 'userInfo' => $item['is_robot'] ? ['nick_name' => $item['robot']['nick_name'], 'avatar_url' => $item['robot']['avatar']['preview_url']] : ['nick_name' => $item['user']['nick_name'], 'avatar_url' => $item['user']['avatar_url']] ]; } return $data; } }