ReturnExchangeOrder.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Model;
  3. use App\Scopes\DepartmentScope;
  4. use Illuminate\Database\Eloquent\Model;
  5. class ReturnExchangeOrder extends Model
  6. {
  7. protected $fillable = ['userData'];
  8. protected $table = "return_exchange_order"; //指定表
  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 $model_type_name = [
  19. self::Model_type_one => '退货单',
  20. self::Model_type_two => '换货单',
  21. ];
  22. const State_zero = 0;//未确认
  23. const State_one = 1;//已确认
  24. public static $state = [
  25. self::State_zero => '未确认',
  26. self::State_one => '已确认',
  27. ];
  28. public static $prefix = [
  29. self::Model_type_one => 'TH',
  30. self::Model_type_two => 'HH',
  31. ];
  32. public static $user = [];
  33. public static $is_search = false;
  34. public function __construct(array $attributes = [])
  35. {
  36. if(! empty($attributes['userData'])) {
  37. self::$user = $attributes['userData'];
  38. self::$is_search = true;
  39. }
  40. parent::__construct($attributes);
  41. }
  42. protected static function boot(){
  43. parent::boot();
  44. if(self::$is_search){
  45. static::addGlobalScope(new DepartmentScope(self::$user));
  46. }
  47. }
  48. }