// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\api\controller; use app\api\service\recharge\PayPal; use think\App; use think\facade\Cache; use think\response\Json; use app\api\model\Order as OrderModel; use app\api\model\Setting as SettingModel; use app\api\service\User as UserService; use app\api\service\Order as OrderService; use cores\exception\BaseException; /** * 我的订单控制器 * Class Order * @package app\api\controller */ class Order extends Controller { /** * 我的订单列表 * @param string $dataType 订单类型 * @return Json * @throws BaseException * @throws \think\db\exception\DbException */ public function list(string $dataType): Json { $model = new OrderModel; $list = $model->getList($dataType); return $this->renderSuccess(compact('list')); } /** * 订单详情信息 * @param int $orderId 订单ID * @return Json * @throws BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function detail(int $orderId): Json { // 订单详情 $model = OrderModel::getUserOrderDetail($orderId); return $this->renderSuccess([ 'order' => $model, // 订单详情 'setting' => [ // 积分名称 'points_name' => SettingModel::getPointsName(), ], ]); } /** * 获取物流跟踪信息 * @param int $orderId 订单ID * @return Json * @throws BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function express(int $orderId): Json { $service = new OrderService; $express = $service->express($orderId); return $this->renderSuccess(compact('express')); } /** * 取消订单 * @param int $orderId * @return Json * @throws BaseException */ public function cancel(int $orderId): Json { $model = OrderModel::getDetail($orderId); if ($model->cancel()) { return $this->renderSuccess($model->getMessage()); } return $this->renderError($model->getError() ?: '订单取消失败'); } /** * 确认收货 * @param int $orderId * @return Json * @throws BaseException */ public function receipt(int $orderId): Json { $model = OrderModel::getDetail($orderId); if ($model->receipt()) { return $this->renderSuccess('确认收货成功'); } return $this->renderError($model->getError()); } /** * 获取当前用户待处理的订单数量 * @return Json * @throws BaseException */ public function todoCounts(): Json { $model = new OrderModel; $counts = $model->getTodoCounts(); return $this->renderSuccess(compact('counts')); } public function createOrderPaypal() { $clientId = 'AS0FH780ZGtSAdpT1NTjwkFzryCPf69rZb_FR9Rt_rZdasB80cmjqTQ6CQELWiFVh_MU9e31CSnyz7Ai'; $clientSecret = 'EDqRQhgLNHCb5bxld98T8-JJJZKvMIeqxudO7lMwDFOxBfy138PjM5A21FnDNyb3q4yYUh8r7Qr2BnVi'; $pappalService = new PayPal($clientId,$clientSecret); //$b = $pappalService->captureOrder('8LJ66491SN1477024'); $b = $pappalService->createOrderV2(); return $this->renderSuccess(compact('b')); $a = $pappalService->getAccessToken(); dd($a); $url = 'https://api-m.sandbox.paypal.com/v2/checkout/orders'; $headers = [ 'Content-Type' => 'application/json', //'PayPal-Request-Id' => $PayPalRequestId, //'Authorization' => $PayPalRequestId, ]; $a = curl_request($url, 'get'); dd($a); } public function captureOrderPaypal() { $clientId = 'AS0FH780ZGtSAdpT1NTjwkFzryCPf69rZb_FR9Rt_rZdasB80cmjqTQ6CQELWiFVh_MU9e31CSnyz7Ai'; $clientSecret = 'EDqRQhgLNHCb5bxld98T8-JJJZKvMIeqxudO7lMwDFOxBfy138PjM5A21FnDNyb3q4yYUh8r7Qr2BnVi'; $pappalService = new PayPal($clientId,$clientSecret); $b = $pappalService->captureOrder('8LJ66491SN1477024'); return $this->renderSuccess(compact('b')); } }