Customer.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. const range_function = 'customerRange';
  25. public function __construct(array $attributes = [])
  26. {
  27. if(! empty($attributes['userData'])) {
  28. self::$user = $attributes['userData'];
  29. self::$search = $attributes['search'];
  30. self::$user['range_function'] = self::range_function;
  31. self::$is_search = true;
  32. if(! empty(self::$search['pond_state'])) self::$is_pond_state = false;
  33. }
  34. parent::__construct($attributes);
  35. }
  36. protected static function boot(){
  37. parent::boot();
  38. if(self::$is_search && self::$is_pond_state){
  39. static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
  40. }
  41. }
  42. }