海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.3 KiB

  1. <?php
  2. namespace App\Models;
  3. use App\Common\PayType;
  4. use Illuminate\Database\Eloquent\Factories\HasFactory;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. use App\Common\OrderStatus as Status;
  7. use Illuminate\Support\Facades\Storage;
  8. class Order extends BaseModel
  9. {
  10. use HasFactory, SoftDeletes;
  11. protected $guarded = ['created_at', 'updated_at']; //不可批量赋值的属性
  12. public function getCouponIdAttribute($value)
  13. {
  14. return explode(',', $value);
  15. }
  16. public function getStatusAttribute($value)
  17. {
  18. $this->append('status_text');
  19. return $value;
  20. }
  21. public function getStatusTextAttribute()
  22. {
  23. return Status::array()[$this->attributes['status']] ?? '未知';
  24. }
  25. public function getPayTypeAttribute($value)
  26. {
  27. $this->append('pay_type_text');
  28. return $value;
  29. }
  30. public function getPayTypeTextAttribute()
  31. {
  32. return PayType::array()[$this->attributes['pay_type']] ?? '未知';
  33. }
  34. //退款信息
  35. public function getRefundInfoAttribute($value): array
  36. {
  37. $value = $value ? json_decode($value, true) : [];
  38. if (!empty($value['pictures']) && is_array($value['pictures'])) {
  39. $prefix = Storage::disk('public')->url('');
  40. foreach ($value['pictures'] as &$v) {
  41. if ($v && strpos($v, $prefix) === false) {
  42. $v = $prefix . $v;
  43. }
  44. }
  45. }
  46. return $value ?? [];
  47. }
  48. public function getPictureAttribute($value): string
  49. {
  50. $prefix = Storage::disk('public')->url('');
  51. return $value && substr($value, 0, 4) != 'http' ? $prefix . $value : '';
  52. }
  53. public function setPictureAttribute($value)
  54. {
  55. //修改器里面$this->host变量为空
  56. $this->attributes['picture'] = str_replace(env('APP_URL'), '', $value);
  57. }
  58. public function agentProduct()
  59. {
  60. return $this->belongsTo(AgentProduct::class);
  61. }
  62. public function product()
  63. {
  64. return $this->belongsTo(Product::class);
  65. }
  66. public function coupon()
  67. {
  68. return $this->belongsTo(Coupon::class);
  69. }
  70. public function agent()
  71. {
  72. return $this->belongsTo(Agent::class);
  73. }
  74. public function supplier()
  75. {
  76. return $this->belongsTo(Supplier::class);
  77. }
  78. public function user()
  79. {
  80. return $this->belongsTo(User::class);
  81. }
  82. public function agentProductItem()
  83. {
  84. return $this->hasMany(AgentProductItem::class, 'agent_product_id', 'agent_product_id');
  85. }
  86. public function orderProductItem()
  87. {
  88. return $this->hasMany(OrderProductItem::class);
  89. }
  90. }