Customer.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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'];
  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 function __construct(array $attributes = [])
  21. {
  22. if(! empty($attributes['userData'])) {
  23. self::$user = $attributes['userData'];
  24. self::$is_search = true;
  25. }
  26. parent::__construct($attributes);
  27. }
  28. protected static function boot(){
  29. parent::boot();
  30. if(self::$is_search){
  31. static::addGlobalScope(new DepartmentScope(self::$user));
  32. }
  33. }
  34. }