Product.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 $table = "product"; //指定表
  9. const CREATED_AT = 'crt_time';
  10. const UPDATED_AT = 'upd_time';
  11. protected $dateFormat = 'U';
  12. const State_zero = 0;
  13. const State_one = 1;
  14. const State_two = 2;
  15. public static $state = [
  16. self::State_zero => '新增',
  17. self::State_one => '上架',
  18. self::State_two => '下架',
  19. ];
  20. public static $user = [];
  21. public static $is_search = false;
  22. public function __construct(array $attributes = [])
  23. {
  24. if(! empty($attributes['userData'])) {
  25. self::$user = $attributes['userData'];
  26. self::$is_search = true;
  27. }
  28. parent::__construct($attributes);
  29. }
  30. protected static function boot(){
  31. parent::boot();
  32. if(self::$is_search){
  33. static::addGlobalScope(new DepartmentScope(self::$user));
  34. }
  35. }
  36. }