Files
huangjingfen/pro_v3.5.1/app/model/product/shipping/ShippingTemplates.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

158 lines
3.2 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | Author: ScottPan Team
// +----------------------------------------------------------------------
namespace app\model\product\shipping;
use crmeb\traits\ModelTrait;
use crmeb\basic\BaseModel;
use think\Model;
/**
* 运费模板Model
* Class ShippingTemplates
* @package app\model\product\shipping
*/
class ShippingTemplates extends BaseModel
{
use ModelTrait;
/**
* 数据表主键
* @var string
*/
protected $pk = 'id';
/**
* 模型名称
* @var string
*/
protected $name = 'shipping_templates';
/**
* 是否开启包邮获取器
* @param $value
* @return string
*/
public function getAppointAttr($value)
{
$status = [1 => '开启', 0 => '关闭'];
return $status[$value];
}
/**
* 添加时间获取器
* @param $value
* @return false|string
*/
public function getAddTimeAttr($value)
{
$value = date('Y-m-d H:i:s', $value);
return $value;
}
/**
* 运费地区一对多关联
* @return \think\model\relation\HasMany
*/
public function region()
{
return $this->hasMany(ShippingTemplatesRegion::class, 'temp_id', 'id');
}
/**
* 包邮地区一对多关联
* @return \think\model\relation\HasMany
*/
public function free()
{
return $this->hasMany(ShippingTemplatesFree::class, 'temp_id', 'id');
}
/**
* ID搜索器
* @param Model $query
* @param $value
* @param $data
*/
public function searchIdAttr($query, $value)
{
if (is_array($value)) {
$query->whereIn('id', $value);
} else {
$query->where('id', $value);
}
}
/**
* 模板名称搜索器
* @param Model $query
* @param $value
* @param $data
*/
public function searchNameAttr($query, $value)
{
if ($value) {
$query->where('name', 'like', '%' . $value . '%');
}
}
/**
* 计费方式搜索器
* @param Model $query
* @param $value
*/
public function searchGroupAttr($query, $value)
{
if (is_array($value)) {
if ($value) $query->whereIn('group', $value);
} else {
if ($value !== '') $query->where('group', $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);
}
}
}