Construction.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Model;
  3. use App\Scopes\DepartmentScope;
  4. use Illuminate\Database\Eloquent\Model;
  5. class Construction extends Model
  6. {
  7. protected $fillable = ['userData'];
  8. protected $table = "construction"; //指定表
  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; // 分社网点安装
  14. public static $model_type = [
  15. self::Model_type_one,
  16. self::Model_type_two,
  17. ];
  18. public static $prefix = [
  19. self::Model_type_one => 'WO0.',
  20. self::Model_type_two => 'T9SH.',
  21. ];
  22. public static $user = [];
  23. public static $is_search = false;
  24. public function __construct(array $attributes = [])
  25. {
  26. if(! empty($attributes['userData'])) {
  27. self::$user = $attributes['userData'];
  28. self::$is_search = true;
  29. }
  30. parent::__construct($attributes);
  31. }
  32. protected static function boot(){
  33. parent::boot();
  34. if(self::$is_search){
  35. static::addGlobalScope(new DepartmentScope(self::$user));
  36. }
  37. }
  38. }