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

71 lines
1.4 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)
  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)
  35. {
  36. return $value ? $this->host . $value : '';
  37. }
  38. public function agentProduct()
  39. {
  40. return $this->belongsTo(AgentProduct::class);
  41. }
  42. public function product()
  43. {
  44. return $this->belongsTo(Product::class);
  45. }
  46. public function coupon()
  47. {
  48. return $this->belongsTo(Coupon::class);
  49. }
  50. public function agent()
  51. {
  52. return $this->belongsTo(Agent::class);
  53. }
  54. public function supplier()
  55. {
  56. return $this->belongsTo(Supplier::class);
  57. }
  58. }