mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-28 21:40:50 +00:00
88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||
// +----------------------------------------------------------------------
|
||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||
// +----------------------------------------------------------------------
|
||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||
// +----------------------------------------------------------------------
|
||
// | Author: CRMEB Team <admin@crmeb.com>
|
||
// +----------------------------------------------------------------------
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace app\model\driver\email;
|
||
|
||
use crmeb\basic\BaseModel;
|
||
|
||
/**
|
||
* 邮件驱动字典模型
|
||
* Class EmailDriver
|
||
* @package app\model\driver\email
|
||
*/
|
||
class EmailDriver extends BaseModel
|
||
{
|
||
/**
|
||
* 驱动类型标识(对应 eb_driver.driver_type)
|
||
*/
|
||
const DRIVER_TYPE = 'email';
|
||
|
||
/**
|
||
* @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;
|
||
}
|
||
}
|