feat: 完善协议管理、师傅资质认证、分账配置并完成测试环境全量部署与同步

这个提交包含在:
2026-11-12 17:19:49 +08:00
父节点 fafddceaf2
当前提交 72cea8445f
共有 179 个文件被更改,包括 29242 次插入 和 3340 次删除

46
scripts/deploy_db.py 普通文件
查看文件

@@ -0,0 +1,46 @@
import paramiko
import os
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('8.137.181.63', port=22, username='root', password='liyanxia@6688', timeout=15)
def run(cmd):
stdin, stdout, stderr = ssh.exec_command(cmd)
out = stdout.read().decode('utf-8', errors='ignore')
err = stderr.read().decode('utf-8', errors='ignore')
return out, err
print('Step 1: Backup current remote yjyf database...')
out, err = run('mysqldump -uyjyf -pyjyf --default-character-set=utf8mb4 yjyf > /tmp/yjyf_remote_backup_before_deploy.sql')
out2, _ = run('ls -lh /tmp/yjyf_remote_backup_before_deploy.sql')
print('Backup done:', out2.strip())
print('Step 2: Upload local_yjyf_deploy.sql to remote /tmp...')
sftp = ssh.open_sftp()
local_file = r'd:\Projects\phpstudy_pro\WWW\yjyf\db\local_yjyf_deploy.sql'
remote_file = '/tmp/local_yjyf_deploy.sql'
sftp.put(local_file, remote_file)
sftp.close()
out3, _ = run('ls -lh /tmp/local_yjyf_deploy.sql')
print('Uploaded:', out3.strip())
print('Step 3: Import into remote yjyf database...')
out4, err4 = run('mysql -uyjyf -pyjyf --default-character-set=utf8mb4 yjyf < /tmp/local_yjyf_deploy.sql')
if err4 and 'Warning' not in err4:
print('Import error:', err4)
else:
print('Import command finished.')
print('Step 4: Verify tables count and key tables...')
out5, _ = run("mysql -uyjyf -pyjyf yjyf -e 'SHOW TABLES;'")
tables = [l.strip() for l in out5.strip().splitlines() if l.strip()]
print('Remote table count now:', max(0, len(tables) - 1))
out6, _ = run("mysql -uyjyf -pyjyf yjyf -e 'SELECT \"fa_user\", COUNT(*) FROM fa_user UNION ALL SELECT \"fa_master\", COUNT(*) FROM fa_master UNION ALL SELECT \"fa_order\", COUNT(*) FROM fa_order UNION ALL SELECT \"fa_service\", COUNT(*) FROM fa_service UNION ALL SELECT \"fa_agreement\", COUNT(*) FROM fa_agreement;'")
print('Key tables counts:\n' + out6)
# 删除远程临时 sql 文件保障安全
run('rm -f /tmp/local_yjyf_deploy.sql')
ssh.close()

122
scripts/deploy_server.py 普通文件
查看文件

