better-staridc-MNBT
1<?php
2/**
3 * domain_shop 插件 - 域名购买下单
4 * 迁移自 user/pay.php 的 $pay_lx=='ymgm' 分支
5 *
6 * 接收 POST:urla(一级域名)/ urlb(前缀)/ urlzml(子目录)/ yzdip(源站IP)/ type(支付方式)
7 * 创建 MN_dd 订单后调 mnbt_pay_dispatch_gateway 分发到支付插件
8 */
9if (!defined('IN_CRONLITE')) exit;
10
11function domain_shop_handle_buy()
12{
13 global $DB, $yhc, $ssbt, $zjid, $date, $conf, $siteurl;
14
15 mnbt_plugin_require_user();
16
17 $ym_a = daddslashes($_POST['urla'] ?? ''); // 一级域名
18 $ym_b = daddslashes($_POST['urlb'] ?? ''); // 域名前缀
19 $type = daddslashes($_POST['type'] ?? ''); // 支付方式 type
20 $urlzml = $_POST['urlzml'] ?? '/';
21 $yzdip = $_POST['yzdip'] ?? '';
22
23 // 查商品(从 plg_domain_product 取代原 MN_ym)
24 $bs_cx = domain_product_get_by_url($ym_a);
25 if (!$bs_cx) {
26 exit("<script>alert('域名商品不存在!');history.go(-1);</script>");
27 }
28 if ($bs_cx['qk'] != 'true') {
29 exit("<script>alert('该域名已下架!');history.go(-1);</script>");
30 }
31 if (!preg_match('/^[0-9a-zA-Z]{1,24}$/', $ym_b)) {
32 exit("<script>alert('前缀不合法!');history.go(-1);</script>");
33 }
34
35 $money = $bs_cx['jg'];
36 $out_trade_no = date("YmdHis") . mt_rand(100, 999);
37 $name = 'MNBT域名购买';
38 $ip = $_SERVER["REMOTE_ADDR"] ?? '127.0.0.1';
39
40 // 取节点信息(与原 pay.php ymgm 分支一致)
41 $cert = $DB->get_row_prepare("SELECT * FROM MN_bt WHERE btdh=? limit 1", [$ssbt]);
42 if (!$cert) {
43 exit("<script>alert('宝塔节点不存在!');history.go(-1);</script>");
44 }
45 $btipe = ($cert['ptl'] == 'true' ? 'https' : 'http') . '://' . $cert['btip'] . ':' . $cert['btdk'];
46 $btkeye = $cert['btmy'];
47 include_once __DIR__ . "/../../user/class.php";
48 $apie = new bt_api_set($btipe, $btkeye);
49 $ymzce = $apie->GetLogsy($zjid) ?: [];
50 $azxcr = count($ymzce);
51
52 if ($cert['btos'] == '1') {
53 $l_ler_a = '/etc/hosts';
54 } else {
55 $l_ler_a = 'C:\Windows\System32\drivers\etc\hosts';
56 }
57 $urlpath = ($urlzml == '') ? '/' : $urlzml;
58
59 if ($azxcr >= $yhc['ymbds'] + 1 && $yhc['ymbds'] != '0' && $yhc['ymbds'] != '') {
60 exit("<script>alert('您域名绑定数已达最大!');history.go(-1);</script>");
61 }
62
63 // 构造订单参数(与原 pay.php 一致)
64 $cs = json_encode([
65 'user' => $yhc['user'],
66 'url_qz' => $ym_b,
67 'url_zd' => $ym_a,
68 'path' => $urlpath,
69 'url_zy' => $ym_b . '.' . $ym_a,
70 'type' => $yhc['hxc'],
71 'yz_ip' => $yzdip,
72 'hostly' => $l_ler_a,
73 ], 256);
74
75 $row1 = $DB->get_row_prepare("SELECT * FROM MN_dd WHERE 1 order by id desc limit 1");
76 $id = $row1['id'] + 1;
77 $DB->query_prepare(
78 "INSERT INTO `MN_dd` (`id`, `cs`, `date`, `zffs`, `je`, `ddh`, `lx`, `qk`, `ip`) VALUES (?,?,?,?,?,?,?,?,?)",
79 [$id, $cs, $date, $type, $money, $out_trade_no, 'ymgm', 'false', $ip]
80 );
81
82 // 分发到支付插件
83 $order_context = [
84 'out_trade_no' => $out_trade_no,
85 'name' => $name,
86 'money' => $money,
87 'type' => $type,
88 'siteurl' => $siteurl,
89 'pay_lx' => 'ymgm',
90 ];
91
92 $html = mnbt_pay_dispatch_gateway($type, $order_context);
93 if ($html === false) {
94 exit("<script>alert('支付方式不可用');history.go(-1);</script>");
95 }
96 echo $html;
97}