| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- namespace App\Http\Controllers\admin;
- use App\Constants\HttpStatus;
- use App\Http\Controllers\Controller;
- use App\Services\BalanceLogService;
- use App\Services\PaymentOrderService;
- use App\Services\TopUpService;
- use App\Services\WalletService;
- use App\Services\WithdrawService;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Validation\ValidationException;
- use Exception;
- use App\Models\Withdraw as WithdrawModel;
- use App\Models\PaymentOrder;
- use App\Models\Config;
- class Withdraw extends Controller
- {
- function setRmbNote()
- {
- try {
- $params = request()->validate([
- 'id' => ['required', 'integer', 'min:1'],
- 'admin_note' => ['required', 'string', 'min:1', 'max:120'],
- ]);
- $po = PaymentOrder::where('id', $params['id'])
- ->where('type', 2)->first();
- if (!$po) throw new Exception("记录不存在", HttpStatus::CUSTOM_ERROR);
- $po->admin_note = $params['admin_note'];
- $po->save();
- } catch (ValidationException $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
- } catch (Exception $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
- }
- return $this->success();
- }
- public function rmb()
- {
- try {
- $params = request()->validate([
- 'page' => ['nullable', 'integer', 'min:1'],
- 'limit' => ['nullable', 'integer', 'min:1'],
- 'member_id' => ['nullable', 'string', 'min:1'],
- 'status' => ['nullable', 'integer', 'min:0', 'max:3']
- ]);
- $page = request()->input('page', 1);
- $limit = request()->input('limit', 10);
- $params['type'] = 2;
- $query = PaymentOrder::query();
- $where = PaymentOrderService::getWhere($params);
- $count = $query->where($where)->count();
- $list = $query->where($where)
- ->with(['userInfo'])
- ->orderBy('status')
- ->orderByDesc('created_at')
- ->forpage($page, $limit)->get();
- $result = [
- // 'total_fail' => $totalFail,
- // 'total_success' => $totalSuccess,
- // 'total_amount' => $totalAmount,
- 'total' => $count,
- 'data' => $list
- ];
- } catch (ValidationException $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
- } catch (Exception $e) {
- return $this->error($e->getCode(), $e->getmessage());
- }
- return $this->success($result);
- }
- public function setNote()
- {
- try {
- $params = request()->validate([
- 'id' => ['required', 'integer', 'min:1'],
- 'admin_note' => ['required', 'string', 'min:1', 'max:120'],
- ]);
- $w = WithdrawModel::where('id', $params['id'])->first();
- if (!$w) throw new Exception("记录不存在", HttpStatus::CUSTOM_ERROR);
- $w->admin_note = $params['admin_note'];
- $w->save();
- } catch (ValidationException $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
- } catch (Exception $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
- }
- return $this->success();
- }
- public function index()
- {
- try {
- $params = request()->validate([
- 'page' => ['nullable', 'integer', 'min:1'],
- 'limit' => ['nullable', 'integer', 'min:1'],
- 'member_id' => ['nullable', 'string', 'min:1'],
- 'status' => ['nullable', 'integer', 'min:0', 'max:2']
- ]);
- $page = request()->input('page', 1);
- $limit = request()->input('limit', 10);
- $query = WithdrawModel::query();
- $where = WithdrawService::getWhere($params);
- $count = $query->where($where)->count();
- $list = $query->where($where)
- ->with(['member'])
- ->orderBy('created_at', 'desc')
- ->forpage($page, $limit)->get();
- foreach ($list as &$item) {
- $item['exchange_rate'] = floatval($item['exchange_rate']);
- $item['after_balance'] = floatval($item['after_balance']);
- $item['service_charge'] = floatval($item['service_charge']);
- $item['amount'] = floatval($item['amount']);
- $item['to_account'] = floatval($item['to_account']);
- $item['exchange_rate'] = $item['exchange_rate'] <= 0 ? 7.3 : $item['exchange_rate'];
- $item['to_account_usdt'] = floatval($item['to_account']);
- }
- $result = ['total' => $count, 'data' => $list];
- } catch (ValidationException $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
- } catch (Exception $e) {
- return $this->error(intval($e->getCode()));
- }
- return $this->success($result);
- }
- /**
- * @api {post} /admin/withdraw/setStatus 通过|拒绝
- * @apiGroup 提现管理
- *
- * @apiUse result
- * @apiUse header
- * @apiVersion 1.0.0
- *
- * @apiParam {string} id 提现表ID
- * @apiParam {int} status 状态
- * - 1 通过
- * - 2 拒绝
- */
- public function setStatus()
- {
- DB::beginTransaction();
- try {
- $validate = [
- 'ids' => ['required', 'array', 'min:1', 'max:20'],
- 'ids.*' => ['required', 'integer', 'min:1'],
- 'status' => ['required', 'integer', 'in:1,2'],
- ];
- $status = request()->input('status');
- if ($status == 2) {
- $validate['remark'] = ['required', 'string', 'min:1', 'max:200'];
- }
- request()->validate($validate);
- $ids = request()->input('ids');
- $remark = request()->input('remark');
- foreach ($ids as $id) {
- WithdrawService::setStatus($id, $status, $remark);
- }
- DB::commit();
- } catch (ValidationException $e) {
- DB::rollBack();
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
- } catch (Exception $e) {
- DB::rollBack();
- return $this->error($e->getCode(), $e->getMessage());
- }
- return $this->success();
- }
- public function batch()
- {
- try {
-
- WithdrawService::batchReject();
-
- DB::commit();
- } catch (ValidationException $e) {
- DB::rollBack();
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
- } catch (Exception $e) {
- DB::rollBack();
- return $this->error($e->getCode(), $e->getMessage());
- }
- return $this->success();
- }
- }
|