OrderGoods.php
2.0 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
77
78
<?php
namespace app\common\model;
use think\Model;
class OrderGoods extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'goods_style_text',
'make_type_text'
];
/**
* 商品
*/
public function goods()
{
return $this->belongsTo('Goods', 'goods_id')->setEagerlyType(0);
}
/**
* 尺寸
*/
public function userSize(){
return $this->belongsTo('UserSize', 'user_size_id');
}
/**
* 关联商品规格表
*/
public function spec()
{
return $this->belongsTo('GoodsSpec', 'spec_sku_id', 'spec_sku_id');
}
/**
* 定制项详情
*/
public function getGoodsStyleTextAttr($value,$data){
$goods_style_text = [];
if(!empty($data['goods_style'])){
$goods_style = json_decode($data['goods_style'],true);
foreach($goods_style as $k => $v){
$style = Style::where('id',$k)->field('style_name,style_type')->find()->toArray();
$style['style_value'] = '';
switch ($style['style_type']) {
case '1':
$style['style_value'] = StyleValue::where('id',$v)->value('style_value_name');
break;
case '2':
$style['style_value'] = $v;
break;
case '3':
$style['style_value'] = cdnurl($v,true);
break;
}
$goods_style_text[] = $style;
}
}
return $goods_style_text;
}
/**
* 定制项名称
*/
public function getMakeTypeTextAttr($value,$data){
$make_type_arr = ['0'=>'','1'=>'模特款','2'=>'自定义'];
return $make_type_arr[$data['make_type']];
}
}