<?php
namespace App\Models\Api\v1;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
class Oauth extends Base
{
use HasFactory;
public $table = 'os_oauth';
private static $instance;
private function __clone()
{
}
public static function getInstance()
{
if (!self::$instance instanceof self) {
self::$instance = new static();
}
return self::$instance;
}
public function getOne($where, $columns = ['*'])
{
return $this->getResult($this->table, $where, $columns);
}
public function updateOne($where, $form)
{
return $this->updateResult($this->table, $where, $form);
}
public function saveOne($form)
{
return $this->saveResult($this->table, $form);
}
public function getLists($user, array $pagination = ['page' => 1, 'limit' => 10], array $order = ['order' => 'id', 'direction' => 'asc'], bool $getAll = false, array $column = ['*'])
{
if ($getAll) {
return DB::table($this->table)->get($column);
}
$where = [];
if (!empty($user) && !in_array($user->role_id, [1])) {
$where[] = ['os_oauth.id', $user->uid];
}
$result['data'] = DB::table($this->table)->join('os_role', $this->table.'.role_id', '=', 'os_role.id')
->limit($pagination['limit'])->offset($pagination['limit'] * ($pagination['page'] - 1))
->orderBy($order['order'],$order['direction'])
->where($where)
->get(['os_oauth.*', 'os_role.id as role_id']);
$result['total'] = DB::table($this->table)->where($where)->count();
return $result;
}
}