'decimal:2', 'processed_at' => 'datetime', 'completed_at' => 'datetime', ]; // 售后类型 const TYPE_REFUND_ONLY = 'refund_only'; // 仅退款 const TYPE_RETURN = 'return'; // 退货 const TYPE_EXCHANGE = 'exchange'; // 换货 // 售后状态 const STATUS_PENDING = 'pending'; // 待处理 const STATUS_PROCESSING = 'processing'; // 处理中 const STATUS_COMPLETED = 'completed'; // 已完成 const STATUS_REJECTED = 'rejected'; // 已拒绝 // 获取类型文本 public static function getTypeText(string $type): string { return match($type) { self::TYPE_REFUND_ONLY => '仅退款', self::TYPE_RETURN => '退货', self::TYPE_EXCHANGE => '换货', default => $type, }; } // 获取状态文本 public static function getStatusText(string $status): string { return match($status) { self::STATUS_PENDING => '待处理', self::STATUS_PROCESSING => '处理中', self::STATUS_COMPLETED => '已完成', self::STATUS_REJECTED => '已拒绝', default => $status, }; } // 生成售后单号 public static function generateShortId(): string { return 'AS' . date('Ymd') . str_pad(random_int(1, 9999), 4, '0', STR_PAD_LEFT); } // 关联订单 public function order(): BelongsTo { return $this->belongsTo(Order::class, 'order_id'); } // 关联处理人 public function processor(): BelongsTo { return $this->belongsTo(User::class, 'processed_by'); } // 关联申请人 public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); } // 关联明细 public function items(): HasMany { return $this->hasMany(AfterSaleItem::class, 'after_sale_id'); } }