Customer.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 $table = "customer"; //指定表
  9. const CREATED_AT = 'crt_time';
  10. const UPDATED_AT = 'upd_time';
  11. protected $dateFormat = 'U';
  12. const Model_type_one = 1; // 基础模板
  13. const Model_type_two = 2; // T9二手车客户模板
  14. public static $model_type = [
  15. self::Model_type_one,
  16. self::Model_type_two
  17. ];
  18. public static $user = [];
  19. public static $is_search = false;
  20. public static $is_pond_state = true;
  21. public static $limitKey = "customerPondState";
  22. public function __construct(array $attributes = [])
  23. {
  24. if(! empty($attributes['userData'])) {
  25. self::$user = $attributes['userData'];
  26. self::$is_search = true;
  27. if(! empty($attributes['search']['pond_state'])) self::$is_pond_state = false;
  28. }
  29. parent::__construct($attributes);
  30. }
  31. protected static function boot(){
  32. parent::boot();
  33. if(self::$is_search && self::$is_pond_state){
  34. static::addGlobalScope(new DepartmentScope(self::$user));
  35. }
  36. }
  37. }