Withdraw.php 6.8 KB

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