Spec.php
2.2 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
73
74
75
76
<?php
namespace app\common\model;
use think\Model;
class Spec extends Model
{
/**
* 正常显示规格
*/
public static function specList($spec_template_id){
// 一级规格组
$list = self::getSpecList(['spec_template_id'=>$spec_template_id,'pid'=>0,'display_mode'=>'1']);
return $list;
}
/**
* 规格值下规格
*/
public static function valueSpecList($spec_value_id)
{
//规格值下规格组ID集合
$spec_ids = SpecValue::where('id',$spec_value_id)->value('spec_ids');
// 一级规格组
$list = self::where('id','in',$spec_ids)
->field('id,pid,spec_name,spec_type')
->order('weigh desc')
->select();
foreach($list as &$v){
// 规格组选项
$v['options'] = self::getOptions($v['id']);
}
return $list;
}
/**
* 身体信息
*/
public static function bodyInfo($spec_template_id){
// 一级规格组
$list = self::getSpecList(['spec_template_id'=>$spec_template_id,'pid'=>0,'display_mode'=>'1']);
return $list;
}
/**
* 获取规格列表
*/
public static function getSpecList($where){
$list = self::where($where)
->order('weigh desc')
->select();
foreach($list as $v){
$v['spec_value_list'] = self::getSpecValueList($v['id']);
$v['two_spec_list'] = self::getSpecList(['pid'=>$v['id']]);
$v->visible(['id','spec_name','spec_type','display_mode'])->append(['spec_value_list','two_spec_list']);
}
$list = collection($list)->toArray();
return $list;
}
/**
* 获取规格值列表
*/
public static function getSpecValueList($spec_id){
$list = SpecValue::where('spec_id',$spec_id)
->order('weigh desc')
->select();
foreach($list as $v){
$v['spec_list'] = self::getSpecList(['id'=>['in',$v['spec_ids']]]);
$v->visible(['id','spec_id','spec_value','spec_value_image','spec_value_description','spec_ids'])->append(['spec_list']);
}
$list = collection($list)->toArray();
return $list;
}
}