GoodsModel.php 1.7 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <bronet@126.com>
// +----------------------------------------------------------------------
namespace app\portal\model;

use think\Model;
use traits\model\SoftDelete;
class GoodsModel extends Model
{
    use SoftDelete;

    protected  $pk='id';

    protected $autoWriteTimestamp = 'true';

    public function goodsCategory()
    {
        return $this->belongsTo('GoodsCategoryModel','category_id','id');
    }


//查询范围
//    public function scopeName($query, $name)
//    {
//        $query->where('name', 'like', '%' . $name . '%');
//    }
    // 定义全局的查询范围
//    protected function base($query)
//    {
//        $query->where('status',1);
//    }

    //类型转换
//    protected $type = [
//        'more'    =>  'type',
//    ];


//自动完成
//    protected $auto = ['name', '测试商品啦'];
//    protected $insert = ['status' => 0];
//    protected $update = [];

//只读字段
//    protected $readonly = ['id'];






    //获取器
    function getStatusAttr($value){
        $status = [0=>'下架',1=>'上架',2=>'售空'];
        return $status[$value];
//        $status = [0=>'下架',1=>'上架',2=>'售空'];
//        return $status[$data['status']];
    }

    public function index(){

    }
}