74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | 作者:修缘 联系QQ:278896498 QQ群:1054861244
|
||
// | 声明:未经作者许可,禁止倒卖等商业运营,违者必究
|
||
// | 另接php业务,网站制作、代理后台、gm后台、支付对接等
|
||
// +----------------------------------------------------------------------
|
||
// | 创建时间: 2022/1/1 2:55
|
||
// +----------------------------------------------------------------------
|
||
|
||
|
||
namespace app\common\model;
|
||
|
||
|
||
|
||
use app\admin\model\AgencyUser;
|
||
use think\facade\Config;
|
||
|
||
class Player extends Model
|
||
{
|
||
protected $table = 'qy_role';
|
||
protected $pk = 'roleid';
|
||
|
||
protected $searchField = ['roleid', 'name'];
|
||
protected $whereField = ['serverid'];
|
||
protected $specialTimeFiled = 'create_time';
|
||
|
||
|
||
public function getServeridAttr($value)
|
||
{
|
||
$server_config = Config::get('game.server');
|
||
$server_name_text = array_column($server_config, 'name', 'id');
|
||
return $server_name_text[$value];
|
||
}
|
||
|
||
public function scopeWhere($query, $param): void
|
||
{
|
||
//关键词like搜索
|
||
$keywords = $param['_keywords'] ?? '';
|
||
if ('' !== $keywords && count($this->searchField) > 0) {
|
||
$this->searchField = implode('|', $this->searchField);
|
||
$query->where($this->searchField, 'like', '%' . $keywords . '%');
|
||
}
|
||
|
||
//字段条件查询
|
||
if (count($this->whereField) > 0 && count($param) > 0) {
|
||
foreach ($param as $key => $value) {
|
||
if ($value !== '' && in_array((string)$key, $this->whereField, true)) {
|
||
$query->where($key, $value);
|
||
}
|
||
}
|
||
}
|
||
if (!empty($this->specialTimeFiled) && !empty($param['special_create_time'])) {
|
||
$query->whereTime($this->specialTimeFiled, urldecode($param['special_create_time']));
|
||
}
|
||
|
||
//排序
|
||
$order = $param['_order'] ?? '';
|
||
$by = $param['_by'] ?? 'desc';
|
||
$query->order($order ?: 'roleid', $by ?: 'desc');
|
||
}
|
||
|
||
|
||
public function account()
|
||
{
|
||
return $this->belongsTo(User::class,'accountid','accountid');
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |