Merge pull request #109 from xpack-ai/feature/1.3-liujian
Feature/1.3 liujian
This commit is contained in:
14 files changed
+259
-15
No files matched your search
@@ -0,0 +1,8 @@
|
||||
INSERT INTO `sys_config` (`id`,`key`, `value`,`description`,`created_at`,`updated_at`)
|
||||
VALUES ('xpack-tag-bar-display','tag_bar_display', 'true', 'Display tag bar on the top of the page', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
ON DUPLICATE KEY UPDATE `value` = VALUES(`value`), `description` = VALUES(`description`), `updated_at` = CURRENT_TIMESTAMP;
|
||||
|
||||
|
||||
INSERT INTO `sys_config` (`id`,`key`, `value`,`description`,`created_at`,`updated_at`)
|
||||
VALUES ('xpack-version','version', '1.3.0', 'The user interface supports viewing the transaction list.', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
ON DUPLICATE KEY UPDATE `value` = VALUES(`value`), `description` = VALUES(`description`), `updated_at` = CURRENT_TIMESTAMP;
|
||||
@@ -7,6 +7,7 @@ KEY_SUBHEADLINE = "subheadline"
|
||||
KEY_LANGUAGE = "language"
|
||||
KEY_THEME = "theme"
|
||||
KEY_ABOUT_PAGE = "about_page"
|
||||
KEY_TAG_BAR_DISPLAY = "tag_bar_display"
|
||||
KEY_ADMIN_USERNAME = "admin_username"
|
||||
KEY_ADMIN_PASSWORD = "admin_password"
|
||||
KEY_LOGIN_GOOGLE_CLIENT = "login_google_client_id"
|
||||
|
||||
@@ -67,6 +67,7 @@ def get_config(
|
||||
"facebook_image_url": values.get(KEY_FACEBOOK_IMAGE_URL, ""),
|
||||
"social_account_facebook_url": values.get(KEY_SOCIAL_ACCOUNT_FACEBOOK_URL, ""),
|
||||
"social_account_x_url": values.get(KEY_SOCIAL_ACCOUNT_X_URL, ""),
|
||||
"tag_bar_display": values.get(KEY_TAG_BAR_DISPLAY, "false").lower() in ("true", "t", "yes", "y", "1"),
|
||||
},
|
||||
"faq": faq,
|
||||
"embeded_html": embeded_html,
|
||||
|
||||
@@ -270,6 +270,20 @@ def get_mcp_service_simple_list(
|
||||
logger.error(f"Failed to get service simple list: {str(e)}")
|
||||
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
||||
|
||||
@router.get("/service/tags", summary="Get MCP service tags")
|
||||
def get_mcp_service_tags(
|
||||
request: Request,
|
||||
mcp_manager_service: McpManagerService = Depends(get_mcp_manager),
|
||||
):
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
try:
|
||||
tags = mcp_manager_service.get_tags_list(enabled_only=False)
|
||||
return ResponseUtils.success(data=tags)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get service tags: {str(e)}")
|
||||
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
||||
|
||||
@router.get("/service/resource_group/list", summary="Get MCP service's resource group list")
|
||||
def get_mcp_service_resource_group_list(
|
||||
request: Request,
|
||||
@@ -360,4 +374,4 @@ def unbind_group(
|
||||
return ResponseUtils.success()
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to unbind resource groups: {str(e)}")
|
||||
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
||||
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
||||
@@ -1,4 +1,7 @@
|
||||
from os import stat
|
||||
from typing import Optional, List
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from services.common.models.user_wallet_history import TransactionType
|
||||
from sqlalchemy import table
|
||||
from sqlalchemy.orm import Session
|
||||
from services.common.database import get_db
|
||||
@@ -52,3 +55,39 @@ def get_user_order_list(
|
||||
)
|
||||
|
||||
return ResponseUtils.success_page(data=result, total=total, page_num=page, page_size=page_size)
|
||||
|
||||
@router.get("/list/by_user", summary="Get user order list by user id")
|
||||
def get_user_order_list_by_user_id(
|
||||
user_id: str = Query(..., description="User ID"),
|
||||
page: int = Query(1, description="Current page number"),
|
||||
page_size: int = Query(15, description="Number of items per page"),
|
||||
order_type: Optional[str] = Query(None, description="Order type"),
|
||||
status: Optional[str] = Query(None, description="Order status"),
|
||||
user_service: UserService = Depends(get_user_service),
|
||||
user_wallet_history_service: UserWalletHistoryService = Depends(get_user_wallet_history_service),
|
||||
):
|
||||
"""Get paginated list of user order history by user id."""
|
||||
user = user_service.get_by_id(user_id)
|
||||
if not user:
|
||||
return ResponseUtils.error(message="not found user", code=404)
|
||||
offset = (page - 1) * page_size
|
||||
order_type_list = []
|
||||
if order_type:
|
||||
# 将字符串转成列表,中间使用逗号分隔
|
||||
ots = order_type.split(",")
|
||||
for ot in ots:
|
||||
ot = ot.strip()
|
||||
if ot == "purchase":
|
||||
order_type_list.append("api_call")
|
||||
elif ot == "recharge":
|
||||
order_type_list.append("deposit")
|
||||
else:
|
||||
order_type_list.append(ot)
|
||||
status_list: Optional[List[int]] = []
|
||||
if status:
|
||||
sl = status.split(",")
|
||||
for s in sl:
|
||||
status_list.append(int(s.strip()))
|
||||
total, orders = user_wallet_history_service.success_order_list_by_user(user_id, offset, page_size, order_type_list, status_list)
|
||||
|
||||
return ResponseUtils.success_page(data=orders, total=total, page_num=page, page_size=page_size)
|
||||
@@ -144,6 +144,7 @@ def get_sysconfig(
|
||||
"social_account_facebook_url": small_values.get(sys_config_key.KEY_SOCIAL_ACCOUNT_FACEBOOK_URL, ""),
|
||||
"social_account_x_url": small_values.get(sys_config_key.KEY_SOCIAL_ACCOUNT_X_URL, ""),
|
||||
"cname_a_ip": cname_a_ip,
|
||||
"tag_bar_display": small_values.get(sys_config_key.KEY_TAG_BAR_DISPLAY, "").lower() in ("true", "t", "yes", "y", "1"),
|
||||
},
|
||||
"account": {
|
||||
"username": admin_username,
|
||||
@@ -219,6 +220,9 @@ def set_sysconfig(
|
||||
facebook_image_url = platform.get("facebook_image_url")
|
||||
social_account_facebook_url = platform.get("social_account_facebook_url")
|
||||
social_account_x_url = platform.get("social_account_x_url")
|
||||
tag_bar_display = platform.get("tag_bar_display")
|
||||
|
||||
|
||||
|
||||
account = body.get("account", {})
|
||||
admin_username = account.get("username")
|
||||
@@ -270,6 +274,7 @@ def set_sysconfig(
|
||||
(sys_config_key.KEY_FACEBOOK_IMAGE_URL, facebook_image_url, "Facebook image URL"),
|
||||
(sys_config_key.KEY_SOCIAL_ACCOUNT_FACEBOOK_URL, social_account_facebook_url, "Facebook URL"),
|
||||
(sys_config_key.KEY_SOCIAL_ACCOUNT_X_URL, social_account_x_url, "X URL"),
|
||||
(sys_config_key.KEY_TAG_BAR_DISPLAY, tag_bar_display, "Tag bar display"),
|
||||
(sys_config_key.KEY_LOGIN_GOOGLE_CLIENT, login_google_client, "Google login client ID"),
|
||||
(sys_config_key.KEY_LOGIN_GOOGLE_SECRET, login_google_secret, "Google login client secret"),
|
||||
(sys_config_key.KEY_LOGIN_GOOGLE_ENABLE, login_google_enable, "Google login enabled"),
|
||||
@@ -318,6 +323,7 @@ def set_sysconfig(
|
||||
"facebook_image_url": facebook_image_url,
|
||||
"social_account_facebook_url": social_account_facebook_url,
|
||||
"social_account_x_url": social_account_x_url,
|
||||
"tag_bar_display": tag_bar_display,
|
||||
}
|
||||
|
||||
# Use background reporting to avoid blocking the main configuration update
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, Depends, Request,Body
|
||||
from fastapi import APIRouter, Depends, Request,Body,Query
|
||||
from sqlalchemy.orm import Session
|
||||
from services.common.database import get_db
|
||||
from services.admin_service.constants.user_task import user_task_ids
|
||||
@@ -10,6 +10,9 @@ from services.admin_service.services.user_wallet_service import UserWalletServic
|
||||
from services.admin_service.services.user_task_service import UserTaskService
|
||||
from services.admin_service.services.auth_service import AuthService
|
||||
from services.admin_service.services.resource_group_service import ResourceGroupService
|
||||
from services.admin_service.services.user_wallet_history_service import UserWalletHistoryService
|
||||
|
||||
from typing import Optional,List
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -27,6 +30,10 @@ def get_user_task_service(db: Session = Depends(get_db)) -> UserTaskService:
|
||||
def get_resource_group_service(db: Session = Depends(get_db)) -> ResourceGroupService:
|
||||
return ResourceGroupService(db)
|
||||
|
||||
def get_order_service(db: Session = Depends(get_db)) -> UserWalletHistoryService:
|
||||
return UserWalletHistoryService(db)
|
||||
|
||||
|
||||
@router.get("/info", response_model=dict)
|
||||
def get_user(request: Request, user_wallet: UserWalletService = Depends(get_user_wallet), user_task: UserTaskService = Depends(get_user_task_service), resource_group_service: ResourceGroupService = Depends(get_resource_group_service)):
|
||||
"""Get current user information and wallet balance."""
|
||||
@@ -87,3 +94,37 @@ def update_password(
|
||||
|
||||
return ResponseUtils.error(message="not found user", code=404)
|
||||
|
||||
@router.get("/order/list", summary="Get order list")
|
||||
def get_order_list(
|
||||
request: Request,
|
||||
page: int = Query(1, description="Current page number"),
|
||||
page_size: int = Query(15, description="Number of items per page"),
|
||||
order_type: Optional[str] = Query(None, description="Order type"),
|
||||
status: Optional[str] = Query(None, description="Order status"),
|
||||
user_wallet_history_service: UserWalletHistoryService = Depends(get_order_service),
|
||||
):
|
||||
"""Get order list."""
|
||||
user = UserUtils.get_request_user(request)
|
||||
if not user:
|
||||
return ResponseUtils.error(message="not found user", code=404)
|
||||
offset = (page - 1) * page_size
|
||||
order_type_list = []
|
||||
if order_type:
|
||||
# 将字符串转成列表,中间使用逗号分隔
|
||||
ots = order_type.split(",")
|
||||
for ot in ots:
|
||||
ot = ot.strip()
|
||||
if ot == "purchase":
|
||||
order_type_list.append("api_call")
|
||||
elif ot == "recharge":
|
||||
order_type_list.append("deposit")
|
||||
else:
|
||||
order_type_list.append(ot)
|
||||
status_list: Optional[List[int]] = []
|
||||
if status:
|
||||
sl = status.split(",")
|
||||
for s in sl:
|
||||
status_list.append(int(s.strip()))
|
||||
total, orders = user_wallet_history_service.success_order_list_by_user(user.id, offset, page_size, order_type_list, status_list)
|
||||
|
||||
return ResponseUtils.success_page(data=orders, total=total, page_num=page, page_size=page_size)
|
||||
@@ -29,6 +29,7 @@ def get_public_mcp_services(
|
||||
keyword: Optional[str] = Query(None, description="Search keyword"),
|
||||
page: Optional[int] = Query(1, description="Page number (starts from 1)"),
|
||||
page_size: Optional[int] = Query(10, description="Page size (default 10)"),
|
||||
tag: Optional[str] = Query(None, description="Filter by tag"),
|
||||
mcp_manager_service: McpManagerService = Depends(get_mcp_manager),
|
||||
):
|
||||
"""Get paginated list of public MCP services with keyword search."""
|
||||
@@ -43,12 +44,19 @@ def get_public_mcp_services(
|
||||
|
||||
# Get service list - let any exception bubble up to middleware
|
||||
service_list, total = mcp_manager_service.get_public_services_paginated(
|
||||
keyword=search_keyword, page=validated_page, page_size=validated_page_size
|
||||
keyword=search_keyword, page=validated_page, page_size=validated_page_size, tag=tag
|
||||
)
|
||||
|
||||
logger.info(f"Successfully retrieved {len(service_list)} services")
|
||||
return ResponseUtils.success_page(data=service_list, page_num=validated_page, page_size=validated_page_size, total=total)
|
||||
|
||||
@router.get("/mcp_tags", summary="Get public MCP tags list")
|
||||
def get_public_mcp_tags(
|
||||
mcp_manager_service: McpManagerService = Depends(get_mcp_manager),
|
||||
):
|
||||
tags = mcp_manager_service.get_tags_list(enabled_only=True)
|
||||
return ResponseUtils.success(data=tags)
|
||||
|
||||
|
||||
@router.get("/mcp_service_info", summary="Get public MCP service information")
|
||||
def get_public_mcp_service_info(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime, timezone
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.orm import Session
|
||||
from services.common.models.mcp_service import McpService
|
||||
from typing import Optional, Tuple, List
|
||||
@@ -103,7 +104,7 @@ class McpServiceRepository:
|
||||
self.db.refresh(mcp_service)
|
||||
return mcp_service
|
||||
|
||||
def get_public_services_paginated(self, keyword: str, page: int = 1, page_size: int = 10) -> Tuple[List[McpService], int]:
|
||||
def get_public_services_paginated(self, keyword: str, page: int = 1, page_size: int = 10, tag: Optional[str] = None) -> Tuple[List[McpService], int]:
|
||||
"""Get public service list with pagination, supports keyword search"""
|
||||
offset = (page - 1) * page_size
|
||||
|
||||
@@ -112,9 +113,21 @@ class McpServiceRepository:
|
||||
if keyword:
|
||||
keyword = f"%{keyword}%"
|
||||
query = query.filter((McpService.name.like(keyword)) | (McpService.short_description.like(keyword)))
|
||||
if tag:
|
||||
normalized_tag = tag.strip()
|
||||
if normalized_tag:
|
||||
normalized_tags = func.replace(func.replace(McpService.tags, ", ", ","), " ,", ",")
|
||||
query = query.filter(func.find_in_set(normalized_tag, normalized_tags) > 0)
|
||||
|
||||
|
||||
total = query.count()
|
||||
|
||||
services = query.order_by(McpService.created_at.desc()).offset(offset).limit(page_size).all()
|
||||
|
||||
return services, total
|
||||
|
||||
def get_tags_strings(self, enabled_only: bool = False) -> List[str]:
|
||||
query = self.db.query(McpService.tags).filter(McpService.tags.isnot(None)).filter(McpService.tags != "")
|
||||
if enabled_only:
|
||||
query = query.filter(McpService.enabled == 1)
|
||||
return [row[0] for row in query.all() if row and row[0]]
|
||||
@@ -18,8 +18,20 @@ class UserWalletHistoryRepository:
|
||||
|
||||
def __init__(self, db: Session):
|
||||
self.db = db
|
||||
|
||||
def get_by_id(self, transaction_id: str) -> Optional[UserWalletHistory]:
|
||||
"""
|
||||
Get a user wallet history record by ID.
|
||||
|
||||
def add_deposit(self, user_id: str, amount: float, payment_method: str, transaction_id: str = "", status: int = 0) -> UserWalletHistory:
|
||||
Args:
|
||||
transaction_id: Transaction ID
|
||||
|
||||
Returns:
|
||||
Optional[UserWalletHistory]: Found record or None
|
||||
"""
|
||||
return self.db.query(UserWalletHistory).filter(UserWalletHistory.id == transaction_id).first()
|
||||
|
||||
def add_deposit(self, user_id: str, amount: float, payment_method: str, transaction_id: str = "", status: int = 0, balance_after: float = 0.00) -> UserWalletHistory:
|
||||
"""
|
||||
Create a new deposit record.
|
||||
|
||||
@@ -40,7 +52,7 @@ class UserWalletHistoryRepository:
|
||||
user_id=user_id,
|
||||
payment_method=PaymentMethod(payment_method),
|
||||
amount=amount,
|
||||
balance_after=0.00,
|
||||
balance_after=balance_after,
|
||||
type=TransactionType.DEPOSIT,
|
||||
transaction_id=transaction_id,
|
||||
status=status,
|
||||
@@ -81,7 +93,7 @@ class UserWalletHistoryRepository:
|
||||
self.db.refresh(history)
|
||||
return history
|
||||
|
||||
def set_balance(self,user_id: str,amount:float, payment_method: str, transaction_id: str = "", status: int = 0) -> UserWalletHistory:
|
||||
def set_balance(self,user_id: str,amount:float, payment_method: str, transaction_id: str = "", status: int = 0, balance_after: float = 0.00) -> UserWalletHistory:
|
||||
"""
|
||||
Create a new balance record.
|
||||
|
||||
@@ -102,7 +114,7 @@ class UserWalletHistoryRepository:
|
||||
user_id=user_id,
|
||||
payment_method=PaymentMethod(payment_method),
|
||||
amount=amount,
|
||||
balance_after=0.00,
|
||||
balance_after=balance_after,
|
||||
type=TransactionType.RESET,
|
||||
status=status, # 0=new, 1=completed, 2=refunded
|
||||
created_at=now,
|
||||
@@ -242,8 +254,8 @@ class UserWalletHistoryRepository:
|
||||
.all()
|
||||
)
|
||||
return total, history
|
||||
|
||||
def get_by_id(self, history_id: str) -> Optional[UserWalletHistory]:
|
||||
|
||||
def success_order_list_by_user(self, user_id: str, offset: int, limit: int, order_type: Optional[List[str]] = None, status: Optional[List[int]] = None) -> Tuple[int, List[UserWalletHistory]]:
|
||||
"""
|
||||
Get user wallet history record by ID.
|
||||
|
||||
@@ -253,7 +265,25 @@ class UserWalletHistoryRepository:
|
||||
Returns:
|
||||
Optional[UserWalletHistory]: UserWalletHistory object or None
|
||||
"""
|
||||
return self.db.query(UserWalletHistory).filter(UserWalletHistory.id == history_id).first()
|
||||
|
||||
query = self.db.query(UserWalletHistory).filter(
|
||||
UserWalletHistory.user_id == user_id,
|
||||
)
|
||||
if order_type and len(order_type) > 0:
|
||||
query = query.filter(UserWalletHistory.type.in_(order_type))
|
||||
if status and len(status) > 0:
|
||||
query = query.filter(UserWalletHistory.status.in_(status))
|
||||
total = query.count()
|
||||
if total < offset:
|
||||
return total, []
|
||||
history = (
|
||||
query
|
||||
.order_by(UserWalletHistory.created_at.desc())
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
.all()
|
||||
)
|
||||
return total, history
|
||||
|
||||
def add_consume_record(self, wallet_history: UserWalletHistory) -> Optional[UserWalletHistory]:
|
||||
"""
|
||||
|
||||
@@ -329,6 +329,31 @@ class McpManagerService:
|
||||
"""Get service list with pagination"""
|
||||
return self.mcp_service_repository.get_all_paginated(page=page, page_size=page_size)
|
||||
|
||||
def get_tags_list(self, enabled_only: bool = False) -> List[str]:
|
||||
tags_strings = self.mcp_service_repository.get_tags_strings(enabled_only=enabled_only)
|
||||
tag_counts: dict[str, int] = {}
|
||||
canonical: dict[str, str] = {}
|
||||
|
||||
for tags_str in tags_strings:
|
||||
normalized_in_service: set[str] = set()
|
||||
for tag in parse_tags_to_array(tags_str):
|
||||
normalized = tag.casefold()
|
||||
if not normalized:
|
||||
continue
|
||||
if normalized in normalized_in_service:
|
||||
continue
|
||||
normalized_in_service.add(normalized)
|
||||
canonical.setdefault(normalized, tag)
|
||||
|
||||
for normalized in normalized_in_service:
|
||||
tag_counts[normalized] = tag_counts.get(normalized, 0) + 1
|
||||
|
||||
sorted_normalized = sorted(
|
||||
tag_counts.keys(),
|
||||
key=lambda normalized: (-tag_counts[normalized], canonical[normalized].casefold()),
|
||||
)
|
||||
return [canonical[normalized] for normalized in sorted_normalized]
|
||||
|
||||
def create_service_from_openapi(self, openapi_data: OpenApiForAI) -> str:
|
||||
# Convert OpenApiForAI info to McpService object and McpToolApi object list, return service ID or exception.
|
||||
try:
|
||||
@@ -488,9 +513,9 @@ class McpManagerService:
|
||||
logger.error(f"Failed to update service from OpenAPI: {str(e)}")
|
||||
raise ValueError(f"Failed to update service from OpenAPI.")
|
||||
|
||||
def get_public_services_paginated(self, keyword: str, page: int = 1, page_size: int = 10) -> Tuple[List[dict], int]:
|
||||
def get_public_services_paginated(self, keyword: str, page: int = 1, page_size: int = 10, tag: Optional[str] = None) -> Tuple[List[dict], int]:
|
||||
"""Get public services list with pagination, returns formatted data with API info"""
|
||||
services, total = self.mcp_service_repository.get_public_services_paginated(keyword, page, page_size)
|
||||
services, total = self.mcp_service_repository.get_public_services_paginated(keyword, page, page_size, tag)
|
||||
|
||||
service_list = []
|
||||
for service in services:
|
||||
|
||||
@@ -403,11 +403,21 @@ class PaymentService:
|
||||
try:
|
||||
if typ == "incr":
|
||||
self.user_wallet_history_repository.add_deposit(
|
||||
user_id=user_id, amount=amount, payment_method=payment_method, transaction_id=transaction_id,status=1
|
||||
user_id=user_id,
|
||||
amount=amount,
|
||||
payment_method=payment_method,
|
||||
transaction_id=transaction_id,
|
||||
status=1,
|
||||
balance_after=new_balance,
|
||||
)
|
||||
elif typ == "set":
|
||||
self.user_wallet_history_repository.set_balance(
|
||||
user_id=user_id, amount=amount, payment_method=payment_method, transaction_id=transaction_id,status=1
|
||||
user_id=user_id,
|
||||
amount=amount,
|
||||
payment_method=payment_method,
|
||||
transaction_id=transaction_id,
|
||||
status=1,
|
||||
balance_after=new_balance,
|
||||
)
|
||||
self._delete_wallet_cache(user_id)
|
||||
logger.info(f"Successfully updated balance for user_id {user_id}: {current_wallet.balance} -> {new_balance}")
|
||||
|
||||
@@ -3,11 +3,16 @@ from services.common.models.user_wallet_history import UserWalletHistory
|
||||
from services.admin_service.repositories.user_wallet_history_repository import UserWalletHistoryRepository
|
||||
from typing import Optional, Dict, Any, List, Tuple
|
||||
from datetime import datetime
|
||||
from services.common.models.user_wallet_history import TransactionType
|
||||
from services.admin_service.repositories.mcp_service_repository import McpServiceRepository
|
||||
import json
|
||||
|
||||
|
||||
|
||||
class UserWalletHistoryService:
|
||||
def __init__(self, db: Session):
|
||||
self.user_wallet_history_repository = UserWalletHistoryRepository(db)
|
||||
self.mcp_service_repository = McpServiceRepository(db)
|
||||
|
||||
def add_deposit(self, user_id: str, amount: float, payment_method: str) -> UserWalletHistory:
|
||||
return self.user_wallet_history_repository.add_deposit(user_id, amount, payment_method)
|
||||
@@ -18,6 +23,48 @@ class UserWalletHistoryService:
|
||||
def success_deposit_order_list(self, offset: int, limit: int) -> Tuple[int, List[UserWalletHistory]]:
|
||||
return self.user_wallet_history_repository.success_deposit_order_list(offset, limit)
|
||||
|
||||
def success_order_list_by_user(self, user_id: str, offset: int, limit: int, order_type: Optional[List[str]] = None, status: Optional[List[int]] = None) -> Tuple[int, List[dict]]:
|
||||
total, orders = self.user_wallet_history_repository.success_order_list_by_user(user_id, offset, limit, order_type, status)
|
||||
if total == 0:
|
||||
return total, []
|
||||
result = []
|
||||
for order in orders:
|
||||
confirm_at = ""
|
||||
if order.status == 1:
|
||||
confirm_at = order.updated_at
|
||||
info = {
|
||||
"id": order.id,
|
||||
"user_id": order.user_id,
|
||||
"order_id": order.transaction_id,
|
||||
"payment_type": order.payment_method,
|
||||
"payment_state": order.status,
|
||||
"amount": order.amount,
|
||||
"create_at": order.created_at,
|
||||
"confirm_at": confirm_at,
|
||||
}
|
||||
if order.type == TransactionType.API_CALL:
|
||||
info["order_type"] = "purchase"
|
||||
try:
|
||||
callback_data = json.loads(order.callback_data)
|
||||
service = self.mcp_service_repository.get_by_id(callback_data["service_id"])
|
||||
if service:
|
||||
info["description"] = service.name
|
||||
except:
|
||||
info["description"] = "-"
|
||||
info["balance"] = order.balance_after
|
||||
elif order.type == TransactionType.DEPOSIT:
|
||||
info["order_type"] = "recharge"
|
||||
if order.status == 1:
|
||||
info["balance"] = order.balance_after
|
||||
else:
|
||||
info["balance"] = "-"
|
||||
info["description"] = order.payment_method
|
||||
else:
|
||||
info["order_type"] = order.type
|
||||
result.append(info)
|
||||
return total, result
|
||||
return total, orders
|
||||
|
||||
def order_list(self, payment_method: str, status: int, start: Optional[datetime] = None, end: Optional[datetime] = None) -> List[UserWalletHistory]:
|
||||
return self.user_wallet_history_repository.order_list(payment_method, status, start, end)
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ class Config:
|
||||
"/api/auth/account/sign",
|
||||
"/api/auth/email/send_captcha",
|
||||
"/api/auth/google/sign",
|
||||
"/api/web/mcp_tags",
|
||||
"/api/web/mcp_services",
|
||||
"/api/web/mcp_service_info",
|
||||
"/api/payment/callback_stripe",
|
||||
|
||||
Reference in new issue
Block a user