| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace App\Module\AppGame\Handler\Matchexchange;
- use App\Module\AppGame\Handler\BaseHandler;
- use App\Module\AppGame\Validations\MatchexchangeCancelValidation;
- 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
- {
- // 创建验证对象
- $validation = MatchexchangeCancelValidation::makeByProrobufUser($data);
- // 验证请求数据
- $validation->validated();
- // 获取验证后的安全数据
- $orderId = $validation->getOrderId();
- $userId = $validation->getUserId();
- // 创建响应对象
- $response = new ResponseMatchexchangeCancel();
- try {
- // 调用服务取消订单
- $result = MexOrderService::cancelOrder($userId, $orderId);
- // 检查操作结果
- if (!$result['success']) {
- $this->response->setCode(RESPONSE_CODE::VALIDATE_ERROR);
- $this->response->setMsg($result['message'] ?? '取消订单失败');
- return $response;
- }
- // 更新用户活动时间
- $this->updateUserActivityTime();
- // 设置成功响应
- $this->response->setCode(RESPONSE_CODE::OK);
- $this->response->setMsg('订单取消成功');
- } catch (LogicException $e) {
- // 业务逻辑异常
- Log::warning('取消挂单业务异常', [
- 'user_id' => $userId,
- 'order_id' => $orderId,
- 'error' => $e->getMessage()
- ]);
- $this->response->setCode(RESPONSE_CODE::VALIDATE_ERROR);
- $this->response->setMsg($e->getMessage());
- } catch (\Exception $e) {
- // 系统异常
- Log::error('取消挂单系统异常', [
- 'user_id' => $userId,
- 'order_id' => $orderId,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- $this->response->setCode(RESPONSE_CODE::SERVER_ERROR);
- $this->response->setMsg('系统繁忙,请稍后重试');
- }
- return $response;
- }
- }
|