Product.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. const range_function = 'productRange';
  24. public function __construct(array $attributes = [])
  25. {
  26. if(! empty($attributes['userData'])) {
  27. self::$user = $attributes['userData'];
  28. self::$user['range_function'] = self::range_function;
  29. self::$search = $attributes['search'] ?? [];
  30. static::addGlobalScope(new DepartmentScope(self::$user,self::$search));
  31. }
  32. parent::__construct($attributes);
  33. }
  34. }