feat : order
This commit is contained in:
@@ -31,7 +31,6 @@ class OrderController extends AbstractController
|
||||
#[Scene(scene: "list")]
|
||||
public function list()
|
||||
{
|
||||
//todo
|
||||
return (new OrderListService())->handle();
|
||||
}
|
||||
|
||||
@@ -39,7 +38,6 @@ class OrderController extends AbstractController
|
||||
#[Scene(scene: "info")]
|
||||
public function info()
|
||||
{
|
||||
//todo
|
||||
return (new OrderInfoService())->handle();
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +91,8 @@ class OrderController extends AbstractController
|
||||
/**
|
||||
* 订单列表
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'order_list',methods: 'get')]
|
||||
#[Scene(scene: 'order_list')]
|
||||
|
||||
@@ -10,13 +10,124 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\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\Admin\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;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
//todo Write logic
|
||||
return $this->return->success();
|
||||
$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
|
||||
{
|
||||
//todo 支付信息 退款信息 优惠券信息
|
||||
$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['copies'] ?? 0); $i++) {
|
||||
|
||||
$oneCopiesInfo = [
|
||||
'total_price' => '0.00',
|
||||
'total_quantity' => 0,
|
||||
'sku_list' => [],
|
||||
'image_list' => [],
|
||||
'take_food_code' => '', //todo 取餐码
|
||||
];
|
||||
|
||||
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] ?? [];
|
||||
}
|
||||
$orderCopiesList[] = $oneCopiesInfo;
|
||||
}
|
||||
|
||||
$orderInfo['copies_list'] = $orderCopiesList;
|
||||
$orderInfo['site'] = $this->siteCache->getSiteInfo($orderInfo['site_id']);
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class OrderListService extends BaseService
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 20);
|
||||
|
||||
//todo where kitchenID
|
||||
//todo where
|
||||
$orderList = $this->orderModel
|
||||
->when($this->request->input('search_user_id'), function ($query) {
|
||||
$query->where('user_id', $this->request->input('search_user_id'));
|
||||
@@ -62,14 +62,18 @@ class OrderListService extends BaseService
|
||||
->when($this->request->input('search_status'), function ($query) {
|
||||
$query->where('status', $this->request->input('search_status'));
|
||||
})
|
||||
->when($this->request->input('city_id'), function ($query) {
|
||||
$query->where('city_id', $this->request->input('city_id'));
|
||||
->when($this->request->input('search_city_id'), function ($query) {
|
||||
$query->where('city_id', $this->request->input('search_city_id'));
|
||||
})
|
||||
->when($this->request->input('search_kitchen_id'), function ($query) {
|
||||
$query->where('kitchen_id', $this->request->input('search_kitchen_id'));
|
||||
})
|
||||
->select([
|
||||
'id',
|
||||
'cycle_id',
|
||||
'order_sno',
|
||||
'user_id',
|
||||
'kitchen_id',
|
||||
'site_id',
|
||||
'copies',
|
||||
'type',
|
||||
|
||||
Reference in New Issue
Block a user