PaymentOrder.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. DB::beginTransaction();
  14. try {
  15. $validate = [
  16. // 'id' => ['required', 'integer', 'min:1'],
  17. 'ids' => ['required', 'array', 'min:1','max:20'],
  18. 'ids.*' => ['required', 'integer', 'min:1'],
  19. 'status' => ['required', 'integer', 'in:1,3'],
  20. ];
  21. $status = request()->input('status', null);
  22. if ($status != 1) {
  23. $validate['remark'] = ['required', 'string', 'min:1', 'max:120'];
  24. }
  25. $params = request()->validate($validate);
  26. $remark = request()->input('remark', '');
  27. $count = 0;
  28. if ($params['status'] == 1) {
  29. $ret = PaymentOrderService::createPayout($params['id']);
  30. if ($ret['code'] === 0)$count++;
  31. if ($ret['code'] !== 0) throw new Exception($ret['msg'], HttpStatus::CUSTOM_ERROR);
  32. } else {
  33. $ret = PaymentOrderService::withdrawalFailed($params['id'], $remark);
  34. if ($ret['code'] === 0)$count++;
  35. if ($ret['code'] !== 0) throw new Exception($ret['msg'], HttpStatus::CUSTOM_ERROR);
  36. }
  37. if ($count < 1) {
  38. throw new Exception('操作失败', HttpStatus::CUSTOM_ERROR);
  39. }
  40. DB::commit();
  41. } catch (ValidationException $e) {
  42. DB::rollBack();
  43. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  44. } catch (Exception $e) {
  45. DB::rollBack();
  46. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  47. }
  48. return $this->success();
  49. }
  50. /**
  51. * @apiParam {int} [page]
  52. * @apiParam {int} [limit]
  53. * @apiParam {int=0,1,2} type 类型 0全部 1=代收,2=代付
  54. * @apiParam {String} order_no 订单号
  55. * @apiPaaram {String} member_id 会员ID
  56. * @apiParam {int=0,1,2,3} [status] 状态:0待处理 1处理中 2成功 3失败
  57. *
  58. */
  59. public function index()
  60. {
  61. try {
  62. $params = request()->validate([
  63. 'page' => ['nullable', 'integer', 'min:1'],
  64. 'limit' => ['nullable', 'integer', 'min:1'],
  65. 'type' => ['required', 'integer', 'in:0,1,2'],
  66. 'order_no' => ['nullable', 'string'],
  67. 'status' => ['nullable', 'integer', 'in:0,1,2,3'],
  68. ]);
  69. $result = PaymentOrderService::paginate($params);
  70. } catch (ValidationException $e) {
  71. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  72. } catch (Exception $e) {
  73. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  74. }
  75. return $this->success($result);
  76. }
  77. /**
  78. * @description: 查询订单的支付情况
  79. * @return {*}
  80. */
  81. public function check()
  82. {
  83. $id = request()->input('id');
  84. if (empty($id)) {
  85. return $this->error(HttpStatus::CUSTOM_ERROR, '参数错误');
  86. }
  87. try {
  88. $result = PaymentOrderService::singlePayOrder($id);
  89. $this->success([], $result['msg'] ?? '操作成功');
  90. } catch (Exception $e) {
  91. return $this->error(intval($e->getCode()));
  92. }
  93. return $this->success([], $result['msg'] ?? '操作成功');
  94. }
  95. }