InOutRecord.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Model;
  3. use App\Scopes\ProductInventoryScope;
  4. use Illuminate\Database\Eloquent\Model;
  5. class InOutRecord extends Model
  6. {
  7. protected $guarded = [];
  8. protected $table = "in_out_record"; //指定表
  9. const CREATED_AT = 'crt_time';
  10. const UPDATED_AT = 'upd_time';
  11. protected $dateFormat = 'U';
  12. public static $user = [];
  13. public static $search = [];
  14. public static $is_search = false;
  15. const range_function = '';
  16. public function __construct(array $attributes = [])
  17. {
  18. if(! empty($attributes['userData'])) {
  19. self::$user = $attributes['userData'];
  20. self::$search = $attributes['search'] ?? [];
  21. self::$user['range_function'] = self::range_function;
  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 ProductInventoryScope(self::$user, self::$search));
  30. }
  31. }
  32. }