|
|
@@ -1,31 +1,33 @@
|
|
|
-from sqlalchemy.orm import Session
|
|
|
-from sqlalchemy import or_
|
|
|
-from typing import List, Optional
|
|
|
+from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
from alien_store.db.models.contract_store import ContractStore
|
|
|
|
|
|
+
|
|
|
class ContractRepository:
|
|
|
"""合同数据访问层"""
|
|
|
|
|
|
-
|
|
|
- def __init__(self, db: Session):
|
|
|
+ def __init__(self, db: AsyncSession):
|
|
|
self.db = db
|
|
|
|
|
|
- def get_by_id(self, store_id: int):
|
|
|
+ async def get_by_id(self, store_id: int):
|
|
|
"""根据店铺id查询所有合同"""
|
|
|
- return self.db.query(ContractStore).filter(ContractStore.id == store_id).all()
|
|
|
+ result = await self.db.execute(
|
|
|
+ ContractStore.__table__.select().where(ContractStore.id == store_id)
|
|
|
+ )
|
|
|
+ return result.fetchall()
|
|
|
|
|
|
- def create(self, user_data):
|
|
|
+ async def create(self, user_data):
|
|
|
"""创建未签署合同模板"""
|
|
|
db_templates = ContractStore(
|
|
|
- store_id = user_data.store_id,
|
|
|
- merchant_name = user_data.merchant_name,
|
|
|
- contact_phone = user_data.contact_phone,
|
|
|
- contract_url = user_data.contract_url,
|
|
|
- seal_url = user_data.seal_url
|
|
|
+ store_id=user_data.store_id,
|
|
|
+ merchant_name=user_data.merchant_name,
|
|
|
+ business_segment=user_data.business_segment,
|
|
|
+ contact_phone=user_data.contact_phone,
|
|
|
+ contract_url=user_data.contract_url,
|
|
|
+ seal_url='0.0',
|
|
|
)
|
|
|
self.db.add(db_templates)
|
|
|
- self.db.commit()
|
|
|
- self.db.refresh(db_templates)
|
|
|
+ await self.db.commit()
|
|
|
+ await self.db.refresh(db_templates)
|
|
|
return db_templates
|
|
|
|
|
|
|