scene('index')->check($param); $where = []; $userId = 0; // 用户号精确搜索 if (!empty($param['user_no'])) { $user = UserModel::where('user_no', $param['user_no'])->find(); if (empty($user)) { return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], ]); } $userId = $user['user_id']; } $statusList = RechargeApplyModel::$statusList; // 判断是否是代理 如果是代理 只能看他自己管理的用户 $whereU = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId); if (!is_array($whereU)) { return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extend' => $statusList]); } // 订单号 if (!empty($param['order_id'])) { $where['order_no'] = $param['order_id']; } if (isset($param['is_online'])) { $where['is_online'] = $param['is_online']; if ($param['is_online'] == 1) $statusList[0] = '用户取消'; } if (isset($param['status'])) { $where['status'] = $param['status']; } if (!empty($param['start_time']) && !empty($param['end_time'])) { $where['update_time'] = ['between time', [$param['start_time'], $param['end_time']]]; } // 列表 $list = RechargeApplyModel::where($where)->where($whereU)->order('id', 'desc')->page($param['page'], $param['limit'])->select(); // 总数 $total = RechargeApplyModel::where($where)->where($whereU)->count(); // 统计 充值成功 $sum = RechargeApplyModel::where($where)->where($whereU)->where('status', 1)->sum('recharge_num'); $rows = []; if (!$list->isEmpty()) { // 获取用户号 $userIdArr = []; foreach ($list as $idItem) { $userIdArr[] = $idItem['user_id']; } $userNoArr = UserModel::where('user_id', 'in', $userIdArr)->column('user_no', 'user_id'); $rows = $list->toArray(); foreach ($rows as $key => $item) { $rows[$key]['status_text'] = $statusList[$item['status']]; $rows[$key]['user_no'] = $userNoArr[$item['user_id']] ?? '-'; // 用户号 $rows[$key]['order_id'] = $item['order_no']; $rows[$key]['recharge_channel'] = PaymentListModel::where('id', $item['recharge_channel'])->value('channel'); } } return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows, 'sum' => $sum . 'USD', 'extend' => $statusList]); } catch (\Exception $exception) { return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } public function info($param, $adminId) { try { // 参数校验 validate(RechargeValidate::class)->scene('info')->check($param); $where = [ 'id' => $param['id'] ]; $userId = 0; $where = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId); if (!is_array($where)) { return $this->toData('0', 'SUCCESS', []); } $info = RechargeApplyModel::getOrderInfo($where); if ($info['file_id']) { $info['file_url'] = FileModel::getFilePath($info['file_id']); } $payment_info = PaymentListModel::getPaymentInfo([ 'id' => $info['recharge_channel'] ]); if ($payment_info) { $info['recharge_channel'] = !isset($payment_info['channel']) ? $payment_info['channel'] : $info['recharge_channel']; $info['bank_name'] = !isset($payment_info['bank_name']) ? $payment_info['bank_name'] : ''; $info['bank_branch'] = !isset($payment_info['bank_branch']) ? $payment_info['bank_branch'] : ''; $info['bank_user'] = !isset($payment_info['bank_user']) ? $payment_info['bank_user'] : ''; $info['bank_account'] = !isset($payment_info['bank_account']) ? $payment_info['bank_account'] : ''; $info['wallet_address'] = !isset($payment_info['wallet_address']) ? $payment_info['wallet_address'] : ''; } return $this->toData('0', 'SUCCESS', $info); } catch (\Exception $exception) { return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } public function check($param, $adminId) { try { // 参数校验 validate(RechargeValidate::class)->scene('info')->check($param); $isAgent = AdminModel::checkUserIsAgent($adminId); if ($isAgent) { return $this->toData('10040', '代理无权限操作'); } $where = [ 'id' => $param['id'] ]; $userId = 0; $where = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId); if (!is_array($where)) { return $this->toData('0', 'SUCCESS', []); } $info = RechargeApplyModel::getOrderInfo($where); if ($info) { if ($info['is_online'] == 1){ return $this->toData('10040', '在线充值 不可操作'); } if ($info['is_check'] == 0) { if ($param['check_status'] == 1) { $result = $this->updateUserAsset($info['user_id'], $info['account_type'], 1, $info['market_amount'], 0, $info['order_no']); if ($result['status'] == 200) { RechargeApplyModel::where('id', $info['id'])->update([ 'is_check' => 1, 'status' => 1, 'deal_time' => date('Y-m-d H:i:s') ]); } else { return $this->toData('1015', '系统异常 请稍后重试'); } } else { RechargeApplyModel::where('id', $info['id'])->update([ 'is_check' => 2, 'status' => 2 ]); } } if ($info['file_id']) { $info['file_url'] = FileModel::getFilePath($info['file_id']); $file = dirname(dirname(dirname(__DIR__))) . "/public" . $info['file_url']; @unlink($file); } return $this->toData('0', 'SUCCESS', []); } else { return $this->toData('1', '参数错误', []); } } catch (\Exception $exception) { return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } // 支付码配置列表 & 会员支付码配置列表 (用户提交的充值订单,等待后台为其配置支付码) public function paymentCodeLogList($param, $adminId) { try { if (empty($param['page']) || !is_numeric($param['page'])) { return $this->toData('400', '参错错误'); } if (empty($param['limit']) || !is_numeric($param['limit'])) { return $this->toData('400', '参错错误'); } // payment_code_config_id = 0 表示该订单还没有为其配置支付码, 这个接口只查询待配置支付码的记录 $where = [['payment_code_config_id', '=', 0]]; // 根据用户ID过滤 if (isset($param['user_id'])) { $where[] = ['user_id', '=', $param['user_id']]; } // 根据支付渠道名称过滤 if (isset($param['channel_name'])) { $paymentCodeConfig = PaymentCodeConfigModel::where(['channel_name'=>$param['channel_name']])->find(); // bot_payment_code_config 表找对应的主键ID if (empty($paymentCodeConfig)){ return $this->toData('400', '查询的渠道名称不存在'); } $where[] = ['payment_code_config_id', '=', $paymentCodeConfig->id]; } $list = PaymentCodeLogModel::where($where)->order('id', 'desc')->paginate([ 'list_rows' => $param['limit'], 'page' => $param['page'], ]); if (!empty($list->items())) { $uidList = []; foreach ($list->items() as $key => $value) { $uidList[] = $value['user_id']; } // 查询用户信息 $userList = UserModel::where('user_id', 'in', $uidList)->select()->toArray(); // 填充用户信息字段 foreach ($list->items() as &$item) { foreach ($userList as $user) { if ($item['user_id'] == $user['user_id']) { $item['user_no'] = $user['user_no']; $item['nick_name'] = $user['nick_name']; $item['agent_id'] = $user['agent_id']; $item['customer_id'] = $user['customer_id']; $item['customer_remark'] = $user['customer_remark']; } } } unset($item); } return $this->toData('0', 'SUCCESS', [ 'list' => $list->items(), // 当前页的数据 'page' => $list->currentPage(), // 当前页码 'total' => $list->total(), // 总记录数 'last_page' => $list->lastPage(), // 最后一页页码 ]); } catch (\Exception $exception) { return $this->toData('500', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } // 给用户的充值订单配置支付码 public function paymentCodeLogUpdate($param, $adminId) { try { if (empty($param['id']) || empty($param['payment_code_config_id'])) { return $this->toData('400', '参错错误'); } // 检查支付码配置信息 $paymentCodeConfig = PaymentCodeConfigModel::where(['id'=>$param['payment_code_config_id']])->find(); if (empty($paymentCodeConfig)) { return $this->toData('400', '支付渠道配数据为空'); } // 更新该比订单的支付码配置字段 $info = PaymentCodeLogModel::where(['id'=>$param['id']])->find(); if (empty($info)) { return $this->toData('400', '数据不存在'); } $info->payment_code_config_id = $param['payment_code_config_id']; $info->is_vip_config = $paymentCodeConfig->is_vip == 1 ? 1 : 0; // 是否为vip配置渠道 $info->save(); return $this->toData('0', 'SUCCESS', []); } catch (\Exception $exception) { return $this->toData('500', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } // 获取支付码配置列表下拉框 public function paymentCodeConfigSelect() { try { $list = PaymentCodeConfigModel::where(['status' => 1])->field('id,channel_name')->select()->toArray(); return $this->toData('0', 'SUCCESS', [ 'list' => $list ]); } catch (\Exception $exception) { return $this->toData('500', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } // 支付码管理 (包含普通股支付码 & vip支付码) public function paymentCodeConfigList($param, $adminId) { try { if (empty($param['page']) || !is_numeric($param['page'])) { return $this->toData('400', '参错错误'); } if (empty($param['limit']) || !is_numeric($param['limit'])) { return $this->toData('400', '参错错误'); } $where = []; if (isset($param['channel_name'])) { $where['channel_name'] = $param['channel_name']; } // 查询vip支付码配置列表 if (!empty($param['is_vip'])) { $where['is_vip'] = $param['is_vip']; } $list = PaymentCodeConfigModel::where($where)->order('id', 'desc')->paginate([ 'list_rows' => $param['limit'], 'page' => $param['page'], ]); return $this->toData('0', 'SUCCESS', [ 'list' => $list->items(), // 当前页的数据 'page' => $list->currentPage(), // 当前页码 'total' => $list->total(), // 总记录数 'last_page' => $list->lastPage(), // 最后一页页码 ]); } catch (\Exception $exception) { return $this->toData('500', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } // 新增支付码配置 public function paymentCodeConfigAdd($param, $adminId) { try { if (empty($param['channel_name']) || empty($param['qr_code']) || empty($param['total_amount']) || !isset($param['is_vip'])) { return $this->toData('400', '缺少参数'); } PaymentCodeConfigModel::create([ 'channel_name' => $param['channel_name'], 'qr_code' => $param['qr_code'], 'total_amount' => $param['total_amount'], 'is_vip' => $param['is_vip'], ]); return $this->toData('0', 'SUCCESS', []); } catch (\Exception $exception) { return $this->toData('500', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } // 支付码管理 - 编辑 public function paymentCodeConfigUpdate($param, $adminId) { try { if (empty($param['id']) || !isset($param['status'])) { return $this->toData('400', '参错错误'); } if (!in_array($param['status'], [0,1])) { return $this->toData('400', 'status参数不在允许范围内'); } $info = PaymentCodeConfigModel::where(['id'=>$param['id']])->find(); if (empty($info)) { return $this->toData('400', '编辑的数据不存在'); } $info->status = $param['status']; $info->save(); return $this->toData('0', 'SUCCESS', []); } catch (\Exception $exception) { return $this->toData('500', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } // 支付码流水查询 public function userPaymentCodeLogList($param) { try { if (empty($param['page']) || !is_numeric($param['page'])) { return $this->toData('400', '参错错误'); } if (empty($param['limit']) || !is_numeric($param['limit'])) { return $this->toData('400', '参错错误'); } $where = []; // 根据用户ID过滤 if (isset($param['user_id'])) { $where[] = ['user_id', '=', $param['user_id']]; } // 根据支付渠道名称过滤 if (isset($param['channel_name'])) { $paymentCodeConfig = PaymentCodeConfigModel::where(['channel_name'=>$param['channel_name']])->find(); // bot_payment_code_config 表找对应的主键ID if (empty($paymentCodeConfig)){ return $this->toData('400', '查询的渠道名称不存在'); } $where[] = ['payment_code_config_id', '=', $paymentCodeConfig->id]; } // 过滤VIP支付码的流水记录 if (isset($param['is_vip'])) { $where[] = ['is_vip_config', '=', 1]; } $list = PaymentCodeLogModel::where($where)->order('id', 'desc')->paginate([ 'list_rows' => $param['limit'], 'page' => $param['page'], ]); return $this->toData('0', 'SUCCESS', [ 'list' => $list->items(), // 当前页的数据 'page' => $list->currentPage(), // 当前页码 'total' => $list->total(), // 总记录数 'last_page' => $list->lastPage(), // 最后一页页码 ]); } catch (\Exception $exception) { return $this->toData('500', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]); } } }