海南旅游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.

85 lines
1.8 KiB

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