1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace App\Model;
- use App\Scopes\DepartmentScope;
- use Illuminate\Database\Eloquent\Model;
- class Product extends Model
- {
- // protected $fillable = ['userData'];
- protected $guarded = [];
- protected $table = "product"; //指定表
- const CREATED_AT = 'crt_time';
- const UPDATED_AT = 'upd_time';
- protected $dateFormat = 'U';
- const State_zero = 0;
- const State_one = 1;
- const State_two = 2;
- public static $state = [
- self::State_zero => '新增',
- self::State_one => '上架',
- self::State_two => '下架',
- ];
- public static $user = [];
- public static $search = [];
- public static $is_search = false;
- const range_function = 'productRange';
- public function __construct(array $attributes = [])
- {
- if(! empty($attributes['userData'])) {
- self::$user = $attributes['userData'];
- self::$user['range_function'] = self::range_function;
- self::$search = $attributes['search'] ?? [];
- self::$is_search = true;
- }
- parent::__construct($attributes);
- }
- protected static function boot(){
- parent::boot();
- if(self::$is_search){
- static::addGlobalScope(new DepartmentScope(self::$user,self::$search));
- }
- }
- }
|