InvoiceOrder.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Model;
  3. use App\Scopes\DepartmentScope;
  4. use Illuminate\Database\Eloquent\Model;
  5. class InvoiceOrder extends Model
  6. {
  7. // protected $fillable = ['userData'];
  8. protected $guarded = [];
  9. protected $table = "invoice_order"; //指定表
  10. const CREATED_AT = 'crt_time';
  11. const UPDATED_AT = 'upd_time';
  12. protected $dateFormat = 'U';
  13. const STATE_ZERO = 0;//未确认
  14. const STATE_ONE = 1;//已确认
  15. const prefix = 'FH';
  16. public static $name = [
  17. 0 => '未确认',
  18. 1 => '已确认',
  19. ];
  20. public static $user = [];
  21. public static $search = [];
  22. public static $is_search = false;
  23. const range_function = 'invoiceRange';
  24. public function __construct(array $attributes = [])
  25. {
  26. if(! empty($attributes['userData'])) {
  27. self::$user = $attributes['userData'];
  28. self::$search = $attributes['search'] ?? [];
  29. self::$user['range_function'] = self::range_function;
  30. self::$is_search = true;
  31. }
  32. parent::__construct($attributes);
  33. }
  34. protected static function boot(){
  35. parent::boot();
  36. if(self::$is_search){
  37. static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
  38. }
  39. }
  40. }