You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

98 lines
2.6 KiB

<?php
namespace App\JsonRpc;
use App\Commons\Log;
use App\Constants\v3\ErrorCode;
use App\Constants\v3\LogLabel;
use App\Exception\ErrorCodeException;
use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
use App\Service\v3\Interfaces\SeparateAccountsServiceInterface;
use Hyperf\DbConnection\Db;
use Hyperf\RpcServer\Annotation\RpcService;
use Hyperf\Di\Annotation\Inject;
use function AlibabaCloud\Client\json;
/**
* @RpcService(name="OrderService", protocol="jsonrpc-http", server="jsonrpc-http", publishTo="")
*/
class OrderService implements OrderServiceInterface
{
/**
* @Inject
* @var Log
*/
protected $log;
/**
* @Inject
* @var OrderOnlineServiceInterface
*/
protected $orderOnlineService;
/**
* @Inject
* @var SeparateAccountsServiceInterface
*/
protected $separateAccountsService;
/**
* 订单完成
* @param $global_order_id
* @param $user_id
* @return array
*/
public function onlineComplete($global_order_id, $user_id)
{
Db::beginTransaction();
try {
$this->orderOnlineService->doComplete($global_order_id, $user_id);
$this->separateAccountsService->orderOnlineCompleted($global_order_id, $user_id);
Db::commit();
return [
"status" => 200,
"code" => 0,
"result" => [],
"message" => '处理成功'
];
} catch (\Exception $e) {
Db::rollBack();
$this->log->event(LogLabel::ORDER_COMPLETE_LOG, ['jsonrpc_order_service_exception_onlineComplete' => $e->getMessage(), 'params' => json([$global_order_id, $user_id])]);
throw new ErrorCodeException(ErrorCode::ORDER_COMPLETE_FAIL);
}
}
/**
* 线上订单退款,整个订单退
* @param $global_order_id
* @param $user_id
* @return array
*/
public function onlineRefund($global_order_id, $user_id){
Db::beginTransaction();
try {
$this->orderOnlineService->doRefund($global_order_id, $user_id);
Db::commit();
return [
"status" => 200,
"code" => 0,
"result" => [],
"message" => '处理成功'
];
} catch (\Exception $e) {
Db::rollBack();
$this->log->event(LogLabel::ORDER_REFUND_LOG, ['jsonrpc_order_service_exception_onlineRefund' => $e->getMessage(), 'params' => json([$global_order_id, $user_id])]);
throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL);
}
}
}