feat : order
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Middleware\Api\JwtAuthMiddleware;
|
|||||||
use App\Service\Api\Order\CancelOrderService;
|
use App\Service\Api\Order\CancelOrderService;
|
||||||
use App\Service\Api\Order\CheckCartService;
|
use App\Service\Api\Order\CheckCartService;
|
||||||
use App\Service\Api\Order\ConfirmationOrderService;
|
use App\Service\Api\Order\ConfirmationOrderService;
|
||||||
|
use App\Service\Api\Order\OrderInfoService;
|
||||||
use App\Service\Api\Order\OrderListService;
|
use App\Service\Api\Order\OrderListService;
|
||||||
use App\Service\Api\Order\PlaceOrderService;
|
use App\Service\Api\Order\PlaceOrderService;
|
||||||
use App\Service\Api\Order\RefundOrderService;
|
use App\Service\Api\Order\RefundOrderService;
|
||||||
@@ -87,10 +88,27 @@ class OrderController extends AbstractController
|
|||||||
return (new RefundOrderService)->handle();
|
return (new RefundOrderService)->handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[RequestMapping(path: 'order_list',methods: 'post')]
|
/**
|
||||||
|
* 订单列表
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: 'order_list',methods: 'get')]
|
||||||
#[Scene(scene: 'order_list')]
|
#[Scene(scene: 'order_list')]
|
||||||
public function orderList()
|
public function orderList()
|
||||||
{
|
{
|
||||||
return (new OrderListService)->handle();
|
return (new OrderListService)->handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单详情
|
||||||
|
* @return array
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: 'order_info',methods: 'get')]
|
||||||
|
#[Scene(scene: 'order_info')]
|
||||||
|
public function orderInfo()
|
||||||
|
{
|
||||||
|
return (new OrderInfoService)->handle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
150
app/Service/Api/Order/OrderInfoService.php
Normal file
150
app/Service/Api/Order/OrderInfoService.php
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This service file is part of item.
|
||||||
|
*
|
||||||
|
* @author ctexthuang
|
||||||
|
* @contact ctexthuang@qq.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service\Api\Order;
|
||||||
|
|
||||||
|
use App\Cache\Redis\Api\SiteCache;
|
||||||
|
use App\Exception\ErrException;
|
||||||
|
use App\Model\Order;
|
||||||
|
use App\Model\OrderGood;
|
||||||
|
use App\Model\Sku;
|
||||||
|
use App\Model\Spu;
|
||||||
|
use App\Service\Api\BaseService;
|
||||||
|
use App\Service\ServiceTrait\Common\OssTrait;
|
||||||
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
|
||||||
|
class OrderInfoService extends BaseService
|
||||||
|
{
|
||||||
|
use OssTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Order
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Order $orderModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OrderGood
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected OrderGood $orderGoodModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Sku
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Sku $skuModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Spu
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Spu $spuModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SiteCache
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected SiteCache $siteCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
public function handle(): array
|
||||||
|
{
|
||||||
|
$orderId = (int)$this->request->input('order_id');
|
||||||
|
|
||||||
|
$orderInfo = $this->orderModel->getInfoById($orderId);
|
||||||
|
|
||||||
|
if (empty($orderInfo)) throw new ErrException('订单不存在');
|
||||||
|
|
||||||
|
$orderInfo = $orderInfo->toArray();
|
||||||
|
$this->buildData($orderInfo);
|
||||||
|
|
||||||
|
return $this->return->success('success', $orderInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $orderInfo
|
||||||
|
* @return void
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
private function buildData(array &$orderInfo): void
|
||||||
|
{
|
||||||
|
$orderSkuList = $this->orderGoodModel->where('order_id', $orderInfo['id'])->get()->toArray();
|
||||||
|
|
||||||
|
$skuIds = [];
|
||||||
|
$newOrderSkuList = [];
|
||||||
|
foreach ($orderSkuList as $orderSku) {
|
||||||
|
if (empty($newOrderSkuList[$orderSku['copies']])) {
|
||||||
|
$newOrderSkuList[$orderSku['copies']] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$newOrderSkuList[$orderSku['copies']][] = $orderSku;
|
||||||
|
|
||||||
|
if (in_array($orderSku['sku_id'], $skuIds)) continue;
|
||||||
|
|
||||||
|
$skuIds[] = $orderSku['sku_id'];
|
||||||
|
}
|
||||||
|
unset($orderSkuList);
|
||||||
|
|
||||||
|
$skuList = $this->skuModel->getDataArrByIds($skuIds);
|
||||||
|
$imageIdArr = array_column($skuList,'image_ids');
|
||||||
|
$skuList = array_column($skuList, null,'id');
|
||||||
|
$imageIds = array_unique(explode(',',implode(',',$imageIdArr)));
|
||||||
|
$imageList = $this->getOssObjects($imageIds);
|
||||||
|
|
||||||
|
$orderCopiesList = [];
|
||||||
|
for ($i = 1; $i <= ($orderInfo['meal_copies'] + $orderInfo['optional_copies']); $i++) {
|
||||||
|
|
||||||
|
$oneCopiesInfo = [
|
||||||
|
'total_price' => '0.00',
|
||||||
|
'total_quantity' => 0,
|
||||||
|
'sku_list' => [],
|
||||||
|
'image_list' => [],
|
||||||
|
'take_food_code' => '', //todo 取餐码
|
||||||
|
'copies_type' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($newOrderSkuList[$i] as $item) {
|
||||||
|
if ($item['order_id'] != $orderInfo['id'] || $item['copies'] != $i) continue;
|
||||||
|
|
||||||
|
$skuInfo = $skuList[$item['sku_id']] ?? [];
|
||||||
|
$imageId = !empty($skuInfo) && !empty(explode(',',$skuInfo['image_ids'])[0]) ? explode(',',$skuInfo['image_ids'])[0] : [];
|
||||||
|
$oneCopiesInfo['total_price'] = bcadd($oneCopiesInfo['total_price'], bcmul($item['unit_price'],(string)$item['quantity'],2), 2);
|
||||||
|
$oneCopiesInfo['total_quantity'] += $item['quantity'];
|
||||||
|
$oneCopiesInfo['sku_list'][] = $skuInfo;
|
||||||
|
$oneCopiesInfo['image_list'][] = $imageList[$imageId] ?? [];
|
||||||
|
|
||||||
|
if ($oneCopiesInfo['copies_type'] == 0) $oneCopiesInfo['copies_type'] = $item['type'];
|
||||||
|
}
|
||||||
|
// foreach ($newOrderSkuList as $item) {
|
||||||
|
// if ($item['order_id'] != $order['id'] || $item['copies'] != $i) continue;
|
||||||
|
//
|
||||||
|
// $skuInfo = $skuList[$item['sku_id']] ?? [];
|
||||||
|
// $imageId = !empty($skuInfo) && !empty(explode(',',$skuInfo['image_ids'])[0]) ? explode(',',$skuInfo['image_ids'])[0] : [];
|
||||||
|
// $oneCopiesInfo['total_price'] = bcadd($oneCopiesInfo['total_price'], bcmul($item['unit_price'],$item['quantity'],2), 2);
|
||||||
|
// $oneCopiesInfo['total_quantity'] += $item['quantity'];
|
||||||
|
// $oneCopiesInfo['sku_list'][] = $skuInfo;
|
||||||
|
// $oneCopiesInfo['image_list'][] = $imageList[$imageId] ?? [];
|
||||||
|
// }
|
||||||
|
|
||||||
|
$orderCopiesList[] = $oneCopiesInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderInfo['copies_list'] = $orderCopiesList;
|
||||||
|
$orderInfo['site'] = $this->siteCache->getSiteInfo($orderInfo['site_id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,13 +10,19 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Service\Api\Order;
|
namespace App\Service\Api\Order;
|
||||||
|
|
||||||
|
use App\Cache\Redis\Api\SiteCache;
|
||||||
use App\Model\Order;
|
use App\Model\Order;
|
||||||
use App\Model\OrderGood;
|
use App\Model\OrderGood;
|
||||||
|
use App\Model\Sku;
|
||||||
use App\Service\Api\BaseService;
|
use App\Service\Api\BaseService;
|
||||||
|
use App\Service\ServiceTrait\Common\OssTrait;
|
||||||
use Hyperf\Di\Annotation\Inject;
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
|
||||||
class OrderListService extends BaseService
|
class OrderListService extends BaseService
|
||||||
{
|
{
|
||||||
|
use OssTrait;
|
||||||
/**
|
/**
|
||||||
* @var Order
|
* @var Order
|
||||||
*/
|
*/
|
||||||
@@ -29,7 +35,22 @@ class OrderListService extends BaseService
|
|||||||
#[Inject]
|
#[Inject]
|
||||||
protected OrderGood $orderGoodModel;
|
protected OrderGood $orderGoodModel;
|
||||||
|
|
||||||
public function handle()
|
/**
|
||||||
|
* @var Sku
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Sku $skuModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SiteCache
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected SiteCache $siteCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function handle(): array
|
||||||
{
|
{
|
||||||
$limit = $this->request->input('limit', 20);
|
$limit = $this->request->input('limit', 20);
|
||||||
|
|
||||||
@@ -38,6 +59,17 @@ class OrderListService extends BaseService
|
|||||||
->when($this->request->input('status'), function ($query) {
|
->when($this->request->input('status'), function ($query) {
|
||||||
$query->where('status', $this->request->input('status'));
|
$query->where('status', $this->request->input('status'));
|
||||||
})
|
})
|
||||||
|
->select([
|
||||||
|
'id',
|
||||||
|
'order_sno',
|
||||||
|
'user_id',
|
||||||
|
'site_id',
|
||||||
|
'meal_copies',
|
||||||
|
'optional_copies',
|
||||||
|
'actual_price',
|
||||||
|
'total_price',
|
||||||
|
'status',
|
||||||
|
])
|
||||||
->orderByDesc('id')
|
->orderByDesc('id')
|
||||||
->paginate($limit)
|
->paginate($limit)
|
||||||
->toArray();
|
->toArray();
|
||||||
@@ -49,14 +81,87 @@ class OrderListService extends BaseService
|
|||||||
return $this->return->success('success', ['list' => $orderList]);
|
return $this->return->success('success', ['list' => $orderList]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildData(array &$orderList)
|
/**
|
||||||
|
* 构建订单列表数据
|
||||||
|
* @param array $orderList
|
||||||
|
* @return void
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
private function buildData(array &$orderList): void
|
||||||
{
|
{
|
||||||
$orderIds = array_column($orderList, 'id');
|
$orderIds = array_column($orderList, 'id');
|
||||||
|
$siteIds = array_column($orderList, 'site_id');
|
||||||
|
|
||||||
$skuId = $this->orderGoodModel->whereIn('order_id', $orderIds)->pluck('sku_id')->toArray();
|
$orderSkuList = $this->orderGoodModel->whereIn('order_id', $orderIds)->get()->toArray();
|
||||||
|
$skuIds = [];
|
||||||
|
$newOrderSkuList = [];
|
||||||
|
foreach ($orderSkuList as $orderSku) {
|
||||||
|
if (empty($newOrderSkuList[$orderSku['order_id']])) {
|
||||||
|
$newOrderSkuList[$orderSku['order_id']] = [];
|
||||||
|
}
|
||||||
|
|
||||||
// foreach ($orderList as &$order) {
|
if (empty($newOrderSkuList[$orderSku['order_id']][$orderSku['copies']])) {
|
||||||
|
$newOrderSkuList[$orderSku['order_id']][$orderSku['copies']] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$newOrderSkuList[$orderSku['order_id']][$orderSku['copies']][] = $orderSku;
|
||||||
|
|
||||||
|
if (in_array($orderSku['sku_id'], $skuIds)) continue;
|
||||||
|
|
||||||
|
$skuIds[] = $orderSku['sku_id'];
|
||||||
|
}
|
||||||
|
unset($orderSkuList);
|
||||||
|
|
||||||
|
|
||||||
|
// $skuIds = array_unique(array_column($orderSkuList, 'sku_id'));
|
||||||
|
$skuList = $this->skuModel->getDataArrByIds($skuIds);
|
||||||
|
$imageIdArr = array_column($skuList,'image_ids');
|
||||||
|
$skuList = array_column($skuList, null,'id');
|
||||||
|
$imageIds = array_unique(explode(',',implode(',',$imageIdArr)));
|
||||||
|
$imageList = $this->getOssObjects($imageIds);
|
||||||
|
|
||||||
|
foreach ($orderList as &$order) {
|
||||||
|
$orderCopiesList = [];
|
||||||
|
for ($i = 1; $i <= ($order['meal_copies'] + $order['optional_copies']); $i++) {
|
||||||
|
|
||||||
|
$oneCopiesInfo = [
|
||||||
|
'total_price' => '0.00',
|
||||||
|
'total_quantity' => 0,
|
||||||
|
// 'sku_list' => [],
|
||||||
|
'image_list' => [],
|
||||||
|
'take_food_code' => [], //todo 取餐码
|
||||||
|
'copies_type' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($newOrderSkuList[$order['id']][$i] as $item) {
|
||||||
|
if ($item['order_id'] != $order['id'] || $item['copies'] != $i) continue;
|
||||||
|
|
||||||
|
$skuInfo = $skuList[$item['sku_id']] ?? [];
|
||||||
|
$imageId = !empty($skuInfo) && !empty(explode(',',$skuInfo['image_ids'])[0]) ? explode(',',$skuInfo['image_ids'])[0] : [];
|
||||||
|
$oneCopiesInfo['total_price'] = bcadd($oneCopiesInfo['total_price'], bcmul($item['unit_price'],(string)$item['quantity'],2), 2);
|
||||||
|
$oneCopiesInfo['total_quantity'] += $item['quantity'];
|
||||||
|
// $oneCopiesInfo['sku_list'][] = [];
|
||||||
|
$oneCopiesInfo['image_list'][] = $imageList[$imageId]['url'] ?? [];
|
||||||
|
|
||||||
|
if ($oneCopiesInfo['copies_type'] == 0) $oneCopiesInfo['copies_type'] = $item['type'];
|
||||||
|
}
|
||||||
|
// foreach ($newOrderSkuList as $item) {
|
||||||
|
// if ($item['order_id'] != $order['id'] || $item['copies'] != $i) continue;
|
||||||
//
|
//
|
||||||
|
// $skuInfo = $skuList[$item['sku_id']] ?? [];
|
||||||
|
// $imageId = !empty($skuInfo) && !empty(explode(',',$skuInfo['image_ids'])[0]) ? explode(',',$skuInfo['image_ids'])[0] : [];
|
||||||
|
// $oneCopiesInfo['total_price'] = bcadd($oneCopiesInfo['total_price'], bcmul($item['unit_price'],$item['quantity'],2), 2);
|
||||||
|
// $oneCopiesInfo['total_quantity'] += $item['quantity'];
|
||||||
|
// $oneCopiesInfo['sku_list'][] = $skuInfo;
|
||||||
|
// $oneCopiesInfo['image_list'][] = $imageList[$imageId] ?? [];
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
$orderCopiesList[] = $oneCopiesInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
$order['copies_list'] = $orderCopiesList;
|
||||||
|
$order['site'] = $this->siteCache->getSiteInfo((int)$order['site_id']) ?? [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,10 +38,10 @@ trait CouponDispenseTrait
|
|||||||
unset($cycleInfo);
|
unset($cycleInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getSiteAndGoodsValueAndCheckDate()
|
// protected function getSiteAndGoodsValueAndCheckDate()
|
||||||
{
|
// {
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
|
|||||||
Reference in New Issue
Block a user