Files
huangjingfen/pro_v3.5.1/app/model/other/Category.php
panchengyong c1e74d8e68 chore(php): 统一 ScottPan 文件头与注释域名替换
- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明

Made-with: Cursor
2026-03-29 11:22:58 +08:00

171 lines
3.5 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
// +----------------------------------------------------------------------
// | Author: ScottPan Team
// +----------------------------------------------------------------------
namespace app\model\other;
use app\model\product\label\StoreProductLabel;
use app\model\product\specs\StoreProductSpecs;
use app\model\user\label\UserLabel;
use crmeb\basic\BaseModel;
use crmeb\traits\ModelTrait;
use think\Model;
/**
* 分类表
* Class Category
* @package app\model\other
*/
class Category extends BaseModel
{
use ModelTrait;
/**
* 表名
* @var string
*/
protected $name = 'category';
/**
* 主键
* @var string
*/
protected $pk = 'id';
/**
* 用户标签
* @return \think\model\relation\HasMany
*/
public function label()
{
return $this->hasMany(UserLabel::class, 'label_cate', 'id');
}
/**
* 商品标签
* @return \think\model\relation\HasMany
*/
public function productLabel()
{
return $this->hasMany(StoreProductLabel::class, 'label_cate', 'id');
}
/**
* 商品参数
* @return \think\model\relation\HasMany
*/
public function specs()
{
return $this->hasMany(StoreProductSpecs::class, 'temp_id', 'id')->order('sort desc');
}
/**
* 获取子集分类查询条件
* @return \think\model\relation\HasMany
*/
public function children()
{
return $this->hasMany(self::class, 'pid', 'id')->where('is_show', 1)->order('sort DESC,id DESC');
}
/**
* 归属人
* @param Model $query
* @param $value
*/
public function searchOwnerIdAttr($query, $value)
{
$query->where('owner_id', $value);
}
/**
* 商户搜索器
* @param Model $query
* @param $value
*/
public function searchTypeAttr($query, $value)
{
if (is_array($value)) {
if ($value) $query->whereIn('type', $value);
} else {
if ($value !== '') $query->where('type', $value);
}
}
/**
* 关联门店ID、供应商ID搜索器
* @param Model $query
* @param $value
*/
public function searchRelationIdAttr($query, $value)
{
if (is_array($value)) {
if ($value) $query->whereIn('relation_id', $value);
} else {
if ($value !== '') $query->where('relation_id', $value);
}
}
/**
* 供应商
* @param Model $query
* @param $value
*/
public function searchSupplierIdAttr($query, $value)
{
if (is_array($value)) {
if ($value) $query->whereIn('relation_id', $value)->where('type', 2);
} else {
if ($value !== '') $query->where('relation_id', $value)->where('type', 2);
}
}
/**
* 门店
* @param Model $query
* @param $value
*/
public function searchStoreIdAttr($query, $value)
{
if (is_array($value)) {
if ($value) $query->whereIn('relation_id', $value)->where('type', 1);
} else {
if ($value !== '') $query->where('relation_id', $value)->where('type', 1);
}
}
/**
* 标签类型0用户1客服话术
* @param Model $query
* @param $value
*/
public function searchGroupAttr($query, $value)
{
$query->where('group', $value);
}
/**
* @param $query
* @param $value
*/
public function searchNotIdAttr($query, $value)
{
$query->where('id', '<>', $value);
}
/**
* 分类是否显示搜索器
* @param Model $query
* @param $value
* @param $data
*/
public function searchIsShowAttr($query, $value, $data)
{
if ($value !== '') $query->where('is_show', $value);
}
}