|
@@ -22,7 +22,6 @@ class Category extends Model
|
|
protected $updateTime = 'updatetime';
|
|
protected $updateTime = 'updatetime';
|
|
// 追加属性
|
|
// 追加属性
|
|
protected $append = [
|
|
protected $append = [
|
|
- 'url',
|
|
|
|
'flag_text',
|
|
'flag_text',
|
|
];
|
|
];
|
|
|
|
|
|
@@ -51,40 +50,6 @@ class Category extends Model
|
|
return is_array($value) ? implode(',', $value) : $value;
|
|
return is_array($value) ? implode(',', $value) : $value;
|
|
}
|
|
}
|
|
|
|
|
|
- public function getUrlAttr($value, $data)
|
|
|
|
- {
|
|
|
|
- return $this->buildUrl($value, $data);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public function getFullurlAttr($value, $data)
|
|
|
|
- {
|
|
|
|
- return $this->buildUrl($value, $data, true);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private function buildUrl($value, $data, $domain = false)
|
|
|
|
- {
|
|
|
|
- $diyname = isset($data['diyname']) && $data['diyname'] ? $data['diyname'] : $data['id'];
|
|
|
|
- $cateid = $data['id'] ?? 0;
|
|
|
|
- $catename = isset($data['diyname']) && $data['diyname'] ? $data['diyname'] : 'all';
|
|
|
|
- $time = $data['createtime'] ?? time();
|
|
|
|
-
|
|
|
|
- $vars = [
|
|
|
|
- ':id' => $data['id'],
|
|
|
|
- ':diyname' => $diyname,
|
|
|
|
- ':category' => $cateid,
|
|
|
|
- ':catename' => $catename,
|
|
|
|
- ':cateid' => $cateid,
|
|
|
|
- ':year' => date("Y", $time),
|
|
|
|
- ':month' => date("m", $time),
|
|
|
|
- ':day' => date("d", $time)
|
|
|
|
- ];
|
|
|
|
- if (isset($data['type']) && isset($data['outlink']) && $data['type'] == 'link') {
|
|
|
|
- return $this->getAttr('outlink');
|
|
|
|
- }
|
|
|
|
- $suffix = static::$config['moduleurlsuffix']['category'] ?? static::$config['urlsuffix'];
|
|
|
|
- return addon_url('shop/category/index', $vars, $suffix, $domain);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public function getImageAttr($value, $data)
|
|
public function getImageAttr($value, $data)
|
|
{
|
|
{
|
|
$value = $value ? $value : self::$config['default_category_img'];
|
|
$value = $value ? $value : self::$config['default_category_img'];
|
|
@@ -96,62 +61,13 @@ class Category extends Model
|
|
return ['hot' => __('Hot'), 'index' => __('Index'), 'recommend' => __('Recommend')];
|
|
return ['hot' => __('Hot'), 'index' => __('Index'), 'recommend' => __('Recommend')];
|
|
}
|
|
}
|
|
|
|
|
|
- public function getOutlinkAttr($value, $data)
|
|
|
|
- {
|
|
|
|
- $indexUrl = $view_replace_str = config('view_replace_str.__PUBLIC__');
|
|
|
|
- $indexUrl = rtrim($indexUrl, '/');
|
|
|
|
- return str_replace('__INDEX__', $indexUrl, $value ?: '');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public function getFlagTextAttr($value, $data)
|
|
public function getFlagTextAttr($value, $data)
|
|
{
|
|
{
|
|
$value = $value ?: ($data['flag'] ?? '');
|
|
$value = $value ?: ($data['flag'] ?? '');
|
|
$valueArr = explode(',', $value);
|
|
$valueArr = explode(',', $value);
|
|
$list = $this->getFlagList();
|
|
$list = $this->getFlagList();
|
|
return implode(',', array_intersect_key($list, array_flip($valueArr)));
|
|
return implode(',', array_intersect_key($list, array_flip($valueArr)));
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 判断是否拥有子列表
|
|
|
|
- * @param $value
|
|
|
|
- * @param $data
|
|
|
|
- * @return bool|mixed
|
|
|
|
- */
|
|
|
|
- public function getHasChildAttr($value, $data)
|
|
|
|
- {
|
|
|
|
- static $checked = [];
|
|
|
|
- if (isset($checked[$data['id']])) {
|
|
|
|
- return $checked[$data['id']];
|
|
|
|
- }
|
|
|
|
- if (is_null(self::$parentIds)) {
|
|
|
|
- self::$parentIds = self::where('pid', '>', 0)->cache(true, null, 'shop')->where('status', 'normal')->column('pid');
|
|
|
|
- }
|
|
|
|
- if (self::$parentIds && in_array($data['id'], self::$parentIds)) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 判断导航是否拥有子列表
|
|
|
|
- * @param $value
|
|
|
|
- * @param $data
|
|
|
|
- * @return bool|mixed
|
|
|
|
- */
|
|
|
|
- public function getHasNavChildAttr($value, $data)
|
|
|
|
- {
|
|
|
|
- static $checked = [];
|
|
|
|
- if (isset($checked[$data['id']])) {
|
|
|
|
- return $checked[$data['id']];
|
|
|
|
- }
|
|
|
|
- if (is_null(self::$navParentIds)) {
|
|
|
|
- self::$navParentIds = self::where('pid', '>', 0)->cache(true, null, 'shop')->where('status', 'normal')->where('isnav', 1)->column('pid');
|
|
|
|
- }
|
|
|
|
- if (self::$navParentIds && in_array($data['id'], self::$navParentIds)) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
public static function getIndexCategoryList()
|
|
public static function getIndexCategoryList()
|
|
{
|
|
{
|
|
@@ -165,73 +81,6 @@ class Category extends Model
|
|
$categoryList = collection($categoryList)->toArray();
|
|
$categoryList = collection($categoryList)->toArray();
|
|
return $categoryList;
|
|
return $categoryList;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取面包屑导航
|
|
|
|
- * @param array $category
|
|
|
|
- * @param array $goods
|
|
|
|
- * @param array $page
|
|
|
|
- * @return array
|
|
|
|
- */
|
|
|
|
- public static function getBreadcrumb($category, $goods = [], $page = [])
|
|
|
|
- {
|
|
|
|
- $list = [];
|
|
|
|
- $list[] = ['name' => __('Home'), 'url' => addon_url('shop/index/index', [], false)];
|
|
|
|
- if ($category) {
|
|
|
|
- if ($category['pid']) {
|
|
|
|
- $categoryList = self::where('status', 'normal')
|
|
|
|
- ->order('weigh desc,id desc')
|
|
|
|
- ->field('id,name,pid,diyname')
|
|
|
|
- ->cache(true, null, 'shop')
|
|
|
|
- ->select();
|
|
|
|
- //获取栏目的所有上级栏目
|
|
|
|
- $parents = \fast\Tree::instance()->init(collection($categoryList)->toArray(), 'pid')->getParents($category['id']);
|
|
|
|
- foreach ($parents as $k => $v) {
|
|
|
|
- $list[] = ['name' => $v['name'], 'url' => $v['url']];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- $list[] = ['name' => $category['name'], 'url' => $category['url']];
|
|
|
|
- }
|
|
|
|
- if ($goods) {
|
|
|
|
- //$list[] = ['name' => $goods['title'], 'url' => $goods['url']];
|
|
|
|
- }
|
|
|
|
- if ($page && $category['url'] != $page['url']) {
|
|
|
|
- $list[] = ['name' => $page['title'], 'url' => $page['url']];
|
|
|
|
- }
|
|
|
|
- return $list;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取导航分类列表HTML
|
|
|
|
- * @param $category
|
|
|
|
- * @param array $tag
|
|
|
|
- * @return mixed|string
|
|
|
|
- */
|
|
|
|
- public static function getNav($category, $tag = [])
|
|
|
|
- {
|
|
|
|
- $config = get_addon_config('shop');
|
|
|
|
- $condition = empty($tag['condition']) ? '' : $tag['condition'];
|
|
|
|
- $maxLevel = !isset($tag['maxlevel']) ? 0 : $tag['maxlevel'];
|
|
|
|
-
|
|
|
|
- list($cacheKey, $cacheExpire) = Service::getCacheKeyExpire('nav', $tag);
|
|
|
|
-
|
|
|
|
- $cacheName = 'shop-nav-' . md5(serialize($tag));
|
|
|
|
- $result = Cache::tag('shop')->get($cacheName);
|
|
|
|
- if ($result === false) {
|
|
|
|
- $categoryList = Category::where($condition)
|
|
|
|
- ->where('status', 'normal')
|
|
|
|
- ->order('weigh desc,id desc')
|
|
|
|
- ->cache($cacheKey, $cacheExpire, 'shop')
|
|
|
|
- ->select();
|
|
|
|
- $tree = \fast\Tree::instance();
|
|
|
|
- $tree->init(collection($categoryList)->toArray(), 'pid');
|
|
|
|
- $result = self::getTreeUl($tree, 0, $category ? $category['id'] : '', '', 1, $maxLevel);
|
|
|
|
- Cache::tag('shop')->set($cacheName, $result);
|
|
|
|
- }
|
|
|
|
- return $result;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 获取栏目所有子级的ID
|
|
* 获取栏目所有子级的ID
|
|
* @param mixed $ids 栏目ID或集合ID
|
|
* @param mixed $ids 栏目ID或集合ID
|