From b900ae7704105ebe2bbf3e9945c58caa8fa7e073 Mon Sep 17 00:00:00 2001 From: chuan <2154243450@qq.com> Date: Tue, 10 Jun 2025 13:04:53 +0800 Subject: [PATCH] payment config --- app/admin/controller/Recharge.php | 57 +++++++ app/admin/route/app.php | 11 ++ app/admin/service/RechargeService.php | 219 ++++++++++++++++++++++++++ app/home/controller/Pay.php | 16 ++ app/home/route/app.php | 2 + app/home/service/PayService.php | 54 ++++++- app/model/PaymentCodeConfigModel.php | 6 + app/model/PaymentCodeLogModel.php | 6 + app/model/RechargeApplyModel.php | 3 +- 9 files changed, 372 insertions(+), 2 deletions(-) create mode 100644 app/model/PaymentCodeConfigModel.php create mode 100644 app/model/PaymentCodeLogModel.php diff --git a/app/admin/controller/Recharge.php b/app/admin/controller/Recharge.php index 9f730cca..83021b4f 100644 --- a/app/admin/controller/Recharge.php +++ b/app/admin/controller/Recharge.php @@ -26,4 +26,61 @@ class Recharge extends AdminBaseController $result = $service->check($this->request->param(),$this->getAdminId()); return json($result); } + + // 支付码配置列表 & 会员支付码配置列表 (用户提交的充值订单,等待后台为其配置支付码) + public function paymentCodeLogList() + { + $service = new RechargeService(); + $result = $service->paymentCodeLogList($this->request->param(),$this->getAdminId()); + return json($result); + } + + // 给充值订单配置支付码 + public function paymentCodeLogUpdate() + { + $service = new RechargeService(); + $result = $service->paymentCodeLogUpdate($this->request->param(),$this->getAdminId()); + return json($result); + } + + // 获取支付码配置列表下拉框 + public function paymentCodeConfigSelect() + { + $service = new RechargeService(); + $result = $service->paymentCodeConfigSelect($this->request->param(),$this->getAdminId()); + return json($result); + } + + // 支付码配置列表 + public function paymentCodeConfigList() + { + $service = new RechargeService(); + $result = $service->paymentCodeConfigList($this->request->param(),$this->getAdminId()); + return json($result); + } + + // 支付码管理 - 新增 + public function paymentCodeConfigAdd() + { + $service = new RechargeService(); + $result = $service->paymentCodeConfigAdd($this->request->param(),$this->getAdminId()); + return json($result); + } + + // 支付码管理 -编辑 + public function paymentCodeConfigUpdate() + { + $service = new RechargeService(); + $result = $service->paymentCodeConfigUpdate($this->request->param(),$this->getAdminId()); + return json($result); + } + + // 支付码流水查询 + public function userPaymentCodeLogList() + { + $service = new RechargeService(); + $result = $service->userPaymentCodeLogList($this->request->param(),$this->getAdminId()); + return json($result); + } + } \ No newline at end of file diff --git a/app/admin/route/app.php b/app/admin/route/app.php index ade87357..75d3481b 100644 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -581,6 +581,17 @@ Route::group('/', function () { Route::post('/recharge/info', 'Recharge/info'); Route::post('/recharge/check', 'Recharge/check')->middleware('admin_log'); + // 支付码配置相关 + Route::post('/recharge/payment_code_log_list', 'Recharge/paymentCodeLogList'); // 支付码配置列表 & 会员支付码配置列表 (用户提交的充值订单,等待后台为其配置支付码) + Route::post('/recharge/payment_code_log_update', 'Recharge/paymentCodeLogUpdate'); // 给用户的充值订单配置支付码 + Route::post('/recharge/payment_code_config_select', 'Recharge/paymentCodeConfigSelect'); // 获取支付码配置列表下拉框 + + Route::post('/recharge/payment_code_config_list', 'Recharge/paymentCodeConfigList'); // 支付码管理 + Route::post('/recharge/payment_code_config_add', 'Recharge/paymentCodeConfigAdd'); // 支付码管理 - 新增 + Route::post('/recharge/payment_code_config_update', 'Recharge/paymentCodeConfigUpdate'); // 支付码管理 - 编辑 + + Route::post('/recharge/user_payment_code_log_list', 'Recharge/userPaymentCodeLogList'); // 支付码流水查询,包含普通支付码流水 & vip支付码流水 + Route::post('/withdraw/index', 'Withdraw/index'); Route::post('/withdraw/info', 'Withdraw/info'); Route::post('/withdraw/change_status', 'Withdraw/change_status')->middleware('admin_log'); diff --git a/app/admin/service/RechargeService.php b/app/admin/service/RechargeService.php index ba5b0b6c..56b7523f 100644 --- a/app/admin/service/RechargeService.php +++ b/app/admin/service/RechargeService.php @@ -5,6 +5,8 @@ namespace app\admin\service; use app\admin\validate\RechargeValidate; use app\model\AdminModel; use app\model\FileModel; +use app\model\PaymentCodeConfigModel; +use app\model\PaymentCodeLogModel; use app\model\PaymentListModel; use app\model\RechargeApplyModel; use app\model\UserModel; @@ -173,4 +175,221 @@ class RechargeService extends AdminBaseService } } + + // 支付码配置列表 & 会员支付码配置列表 (用户提交的充值订单,等待后台为其配置支付码) + 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()]); + } + } + } \ No newline at end of file diff --git a/app/home/controller/Pay.php b/app/home/controller/Pay.php index da055e53..1d432de8 100644 --- a/app/home/controller/Pay.php +++ b/app/home/controller/Pay.php @@ -48,9 +48,25 @@ class Pay extends HomeBaseController $data['file_id'] = $request->post('file_id', 0); $data['product'] = $request->post('product', ''); $data['extra'] = $request->post('extra', ''); + $data['amount_range'] = $request->post('amount_range', ""); // 支付的金额范围 $result = (new PayService())->insertRechargeApply($data); return json($result); } + + // 获取支付码配置列表 + public function getPaymentCodeList() + { + $result = (new PayService())->getPaymentCodeList(); + return json($result); + } + + // 获取用户的支付码配置下单记录 + public function getUserPaymentCodeLog() + { + $result = (new PayService())->getUserPaymentCodeLog($this->request->userId, $this->request->post()); + return json($result); + } + public function getTRC20BuyList(Request $request): Json { $result=(new StarPayService())->getTRC20BuyList(); diff --git a/app/home/route/app.php b/app/home/route/app.php index 154b2df5..d8c1d9f7 100644 --- a/app/home/route/app.php +++ b/app/home/route/app.php @@ -210,6 +210,8 @@ Route::group('/',function (){ Route::post('payment_list', 'Pay/payChannel'); //获取充值渠道 Route::post('user_recharge', 'Pay/rechargeApply')->middleware(\app\home\middleware\RepeatOperateMiddleware::class); // 用户提交充值订单 + Route::get('get_payment_code_list', 'Pay/getPaymentCodeList'); // 获取支付码配置列表 + Route::post('get_user_payment_code_log', 'Pay/getUserPaymentCodeLog'); // 获取用户在支付码配置方式下充值订单记录 Route::post('user_assets', 'Wallet/getAllAssets'); // 获取用户所有资产列表数据 Route::post('user_balance', 'Wallet/getUserBalance'); // 获取用户所有资产列表数据 diff --git a/app/home/service/PayService.php b/app/home/service/PayService.php index b0ee6780..1695e7fc 100644 --- a/app/home/service/PayService.php +++ b/app/home/service/PayService.php @@ -2,6 +2,8 @@ namespace app\home\service; +use app\model\PaymentCodeConfigModel; +use app\model\PaymentCodeLogModel; use app\model\PaymentListModel; use app\model\RechargeApplyModel; use app\model\StockMarketModel; @@ -101,6 +103,10 @@ class PayService extends BaseHomeService $data['currency_rate'] = $currency_rate; if ($channel['channel_type'] == 'Bank') { $data['recharge_type'] = 2; + // p2新增,如果是银行卡充值需要添加支付码配置的充值记录 + if (empty($data['amount_range'])) { + return $this->toData('500', '缺少充值金额范围参数'); + } } else { $data['recharge_type'] = 1; } @@ -109,6 +115,16 @@ class PayService extends BaseHomeService $order_id = RechargeApplyModel::InsertUserRecharge($data); if ($order_id) { + // p2新增功能,如果是银行卡充值,添加支付码充值记录 + if ($channel['channel_type'] == 'Bank') { + Db::table("bot_payment_code_log")->insert([ + 'recharge_apply_id' => $order_id, + 'user_id' => $data['user_id'], + 'amount_range' => $data['amount_range'], + 'recharge_amount' => $data['recharge_num'], + 'payment_status' => 0, + ]); + } switch ($channel['type']) { case 2: $result = (new IndPayService())->indPay($data['order_no'], $data['total_amount']); @@ -243,12 +259,48 @@ class PayService extends BaseHomeService return $this->toData(0, 'Request successful.', []); break; } - } else { return $this->toData(500, lang('system_busy')); } } + // 获取支付码配置列表 + public function getPaymentCodeList() + { + try { + $list = PaymentCodeConfigModel::where(['status'=>1])->select()->toarray(); + return $this->toData(0, 'success', $list); + } catch (\Exception $e) { + return $this->toData(500, lang('system_busy'), [$e->getMessage(), $e->getTrace()]); + } + } + + // 获取用户的支付码配置下单记录 + public function getUserPaymentCodeLog($userID, $param) + { + try { + if (!isset($param['page']) || !isset($param['limit'])) { + return $this->toData('400', '参错错误'); + } + $where = [['user_id','=',$userID]]; + if (isset($param['payment_status'])) { + $where[] = ['payment_status','=',$param['payment_status']]; + } + $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 $e) { + return $this->toData(500, lang('system_busy'), [$e->getMessage(), $e->getTrace()]); + } + } + public function dealPayNotify($order_info) { $wallet = new WalletService(); diff --git a/app/model/PaymentCodeConfigModel.php b/app/model/PaymentCodeConfigModel.php new file mode 100644 index 00000000..9354bbab --- /dev/null +++ b/app/model/PaymentCodeConfigModel.php @@ -0,0 +1,6 @@ +create_time = date('Y-m-d H:i:s'); $self->update_time = date('Y-m-d H:i:s'); - return $self->save(); + $self->save(); + return $self->id; } public static function getOrderByNo(array $where) {