feat(shop-role): 实现店铺角色继承功能和权限检查优化
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m39s

- 新增店铺角色管理 API 和数据模型
- 实现角色继承和权限检查逻辑
- 添加流程测试框架和集成测试
- 更新权限服务和账号管理逻辑
- 添加数据库迁移脚本
- 归档 OpenSpec 变更文档

Ultraworked with Sisyphus
This commit is contained in:
2026-02-03 10:06:13 +08:00
parent bc7e5d6f6d
commit 5a90caa619
61 changed files with 21284 additions and 131 deletions

74
flow_tests/core/mock.py Normal file
View File

@@ -0,0 +1,74 @@
import logging
import time
from typing import Any, Optional
import redis
from config.settings import settings
from .database import Database
logger = logging.getLogger(__name__)
class MockService:
def __init__(self, db: Optional[Database] = None):
self.db = db or Database()
self._init_redis()
def _init_redis(self):
config = settings.redis_config
self.redis = redis.Redis(
host=config["host"],
port=config["port"],
db=config["db"],
decode_responses=True,
)
def payment_success(self, order_id: int, amount: float, delay: float = 0):
if delay > 0:
time.sleep(delay)
self.db.execute(
"UPDATE tb_order SET status = %s, paid_at = NOW(), paid_amount = %s WHERE id = %s",
("paid", int(amount * 100), order_id)
)
logger.info(f"模拟支付成功: order_id={order_id}, amount={amount}")
def payment_failed(self, order_id: int, reason: str = "支付失败"):
self.db.execute(
"UPDATE tb_order SET status = %s, fail_reason = %s WHERE id = %s",
("failed", reason, order_id)
)
logger.info(f"模拟支付失败: order_id={order_id}, reason={reason}")
def sms_code(self, phone: str, code: str, expire_seconds: int = 300):
key = f"sms:code:{phone}"
self.redis.setex(key, expire_seconds, code)
logger.info(f"模拟短信验证码: phone={phone}, code={code}")
def task_complete(self, task_type: str, task_id: int, result: Any = None):
self.db.execute(
"UPDATE tb_async_task SET status = %s, result = %s, completed_at = NOW() WHERE task_type = %s AND id = %s",
("completed", str(result) if result else None, task_type, task_id)
)
logger.info(f"模拟任务完成: {task_type}#{task_id}")
def task_failed(self, task_type: str, task_id: int, error: str):
self.db.execute(
"UPDATE tb_async_task SET status = %s, error = %s, completed_at = NOW() WHERE task_type = %s AND id = %s",
("failed", error, task_type, task_id)
)
logger.info(f"模拟任务失败: {task_type}#{task_id}, error={error}")
def card_data_balance(self, card_id: int, balance_mb: int):
self.db.execute(
"UPDATE tb_iot_card SET data_balance = %s WHERE id = %s",
(balance_mb, card_id)
)
logger.info(f"模拟卡片流量: card_id={card_id}, balance={balance_mb}MB")
def external_api_response(self, api_name: str, response: dict):
key = f"mock:api:{api_name}"
import json
self.redis.setex(key, 300, json.dumps(response))
logger.info(f"模拟外部 API: {api_name}")