Withdraw.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\BalanceLogService;
  6. use App\Services\TopUpService;
  7. use App\Services\WalletService;
  8. use App\Services\WithdrawService;
  9. use Illuminate\Support\Facades\DB;
  10. use Illuminate\Validation\ValidationException;
  11. use Exception;
  12. class Withdraw extends Controller
  13. {
  14. /**
  15. * @api {get} /admin/withdraw 提现列表
  16. * @apiGroup 提现管理
  17. *
  18. * @apiUse result
  19. * @apiUse header
  20. * @apiVersion 1.0.0
  21. *
  22. * @apiParam {int} [page=1]
  23. * @apiParam {int} [limit=10]
  24. * @apiParam {string} [member_id] tg会员ID
  25. * @apiParam {int} [status] 状态
  26. * - 0 申请中
  27. * - 1 通过
  28. * - 2 拒绝
  29. * @apiSuccess (data) {Object} data
  30. * @apiSuccess (data) {int} data.total 数量
  31. * @apiSuccess (data) {Object[]} data.data 列表
  32. * @apiSuccess (data) {int} data.data.id
  33. * @apiSuccess (data) {int} data.data.member_id tg会员id
  34. * @apiSuccess (data) {string} data.data.amount 提现金额
  35. * @apiSuccess (data) {string} data.data.service_charge 手续费
  36. * @apiSuccess (data) {string} data.data.to_account 到账金额
  37. * @apiSuccess (data) {string} data.data.after_balance 提现后余额
  38. * @apiSuccess (data) {string} data.data.address 钱包地址
  39. * @apiSuccess (data) {string} data.data.updated_at
  40. * @apiSuccess (data) {string} data.data.created_at
  41. * @apiSuccess (data) {int} data.data.status 状态
  42. * - 0 申请中
  43. * - 1 通过
  44. * - 2 拒绝
  45. * @apiSuccess (data) {string} data.data.remark
  46. *
  47. *
  48. */
  49. public function index()
  50. {
  51. try {
  52. request()->validate([
  53. 'member_id' => ['nullable', 'string', 'min:1'],
  54. 'status' => ['nullable', 'integer', 'min:0', 'max:2']
  55. ]);
  56. $search = request()->all();
  57. $result = WithdrawService::paginate($search);
  58. } catch (ValidationException $e) {
  59. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  60. } catch (Exception $e) {
  61. return $this->error(intval($e->getCode()));
  62. }
  63. return $this->success($result);
  64. }
  65. /**
  66. * @api {post} /admin/withdraw/setStatus 通过|拒绝
  67. * @apiGroup 提现管理
  68. *
  69. * @apiUse result
  70. * @apiUse header
  71. * @apiVersion 1.0.0
  72. *
  73. * @apiParam {string} id 提现表ID
  74. * @apiParam {int} status 状态
  75. * - 1 通过
  76. * - 2 拒绝
  77. */
  78. public function setStatus()
  79. {
  80. DB::beginTransaction();
  81. try {
  82. request()->validate([
  83. 'id' => ['required', 'string', 'min:1'],
  84. 'status' => ['required', 'integer', 'min:1', 'max:2']
  85. ]);
  86. $id = request()->input('id');
  87. $status = request()->input('status');
  88. $w = WithdrawService::findOne(['id' => $id, 'status' => 0]);
  89. if (!$w) throw new Exception("数据不存在", HttpStatus::CUSTOM_ERROR);
  90. if ($status == 1) {
  91. $w->status = 1;
  92. $w->save();
  93. } else if ($status == 2) {
  94. $w->status = 2;
  95. $w->save();
  96. $wallet = WalletService::findOne(['member_id' => $w->member_id]);
  97. $afterBalance = bcadd($wallet->available_balance, $w->amount, 10);
  98. BalanceLogService::addLog(
  99. $w->member_id,
  100. $w->amount,
  101. $wallet->available_balance,
  102. $afterBalance,
  103. '提现',
  104. $w->id,
  105. ''
  106. );
  107. $wallet->available_balance = $afterBalance;
  108. $wallet->save();
  109. }
  110. $arr = ['⏳️申请中', '✅️成功', '❌️失败'];
  111. $text = "📢 提现结果通知\n\n";
  112. $temp = floatval($w->service_charge);
  113. $text .= "手续费:{$temp} USDT\n";
  114. $temp = floatval($w->amount);
  115. $text .= "提现金额:{$temp} USDT\n";
  116. $temp = floatval($w->to_account);
  117. $text .= "到账金额:{$temp} USDT\n";
  118. $text .= "提现地址:{$w->address}\n\n";
  119. $text .= "状态:{$arr[$w->status]}\n";
  120. if ($w->remark) $text .= "说明:{$w->remark}";
  121. $res = WithdrawService::notify([
  122. 'chat_id' => $w->member_id,
  123. 'text' => $text,
  124. ]);
  125. DB::commit();
  126. } catch (ValidationException $e) {
  127. DB::rollBack();
  128. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  129. } catch (Exception $e) {
  130. DB::rollBack();
  131. return $this->error(intval($e->getCode()), $e->getMessage());
  132. }
  133. return $this->success($res);
  134. }
  135. }