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

66 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\Service\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. $status_text = [
  22. Status::CANCEL => '已取消',
  23. Status::UNPAID => '待付款',
  24. Status::PAY_EARNEST => '已付定金',
  25. Status::PAID => '已付款',
  26. Status::PAY_RETAINAGE => '已付尾款',
  27. Status::REFUNDING => '退款中',
  28. Status::REFUNDED => '已退款',
  29. Status::SUCCESS => '已完成',
  30. ];
  31. return $status_text[$this->status] ?? '未知';
  32. }
  33. //退款信息
  34. public function getRefundInfoAttribute($value)
  35. {
  36. $value = $value ? json_decode($value, true) : [];
  37. if (!empty($value['pictures']) && is_array($value['pictures'])) {
  38. foreach ($value['pictures'] as &$v) {
  39. $v = $this->host . $v;
  40. }
  41. }
  42. return $value ?? [];
  43. }
  44. public function agentProduct()
  45. {
  46. return $this->belongsTo(AgentProduct::class);
  47. }
  48. public function product()
  49. {
  50. return $this->belongsTo(Product::class);
  51. }
  52. public function coupon()
  53. {
  54. return $this->belongsTo(Coupon::class);
  55. }
  56. }