审查视图

application/api/model/Goods.php 1.8 KB
李忠强 authored
1 2 3 4 5 6
<?php


namespace app\api\model;

何书鹏 authored
7
use addons\litestore\model\Litestoregoodsspec;
李忠强 authored
8 9 10 11 12 13
use think\Model;

class Goods extends Model
{
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
SHW\戥岁。。 authored
14
    protected $resultSetType = 'collection';
李忠强 authored
15 16 17 18 19 20 21
    protected $name = 'litestore_goods';
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $append = [
        'image_text',
        'images_text',
        'down_image_text',
SHW\戥岁。。 authored
22
        'four_image_text',
SHW\戥岁。。 authored
23
        'detail_image_text',
李忠强 authored
24 25
    ];
SHW\戥岁。。 authored
26
    public function getImageTextAttr($value, $data)
李忠强 authored
27
    {
SHW\戥岁。。 authored
28
        $value = !empty($data['image']) ? cdnurl($data['image'], true) : '';
李忠强 authored
29 30 31
        return $value;
    }
SHW\戥岁。。 authored
32
    public function getFourImageTextAttr($value, $data)
李忠强 authored
33
    {
SHW\戥岁。。 authored
34 35 36
        $value = !empty($data['four_images']) ? explode(',', $data['four_images']) : [];
        foreach ($value as $key => &$val) {
            $val = cdnurl($val, true);
李忠强 authored
37 38 39 40
        }
        return $value;
    }
SHW\戥岁。。 authored
41
    public function getDetailImageTextAttr($value, $data)
李忠强 authored
42
    {
SHW\戥岁。。 authored
43 44 45
        $value = !empty($data['detail_images']) ? explode(',', $data['detail_images']) : [];
        foreach ($value as $key => &$val) {
            $val = cdnurl($val, true);
李忠强 authored
46 47 48 49
        }
        return $value;
    }
SHW\戥岁。。 authored
50
    public function getImagesTextAttr($value, $data)
李忠强 authored
51
    {
SHW\戥岁。。 authored
52 53 54 55 56 57 58 59 60 61
        $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) : '';
李忠强 authored
62 63
        return $value;
    }
何书鹏 authored
64 65

    // 总库存
SHW\戥岁。。 authored
66
    public function getStockNumAttr($value, $data)
何书鹏 authored
67
    {
SHW\戥岁。。 authored
68
        $value = GoodsSpec::where('goods_id', $data['goods_id'])->sum('stock_num');
何书鹏 authored
69 70
        return $value;
    }
李忠强 authored
71
}