ProductActivity.php 1.0 KB

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