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.
113 lines
3.1 KiB
113 lines
3.1 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);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 线上订单单笔退款
|
|
* 支持单商品、单店、整单
|
|
* @param $user_id *用户ID
|
|
* @param $global_order_id *全局总订单ID
|
|
* @param $child_order_id *主订单ID,
|
|
* @param $order_goods_id *订单商品ID
|
|
* @param $note
|
|
*/
|
|
public function onlineSingleRefund($user_id, $global_order_id, $child_order_id, $order_goods_id, $note)
|
|
{
|
|
|
|
}
|
|
}
|