Supplier.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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::$search = $attributes['search'] ?? [];
  24. self::$is_search = true;
  25. }
  26. parent::__construct($attributes);
  27. }
  28. protected static function boot(){
  29. parent::boot();
  30. if(self::$is_search){
  31. static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
  32. }
  33. }
  34. }