Goods.php
1.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
<?php
namespace app\api\model;
use addons\litestore\model\Litestoregoodsspec;
use think\Model;
class Goods extends Model
{
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
protected $name = 'litestore_goods';
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $append = [
'image_text',
'images_text',
'down_image_text',
'four_image_text'
];
public function getImageTextAttr($value,$data)
{
$value = !empty($data['image']) ? cdnurl($data['image'],true):'';
return $value;
}
public function getFourImageTextAttr($value,$data)
{
$value = !empty($data['four_images']) ? explode(',',$data['four_images']):[];
foreach ($value as $key => &$val){
$val = cdnurl($val,true);
}
return $value;
}
public function getImagesTextAttr($value,$data)
{
$value = !empty($data['images']) ? explode(',',$data['images']):[];
foreach ($value as $key => &$val){
$val = cdnurl($val,true);
}
return $value;
}
public function getDownImageTextAttr($value,$data)
{
$value = !empty($data['down_image']) ? cdnurl($data['down_image'],true):'';
return $value;
}
// 总库存
public function getStockNumAttr($value,$data)
{
$value = GoodsSpec::where('goods_id',$data['goods_id'])->sum('stock_num');
return $value;
}
}