feat : order

This commit is contained in:
2025-03-06 16:25:25 +08:00
parent 5ad53e55be
commit 88fdd218b3
10 changed files with 82 additions and 57 deletions

View File

@@ -112,6 +112,11 @@ abstract class BaseOrderService extends BaseService
*/
protected int $orderId;
/**
* @var int 订单类型 (参考 SpuCode)
*/
protected int $orderType;
/**
* @var int 自动选择优惠券 (确认订单需要,下单不需要,用子类重置该值)
*/
@@ -133,6 +138,7 @@ abstract class BaseOrderService extends BaseService
$this->copies = 0;
$this->couponId = 0;
$this->siteId = 0;
$this->orderType = 0;
$this->orderRes = [
'total_price' => '0.00', //总价
@@ -151,8 +157,8 @@ abstract class BaseOrderService extends BaseService
'site' => [],
'good_ids' => [],
'good' => [],
'optional_copies' => 0,
'meal_copies' => 0,
'copies' => 0,
// 'meal_copies' => 0,
];
}
@@ -188,7 +194,7 @@ abstract class BaseOrderService extends BaseService
$this->computeSundryPrice();
$this->computeFavorable();
// $this->computeFavorable();
$this->computeFinallyPrice();
}

View File

@@ -23,6 +23,7 @@ class CheckCartService extends BaseOrderService
public function handle(): array
{
$this->siteId = (int)$this->request->input('site_id');
$this->orderType = (int)$this->request->input('order_type');
$this->check();

View File

@@ -32,6 +32,7 @@ class ConfirmationOrderService extends BaseOrderService
{
$this->siteId = (int)$this->request->input('site_id');
$this->couponId = (int)$this->request->input('coupon_id',0);
$this->orderType = (int)$this->request->input('order_type');
$this->check();

View File

@@ -107,7 +107,7 @@ class OrderInfoService extends BaseService
$imageList = $this->getOssObjects($imageIds);
$orderCopiesList = [];
for ($i = 1; $i <= ($orderInfo['meal_copies'] + $orderInfo['optional_copies']); $i++) {
for ($i = 1; $i <= ($orderInfo['copies'] ?? 0); $i++) {
$oneCopiesInfo = [
'total_price' => '0.00',
@@ -115,7 +115,7 @@ class OrderInfoService extends BaseService
'sku_list' => [],
'image_list' => [],
'take_food_code' => '', //todo 取餐码
'copies_type' => 0,
// 'copies_type' => 0,
];
foreach ($newOrderSkuList[$i] as $item) {
@@ -128,7 +128,7 @@ class OrderInfoService extends BaseService
$oneCopiesInfo['sku_list'][] = $skuInfo;
$oneCopiesInfo['image_list'][] = $imageList[$imageId] ?? [];
if ($oneCopiesInfo['copies_type'] == 0) $oneCopiesInfo['copies_type'] = $item['type'];
// if ($oneCopiesInfo['copies_type'] == 0) $oneCopiesInfo['copies_type'] = $item['type'];
}
// foreach ($newOrderSkuList as $item) {
// if ($item['order_id'] != $order['id'] || $item['copies'] != $i) continue;

View File

@@ -64,8 +64,8 @@ class OrderListService extends BaseService
'order_sno',
'user_id',
'site_id',
'meal_copies',
'optional_copies',
'copies',
'type',
'actual_price',
'total_price',
'status',
@@ -91,7 +91,6 @@ class OrderListService extends BaseService
private function buildData(array &$orderList): void
{
$orderIds = array_column($orderList, 'id');
$siteIds = array_column($orderList, 'site_id');
$orderSkuList = $this->orderGoodModel->whereIn('order_id', $orderIds)->get()->toArray();
$skuIds = [];
@@ -123,7 +122,7 @@ class OrderListService extends BaseService
foreach ($orderList as &$order) {
$orderCopiesList = [];
for ($i = 1; $i <= ($order['meal_copies'] + $order['optional_copies']); $i++) {
for ($i = 1; $i <= ($order['copies'] ?? 0); $i++) {
$oneCopiesInfo = [
'total_price' => '0.00',
@@ -131,7 +130,7 @@ class OrderListService extends BaseService
// 'sku_list' => [],
'image_list' => [],
'take_food_code' => [], //todo 取餐码
'copies_type' => 0,
// 'copies_type' => 0,
];
foreach ($newOrderSkuList[$order['id']][$i] as $item) {
@@ -144,7 +143,7 @@ class OrderListService extends BaseService
// $oneCopiesInfo['sku_list'][] = [];
$oneCopiesInfo['image_list'][] = $imageList[$imageId]['url'] ?? [];
if ($oneCopiesInfo['copies_type'] == 0) $oneCopiesInfo['copies_type'] = $item['type'];
// if ($oneCopiesInfo['copies_type'] == 0) $oneCopiesInfo['copies_type'] = $item['type'];
}
// foreach ($newOrderSkuList as $item) {
// if ($item['order_id'] != $order['id'] || $item['copies'] != $i) continue;

View File

@@ -53,6 +53,7 @@ class PlaceOrderService extends BaseOrderService
$this->siteId = (int)$this->request->input('site_id');
$this->couponId = (int)$this->request->input('coupon_id',0);
$this->orderType = (int)$this->request->input('order_type');
// 生成购物车信息 检测商品和库存等
$this->check();
@@ -191,8 +192,8 @@ class PlaceOrderService extends BaseOrderService
$orderInsertModel->site_id = $this->siteId;
$orderInsertModel->city_id = $this->orderRes['site_info']['city_id'];
$orderInsertModel->coupon_id = $this->couponId;
$orderInsertModel->meal_copies = $this->orderRes['meal_copies'];
$orderInsertModel->optional_copies = $this->orderRes['optional_copies'];
$orderInsertModel->copies = $this->orderRes['copies'];
$orderInsertModel->type = $this->orderType;
$orderInsertModel->total_price = $this->orderRes['total_price'];
$orderInsertModel->actual_price = $this->orderRes['actual_price'];
$orderInsertModel->discount_price = $this->orderRes['favorable_sundry_price'] + $this->orderRes['favorable_good_price'];