Withdraw.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. ->orderBy('status')
  55. ->orderByDesc('created_at')
  56. ->forpage($page, $limit)->get();
  57. $result = [
  58. 'total' => $count,
  59. 'data' => $list
  60. ];
  61. } catch (ValidationException $e) {
  62. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  63. } catch (Exception $e) {
  64. return $this->error($e->getCode(), $e->getmessage());
  65. }
  66. return $this->success($result);
  67. }
  68. public function setNote()
  69. {
  70. try {
  71. $params = request()->validate([
  72. 'id' => ['required', 'integer', 'min:1'],
  73. 'admin_note' => ['required', 'string', 'min:1', 'max:120'],
  74. ]);
  75. $w = WithdrawModel::where('id', $params['id'])->first();
  76. if (!$w) throw new Exception("记录不存在", HttpStatus::CUSTOM_ERROR);
  77. $w->admin_note = $params['admin_note'];
  78. $w->save();
  79. } catch (ValidationException $e) {
  80. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  81. } catch (Exception $e) {
  82. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  83. }
  84. return $this->success();
  85. }
  86. public function index()
  87. {
  88. try {
  89. $params = request()->validate([
  90. 'page' => ['nullable', 'integer', 'min:1'],
  91. 'limit' => ['nullable', 'integer', 'min:1'],
  92. 'member_id' => ['nullable', 'string', 'min:1'],
  93. 'status' => ['nullable', 'integer', 'min:0', 'max:2']
  94. ]);
  95. $page = request()->input('page', 1);
  96. $limit = request()->input('limit', 10);
  97. $query = WithdrawModel::query();
  98. $where = WithdrawService::getWhere($params);
  99. $count = $query->where($where)->count();
  100. $list = $query->where($where)
  101. ->with(['member'])
  102. ->orderByRaw('CASE WHEN status = 0 THEN 0 ELSE 1 END')
  103. ->orderByDesc('created_at')
  104. ->forpage($page, $limit)->get();
  105. foreach ($list as &$item) {
  106. $item['exchange_rate'] = floatval($item['exchange_rate']);
  107. $item['after_balance'] = floatval($item['after_balance']);
  108. $item['service_charge'] = floatval($item['service_charge']);
  109. $item['amount'] = floatval($item['amount']);
  110. $item['to_account'] = floatval($item['to_account']);
  111. $item['exchange_rate'] = $item['exchange_rate'] <= 0 ? 7.3 : $item['exchange_rate'];
  112. $item['to_account_usdt'] = floatval($item['to_account']);
  113. }
  114. $result = ['total' => $count, 'data' => $list];
  115. } catch (ValidationException $e) {
  116. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  117. } catch (Exception $e) {
  118. return $this->error(intval($e->getCode()));
  119. }
  120. return $this->success($result);
  121. }
  122. /**
  123. * @api {post} /admin/withdraw/setStatus 通过|拒绝
  124. * @apiGroup 提现管理
  125. *
  126. * @apiUse result
  127. * @apiUse header
  128. * @apiVersion 1.0.0
  129. *
  130. * @apiParam {string} id 提现表ID
  131. * @apiParam {int} status 状态
  132. * - 1 通过
  133. * - 2 拒绝
  134. */
  135. public function setStatus()
  136. {
  137. DB::beginTransaction();
  138. try {
  139. $validate = [
  140. 'ids' => ['required', 'array', 'min:1', 'max:20'],
  141. 'ids.*' => ['required', 'integer', 'min:1'],
  142. 'status' => ['required', 'integer', 'in:1,2'],
  143. ];
  144. $status = request()->input('status');
  145. if ($status == 2) {
  146. $validate['remark'] = ['required', 'string', 'min:1', 'max:200'];
  147. }
  148. request()->validate($validate);
  149. $ids = request()->input('ids');
  150. $remark = request()->input('remark');
  151. foreach ($ids as $id) {
  152. WithdrawService::setStatus($id, $status, $remark);
  153. }
  154. DB::commit();
  155. } catch (ValidationException $e) {
  156. DB::rollBack();
  157. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  158. } catch (Exception $e) {
  159. DB::rollBack();
  160. return $this->error($e->getCode(), $e->getMessage());
  161. }
  162. return $this->success();
  163. }
  164. public function batch()
  165. {
  166. try {
  167. WithdrawService::batchReject();
  168. DB::commit();
  169. } catch (ValidationException $e) {
  170. DB::rollBack();
  171. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  172. } catch (Exception $e) {
  173. DB::rollBack();
  174. return $this->error($e->getCode(), $e->getMessage());
  175. }
  176. return $this->success();
  177. }
  178. }