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

87 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. if ($v && strpos($v, $prefix) === false) {
  32. $v = $prefix . $v;
  33. }
  34. }
  35. }
  36. return $value ?? [];
  37. }
  38. public function getPictureAttribute($value): string
  39. {
  40. $prefix = Storage::disk('public')->url('');
  41. return $value && substr($value, 0, 4) != 'http' ? $prefix . $value : '';
  42. }
  43. public function setPictureAttribute($value)
  44. {
  45. //修改器里面$this->host变量为空
  46. $this->attributes['picture'] = str_replace(env('APP_URL'), '', $value);
  47. }
  48. public function agentProduct()
  49. {
  50. return $this->belongsTo(AgentProduct::class);
  51. }
  52. public function product()
  53. {
  54. return $this->belongsTo(Product::class);
  55. }
  56. public function coupon()
  57. {
  58. return $this->belongsTo(Coupon::class);
  59. }
  60. public function agent()
  61. {
  62. return $this->belongsTo(Agent::class);
  63. }
  64. public function supplier()
  65. {
  66. return $this->belongsTo(Supplier::class);
  67. }
  68. public function user()
  69. {
  70. return $this->belongsTo(User::class);
  71. }
  72. }