Withdraw.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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\PaymentOrderService;
  7. use App\Services\TopUpService;
  8. use App\Services\WalletService;
  9. use App\Services\WithdrawService;
  10. use Illuminate\Support\Facades\DB;
  11. use Illuminate\Validation\ValidationException;
  12. use Exception;
  13. use App\Models\Withdraw as WithdrawModel;
  14. use App\Models\PaymentOrder;
  15. use App\Models\Config;
  16. class Withdraw extends Controller
  17. {
  18. function setRmbNote()
  19. {
  20. try {
  21. $params = request()->validate([
  22. 'id' => ['required', 'integer', 'min:1'],
  23. 'admin_note' => ['required', 'string', 'min:1', 'max:120'],
  24. ]);
  25. $po = PaymentOrder::where('id', $params['id'])
  26. ->where('type', 2)->first();
  27. if (!$po) throw new Exception("记录不存在", HttpStatus::CUSTOM_ERROR);
  28. $po->admin_note = $params['admin_note'];
  29. $po->save();
  30. } catch (ValidationException $e) {
  31. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  32. } catch (Exception $e) {
  33. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  34. }
  35. return $this->success();
  36. }
  37. public function rmb()
  38. {
  39. try {
  40. $params = request()->validate([
  41. 'page' => ['nullable', 'integer', 'min:1'],
  42. 'limit' => ['nullable', 'integer', 'min:1'],
  43. 'member_id' => ['nullable', 'string', 'min:1'],
  44. 'status' => ['nullable', 'integer', 'min:0', 'max:3']
  45. ]);
  46. $page = request()->input('page', 1);
  47. $limit = request()->input('limit', 10);
  48. $params['type'] = 2;
  49. $query = PaymentOrder::query();
  50. $where = PaymentOrderService::getWhere($params);
  51. $count = $query->where($where)->count();
  52. $list = $query->where($where)
  53. ->with(['userInfo'])
  54. ->orderByRaw('CASE WHEN status = 0 THEN 0 ELSE 1 END')
  55. ->orderByDesc('created_at')
  56. ->forpage($page, $limit)->get();
  57. $result = ['total' => $count, 'data' => $list];
  58. } catch (ValidationException $e) {
  59. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  60. } catch (Exception $e) {
  61. return $this->error($e->getCode(), $e->getmessage());
  62. }
  63. return $this->success($result);
  64. }
  65. public function setNote()
  66. {
  67. try {
  68. $params = request()->validate([
  69. 'id' => ['required', 'integer', 'min:1'],
  70. 'admin_note' => ['required', 'string', 'min:1', 'max:120'],
  71. ]);
  72. $w = WithdrawModel::where('id', $params['id'])->first();
  73. if (!$w) throw new Exception("记录不存在", HttpStatus::CUSTOM_ERROR);
  74. $w->admin_note = $params['admin_note'];
  75. $w->save();
  76. } catch (ValidationException $e) {
  77. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  78. } catch (Exception $e) {
  79. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  80. }
  81. return $this->success();
  82. }
  83. public function index()
  84. {
  85. try {
  86. $params = request()->validate([
  87. 'page' => ['nullable', 'integer', 'min:1'],
  88. 'limit' => ['nullable', 'integer', 'min:1'],
  89. 'member_id' => ['nullable', 'string', 'min:1'],
  90. 'status' => ['nullable', 'integer', 'min:0', 'max:2']
  91. ]);
  92. $page = request()->input('page', 1);
  93. $limit = request()->input('limit', 10);
  94. $query = WithdrawModel::query();
  95. $where = WithdrawService::getWhere($params);
  96. $count = $query->where($where)->count();
  97. $list = $query->where($where)
  98. ->with(['member'])
  99. ->orderByRaw('CASE WHEN status = 0 THEN 0 ELSE 1 END')
  100. ->orderByDesc('created_at')
  101. ->forpage($page, $limit)->get();
  102. foreach ($list as &$item) {
  103. $item['exchange_rate'] = floatval($item['exchange_rate']);
  104. $item['after_balance'] = floatval($item['after_balance']);
  105. $item['service_charge'] = floatval($item['service_charge']);
  106. $item['amount'] = floatval($item['amount']);
  107. $item['to_account'] = floatval($item['to_account']);
  108. $item['exchange_rate'] = $item['exchange_rate'] <= 0 ? 7.3 : $item['exchange_rate'];
  109. $item['to_account_usdt'] = floatval($item['to_account']);
  110. }
  111. $result = ['total' => $count, 'data' => $list];
  112. } catch (ValidationException $e) {
  113. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  114. } catch (Exception $e) {
  115. return $this->error(intval($e->getCode()));
  116. }
  117. return $this->success($result);
  118. }
  119. /**
  120. * @api {post} /admin/withdraw/setStatus 通过|拒绝
  121. * @apiGroup 提现管理
  122. *
  123. * @apiUse result
  124. * @apiUse header
  125. * @apiVersion 1.0.0
  126. *
  127. * @apiParam {string} id 提现表ID
  128. * @apiParam {int} status 状态
  129. * - 1 通过
  130. * - 2 拒绝
  131. */
  132. public function setStatus()
  133. {
  134. DB::beginTransaction();
  135. try {
  136. $validate = [
  137. 'ids' => ['required', 'array', 'min:1', 'max:20'],
  138. 'ids.*' => ['required', 'integer', 'min:1'],
  139. 'status' => ['required', 'integer', 'in:1,2'],
  140. ];
  141. $status = request()->input('status');
  142. if ($status == 2) {
  143. $validate['remark'] = ['required', 'string', 'min:1', 'max:200'];
  144. }
  145. request()->validate($validate);
  146. $ids = request()->input('ids');
  147. $remark = request()->input('remark');
  148. foreach ($ids as $id) {
  149. WithdrawService::setStatus($id, $status, $remark);
  150. }
  151. DB::commit();
  152. } catch (ValidationException $e) {
  153. DB::rollBack();
  154. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  155. } catch (Exception $e) {
  156. DB::rollBack();
  157. return $this->error($e->getCode(), $e->getMessage());
  158. }
  159. return $this->success();
  160. }
  161. public function batch()
  162. {
  163. try {
  164. WithdrawService::batchReject();
  165. DB::commit();
  166. } catch (ValidationException $e) {
  167. DB::rollBack();
  168. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  169. } catch (Exception $e) {
  170. DB::rollBack();
  171. return $this->error($e->getCode(), $e->getMessage());
  172. }
  173. return $this->success();
  174. }
  175. }