|
|
|
@ -3,11 +3,15 @@ |
|
|
|
namespace App\Controller; |
|
|
|
|
|
|
|
use App\Constants\ErrorCode; |
|
|
|
use App\Constants\LogLabel; |
|
|
|
use App\Model\OrderMain; |
|
|
|
use App\Request\OrderOfflineRequest; |
|
|
|
use App\Request\OrderOnlineRequest; |
|
|
|
use Hyperf\DbConnection\Db; |
|
|
|
use Hyperf\Di\Annotation\Inject; |
|
|
|
use App\Service\OrderServiceInterface; |
|
|
|
use Hyperf\HttpMessage\Stream\SwooleStream; |
|
|
|
use Hyperf\Validation\ValidationException; |
|
|
|
|
|
|
|
class OrderController extends BaseController |
|
|
|
{ |
|
|
|
@ -35,4 +39,55 @@ class OrderController extends BaseController |
|
|
|
} |
|
|
|
return $this->success(['order_id' => $orderMainId]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 用户完成订单-确认收货 |
|
|
|
*/ |
|
|
|
public function userComp() |
|
|
|
{ |
|
|
|
|
|
|
|
$validator = $this->validationFactory->make( |
|
|
|
$this->request->all(), |
|
|
|
[ |
|
|
|
'user_id' => 'required|nonempty|integer', |
|
|
|
'order_id' => 'required|nonempty|numeric', |
|
|
|
], |
|
|
|
[ |
|
|
|
'*.*' => ':attribute 参数不正确', |
|
|
|
] |
|
|
|
); |
|
|
|
|
|
|
|
if ($validator->fails()) { |
|
|
|
// Handle exception
|
|
|
|
throw new ValidationException($validator); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
$userId = $this->request->input('user_id'); |
|
|
|
$orderId = $this->request->input('order_id'); |
|
|
|
$orderExist = OrderMain::query() |
|
|
|
->where(['id' => $orderId, 'state' => OrderMain::ORDER_STATE_DELIVERY, 'user_id' => $userId]) |
|
|
|
->exists(); |
|
|
|
|
|
|
|
if (!$orderExist) { |
|
|
|
$this->log->event(LogLabel::ONLINE_COMPLETE_LOG, ['order_not_found' => 'order_not_found']); |
|
|
|
return $this->result(ErrorCode::SEPARATE_ACCOUNTS_ERROR, '', '操作失败,订单异常或不存在'); |
|
|
|
} |
|
|
|
|
|
|
|
Db::beginTransaction(); |
|
|
|
try { |
|
|
|
|
|
|
|
$this->orderService->onlineCompleted($orderId); |
|
|
|
$this->separateAccountsService->orderOnlineCompleted($orderId); |
|
|
|
|
|
|
|
Db::commit(); |
|
|
|
return $this->success(['order_id' => $orderId]); |
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
|
Db::rollBack(); |
|
|
|
$this->log->event(LogLabel::ONLINE_COMPLETE_LOG, ['exception' => $e->getMessage()]); |
|
|
|
return $this->result(ErrorCode::SEPARATE_ACCOUNTS_ERROR, '', '操作失败,请稍后重试'); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |