Files
huangjingfen/pro_v3.5.1/app/model/user/label/UserLabel.php
panchengyong 7acbf45ff7 new files
2026-03-07 22:29:07 +08:00

128 lines
3.0 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
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
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', '');
});
}
}