86 lines
2.2 KiB
PHP
86 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
/**
|
|
* @property int $group_id
|
|
* @property int $org_id
|
|
* @property string $group_name
|
|
* @property int $rank
|
|
* @property int $del_flag
|
|
* @property string $create_time
|
|
* @property string $update_time
|
|
*/
|
|
class Group extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'group';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = [];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*/
|
|
protected array $casts = ['group_id' => 'integer', 'org_id' => 'integer', 'rank' => 'integer', 'del_flag' => 'integer'];
|
|
|
|
/**
|
|
* Author: cfn <cfn@leapy.cn>
|
|
* @param array $account
|
|
* @param array $param
|
|
* @return \Hyperf\Contract\LengthAwarePaginatorInterface
|
|
*/
|
|
public static function list(array $account, array $param)
|
|
{
|
|
$model = self::where("del_flag", 0)
|
|
->where("org_id", $account['belong_id']);
|
|
|
|
foreach (['group_name'] as $k) {
|
|
if (isset($param[$k]) && $param[$k] != '') {
|
|
$model = $model->where($k, "like", "%$param[$k]%");
|
|
}
|
|
}
|
|
|
|
return $model->orderByDesc("group_id")
|
|
->paginate((int)$param['limit'], ["group_id", "group_name", "rank", "create_time"], 'page', (int)$param['page']);
|
|
}
|
|
|
|
/**
|
|
* Author: cfn <cfn@leapy.cn>
|
|
* @param array $account
|
|
* @param string $ids
|
|
* @return int
|
|
*/
|
|
public static function del(array $account, string $ids): int
|
|
{
|
|
return self::where("del_flag", 0)
|
|
->where("org_id", $account['belong_id'])
|
|
->whereIn("group_id", explode(",", $ids))
|
|
->update([
|
|
'del_flag' => 1,
|
|
'update_time' => date("Y-m-d H:i:s")
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Author: cfn <cfn@leapy.cn>
|
|
* @param array $account
|
|
* @return array
|
|
*/
|
|
public static function options(array $account): array
|
|
{
|
|
return self::where("del_flag", 0)
|
|
->where("org_id", $account['belong_id'])
|
|
->select(["group_id", "group_name"])
|
|
->orderByDesc("rank")
|
|
->get()
|
|
->toArray();
|
|
}
|
|
}
|