Supplier.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Model;
  3. use App\Scopes\DepartmentScope;
  4. use Illuminate\Database\Eloquent\Model;
  5. class Supplier extends Model
  6. {
  7. // protected $fillable = [];
  8. protected $guarded = [];
  9. protected $table = "supplier"; //指定表
  10. const CREATED_AT = 'crt_time';
  11. const UPDATED_AT = 'upd_time';
  12. protected $dateFormat = 'U';
  13. const is_main = 1;//是否总供应商
  14. public static $user = [];
  15. public static $search = [];
  16. public static $is_search = false;
  17. const range_function = 'supplierRange';
  18. public function __construct(array $attributes = [])
  19. {
  20. if(! empty($attributes['userData'])) {
  21. self::$user = $attributes['userData'];
  22. self::$user['range_function'] = self::range_function;
  23. self::$user['is_search_main'] = 1;
  24. self::$search = $attributes['search'] ?? [];
  25. self::$is_search = true;
  26. }
  27. parent::__construct($attributes);
  28. }
  29. protected static function boot(){
  30. parent::boot();
  31. if(self::$is_search){
  32. static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
  33. }
  34. }
  35. }