Customer.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Model;
  3. use App\Scopes\DepartmentScope;
  4. use Illuminate\Database\Eloquent\Model;
  5. class Customer extends Model
  6. {
  7. // protected $fillable = ['userData','search'];
  8. protected $guarded = [];
  9. protected $table = "customer"; //指定表
  10. const CREATED_AT = 'crt_time';
  11. const UPDATED_AT = 'upd_time';
  12. protected $dateFormat = 'U';
  13. const Model_type_one = 1; // 基础模板
  14. const Model_type_two = 2; // T9二手车客户模板
  15. public static $model_type = [
  16. self::Model_type_one,
  17. self::Model_type_two
  18. ];
  19. public static $user = [];
  20. public static $search = [];
  21. public static $is_search = false;
  22. public static $is_pond_state = true;
  23. public static $limitKey = "customerPondState";
  24. public function __construct(array $attributes = [])
  25. {
  26. if(! empty($attributes['userData'])) {
  27. self::$user = $attributes['userData'];
  28. self::$search = $attributes['search'];
  29. self::$is_search = true;
  30. if(! empty(self::$search['pond_state'])) self::$is_pond_state = false;
  31. }
  32. parent::__construct($attributes);
  33. }
  34. protected static function boot(){
  35. parent::boot();
  36. if(self::$is_search && self::$is_pond_state){
  37. static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
  38. }
  39. }
  40. }