Commit 1d832e1a authored by xianyang's avatar xianyang

优化创建账户

parent 00cf4ad1
......@@ -154,12 +154,22 @@ def get_gift_type(unique_tag):
def create_account(param):
"""创建账户"""
income = ','.join(map(str, param.income))
output = ','.join(map(str, param.output))
clearing_dict = {
'description': param.remark, # 描述信息
'unique_tag': param.unique_tag, # 唯一标识
'beneficiary': 'platform-001', # 受益人,也就是唯一标识
'config_key': param.config_key,
'name': param.name,
}
try:
income = ','.join(map(str, param.income))
output = ','.join(map(str, param.output))
sql = f"insert into fi_account(name, unique_tag, config_key, description, uuid, income, output, create_time) " \
f"values('{param.name}', '{param.unique_tag}', '{param.config_key}', '{param.remark}', '{uuid()}', '{income}', '{output}', {get_now_timestamp()});"
account = LinkMysql(env.DB_3YV2).perform_mysql(sql)
result = search(clearing_dict, 'Server.UserExecute.CreateBalanceUser')
if result['data']['result']['status']:
account_uuid = result['data']['result']['data']['uuid']
sql = f"insert into fi_account(name, unique_tag, config_key, description, uuid, income, output, create_time) " \
f"values('{param.name}', '{param.unique_tag}', '{param.config_key}', '{param.remark}', '{account_uuid}', '{income}', '{output}', {get_now_timestamp()});"
account = LinkMysql(env.DB_3YV2).perform_mysql(sql)
except Exception as e:
print(e)
if 'config_key' in str(e):
......
......@@ -12,10 +12,10 @@ class PublicModel(BaseModel):
class AccountCreate(BaseModel):
name: str
remark: Optional[str] = None
unique_tag: str
config_key: Optional[str] = None
name: Optional[str] = ''
remark: Optional[str] = ''
unique_tag: Optional[str] = ''
config_key: Optional[str] = ''
income: Optional[list] = []
output: Optional[list] = []
......
......@@ -17,6 +17,8 @@ router = APIRouter()
@router.post("/create")
def create_account(data: schemas.AccountCreate, token=Depends(login_required)):
"""添加账户"""
if not all([data.name, data.unique_tag, data.config_key]):
return HttpResultResponse(code=500, msg=HttpMessage.MISSING_PARAMETER)
db_info = crud.get_account(data.name)
if db_info:
return HttpResultResponse(code=400, msg=HttpMessage.ACCOUNT_EXIST)
......
......@@ -23,6 +23,8 @@ class HttpMessage(object):
DELETE_LOSE = '删除失败'
LOSE = '操作失败'
MISSING_PARAMETER = "缺少必传参数"
class DecimalEncoder(json.JSONEncoder):
def default(self, res):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment