- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明 Made-with: Cursor
122 lines
2.5 KiB
PHP
122 lines
2.5 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Author: ScottPan Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\model\user\label;
|
|
|
|
use app\model\other\Category;
|
|
use crmeb\basic\BaseModel;
|
|
use crmeb\traits\ModelTrait;
|
|
use think\Model;
|
|
|
|
/**
|
|
* 用户标签
|
|
* Class UserLabel
|
|
* @package app\model\user\label
|
|
*/
|
|
class UserLabel extends BaseModel
|
|
{
|
|
use ModelTrait;
|
|
|
|
/**
|
|
* 数据表主键
|
|
* @var string
|
|
*/
|
|
protected $pk = 'id';
|
|
|
|
/**
|
|
* 模型名称
|
|
* @var string
|
|
*/
|
|
protected $name = 'user_label';
|
|
|
|
|
|
public function category()
|
|
{
|
|
return $this->hasOne(Category::class, 'id', 'label_cate')->bind(['cate_name' => 'name']);
|
|
}
|
|
|
|
/**
|
|
* 标签分类
|
|
* @param \think\Model $query
|
|
* @param $value
|
|
*/
|
|
public function searchLabelCateAttr($query, $value)
|
|
{
|
|
if ($value !== '') {
|
|
if (is_array($value)) {
|
|
$query->whereIn('label_cate', $value);
|
|
} else {
|
|
$query->where('label_cate', $value);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* type搜索器
|
|
* @param Model $query
|
|
* @param $value
|
|
*/
|
|
public function searchTypeAttr($query, $value)
|
|
{
|
|
if ($value) $query->where('type', $value);
|
|
}
|
|
|
|
|
|
public function searchLabelNameAttr($query, $value)
|
|
{
|
|
if ($value !== '') {
|
|
$query->whereLike('label_name', "%{$value}%");
|
|
}
|
|
}
|
|
|
|
public function searchStatusAttr($query, $value)
|
|
{
|
|
if ($value !== '') $query->where('status', $value);
|
|
}
|
|
|
|
public function searchLabelTypeAttr($query, $value)
|
|
{
|
|
if ($value !== '') $query->where('label_type', $value);
|
|
}
|
|
|
|
/**
|
|
* store_id搜索器
|
|
* @param Model $query
|
|
* @param $value
|
|
*/
|
|
public function searchStoreIdAttr($query, $value)
|
|
{
|
|
if ($value !== '') $query->where('store_id', $value);
|
|
}
|
|
|
|
/**
|
|
* ids搜索器
|
|
* @param Model $query
|
|
* @param $value
|
|
*/
|
|
public function searchIdsAttr($query, $value)
|
|
{
|
|
if ($value !== '') {
|
|
if (is_array($value)) {
|
|
$query->whereIn('id', $value);
|
|
} else {
|
|
$query->where('id', $value);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param $query
|
|
* @param $value
|
|
*/
|
|
public function searchNotTagIdAttr($query, $value)
|
|
{
|
|
$query->where(function ($query) {
|
|
$query->whereNull('tag_id')->whereOr('tag_id', '');
|
|
});
|
|
}
|
|
}
|