| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Module\AppGame\Handler\Matchexchange;
- use App\Module\AppGame\Handler\BaseHandler;
- use App\Module\Mex\Services\MexOrderService;
- use Google\Protobuf\Internal\Message;
- use Uraus\Kku\Request\RequestMatchexchangeCancel;
- use Uraus\Kku\Response\ResponseMatchexchangeCancel;
- use Uraus\Kku\Common\RESPONSE_CODE;
- use UCore\Exception\LogicException;
- use Illuminate\Support\Facades\Log;
- /**
- * 处理取消挂单请求
- */
- class CancelHandler extends BaseHandler
- {
- /**
- * 是否需要登录
- * @var bool
- */
- protected bool $need_login = true;
- /**
- * 处理取消挂单请求
- *
- * @param RequestMatchexchangeCancel $data 取消挂单请求数据
- * @return ResponseMatchexchangeCancel 取消挂单响应
- */
- public function handle(Message $data): Message
- {
- // 创建响应对象
- $response = new ResponseMatchexchangeCancel();
- try {
- // 获取请求参数
- $orderId = $data->getId();
- $userId = $this->user_id;
- // 参数验证
- if (!$orderId || $orderId <= 0) {
- throw new LogicException("订单ID无效");
- }
- // 调用服务取消订单
- $result = MexOrderService::cancelOrder($userId, $orderId);
- // 检查操作结果
- if (!$result['success']) {
- throw new LogicException($result['message'] ?? '取消订单失败');
- }
- // 更新用户活动时间
- $this->updateUserActivityTime();
- } catch (\Exception $e) {
- // 系统异常
- Log::error('取消挂单系统异常', [
- 'user_id' => $this->user_id,
- 'order_id' => $orderId ?? 0,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- $this->response->setCode(RESPONSE_CODE::SERVER_ERROR);
- $this->response->setMsg('系统繁忙,请稍后重试');
- }
- return $response;
- }
- }
|