PaymentOrder.php 3.7 KB

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