PaymentOrder.php 3.6 KB

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