120 lines
3.3 KiB
PHP
120 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
/**
|
|
* @property int $dept_id
|
|
* @property int $parent_id
|
|
* @property int $account_type
|
|
* @property int $belong_id
|
|
* @property string $dept_name
|
|
* @property int $rank
|
|
* @property int $status
|
|
* @property string $remark
|
|
* @property int $del_flag
|
|
* @property string $create_time
|
|
* @property string $update_time
|
|
*/
|
|
class Dept extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'dept';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = [];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*/
|
|
protected array $casts = ['dept_id' => 'integer', 'parent_id' => 'integer', 'account_type' => 'integer', 'belong_id' => 'integer', 'rank' => 'integer', 'status' => 'integer', 'del_flag' => 'integer'];
|
|
|
|
/**
|
|
* 部门列表
|
|
* @param array $account
|
|
* @param $param
|
|
* @return array
|
|
*/
|
|
static function depts(array $account, $param): array
|
|
{
|
|
return self::where('del_flag', 0)
|
|
->where('belong_id', $account['belong_id'])
|
|
->where('account_type', $account['account_type'])
|
|
->when(isset($param['dept_name']) && $param['dept_name'] != "", function ($query) use ($param) {
|
|
$query->where('dept_name', "like", "%{$param['dept_name']}%");
|
|
})->orderByDesc("rank")
|
|
->select(["dept_id", "parent_id", "dept_name", "rank", "status", "remark", "create_time"])
|
|
->get()->toArray();
|
|
}
|
|
|
|
/**
|
|
* 添加
|
|
* @param array $data
|
|
* @return bool
|
|
*/
|
|
public static function add(array $account, array $data)
|
|
{
|
|
$data['account_type'] = $account['account_type'];
|
|
$data['belong_id'] = $account['belong_id'];
|
|
$data['create_time'] = date("Y-m-d H:i:s");
|
|
$data['del_flag'] = 0;
|
|
return self::insert($data);
|
|
}
|
|
|
|
/**
|
|
* 修改
|
|
* Author: cfn <cfn@leapy.cn>
|
|
* @param array $account
|
|
* @param array $data
|
|
* @return int
|
|
*/
|
|
public static function edit(array $account, array $data)
|
|
{
|
|
$data['update_time'] = date("Y-m-d H:i:s");
|
|
return self::where("dept_id", $data['dept_id'])
|
|
->where('belong_id', $account['belong_id'])
|
|
->where('account_type', $account['account_type'])
|
|
->where('del_flag', 0)
|
|
->update($data);
|
|
}
|
|
|
|
/**
|
|
* 删除
|
|
* @param array $account
|
|
* @param string $ids
|
|
* @return int
|
|
*/
|
|
public static function del(array $account, string $ids)
|
|
{
|
|
return self::whereIn('dept_id', explode(",", $ids))
|
|
->where('belong_id', $account['belong_id'])
|
|
->where('account_type', $account['account_type'])
|
|
->where('del_flag', 0)
|
|
->update([
|
|
'update_time' => date('Y-m-d H:i:s'),
|
|
'del_flag' => 1
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 选项
|
|
* @param array $account
|
|
* @return array
|
|
*/
|
|
public static function options(array $account): array
|
|
{
|
|
return self::where('del_flag', 0)
|
|
->where('belong_id', $account['belong_id'])
|
|
->where('account_type', $account['account_type'])
|
|
->orderByDesc("rank")
|
|
->select(["dept_id", "parent_id", "dept_name"])
|
|
->get()->toArray();
|
|
}
|
|
|
|
}
|