Commit 197d295b by Aeolus

update

parent d351ecd1
#!usr/bin/env python
#-*- coding:utf-8 _*-
"""
@version:
author:Aeolus
@time: 2021/07/02
@file: __init__.py.py
@function:
@modify:
"""
\ No newline at end of file
#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@version:
author:Aeolus
@time: 2021/07/02
@file: agent_modules.py
@function:
@modify:
"""
from mongodb_collections.base_collection import BaseCollection
class AdminModules(BaseCollection):
def __init__(self):
super().__init__(collection_name="admin_modules")
class Modules(BaseCollection):
def __init__(self):
super().__init__(collection_name="modules")
#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@version:
author:Aeolus
@time: 2021/07/02
@file: base_collection.py
@function:
@modify:
"""
from pymongo import MongoClient
from config.base_config import MONGO_DATABASE_URI
class BaseCollection(object):
def __init__(self, collection_name, db_name="suishenwan", ):
mongodatabase = MongoClient(MONGO_DATABASE_URI).get_database(db_name)
self.collection = mongodatabase.get_collection(collection_name)
def find_one(self, where):
return self.collection.find_one(where)
...@@ -9,11 +9,11 @@ from config.commen_config import LOGIN_TYPE, ACCOUNT_STATUS ...@@ -9,11 +9,11 @@ from config.commen_config import LOGIN_TYPE, ACCOUNT_STATUS
from service.admin_service import AdminService from service.admin_service import AdminService
from utils.error_code import ACCOUNT_AGENT_SPOT_NULL_ERROR, ACCOUNT_NOT_EXISTS_ERROR, \ from utils.error_code import ACCOUNT_AGENT_SPOT_NULL_ERROR, ACCOUNT_NOT_EXISTS_ERROR, \
ACCOUNT_ALREADY_EXISTS_ERROR, ACCOUNT_ALREADY_DELETE_ERROR, AGNET_MODULES_ERROR, MODULES_NOT_EXISTS_ERROR, \ ACCOUNT_ALREADY_EXISTS_ERROR, ACCOUNT_ALREADY_DELETE_ERROR, AGNET_MODULES_ERROR, MODULES_NOT_EXISTS_ERROR, \
OPERATE_LEVEL_ERROR OPERATE_LEVEL_ERROR, Param_Invalid_Error
from utils.error_code import PHONE_NOT_NULL_ERROR, PHONE_NOT_VALID_ERROR, TOKEN_NOT_VALID_ERROR, \ from utils.error_code import PHONE_NOT_NULL_ERROR, PHONE_NOT_VALID_ERROR, TOKEN_NOT_VALID_ERROR, \
VERIFICATION_CODE_INVALID_ERROR, VERIFICATION_CODE_ERROR, PASSWORD_ERROR VERIFICATION_CODE_INVALID_ERROR, VERIFICATION_CODE_ERROR, PASSWORD_ERROR
from models.base_model import db from models.base_model import db
from models.models import AdminAccount, AdminLoginRecord, AdminMachine from models.models import AdminAccount, AdminLoginRecord, AdminMachine, AdminPlace, Place
from utils.jwt_util import verify_jwt, generate_jwt from utils.jwt_util import verify_jwt, generate_jwt
from utils.my_response import BaseResponse from utils.my_response import BaseResponse
from service.sms_service import SMSService from service.sms_service import SMSService
...@@ -206,22 +206,6 @@ def get_account_detail(): ...@@ -206,22 +206,6 @@ def get_account_detail():
user_info["level"] = agent_info.level user_info["level"] = agent_info.level
user_info["status"] = ACCOUNT_STATUS['on_use'] user_info["status"] = ACCOUNT_STATUS['on_use']
user_info["comment"] = agent_info.comment user_info["comment"] = agent_info.comment
agent_spot_list = AgentSpot.query.filter_by(agent_no=agent_info.id, status=1).all()
if agent_spot_list:
spot_no_list = [i.spot_no for i in agent_spot_list]
else:
user_info["spot_list"] = []
return BaseResponse(data=user_info)
spot_list = db.session.query(Spot).filter(Spot.id.in_(spot_no_list)).all()
if spot_list:
spot_data_list = [
{"spot_name": i.spotname, "spot_id": i.id, "business_id": i.business_id, "spot_address": i.address} for i in
spot_list]
else:
spot_data_list = []
user_info["spot_list"] = spot_data_list
return BaseResponse(data=user_info) return BaseResponse(data=user_info)
...@@ -235,7 +219,6 @@ def edit_user(): ...@@ -235,7 +219,6 @@ def edit_user():
comment = json_data['comment'] if 'comment' in json_data else '' comment = json_data['comment'] if 'comment' in json_data else ''
level = json_data['level'] if 'level' in json_data else '' level = json_data['level'] if 'level' in json_data else ''
status = json_data['status'] if 'status' in json_data else '' status = json_data['status'] if 'status' in json_data else ''
spot_list = json_data['spot_list'] if 'spot_list' in json_data else []
if not old_phone: if not old_phone:
return BaseResponse(error_code=-1, error_message='old phone is null') return BaseResponse(error_code=-1, error_message='old phone is null')
...@@ -245,51 +228,22 @@ def edit_user(): ...@@ -245,51 +228,22 @@ def edit_user():
if not status: if not status:
return BaseResponse(**Param_Invalid_Error) return BaseResponse(**Param_Invalid_Error)
result = Helper.check_phone(new_phone) admin_info = AdminAccount.query.filter_by(phone=old_phone).first()
if not result: if not admin_info:
return BaseResponse(**PHONE_NOT_VALID_ERROR)
if not spot_list:
return BaseResponse(**ACCOUNT_AGENT_SPOT_NULL_ERROR)
agent_info = AdminAccount.query.filter_by(phone=old_phone).first()
if not agent_info:
return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR) return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR)
agent_info.user_name = user_name admin_info.user_name = user_name
agent_info.phone = new_phone admin_info.phone = new_phone
agent_info.status = status admin_info.status = status
agent_info.comment = comment admin_info.comment = comment
if level: if level:
agent_info.level = int(level) admin_info.level = int(level)
if password: if password:
salt = AgentService.gene_salt() admin_info.password = password
agent_info.salt_pwd = salt
agent_info.password = AgentService.gene_pwd(password, salt)
db.session.add(agent_info)
agent_spot_info = AgentSpot.query.filter_by(agent_no=agent_info.id).all()
for info in agent_spot_info:
info.status = ACCOUNT_STATUS['delete']
db.session.add(info)
for i in spot_list:
cur_spot_info = AgentSpot.query.filter_by(agent_no=agent_info.id, spot_no=i).first()
if not cur_spot_info:
cur_agent_spot = AgentSpot()
cur_agent_spot.agent_no = agent_info.id
cur_agent_spot.spot_no = i
cur_agent_spot.status = ACCOUNT_STATUS['on_use']
cur_agent_spot.created_at = datetime.datetime.now()
cur_agent_spot.updated_at = datetime.datetime.now()
db.session.add(cur_agent_spot)
else:
cur_spot_info.status = ACCOUNT_STATUS['on_use']
db.session.add(cur_spot_info)
db.session.add(admin_info)
db.session.commit() db.session.commit()
return BaseResponse() return BaseResponse()
...@@ -301,17 +255,12 @@ def delete_user(): ...@@ -301,17 +255,12 @@ def delete_user():
if not phone: if not phone:
return BaseResponse(**PHONE_NOT_NULL_ERROR) return BaseResponse(**PHONE_NOT_NULL_ERROR)
agent_info = AdminAccount.query.filter_by(phone=phone).first() admin_info = AdminAccount.query.filter_by(phone=phone).first()
if not agent_info: if not admin_info:
return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR) return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR)
agent_spot_info = AgentSpot.query.filter_by(agent_no=agent_info.id).all() admin_info.status = ACCOUNT_STATUS['delete']
for info in agent_spot_info: db.session.add(admin_info)
info.status = ACCOUNT_STATUS['delete']
db.session.add(info)
agent_info.status = ACCOUNT_STATUS['delete']
db.session.add(agent_info)
db.session.commit() db.session.commit()
return BaseResponse() return BaseResponse()
......
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