This commit is contained in:
parent
21727e2b7a
commit
a0bf115f56
|
|
@ -19,6 +19,12 @@ use Illuminate\Database\Eloquent\Collection;
|
|||
|
||||
class OrderProductRepo
|
||||
{
|
||||
/**
|
||||
* 创建商品明细
|
||||
*
|
||||
* @param Order $order
|
||||
* @param $cartProducts
|
||||
*/
|
||||
public static function createOrderProducts(Order $order, $cartProducts)
|
||||
{
|
||||
$orderProducts = [];
|
||||
|
|
@ -26,7 +32,7 @@ class OrderProductRepo
|
|||
$orderProducts[] = [
|
||||
'product_id' => $cartProduct['product_id'],
|
||||
'order_number' => $order->number,
|
||||
'product_sku' => $cartProduct['sku_id'],
|
||||
'product_sku' => $cartProduct['product_sku'],
|
||||
'name' => $cartProduct['name'],
|
||||
'image' => $cartProduct['image'],
|
||||
'quantity' => $cartProduct['quantity'],
|
||||
|
|
@ -36,11 +42,14 @@ class OrderProductRepo
|
|||
$order->orderProducts()->createMany($orderProducts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查找单条商品明细数据
|
||||
*
|
||||
* @param $id
|
||||
* @return Builder|Builder[]|Collection|Model|null
|
||||
*/
|
||||
public static function find($id)
|
||||
public static function find($id): Model|Collection|Builder|array|null
|
||||
{
|
||||
return OrderProduct::query()->findOrFail($id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class CartDetail extends JsonResource
|
|||
$sku = $this->sku;
|
||||
$product = $sku->product;
|
||||
$price = $sku->price;
|
||||
$skuCode = $sku->sku;
|
||||
$description = $product->description;
|
||||
$productName = $description->name;
|
||||
$subTotal = $price * $this->quantity;
|
||||
|
|
@ -29,6 +30,7 @@ class CartDetail extends JsonResource
|
|||
'cart_id' => $this->id,
|
||||
'product_id' => $this->product_id,
|
||||
'sku_id' => $this->product_sku_id,
|
||||
'product_sku' => $skuCode,
|
||||
'name' => $productName,
|
||||
'name_format' => sub_string($productName),
|
||||
'image' => $image,
|
||||
|
|
|
|||
Loading…
Reference in New Issue