status) { 'unpaid' => '未支付', 'paid_gateway' => '已支付(支付网关)', 'paid_balance' => '已支付(账户余额)', 'paid_admin' => '已支付(管理员)', 'cancelled' => '已取消', 'refunded_balance' => '已退款(账户余额)', default => '未知', }; } public function type(): string { return match ($this->type) { 'product' => '商品', 'topup' => '充值', default => '未知', }; } public function refundToBalance(): void { if (in_array($this->status, ['paid_gateway', 'paid_balance', 'paid_admin'])) { $user = (new User())->find($this->user_id); $user->money += $this->price; $user->save(); (new UserMoneyLog())->add( $user->id, $user->money - $this->price, $user->money, $this->price, '账单 #' . $this->id . ' 退款至账户余额' ); $content = json_decode($this->content, true); $content[] = [ 'content_id' => count($content), 'name' => '退款至账户余额', 'price' => '-' . $this->price, ]; $this->content = json_encode($content); $this->status = 'refunded_balance'; $this->update_time = time(); $this->save(); } } }