feat : order list
This commit is contained in:
97
app/Service/Api/Evaluation/ListService.php
Normal file
97
app/Service/Api/Evaluation/ListService.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Evaluation;
|
||||
|
||||
use App\Model\AdminUser;
|
||||
use App\Model\Evaluation;
|
||||
use App\Model\Order;
|
||||
use App\Model\Sku;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Common\OssTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
|
||||
class ListService extends BaseService
|
||||
{
|
||||
use OssTrait;
|
||||
|
||||
/**
|
||||
* @var Evaluation
|
||||
*/
|
||||
#[Inject]
|
||||
protected Evaluation $evaluationModel;
|
||||
|
||||
/**
|
||||
* @var Sku
|
||||
*/
|
||||
#[Inject]
|
||||
protected Sku $skuModel;
|
||||
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
#[Inject]
|
||||
protected Order $orderModel;
|
||||
|
||||
/**
|
||||
* @var AdminUser
|
||||
*/
|
||||
#[Inject]
|
||||
protected AdminUser $adminUserModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$limit = $this->request->input('limit') ?? 10;
|
||||
|
||||
$data = $this->evaluationModel
|
||||
->where('user_id', $this->userId)
|
||||
->orderByDesc('id')
|
||||
->paginate($limit,['content','image_ids','id','order_id','chef_id','sku_id','score','content'])
|
||||
->toArray();
|
||||
|
||||
if (empty($data['data'])) return $this->return->success('success',['list' => $data]);
|
||||
|
||||
$skuIds = array_column($data['data'], 'sku_id');
|
||||
$orderIds = array_column($data['data'], 'order_id');
|
||||
$chefIds = array_column($data['data'], 'chef_id');
|
||||
$skuList = $this->skuModel->whereIn('id', $skuIds)->select(['title','price','chef_id','image_ids','id'])->get()->toArray();
|
||||
$orderTimes = $this->orderModel->whereIn('id', $orderIds)->pluck('create_time','id')->toArray();
|
||||
$skuList = array_column($skuList, null,'id');
|
||||
$chefNames = $this->adminUserModel->whereIn('id', $chefIds)->pluck('name','id')->toArray();
|
||||
$imageIds = array_column($skuList, 'image_ids');
|
||||
|
||||
$imageIdArr = array_column($data['data'],'image_ids');
|
||||
$listImageIds = array_unique(explode(',',implode(',',$imageIdArr)));
|
||||
|
||||
$totalImages = array_merge($imageIds,$listImageIds);
|
||||
unset($listImageIds,$imageIds);
|
||||
|
||||
$imageList = $this->getOssObjects($totalImages);
|
||||
|
||||
foreach ($data['data'] as &$item) {
|
||||
$item['title'] = $skuList[$item['sku_id']]['title'] ?? '';
|
||||
$item['price'] = $skuList[$item['sku_id']]['price'] ?? '';
|
||||
$item['chef_name'] = $chefNames[$item['chef_id']] ?? '';
|
||||
$item['image_url'] = $imageList[$skuList[$item['sku_id']]['image_ids']]['url'] ?? '';
|
||||
$item['order_time'] = $orderTimes[$item['order_id']] ?? '';
|
||||
$oneImage = [];
|
||||
foreach (explode(',',$item['image_ids']) as $imageId) {
|
||||
$oneImage[] = $imageList[$imageId]['url'] ?? '';
|
||||
}
|
||||
$item['content_image_list'] = $oneImage;
|
||||
}
|
||||
|
||||
return $this->return->success('success',['list' => $data]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user