@@ -0,0 +1,122 @@
import os
import tarfile
import paramiko
import time
server_dir = r'D:\Projects\phpstudy_pro\WWW\yjyf\server'
tar_path = r'D:\Projects\phpstudy_pro\WWW\yjyf\server_deploy.tar.gz'
print('Step 1: Packaging local server files...')
exclude_prefixes = [
os.path.join(server_dir, 'runtime'),
os.path.join(server_dir, '.git'),
os.path.join(server_dir, '.idea'),
os.path.join(server_dir, '.vscode')
]
exclude_files = [
'.env',
'composer.phar'
]
with tarfile.open(tar_path, 'w:gz') as tar:
for root, dirs, files in os.walk(server_dir):
# 排除指定目录
if any(root.startswith(p) for p in exclude_prefixes):
continue
for file in files:
if file in exclude_files or file.endswith('.log') or file.endswith('.tmp'):
continue
full_path = os.path.join(root, file)
rel_path = os.path.relpath(full_path, server_dir)
tar.add(full_path, arcname=rel_path)
print(f'Package created: {tar_path}, size: {os.path.getsize(tar_path)/1024/1024:.2f} MB')
print('Step 2: Connecting to remote server...')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('8.137.181.63', port=22, username='root', password='liyanxia@6688', timeout=20)
def run(cmd):
stdin, stdout, stderr = ssh.exec_command(cmd)
out = stdout.read().decode('utf-8', errors='ignore')
err = stderr.read().decode('utf-8', errors='ignore')
return out, err
print('Step 3: Backup current remote yjyf site...')
run('mkdir -p /www/backup')
out_b, err_b = run('tar -zcf /www/backup/yjyf_site_backup_before_deploy.tar.gz -C /www/wwwroot yjyf.gzyakj.com.cn')
out_b_check, _ = run('ls -lh /www/backup/yjyf_site_backup_before_deploy.tar.gz')
print('Remote site backup:', out_b_check.strip())
print('Step 4: Upload package to remote /tmp...')
sftp = ssh.open_sftp()
sftp.put(tar_path, '/tmp/server_deploy.tar.gz')
sftp.close()
out_up, _ = run('ls -lh /tmp/server_deploy.tar.gz')
print('Uploaded:', out_up.strip())
print('Step 5: Extract package to /www/wwwroot/yjyf.gzyakj.com.cn...')
out_ex, err_ex = run('tar -zxvf /tmp/server_deploy.tar.gz -C /www/wwwroot/yjyf.gzyakj.com.cn')
print('Extracted files count:', len(out_ex.splitlines()))
print('Step 6: Ensure .env for remote environment...')
remote_env_content = """[app]
debug = false
trace = false
[database]
hostname = 127.0.0.1
database = yjyf
username = yjyf
password = yjyf
hostport = 3306
prefix = fa_
[wechat]
appid = wx40ca4b02d4d1cb58
secret = f661146ce627e2c57770b7d80164dd65
mch_id = 1119105317
key = ffyqcyyszhdhi398672363efnwvikxlv
key_v3 = ffyqcyyszhdhi398672363efnwvikxlv
public_key_id = PUB_KEY_ID_0111191053172026102200381630000600
notify_domain = https://yjyf.gzyakj.com.cn
transfer_scene_id = 1005
transfer_single_limit = 200.00
transfer_daily_user_limit = 200.00
[tianditu]
key = 55aee666be14cd0100874d6faf3c963c
[sms]
; mock=1 时使用固定验证码(联调用);接入真实短信后置 0
mock = 1
mock_code = 123456
"""
sftp = ssh.open_sftp()
with sftp.file('/www/wwwroot/yjyf.gzyakj.com.cn/.env', 'w') as f:
f.write(remote_env_content)
sftp.close()
print('.env written.')
print('Step 7: Ensure admin.php and s.php exist...')
run('cp -f /www/wwwroot/yjyf.gzyakj.com.cn/public/s.php /www/wwwroot/yjyf.gzyakj.com.cn/public/admin.php')
print('Step 8: Set permissions and clean runtime cache...')
run('mkdir -p /www/wwwroot/yjyf.gzyakj.com.cn/runtime/cache /www/wwwroot/yjyf.gzyakj.com.cn/runtime/temp /www/wwwroot/yjyf.gzyakj.com.cn/runtime/log')
run('rm -rf /www/wwwroot/yjyf.gzyakj.com.cn/runtime/cache/* /www/wwwroot/yjyf.gzyakj.com.cn/runtime/temp/*')
run('chown -R www:www /www/wwwroot/yjyf.gzyakj.com.cn')
run('chmod -R 755 /www/wwwroot/yjyf.gzyakj.com.cn')
print('Step 9: Reload PHP-FPM...')
out_p, _ = run('/etc/init.d/php-fpm-85 reload')
print('PHP-FPM reload result:', out_p.strip())
print('Step 10: Clean up temporary package...')
run('rm -f /tmp/server_deploy.tar.gz')
if os.path.exists(tar_path):
os.remove(tar_path)
ssh.close()
print('Deploy server completed!')

查看文件

@@ -5,7 +5,6 @@ require __DIR__ . '/../server/thinkphp/base.php';
\think\App::initCommon();
use app\common\library\TiandituService;
use app\common\library\SmsService;
use think\Db;
echo "========================================================\n";
@@ -25,13 +24,9 @@ echo " [PASS] 正常打卡测试 (偏离约 {$checkNormal['distance']} 米): "
$checkAbnormal = TiandituService::checkArriveDistance(30.6574, 104.0665, 30.6900, 104.1000, 1000.0);
echo " [PASS] 异地打卡作弊拦截测试 (偏离 {$checkAbnormal['distance']} 米): " . (!$checkAbnormal['is_pass'] ? '成功识别预警' : '未拦截') . "\n";
// 2. 短信网关服务驱动自检
echo "\n>> 2. 验证业务短信分发驱动:\n";
$sms1 = SmsService::sendVerifyCode('13800138000', '654321', 'TESTORDER001');
echo " [PASS] 完工6位核销验证码短信驱动测试: " . ($sms1 ? '成功' : '失败') . "\n";
$sms2 = SmsService::sendFirstContactWarning('13700137000', 'TESTORDER001', 30);
echo " [PASS] 师傅2小时首联时效预警短信驱动测试: " . ($sms2 ? '成功' : '失败') . "\n";
// 2. 短信验证码通道已按当前阶段规范移除
echo "\n>> 2. 短信验证码通道状态:\n";
echo " [INFO] 短信验证码通道已移除,核销码改为订单详情页与站内消息直达。\n";
// 3. 验证 ThinkPHP 定时守护任务注册
echo "\n>> 3. 验证 ThinkPHP 命令行守护任务配置:\n";