where($map)->order('sort desc,id desc'); if (count($data) > 0) { $users = $query->whereIn('id', array_unique(array_column($data, $field)))->column($fields, 'id'); foreach ($data as &$vo) $vo[$target] = $users[$vo[$field]] ?? []; return $users; } else { return $query->column($fields, 'id'); } } /** * 关联身份权限 * @return HasOne */ public function userinfo(): HasOne { return $this->hasOne(SystemBase::class, 'code', 'usertype')->where([ 'type' => '身份权限', 'status' => 1, 'deleted' => 0, ]); } /** * 格式化登录时间 * @param string $value * @return string */ public function getLoginAtAttr(string $value): string { return format_datetime($value); } /** * 格式化创建时间 * @param string $value * @return string */ public function getCreateAtAttr(string $value): string { return format_datetime($value); } }