Category.php
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace app\api\model;
use think\Db;
use think\Model;
class Category extends Model
{
// 表名
protected $name = 'category';
public function getImageAttr($value)
{
if($value) $value = cdnurl($value);
return $value;
}
public function selectData($where, $limit=null,$lang)
{
$where['status'] = ['eq', '1'];
if ($lang == 'ch') $field = 'id,name,image';
else $field = 'id,en_name name,image';
$data = $this->where($where)->field($field)->order('weigh desc')->limit($limit)->select();
return $data;
}
public function getExtend($where,$lang,$whereOr=null)
{
$goodsModel = new Goods();
$ids = $goodsModel->alias('g')
// ->join('fa_category cate1', 'g.category_one_id=cate1.id')
// ->join('fa_category cate2', 'g.category_two_id=cate2.id')
// ->join('fa_category cate3', 'g.category_three_id=cate3.id')
->where($where)
->whereOr($whereOr)
->field('country_id,brand_id,level_id,part_id,category2_id')
->select();
$countryids = [];
$brandids = [];
$levelids = [];
$partids = [];
$category2ids = [];
foreach ($ids as $k=>$v){
$countryids[$k] = $v['country_id'];
$brandids[$k] = $v['brand_id'];
$levelids[$k] = $v['level_id'];
$partids[$k] = $v['part_id'];
$category2ids[$k] = $v['category2_id'];
}
if ($lang == 'ch') $field = 'id,ch_name name';
else $field = 'id,en_name name';
$country = Db::name('country')->where(['id'=>['in',array_unique($countryids)]])->field($field)->select();
$brand = Db::name('brand')->where(['id'=>['in',array_unique($brandids)]])->field($field)->select();
$level = Db::name('level')->where(['id'=>['in',array_unique($levelids)]])->field($field)->select();
$part = Db::name('part')->where(['id'=>['in',array_unique($partids)]])->field($field)->select();
$category2 = Db::name('category2')->where(['id'=>['in',array_unique($category2ids)]])->field($field)->select();
$data = [];
if ($country) $data[] = ['title' => '国家','list'=>$country];
if ($brand) $data[] = ['title' => '品牌','list'=>$brand];
if ($level) $data[] = ['title' => '等级','list'=>$level];
if ($part) $data[] = ['title' => '部位','list'=>$part];
if ($category2) $data[] = ['title' => '品类','list'=>$category2];
return $data;
}
}