OrderPayController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * 订单详情
  4. * Created by PhpStorm.
  5. * Author: 芸众商城 www.yunzshop.com
  6. * Date: 2017/3/4
  7. * Time: 上午11:16
  8. */
  9. namespace app\backend\modules\order\controllers;
  10. use app\backend\modules\order\models\Order;
  11. use app\common\components\BaseController;
  12. use app\common\models\OrderPay;
  13. use app\common\models\PayCallbackException;
  14. class OrderPayController extends BaseController
  15. {
  16. /**
  17. * @return string
  18. * @throws \Throwable
  19. */
  20. public function index()
  21. {
  22. $orderId = request()->query('order_id');
  23. $order = Order::with(['orderPays' => function ($query) {
  24. $query->with('orders');
  25. }])->find($orderId);
  26. return view('order.orderPay', [
  27. 'orderPays' => json_encode($order->orderPays)
  28. ])->render();
  29. }
  30. public function vue()
  31. {
  32. $orderId = intval(request()->input('order_id'));
  33. $order = Order::with(['orderPays' => function ($query) {
  34. $query->with('orders');
  35. }])->find($orderId);
  36. return $this->successJson('orderPay', $order->orderPays);
  37. }
  38. public function callbackException()
  39. {
  40. //回调失败退款记录
  41. $data = [];
  42. return view('order.pay_error_refund', [
  43. 'orderPays' => json_encode($data)
  44. ])->render();
  45. }
  46. public function exceptionList()
  47. {
  48. $search = request()->input('search');
  49. $page = PayCallbackException::getList($search)->orderBy('id','desc')->paginate(15);
  50. if ($page->isNotEmpty()) {
  51. $page->map(function (PayCallbackException $payException) {
  52. $orders = $payException->orderPay->orders;
  53. $payException->orders = $orders;
  54. });
  55. }
  56. return $this->successJson('exceptionList', $page);
  57. }
  58. public function payErrorRefund()
  59. {
  60. $id = intval(request()->input('id'));
  61. if (empty($id)) {
  62. return $this->errorJson('参数错误');
  63. }
  64. $payException = PayCallbackException::find($id);
  65. if (!$payException || $payException->error_code != PayCallbackException::ORDER_CLOSE) {
  66. return $this->errorJson('异常类型不支持操作退款');
  67. }
  68. if ( $payException->status == PayCallbackException::STATUS_SUCCESS) {
  69. return $this->successJson('支付已退款');
  70. }
  71. $result = $payException->refund();
  72. if (!$result['status']) {
  73. return $this->errorJson($result['msg']);
  74. }
  75. return $this->successJson('操作退款成功');
  76. }
  77. }