Construction.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 $guarded = [];
  9. protected $table = "construction"; //指定表
  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; // 分社网点安装
  15. public static $model_type = [
  16. self::Model_type_one,
  17. self::Model_type_two,
  18. ];
  19. public static $prefix = [
  20. self::Model_type_one => 'WO0.',
  21. self::Model_type_two => 'T9SH.',
  22. ];
  23. const STATE_ZERO = 0;//未确认
  24. const STATE_ONE = 1;//已确认
  25. public static $name = [
  26. self::STATE_ZERO => '未确认',
  27. self::STATE_ONE => '已确认',
  28. ];
  29. public static $user = [];
  30. public static $search = [];
  31. public static $is_search = false;
  32. const range_function = 'constructionRange';
  33. public function __construct(array $attributes = [])
  34. {
  35. if(! empty($attributes['userData'])) {
  36. self::$user = $attributes['userData'];
  37. self::$user['range_function'] = self::range_function;
  38. self::$search = $attributes['search'] ?? [];
  39. self::$is_search = true;
  40. }
  41. parent::__construct($attributes);
  42. }
  43. protected static function boot(){
  44. parent::boot();
  45. if(self::$is_search){
  46. static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
  47. }
  48. }
  49. }