CRMEB/backend/app/model/driver/bot/BotDriver.php
2026-09-23 15:15:02 +08:00

74 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
namespace app\model\driver\bot;
use crmeb\basic\BaseModel;
class BotDriver extends BaseModel
{
/**
* 驱动类型标识(对应 eb_driver.driver_type)
*/
const DRIVER_TYPE = 'bot';
/**
* @var string
*/
protected $name = 'driver';
/**
* 全局查询作用域:读取时自动过滤 driver_type
* @var array
*/
protected $globalScope = ['driverType'];
/**
* 插入时自动填充 driver_type
* @var array
*/
protected $insert = ['driver_type' => self::DRIVER_TYPE];
/**
* 更新时自动填充 driver_type
* @var array
*/
protected $update = ['driver_type' => self::DRIVER_TYPE];
/**
* 驱动类型全局作用域
* @param $query
*/
public function scopeDriverType($query)
{
$query->where('driver_type', self::DRIVER_TYPE)->where('owner_plugin_id', '<>', '');
}
protected $autoWriteTimestamp = true;
public function searchStatusAttr($query, $value)
{
if ($value !== '' && $value !== null) {
$query->where('status', $value);
}
}
public function searchDriverKeyAttr($query, $value)
{
if ($value) {
$query->where('driver_key', $value);
}
}
public function getConfigFieldsAttr($value): array
{
return $value ? json_decode($value, true) : [];
}
public function setConfigFieldsAttr($value): string
{
return is_array($value) ? json_encode($value, JSON_UNESCAPED_UNICODE) : $value;
}
}