Construction.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. const STATE_ZERO = 0;//未确认
  23. const STATE_ONE = 1;//已确认
  24. public static $name = [
  25. self::STATE_ZERO => '未确认',
  26. self::STATE_ONE => '已确认',
  27. ];
  28. public static $user = [];
  29. public static $is_search = false;
  30. public function __construct(array $attributes = [])
  31. {
  32. if(! empty($attributes['userData'])) {
  33. self::$user = $attributes['userData'];
  34. self::$is_search = true;
  35. }
  36. parent::__construct($attributes);
  37. }
  38. protected static function boot(){
  39. parent::boot();
  40. if(self::$is_search){
  41. static::addGlobalScope(new DepartmentScope(self::$user));
  42. }
  43. }
  44. }