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

77 lines
1.5 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. class Order extends BaseModel
  7. {
  8. use HasFactory, SoftDeletes;
  9. protected $guarded = ['created_at', 'updated_at']; //不可批量赋值的属性
  10. public function getCouponIdAttribute($value)
  11. {
  12. return explode(',', $value);
  13. }
  14. public function getStatusAttribute($value)
  15. {
  16. $this->append('status_text');
  17. return $value;
  18. }
  19. public function getStatusTextAttribute()
  20. {
  21. return Status::array()[$this->status] ?? '未知';
  22. }
  23. //退款信息
  24. public function getRefundInfoAttribute($value): array
  25. {
  26. $value = $value ? json_decode($value, true) : [];
  27. if (!empty($value['pictures']) && is_array($value['pictures'])) {
  28. foreach ($value['pictures'] as &$v) {
  29. $v = $this->host . $v;
  30. }
  31. }
  32. return $value ?? [];
  33. }
  34. public function getPictureAttribute($value): string
  35. {
  36. return $value ? $this->host . $value : '';
  37. }
  38. public function setPictureAttribute($value)
  39. {
  40. //修改器里面$this->host变量为空
  41. $this->attributes['picture'] = str_replace(env('APP_URL'), '', $value);
  42. }
  43. public function agentProduct()
  44. {
  45. return $this->belongsTo(AgentProduct::class);
  46. }
  47. public function product()
  48. {
  49. return $this->belongsTo(Product::class);
  50. }
  51. public function coupon()
  52. {
  53. return $this->belongsTo(Coupon::class);
  54. }
  55. public function agent()
  56. {
  57. return $this->belongsTo(Agent::class);
  58. }
  59. public function supplier()
  60. {
  61. return $this->belongsTo(Supplier::class);
  62. }
  63. }