Construction.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 $table = "construction"; //指定表
  8. const CREATED_AT = 'crt_time';
  9. const UPDATED_AT = 'upd_time';
  10. protected $dateFormat = 'U';
  11. const Model_type_one = 1; // 总部安装
  12. const Model_type_two = 2; // 分社网点安装
  13. public static $model_type = [
  14. self::Model_type_one,
  15. self::Model_type_two,
  16. ];
  17. public static $prefix = [
  18. self::Model_type_one => 'WO0.',
  19. self::Model_type_two => 'T9SH.',
  20. ];
  21. public static $user = [];
  22. public static $is_search = false;
  23. public function __construct(array $attributes = [])
  24. {
  25. if(! empty($attributes['userData'])) {
  26. self::$user = $attributes['userData'];
  27. self::$is_search = true;
  28. }
  29. parent::__construct($attributes);
  30. }
  31. protected static function boot(){
  32. parent::boot();
  33. if(self::$is_search){
  34. static::addGlobalScope(new DepartmentScope(self::$user));
  35. }
  36. }
  37. }