Order.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\api\controller;
  13. use app\api\service\recharge\PayPal;
  14. use think\App;
  15. use think\facade\Cache;
  16. use think\response\Json;
  17. use app\api\model\Order as OrderModel;
  18. use app\api\model\Setting as SettingModel;
  19. use app\api\service\User as UserService;
  20. use app\api\service\Order as OrderService;
  21. use cores\exception\BaseException;
  22. /**
  23. * 我的订单控制器
  24. * Class Order
  25. * @package app\api\controller
  26. */
  27. class Order extends Controller
  28. {
  29. /**
  30. * 我的订单列表
  31. * @param string $dataType 订单类型
  32. * @return Json
  33. * @throws BaseException
  34. * @throws \think\db\exception\DbException
  35. */
  36. public function list(string $dataType): Json
  37. {
  38. $model = new OrderModel;
  39. $list = $model->getList($dataType);
  40. return $this->renderSuccess(compact('list'));
  41. }
  42. /**
  43. * 订单详情信息
  44. * @param int $orderId 订单ID
  45. * @return Json
  46. * @throws BaseException
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\DbException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. */
  51. public function detail(int $orderId): Json
  52. {
  53. // 订单详情
  54. $model = OrderModel::getUserOrderDetail($orderId);
  55. return $this->renderSuccess([
  56. 'order' => $model, // 订单详情
  57. 'setting' => [
  58. // 积分名称
  59. 'points_name' => SettingModel::getPointsName(),
  60. ],
  61. ]);
  62. }
  63. /**
  64. * 获取物流跟踪信息
  65. * @param int $orderId 订单ID
  66. * @return Json
  67. * @throws BaseException
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\DbException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. */
  72. public function express(int $orderId): Json
  73. {
  74. $service = new OrderService;
  75. $express = $service->express($orderId);
  76. return $this->renderSuccess(compact('express'));
  77. }
  78. /**
  79. * 取消订单
  80. * @param int $orderId
  81. * @return Json
  82. * @throws BaseException
  83. */
  84. public function cancel(int $orderId): Json
  85. {
  86. $model = OrderModel::getDetail($orderId);
  87. if ($model->cancel()) {
  88. return $this->renderSuccess($model->getMessage());
  89. }
  90. return $this->renderError($model->getError() ?: '订单取消失败');
  91. }
  92. /**
  93. * 确认收货
  94. * @param int $orderId
  95. * @return Json
  96. * @throws BaseException
  97. */
  98. public function receipt(int $orderId): Json
  99. {
  100. $model = OrderModel::getDetail($orderId);
  101. if ($model->receipt()) {
  102. return $this->renderSuccess('确认收货成功');
  103. }
  104. return $this->renderError($model->getError());
  105. }
  106. /**
  107. * 获取当前用户待处理的订单数量
  108. * @return Json
  109. * @throws BaseException
  110. */
  111. public function todoCounts(): Json
  112. {
  113. $model = new OrderModel;
  114. $counts = $model->getTodoCounts();
  115. return $this->renderSuccess(compact('counts'));
  116. }
  117. public function createOrderPaypal()
  118. {
  119. $clientId = 'AS0FH780ZGtSAdpT1NTjwkFzryCPf69rZb_FR9Rt_rZdasB80cmjqTQ6CQELWiFVh_MU9e31CSnyz7Ai';
  120. $clientSecret = 'EDqRQhgLNHCb5bxld98T8-JJJZKvMIeqxudO7lMwDFOxBfy138PjM5A21FnDNyb3q4yYUh8r7Qr2BnVi';
  121. $pappalService = new PayPal($clientId,$clientSecret);
  122. //$b = $pappalService->captureOrder('8LJ66491SN1477024');
  123. $b = $pappalService->createOrderV2();
  124. return $this->renderSuccess(compact('b'));
  125. $a = $pappalService->getAccessToken();
  126. dd($a);
  127. $url = 'https://api-m.sandbox.paypal.com/v2/checkout/orders';
  128. $headers = [
  129. 'Content-Type' => 'application/json',
  130. //'PayPal-Request-Id' => $PayPalRequestId,
  131. //'Authorization' => $PayPalRequestId,
  132. ];
  133. $a = curl_request($url, 'get');
  134. dd($a);
  135. }
  136. public function captureOrderPaypal()
  137. {
  138. $clientId = 'AS0FH780ZGtSAdpT1NTjwkFzryCPf69rZb_FR9Rt_rZdasB80cmjqTQ6CQELWiFVh_MU9e31CSnyz7Ai';
  139. $clientSecret = 'EDqRQhgLNHCb5bxld98T8-JJJZKvMIeqxudO7lMwDFOxBfy138PjM5A21FnDNyb3q4yYUh8r7Qr2BnVi';
  140. $pappalService = new PayPal($clientId,$clientSecret);
  141. $b = $pappalService->captureOrder('8LJ66491SN1477024');
  142. return $this->renderSuccess(compact('b'));
  143. }
  144. }