83 lines
2.0 KiB
PHP
83 lines
2.0 KiB
PHP
<?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\Exception\ErrException;
|
|
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 InfoService extends BaseService
|
|
{
|
|
use OssTrait;
|
|
|
|
/**
|
|
* @var Evaluation
|
|
*/
|
|
#[Inject]
|
|
protected Evaluation $evaluationModel;
|
|
|
|
/**
|
|
* @var Sku
|
|
*/
|
|
#[Inject]
|
|
protected Sku $skuModel;
|
|
|
|
/**
|
|
* @var AdminUser
|
|
*/
|
|
#[Inject]
|
|
protected AdminUser $adminUserModel;
|
|
|
|
/**
|
|
* @var Order
|
|
*/
|
|
#[Inject]
|
|
protected Order $orderModel;
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function handle(): array
|
|
{
|
|
$info = $this->evaluationModel->find($this->request->input('id'));
|
|
|
|
if (empty($info)) throw new ErrException('评论不存在');
|
|
|
|
$skuInfo = $this->skuModel->find($info->sku_id);
|
|
if (empty($skuInfo)) throw new ErrException('该菜品信息不存在,请稍后再试');
|
|
|
|
$orderTime = $this->orderModel->where('id',$info->order_id)->value('create_time');
|
|
|
|
$adminInfo = $this->adminUserModel->find($skuInfo->chef_id);
|
|
|
|
$imageIds = explode(',', $info->image_ids);
|
|
$imageList = $this->getOssObjects($imageIds);
|
|
|
|
$res = [
|
|
'title' => $skuInfo->title,
|
|
'price' => $skuInfo->price,
|
|
'chef_id' => $skuInfo->chef_id,
|
|
'chef_name' => $adminInfo->chinese_name,
|
|
'image_url' => $this->getOssObjectById($skuInfo->image_ids),
|
|
'content' => $info->content,
|
|
'content_image_list' => array_column($imageList, 'url'),
|
|
'score' => $info->score,
|
|
'order_time' => $orderTime,
|
|
];
|
|
|
|
return $this->return->success('success',$res);
|
|
}
|
|
} |