feat : order list
This commit is contained in:
@@ -6,6 +6,10 @@ namespace App\Controller\Api;
|
|||||||
|
|
||||||
use App\Controller\AbstractController;
|
use App\Controller\AbstractController;
|
||||||
use App\Middleware\Api\JwtAuthMiddleware;
|
use App\Middleware\Api\JwtAuthMiddleware;
|
||||||
|
use App\Service\Api\Evaluation\EvaluationService;
|
||||||
|
use App\Service\Api\Evaluation\ViewService as EvaluationViewService;
|
||||||
|
use App\Service\Api\Evaluation\InfoService as EvaluationInfoService;
|
||||||
|
use App\Service\Api\Evaluation\ListService as EvaluationListService;
|
||||||
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\CheckStockService;
|
use App\Service\Api\Order\CheckStockService;
|
||||||
@@ -126,4 +130,48 @@ class OrderController extends AbstractController
|
|||||||
{
|
{
|
||||||
return (new OrderInfoService)->handle();
|
return (new OrderInfoService)->handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: 'evaluation',methods: 'POST')]
|
||||||
|
#[Scene(scene: 'evaluation')]
|
||||||
|
public function evaluation()
|
||||||
|
{
|
||||||
|
return (new EvaluationService)->handle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论视图 (商品信息)
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: 'evaluation_view',methods: 'get')]
|
||||||
|
#[Scene(scene: 'evaluation_view')]
|
||||||
|
public function evaluationView()
|
||||||
|
{
|
||||||
|
return (new EvaluationViewService)->handle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论详情
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: 'evaluation_info',methods: 'get')]
|
||||||
|
#[Scene(scene: 'evaluation_info')]
|
||||||
|
public function evaluationInfo()
|
||||||
|
{
|
||||||
|
return (new EvaluationInfoService)->handle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 我的评论
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: 'evaluation_list',methods: 'get')]
|
||||||
|
#[Scene(scene: 'evaluation_list')]
|
||||||
|
public function evaluationList()
|
||||||
|
{
|
||||||
|
return (new EvaluationListService)->handle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
42
app/Model/Evaluation.php
Normal file
42
app/Model/Evaluation.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Model;
|
||||||
|
|
||||||
|
use Hyperf\DbConnection\Model\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id
|
||||||
|
* @property int $user_id
|
||||||
|
* @property int $order_id
|
||||||
|
* @property int $order_good_id
|
||||||
|
* @property int $chef_id
|
||||||
|
* @property int $sku_id
|
||||||
|
* @property int $score
|
||||||
|
* @property string $content
|
||||||
|
* @property string $image_ids
|
||||||
|
* @property string $create_time
|
||||||
|
* @property string $update_time
|
||||||
|
*/
|
||||||
|
class Evaluation extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*/
|
||||||
|
protected ?string $table = 'evaluation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*/
|
||||||
|
protected array $fillable = [];
|
||||||
|
protected array $guarded = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that should be cast to native types.
|
||||||
|
*/
|
||||||
|
protected array $casts = ['id' => 'integer', 'user_id' => 'integer', 'order_id' => 'integer', 'order_good_id' => 'integer', 'chef_id' => 'integer', 'sku_id' => 'integer', 'score' => 'integer'];
|
||||||
|
|
||||||
|
const string CREATED_AT = 'create_time';
|
||||||
|
const string UPDATED_AT = 'update_time';
|
||||||
|
}
|
||||||
94
app/Service/Api/Evaluation/EvaluationService.php
Normal file
94
app/Service/Api/Evaluation/EvaluationService.php
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
<?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\Constants\Common\OrderCode;
|
||||||
|
use App\Exception\ErrException;
|
||||||
|
use App\Model\Evaluation;
|
||||||
|
use App\Model\Order;
|
||||||
|
use App\Model\OrderGood;
|
||||||
|
use App\Model\Sku;
|
||||||
|
use App\Service\Api\BaseService;
|
||||||
|
use App\Service\ServiceTrait\Common\OssTrait;
|
||||||
|
use Hyperf\DbConnection\Db;
|
||||||
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
use function Hyperf\Coroutine\co;
|
||||||
|
|
||||||
|
class EvaluationService extends BaseService
|
||||||
|
{
|
||||||
|
use OssTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Order
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Order $orderModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OrderGood
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected OrderGood $orderGoodModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Sku
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Sku $skuModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function handle(): array
|
||||||
|
{
|
||||||
|
$orderGoodInfo = $this->orderGoodModel->find($this->request->input('order_good_id'));
|
||||||
|
if (empty($orderGoodInfo)) throw new ErrException('订单信息异常,请稍后再试或者联系客服');
|
||||||
|
|
||||||
|
if ($orderGoodInfo->is_comment == OrderCode::GOOD_COMMENT_FINISH) throw new ErrException('该商品您已完成评价,感谢您的参与');
|
||||||
|
|
||||||
|
$orderInfo = $this->orderModel->find($orderGoodInfo->order_id);
|
||||||
|
if (empty($orderInfo)) throw new ErrException('订单不存在');
|
||||||
|
|
||||||
|
if ($orderInfo->status != OrderCode::FINISH) throw new ErrException('订单尚未完成,请稍候');
|
||||||
|
|
||||||
|
$skuInfo = $this->skuModel->find($orderGoodInfo->sku_id);
|
||||||
|
if (empty($skuInfo)) throw new ErrException('该菜品信息不存在,请稍后再试');
|
||||||
|
|
||||||
|
$insertModel = Db::transaction(function () use ($orderInfo, $skuInfo, $orderGoodInfo) {
|
||||||
|
$insertModel = new Evaluation();
|
||||||
|
|
||||||
|
$insertModel->user_id = $orderInfo->user_id;
|
||||||
|
$insertModel->order_id = $orderGoodInfo->order_id;
|
||||||
|
$insertModel->order_good_id = $orderGoodInfo->id;
|
||||||
|
$insertModel->sku_id = $orderGoodInfo->sku_id;
|
||||||
|
$insertModel->chef_id = $skuInfo->chef_id;
|
||||||
|
$insertModel->score = $this->request->input('score');
|
||||||
|
if (!$this->request->input('image_ids')) {
|
||||||
|
$imageIds = explode(',',$this->request->input('image_ids'));
|
||||||
|
if (count($imageIds) > 9) throw new ErrException('超出可以传图片最大值');
|
||||||
|
$this->updateOssObjects($imageIds);
|
||||||
|
$insertModel->image_ids = $this->request->input('image_ids');
|
||||||
|
}
|
||||||
|
// $insertModel->image_ids = $imageIds ?? '';
|
||||||
|
$insertModel->content = $this->request->input('content');
|
||||||
|
|
||||||
|
if (!$insertModel->save()) throw new ErrException('评论失败-001');
|
||||||
|
|
||||||
|
$orderGoodInfo->is_comment = OrderCode::GOOD_COMMENT_FINISH;
|
||||||
|
if (!$orderGoodInfo->save()) throw new ErrException('评论失败-002');
|
||||||
|
|
||||||
|
//todo 厨师商品评分]
|
||||||
|
return $insertModel;
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this->return->success('success', ['id' => $insertModel->id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
83
app/Service/Api/Evaluation/InfoService.php
Normal file
83
app/Service/Api/Evaluation/InfoService.php
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
79
app/Service/Api/Evaluation/ViewService.php
Normal file
79
app/Service/Api/Evaluation/ViewService.php
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<?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\Constants\Common\OrderCode;
|
||||||
|
use App\Exception\ErrException;
|
||||||
|
use App\Model\AdminUser;
|
||||||
|
use App\Model\Order;
|
||||||
|
use App\Model\OrderGood;
|
||||||
|
use App\Model\Sku;
|
||||||
|
use App\Service\Api\BaseService;
|
||||||
|
use App\Service\ServiceTrait\Common\OssTrait;
|
||||||
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
|
||||||
|
class ViewService extends BaseService
|
||||||
|
{
|
||||||
|
use OssTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Order
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Order $orderModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var OrderGood
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected OrderGood $orderGoodModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Sku
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Sku $skuModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var AdminUser
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected AdminUser $adminUserModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function handle(): array
|
||||||
|
{
|
||||||
|
$orderGoodInfo = $this->orderGoodModel->find($this->request->input('order_good_id'));
|
||||||
|
if (empty($orderGoodInfo)) throw new ErrException('订单信息异常,请稍后再试或者联系客服');
|
||||||
|
|
||||||
|
$orderInfo = $this->orderModel->find($orderGoodInfo->order_id);
|
||||||
|
if (empty($orderInfo)) throw new ErrException('订单不存在');
|
||||||
|
|
||||||
|
if ($orderInfo->status != OrderCode::FINISH) throw new ErrException('订单尚未完成,请稍候');
|
||||||
|
|
||||||
|
$skuInfo = $this->skuModel->find($orderGoodInfo->sku_id);
|
||||||
|
if (empty($skuInfo)) throw new ErrException('该菜品信息不存在,请稍后再试');
|
||||||
|
|
||||||
|
$adminInfo = $this->adminUserModel->find($skuInfo->chef_id);
|
||||||
|
|
||||||
|
$res = [
|
||||||
|
'title' => $skuInfo->title,
|
||||||
|
'price' => $skuInfo->price,
|
||||||
|
'chef_id' => $skuInfo->chef_id,
|
||||||
|
'chef_name' => $adminInfo->chinese_name,
|
||||||
|
'image_url' => $this->getOssObjectById($skuInfo->image_ids),
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->return->success('success',$res);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -166,6 +166,8 @@ class OrderInfoService extends BaseService
|
|||||||
'quantity' => $item['quantity'],
|
'quantity' => $item['quantity'],
|
||||||
'price' => bcmul((string)$item['unit_price'], (string)$item['quantity'], 2),
|
'price' => bcmul((string)$item['unit_price'], (string)$item['quantity'], 2),
|
||||||
'chef_name' => $chefList[$item['sku_id']]['chinese_name'] ?? '',
|
'chef_name' => $chefList[$item['sku_id']]['chinese_name'] ?? '',
|
||||||
|
'order_good_id' => $item['id'],
|
||||||
|
'is_comment' => $item['is_comment'],
|
||||||
];
|
];
|
||||||
$oneCopiesInfo['total_price'] = bcadd((string)$oneCopiesInfo['total_price'], bcmul((string)$item['unit_price'],(string)$item['quantity'],2), 2);
|
$oneCopiesInfo['total_price'] = bcadd((string)$oneCopiesInfo['total_price'], bcmul((string)$item['unit_price'],(string)$item['quantity'],2), 2);
|
||||||
$oneCopiesInfo['total_quantity'] += $item['quantity'];
|
$oneCopiesInfo['total_quantity'] += $item['quantity'];
|
||||||
|
|||||||
Reference in New Issue
Block a user