PaymentOrder.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\PaymentOrderService;
  6. use Exception;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Validation\ValidationException;
  9. class PaymentOrder extends Controller
  10. {
  11. public function audit()
  12. {
  13. try {
  14. $validate = [
  15. 'id' => ['required', 'integer', 'min:1'],
  16. 'status' => ['required', 'integer', 'in:1,3'],
  17. ];
  18. $status = request()->input('status', null);
  19. if ($status == 3) {
  20. $validate['remark'] = ['required', 'string', 'min:1', 'max:120'];
  21. }
  22. $params = request()->validate($validate);
  23. $remark = request()->input('remark', '');
  24. if ($params['status'] == 1) {
  25. $ret = PaymentOrderService::createPayout($params['id']);
  26. if ($ret['code'] !== 0) throw new Exception($ret['msg'], HttpStatus::CUSTOM_ERROR);
  27. } else {
  28. $ret = PaymentOrderService::withdrawalFailed($params['id'], $remark);
  29. if ($ret['code'] !== 0) throw new Exception($ret['msg'], HttpStatus::CUSTOM_ERROR);
  30. }
  31. } catch (ValidationException $e) {
  32. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  33. } catch (Exception $e) {
  34. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  35. }
  36. return $this->success();
  37. }
  38. /**
  39. * @apiParam {int} [page]
  40. * @apiParam {int} [limit]
  41. * @apiParam {int=0,1,2} type 类型 0全部 1=代收,2=代付
  42. * @apiParam {String} order_no 订单号
  43. * @apiPaaram {String} member_id 会员ID
  44. * @apiParam {int=0,1,2,3} [status] 状态:0待处理 1处理中 2成功 3失败
  45. *
  46. */
  47. public function index()
  48. {
  49. try {
  50. $params = request()->validate([
  51. 'page' => ['nullable', 'integer', 'min:1'],
  52. 'limit' => ['nullable', 'integer', 'min:1'],
  53. 'type' => ['required', 'integer', 'in:0,1,2'],
  54. 'order_no' => ['nullable', 'string'],
  55. 'status' => ['nullable', 'integer', 'in:0,1,2,3'],
  56. ]);
  57. $result = PaymentOrderService::paginate($params);
  58. } catch (ValidationException $e) {
  59. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  60. } catch (Exception $e) {
  61. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  62. }
  63. return $this->success($result);
  64. }
  65. /**
  66. * @description: 查询订单的支付情况
  67. * @return {*}
  68. */
  69. public function check()
  70. {
  71. $id = request()->input('id');
  72. if (empty($id)) {
  73. return $this->error(HttpStatus::CUSTOM_ERROR, '参数错误');
  74. }
  75. try {
  76. $result = PaymentOrderService::singlePayOrder($id);
  77. $this->success([], $result['msg'] ?? '操作成功');
  78. } catch (Exception $e) {
  79. return $this->error(intval($e->getCode()));
  80. }
  81. return $this->success([], $result['msg'] ?? '操作成功');
  82. }
  83. }