98 lines
3.2 KiB
PHP
98 lines
3.2 KiB
PHP
![]() |
<?php
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | 作者:修缘 联系QQ:278896498 QQ群:1054861244
|
|||
|
// | 声明:未经作者许可,禁止倒卖等商业运营,违者必究
|
|||
|
// | 另接php业务,网站制作、代理后台、gm后台、支付对接等
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | 创建时间: 2022/1/5 19:54
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
|
|||
|
|
|||
|
namespace app\common\model;
|
|||
|
|
|||
|
use app\admin\model\AgencyUser;
|
|||
|
|
|||
|
|
|||
|
class User extends Model
|
|||
|
{
|
|||
|
// 自定义选择数据
|
|||
|
|
|||
|
|
|||
|
protected $table = 'qy_account';
|
|||
|
protected $autoWriteTimestamp = true;
|
|||
|
|
|||
|
//是否字段
|
|||
|
public const BOOLEAN_TEXT = [0 => '是', 1 => '否'];
|
|||
|
|
|||
|
//可搜索字段
|
|||
|
protected $searchField = ['account', 'agency.invite'];
|
|||
|
|
|||
|
//可作为条件的字段
|
|||
|
protected $whereField = ['invite'];
|
|||
|
|
|||
|
//可做为时间
|
|||
|
protected $timeField = ['register_time'];
|
|||
|
protected $specialTimeFiled = 'register_time';
|
|||
|
|
|||
|
//是否启用获取器
|
|||
|
public function getStateTextAttr($value, $data)
|
|||
|
{
|
|||
|
return self::BOOLEAN_TEXT[$data['state']];
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
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("agency.$key", $value);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//时间范围查询
|
|||
|
if (count($this->timeField) > 0 && count($param) > 0) {
|
|||
|
foreach ($param as $key => $value) {
|
|||
|
if ($value !== '' && in_array((string)$key, $this->timeField, true)) {
|
|||
|
$field_type = $this->getFieldsType($this->table, $key);
|
|||
|
$time_range = explode(' - ', $value);
|
|||
|
[$start_time,$end_time] = $time_range;
|
|||
|
//如果是int,进行转换
|
|||
|
if (false !== strpos($field_type, 'int')) {
|
|||
|
$start_time = strtotime($start_time);
|
|||
|
if (strlen($end_time) === 10) {
|
|||
|
$end_time .= '23:59:59';
|
|||
|
}
|
|||
|
$end_time = strtotime($end_time);
|
|||
|
}
|
|||
|
$query->where($key, 'between', [$start_time, $end_time]);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
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 ?: 'accountid', $by ?: 'desc');
|
|||
|
}
|
|||
|
|
|||
|
public function agency()
|
|||
|
{
|
|||
|
return $this->belongsTo(AgencyUser::class, 'invite', 'invite');
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|