ProductInventorySet.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Model;
  3. use App\Scopes\TopDepartmentScope;
  4. use Illuminate\Database\Eloquent\Model;
  5. class ProductInventorySet extends Model
  6. {
  7. protected $guarded = [];
  8. protected $table = "product_inventory_set"; //指定表
  9. const CREATED_AT = 'crt_time';
  10. const UPDATED_AT = 'upd_time';
  11. protected $dateFormat = 'U';
  12. const type_one = 1;//校验锁定
  13. const type_two = 2;//不校验锁定
  14. public static $user = [];
  15. public static $search = [];
  16. public static $is_search = false;
  17. public function __construct(array $attributes = [])
  18. {
  19. if(! empty($attributes['userData'])) {
  20. self::$user = $attributes['userData'];
  21. self::$search = $attributes['search'] ?? [];
  22. self::$is_search = true;
  23. }
  24. parent::__construct($attributes);
  25. }
  26. protected static function boot(){
  27. parent::boot();
  28. if(self::$is_search){
  29. static::addGlobalScope(new TopDepartmentScope(self::$user, self::$search));
  30. }
  31. }
  32. }