Product.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Model;
  3. use App\Scopes\DepartmentScope;
  4. use Illuminate\Database\Eloquent\Model;
  5. class Product extends Model
  6. {
  7. // protected $fillable = ['userData'];
  8. protected $guarded = [];
  9. protected $table = "product"; //指定表
  10. const CREATED_AT = 'crt_time';
  11. const UPDATED_AT = 'upd_time';
  12. protected $dateFormat = 'U';
  13. const State_zero = 0;
  14. const State_one = 1;
  15. const State_two = 2;
  16. public static $state = [
  17. self::State_zero => '新增',
  18. self::State_one => '上架',
  19. self::State_two => '下架',
  20. ];
  21. public static $user = [];
  22. public static $search = [];
  23. public static $is_search = false;
  24. const range_function = 'productRange';
  25. public function __construct(array $attributes = [])
  26. {
  27. if(! empty($attributes['userData'])) {
  28. self::$user = $attributes['userData'];
  29. self::$user['range_function'] = self::range_function;
  30. self::$search = $attributes['search'] ?? [];
  31. self::$is_search = true;
  32. }
  33. parent::__construct($attributes);
  34. }
  35. protected static function boot(){
  36. parent::boot();
  37. if(self::$is_search){
  38. static::addGlobalScope(new DepartmentScope(self::$user,self::$search));
  39. }
  40. }
  41. }