Files
water_new/modules/Mall/Facades/RefundItem.php
2023-03-08 09:16:04 +08:00

69 lines
1.4 KiB
PHP

<?php
namespace Modules\Mall\Facades;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
class RefundItem implements Arrayable, Jsonable
{
public int $qty;
public float $price;
public $order_item_id;
public $order_id;
public $source;
/**
* RefundItem constructor.
* @param $item
* @param int $qty
*/
public function __construct($item, int $qty = 1)
{
$this->qty = $qty;
$this->price = $item->price;
$this->order_id = $item->order_id;
$this->order_item_id = $item->id;
$this->source = $item->source;
}
/**
* Notes: 获取条目总价
* @Author: 玄尘
* @Date : 2020/12/10 9:43
* @return float
*/
public function total(): float
{
return bcmul($this->price, $this->qty, 2);
}
/**
* Notes: 返回数组
* @Author: 玄尘
* @Date : 2021/5/21 10:40
* @return array
*/
public function toArray(): array
{
return [
'qty' => $this->qty,
'price' => $this->price,
'order_id' => $this->order_id,
'order_item_id' => $this->order_item_id,
'source' => $this->source,
];
}
public function toJson($options = 0)
{
return json_encode($this->toArray(), $options);
}
}