mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 06:15:09 +08:00
refactor(Order): 重构订单资源以支持经典订单解析
- 新增 parseClassicOrder 方法用于解析经典订单 - 修改 toArray 方法,根据订单类型选择性调用 parseClassicOrder - 引入 Money库以处理金额和货币
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Singularity\HDK\Pay\Resource\V2;
|
||||
|
||||
use App\Model\ServiceProvider;
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Resource\Json\JsonResource;
|
||||
use Money\Currency;
|
||||
use Money\Money;
|
||||
use Singularity\HDK\Pay\Enum\OrderStatus;
|
||||
use stdClass;
|
||||
|
||||
@@ -48,6 +48,9 @@ class Order extends JsonResource
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
if (empty($this->resource['order_no'])) {
|
||||
return $this->parseClassicOrder();
|
||||
}
|
||||
return [
|
||||
'order_no' => $this->order_no,
|
||||
'state' => $this->state,
|
||||
@@ -65,6 +68,25 @@ class Order extends JsonResource
|
||||
];
|
||||
}
|
||||
|
||||
private function parseClassicOrder(): array
|
||||
{
|
||||
return [
|
||||
'order_no' => $this->orderNo,
|
||||
'state' => $this->state,
|
||||
'transaction_id' => $this->transactionId,
|
||||
'uid' => $this->uid,
|
||||
'method' => $this->payment,
|
||||
'description' => $this->goodsName,
|
||||
'total_amount' => new Money($this->amount['amount'], new Currency($this->amount['currency'])),
|
||||
'currency' => $this->amount['currency'],
|
||||
'items' => [],
|
||||
'external' => [],
|
||||
'remark' => $this->remark,
|
||||
'notification' => $this->notification ?? [],
|
||||
'more_details' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function __get($key)
|
||||
{
|
||||
return $this->resource->{$key} ?? $this->resource[$key];
|
||||
|
||||
Reference in New Issue
Block a user