Manual.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Http\Controllers\Gateway;
  3. use App\Models\Payment;
  4. use Auth;
  5. use Illuminate\Http\JsonResponse;
  6. use Illuminate\Http\Request;
  7. use Response;
  8. class Manual extends AbstractPayment
  9. {
  10. public function purchase(Request $request): JsonResponse
  11. {
  12. $payment = $this->creatNewPayment(Auth::id(), $request->input('id'), $request->input('amount'));
  13. if ($payment) {
  14. $url = route('manual.checkout', ['payment' => $payment->trade_no]);
  15. $payment->update(['url' => $url]);
  16. return Response::json(['status' => 'success', 'url' => $url, 'message' => '创建订单成功!']);
  17. }
  18. return Response::json(['status' => 'fail', 'message' => '购买失败,请尝试其他方式']);
  19. }
  20. public function redirectPage($trade_no)
  21. {
  22. $payment = Payment::uid()->with(['order', 'order.goods'])->whereTradeNo($trade_no)->firstOrFail();
  23. $goods = $payment->order->goods;
  24. return view('user.components.payment.manual', [
  25. 'payment' => $payment,
  26. 'name' => $goods->name ?? trans('user.recharge_credit'),
  27. 'days' => $goods->days ?? 0,
  28. 'pay_type' => $payment->order->pay_type_label ?: 0,
  29. 'pay_type_icon' => $payment->order->pay_type_icon,
  30. ]);
  31. }
  32. public function inform($trade_no)
  33. {
  34. $payment = Payment::uid()->with(['order'])->whereTradeNo($trade_no)->firstOrFail();
  35. $payment->order->update(['status' => 1]);
  36. return Response::json(['status' => 'success', 'message' => '我们将在【24小时】内对购买/充值的款项进行开通!请耐心等待']);
  37. }
  38. public function notify(Request $request): void
  39. {
  40. $code = $request->input('sign');
  41. $status = $request->input('status');
  42. if (isset($status, $code)) {
  43. $payment = Payment::findOrFail((int) string_decrypt($code));
  44. if ($payment && $payment->order && $payment->order->status === 1) {
  45. if ($status) {
  46. $payment->order->complete();
  47. } else {
  48. $payment->order->close();
  49. }
  50. exit('success');
  51. }
  52. exit('fail');
  53. }
  54. exit('No enough information');
  55. }
  56. }