ReturnExchangeOrder.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 $guarded = [];
  9. protected $table = "return_exchange_order"; //指定表
  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 $model_type_name = [
  20. self::Model_type_one => '退货单',
  21. self::Model_type_two => '换货单',
  22. ];
  23. const State_zero = 0;//未确认
  24. const State_one = 1;//已确认
  25. public static $state = [
  26. self::State_zero => '未确认',
  27. self::State_one => '已确认',
  28. ];
  29. public static $prefix = [
  30. self::Model_type_one => 'TH',
  31. self::Model_type_two => 'HH',
  32. ];
  33. public static $user = [];
  34. public static $search = [];
  35. public static $is_search = false;
  36. const range_function = 'returnExchangeOrderRange';
  37. public function __construct(array $attributes = [])
  38. {
  39. if(! empty($attributes['userData'])) {
  40. self::$user = $attributes['userData'];
  41. self::$user['range_function'] = self::range_function;
  42. self::$search = $attributes['search'];
  43. self::$is_search = true;
  44. }
  45. parent::__construct($attributes);
  46. }
  47. protected static function boot(){
  48. parent::boot();
  49. if(self::$is_search){
  50. static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
  51. }
  52. }
  53. }