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