Construction.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. public function __construct(array $attributes = [])
  33. {
  34. if(! empty($attributes['userData'])) {
  35. self::$user = $attributes['userData'];
  36. self::$search = $attributes['search'] ?? [];
  37. self::$is_search = true;
  38. }
  39. parent::__construct($attributes);
  40. }
  41. protected static function boot(){
  42. parent::boot();
  43. if(self::$is_search){
  44. static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
  45. }
  46. }
  47. }