This commit is contained in:
2025-09-24 22:17:21 +08:00
committed by qsc
parent 54b8d90e8d
commit 3fe3ce41de
5 changed files with 524 additions and 21 deletions
+68 -17
View File
@@ -1,6 +1,7 @@
# core/jx3jiaoyihang.py # core/jx3jiaoyihang.py
from astrbot.api import logger from astrbot.api import logger
from urllib.parse import quote from urllib.parse import quote
from datetime import datetime
from .api_data import api_data_get, api_data_post from .api_data import api_data_get, api_data_post
from .sql_data import sql_data_searchdata,sql_data_select from .sql_data import sql_data_searchdata,sql_data_select
@@ -196,36 +197,86 @@ def jx3_data_wujia(inname="秃盒"):
list: 合并后的数据,包含价格和名称信息 list: 合并后的数据,包含价格和名称信息
""" """
datas = { datas = {
"code": 0, # 默奇遇 "code": 0,
"msg": "未获取数据" # 默认服务器 "msg": "未获取数据",
"data": {}
} }
#获取所查询物品的id和官方名称 #获取所查询物品的id和官方名称
idname = sql_data_select(inname) idname = sql_data_select(inname)
if not idname:
datas["code"] = 201
datas["msg"] = f"未搜索到{inname}外观"
return
datas["code"] = 1
datas["msg"] = "获取外观名称ID完成"
datas["data"]["showName"] = idname.get("showName","未知物品")
datas["data"]["searchId"] = idname.get("searchId","未知ID")
datas["data"]["Name"] = inname
#查询爱剑三获取外观数据
aj3_url = "https://www.aijx3.cn/api2/aijx3-wj/goods/getGoodsDetail"
aj3_params = {
"goodsName":datas["data"]["showName"],
}
# 查询万宝楼公示数据 dataaj3 = api_data_post(aj3_url, aj3_params,"data")
custom_url = "https://www.aijx3.cn/api2/aijx3-wblwg/record/queryByCondition" datas["data"]["goodsDesc"] = dataaj3.get("goodsDesc","无描述")
initial_params = { datas["data"]["publishTime"] = dataaj3.get("publishTime","无数据")
datas["data"]["priceNum"] = dataaj3.get("priceNum",0)
datas["data"]["imgs"] = dataaj3.get("imgs",[])[0]
datas["data"]["goodsId"] = dataaj3.get("goodsId","无数据")
datas["code"] = 2
datas["msg"] = "获取外观数据完成"
# 查询万宝楼数据
wbl_url = "https://www.aijx3.cn/api2/aijx3-wblwg/record/queryByCondition"
wbl_params = {
"tradeStatus": "3", "tradeStatus": "3",
"accoSeq": "", "accoSeq": "",
"orderMode": 1, # 按时间降序 "orderMode": 1, # 按时间降序
"orderBy":"price_num", "orderBy":"price_num",
"searchId":[idname["searchId"]], "searchId":[idname['searchId']],
"current":1, "current":1,
"size":10 "size":10
} }
datawblgs = api_data_post(custom_url, initial_params,"data") #第一次查询万宝楼数据,获取公示数据
datas["data"]["wblgs"] = []
if not datawblgs: datawblgs = api_data_post(wbl_url, wbl_params,"data")
datas["code"] = 0 #处理万宝楼公示数据
datas["msg"] = "数据为空" for record in datawblgs.get("records",[]):
return # 转换时间戳为可读格式
dt = datetime.fromtimestamp(record.get("replyTime",0)/1000)
goodsId = datawblgs.get("records", "").get("goodsId", "") record_info = {
"priceNum": record.get("priceNum",0),
"belongQf2": record.get("belongQf2","无数据"),
"replyTime": dt.strftime("%Y-%m-%d %H:%M:%S"),
"discountRate": record.get("discountRate",0.0),
}
datas["data"]["wblgs"].append(record_info)
datas["data"] = goodsId #数据更新
datas["code"] = 200 datas["code"] = 3
datas["msg"] = "处理完成" datas["msg"] = "获取万宝楼公示数据完成"
#第二次查询万宝楼数据,获取在售数据
wbl_params["tradeStatus"] = "5"
datas["data"]["wblzs"] = []
datawblzs = api_data_post(wbl_url, wbl_params,"data")
#处理万宝楼在售数据
for record in datawblzs.get("records",[]):
# 转换时间戳为可读格式
dt = datetime.fromtimestamp(record.get("replyTime",0)/1000)
record_info = {
"priceNum": record.get("priceNum",0),
"belongQf2": record.get("belongQf2","无数据"),
"replyTime": dt.strftime("%Y-%m-%d %H:%M:%S"),
"discountRate": record.get("discountRate",0.0),
}
datas["data"]["wblzs"].append(record_info)
#数据更新
datas["code"] = 4
datas["msg"] = "获取万宝楼在售数据完成"
return datas return datas
+1 -1
View File
@@ -135,4 +135,4 @@ def sql_data_select(search_string):
finally: finally:
connection.close() connection.close()
return results return results[0]
+13 -3
View File
@@ -370,9 +370,19 @@ class Jx3ApiPlugin(Star):
if len(parts) > 1: if len(parts) > 1:
inname = parts[1] # 外观名称 inname = parts[1] # 外观名称
try: try:
test = jx3_data_wujia(inname) # 加载模板
yield event.plain_result(f"{test}") try:
template_content = load_template("wujia.html")
except FileNotFoundError as e:
logger.error(f"加载模板失败: {e}")
yield event.plain_result("系统错误:模板文件不存在")
return
render_data = jx3_data_wujia(inname)
url = await self.html_render(template_content, render_data, options={})
yield event.image_result(url)
except Exception as e: except Exception as e:
logger.error(f"处理数据时出错: {e}") logger.error(f"处理数据时出错: {e}")
+220
View File
@@ -0,0 +1,220 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ data.showName }} - 剑网3万宝楼</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
:root {
--jx3-primary: #ffd700;
--jx3-secondary: #8b4513;
--jx3-dark: #1a1a1a;
--jx3-light: #f8f9fa;
}
body {
background-color: #f5f5f5;
font-family: 'Microsoft YaHei', sans-serif;
color: #333;
}
.container {
max-width: 1200px;
}
.product-img {
width: 100%;
max-width: 850px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.price-tag {
color: #e74c3c;
font-weight: bold;
font-size: 1.2em;
}
.server-badge {
background-color: #e9ecef;
padding: 4px 8px;
border-radius: 4px;
font-size: 0.9em;
}
.discount-badge {
padding: 4px 8px;
border-radius: 4px;
font-size: 0.9em;
background-color: #f8d7da;
color: #721c24;
}
.discount-positive {
background-color: #d4edda;
color: #155724;
}
.card {
border: none;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
.card-header {
background-color: var(--jx3-secondary);
color: white;
border-radius: 10px 10px 0 0 !important;
padding: 12px 20px;
}
.table th {
background-color: var(--jx3-light);
font-weight: 600;
}
.footer {
background-color: var(--jx3-dark);
color: white;
text-align: center;
padding: 15px 0;
margin-top: 30px;
}
.price-cell {
font-weight: bold;
color: #e74c3c;
}
/* 双列布局 */
.dual-columns {
display: flex;
gap: 20px;
}
.dual-columns > div {
flex: 1;
}
@media (max-width: 768px) {
.dual-columns {
flex-direction: column;
}
}
</style>
</head>
<body>
<div class="container mt-4">
<!-- 商品基本信息 -->
<div class="card mb-4">
<div class="card-header">
<h3 class="mb-0"><i class="fas fa-box-open"></i> 商品基本信息</h3>
</div>
<div class="card-body">
<div class="row">
<!-- 图片在上方 -->
<div class="col-12 text-center mb-3">
<img src="{{ data.imgs }}" alt="{{ data.showName }}" class="product-img">
</div>
<!-- 文字信息在下方 -->
<div class="col-12 text-center">
<h2 class="mb-2">{{ data.showName }}({{data.Name}})</h2>
<p class="mb-3">{{ data.goodsDesc }}</p>
<div class="row mb-3">
<div class="col-sm-6">
<strong>发布时间:</strong> {{ data.publishTime.split('T')[0] if data.publishTime else '未知' }}
</div>
<div class="col-sm-6">
<strong>参考价格:</strong> <span class="price-tag">{{ data.priceNum }} 元</span>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 双列数据布局 -->
<div class="dual-columns">
<!-- 万宝楼公示 -->
<div class="card mb-4">
<div class="card-header">
<h4 class="mb-0"><i class="fas fa-store"></i> 万宝楼公示 </h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>上架时间</th>
<th>服务器</th>
<th>价格</th>
<th>折扣率</th>
</tr>
</thead>
<tbody>
{% for item in data.wblgs %}
<tr>
<td>{{ item.replyTime }}</td>
<td><span class="server-badge">{{ item.belongQf2 }}</span></td>
<td class="price-cell">{{ item.priceNum }}元</td>
<td>
<span class="discount-badge {% if item.discountRate > 0 %}discount-positive{% endif %}">
{{ item.discountRate }}%
</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<!-- 万宝楼在售 -->
<div class="card mb-4">
<div class="card-header">
<h4 class="mb-0"><i class="fas fa-history"></i> 万宝楼在售 </h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>上架时间</th>
<th>服务器</th>
<th>价格</th>
<th>折扣率</th>
</tr>
</thead>
<tbody>
{% for item in data.wblzs %}
<tr>
<td>{{ item.replyTime }}</td>
<td><span class="server-badge">{{ item.belongQf2 }}</span></td>
<td class="price-cell">{{ item.priceNum }}元</td>
<td>
<span class="discount-badge {% if item.discountRate > 0 %}discount-positive{% endif %}">
{{ item.discountRate }}%
</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<div class="container">
<p>剑网3万宝楼商品数据展示 &copy; 2025 | 数据仅供参考,实际价格以游戏内为准</p>
</div>
</div>
</body>
</html>
+222
View File
@@ -0,0 +1,222 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ data.showName }} - 剑网3万宝楼</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
/* 上面的CSS样式 */
</style>
</head>
<body>
<div class="header">
<div class="container">
<div class="row align-items-center">
<div class="col-md-6">
<div class="logo">
<i class="fas fa-dragon"></i> 剑网3万宝楼
</div>
</div>
<div class="col-md-6 text-end">
<span class="status-badge {% if code == 4 %}code-success{% else %}code-error{% endif %}">
<i class="fas fa-{% if code == 4 %}check-circle{% else %}exclamation-circle{% endif %}"></i>
{{ msg }}
</span>
<span class="time-badge ms-2">
<i class="far fa-clock"></i> 数据更新时间: {{ now.strftime('%Y-%m-%d %H:%M:%S') if now else '未知' }}
</span>
</div>
</div>
</div>
</div>
<div class="container">
<!-- 商品基本信息 -->
<div class="card mb-4">
<div class="card-header">
<h3 class="mb-0"><i class="fas fa-box-open"></i> 商品基本信息</h3>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-4">
<img src="{{ data.imgs }}" alt="{{ data.showName }}" class="product-img">
</div>
<div class="col-md-8">
<h2 class="mb-3">{{ data.showName }}</h2>
<p class="text-muted">商品ID: {{ data.goodsId }} | 搜索ID: {{ data.searchId }}</p>
<p class="mb-3">{{ data.goodsDesc }}</p>
<div class="row mb-3">
<div class="col-sm-6">
<strong>发布时间:</strong> {{ data.publishTime.split('T')[0] if data.publishTime else '未知' }}
</div>
<div class="col-sm-6">
<strong>参考价格:</strong> <span class="price-tag">{{ data.priceNum }} 元</span>
</div>
</div>
<div class="d-flex">
<button class="btn me-2" style="background-color: var(--jx3-primary); color: var(--jx3-dark);">
<i class="fas fa-shopping-cart"></i> 加入关注
</button>
<button class="btn" style="background-color: var(--jx3-secondary); color: white;">
<i class="fas fa-bell"></i> 价格提醒
</button>
</div>
</div>
</div>
</div>
</div>
<!-- 价格摘要 -->
<div class="card summary-card mb-4">
<div class="card-body">
<div class="row">
<div class="col-md-6">
<h5><i class="fas fa-store"></i> 当前在售摘要</h5>
{% set min_price = data.wblgs|min(attribute='priceNum') %}
{% set max_price = data.wblgs|max(attribute='priceNum') %}
{% set avg_price = (data.wblgs|sum(attribute='priceNum') / data.wblgs|length)|round(1) %}
<div class="summary-item">
<span>在售商品数量:</span>
<span class="price-cell">{{ data.wblgs|length }}件</span>
</div>
<div class="summary-item">
<span>最低价格:</span>
<span class="price-cell">{{ min_price.priceNum if min_price else 0 }}元 ({{ min_price.belongQf2 if min_price else '未知' }})</span>
</div>
<div class="summary-item">
<span>最高价格:</span>
<span class="price-cell">{{ max_price.priceNum if max_price else 0 }}元 ({{ max_price.belongQf2 if max_price else '未知' }})</span>
</div>
<div class="summary-item">
<span>平均价格:</span>
<span class="price-cell">{{ avg_price }}元</span>
</div>
</div>
<div class="col-md-6">
<h5><i class="fas fa-history"></i> 历史在售摘要</h5>
{% set min_price_hist = data.wblzs|min(attribute='priceNum') %}
{% set max_price_hist = data.wblzs|max(attribute='priceNum') %}
{% set avg_price_hist = (data.wblzs|sum(attribute='priceNum') / data.wblzs|length)|round(1) %}
<div class="summary-item">
<span>历史记录数量:</span>
<span class="price-cell">{{ data.wblzs|length }}条</span>
</div>
<div class="summary-item">
<span>最低价格:</span>
<span class="price-cell">{{ min_price_hist.priceNum if min_price_hist else 0 }}元</span>
</div>
<div class="summary-item">
<span>最高价格:</span>
<span class="price-cell">{{ max_price_hist.priceNum if max_price_hist else 0 }}元</span>
</div>
<div class="summary-item">
<span>平均价格:</span>
<span class="price-cell">{{ avg_price_hist }}元</span>
</div>
</div>
</div>
</div>
</div>
<!-- 在售数据 -->
<div class="card mb-4">
<div class="card-header d-flex justify-content-between align-items-center">
<h4 class="mb-0"><i class="fas fa-store"></i> 当前在售商品 ({{ data.wblgs|length }}件)</h4>
<div>
{% set min_price = data.wblgs|min(attribute='priceNum') %}
{% set max_price = data.wblgs|max(attribute='priceNum') %}
<span class="badge bg-success">最低: {{ min_price.priceNum if min_price else 0 }}元</span>
<span class="badge bg-danger ms-2">最高: {{ max_price.priceNum if max_price else 0 }}元</span>
</div>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>价格</th>
<th>服务器</th>
<th>折扣率</th>
<th>更新时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{% for item in data.wblgs %}
<tr>
<td class="price-cell">{{ item.priceNum }}元</td>
<td><span class="server-badge">{{ item.belongQf2 }}</span></td>
<td>
<span class="discount-badge {% if item.discountRate > 0 %}discount-positive{% endif %}">
{{ item.discountRate }}%
</span>
</td>
<td>{{ item.replyTime }}</td>
<td><button class="btn btn-sm" style="background-color: var(--jx3-primary); color: var(--jx3-dark);">购买</button></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<!-- 历史在售数据 -->
<div class="card mb-4">
<div class="card-header d-flex justify-content-between align-items-center">
<h4 class="mb-0"><i class="fas fa-history"></i> 历史在售记录 ({{ data.wblzs|length }}条)</h4>
<div>
{% set min_price_hist = data.wblzs|min(attribute='priceNum') %}
{% set max_price_hist = data.wblzs|max(attribute='priceNum') %}
<span class="badge bg-success">最低: {{ min_price_hist.priceNum if min_price_hist else 0 }}元</span>
<span class="badge bg-danger ms-2">最高: {{ max_price_hist.priceNum if max_price_hist else 0 }}元</span>
</div>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>价格</th>
<th>服务器</th>
<th>折扣率</th>
<th>更新时间</th>
</tr>
</thead>
<tbody>
{% for item in data.wblzs %}
<tr>
<td class="price-cell">{{ item.priceNum }}元</td>
<td><span class="server-badge">{{ item.belongQf2 }}</span></td>
<td>
<span class="discount-badge {% if item.discountRate > 0 %}discount-positive{% endif %}">
{{ item.discountRate }}%
</span>
</td>
<td>{{ item.replyTime }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="footer">
<div class="container">
<p>剑网3万宝楼商品数据展示 &copy; 2025 | 数据仅供参考,实际价格以游戏内为准</p>
</div>
</div>
<script>
// 上面的JavaScript代码
</script>
</body>
</html>