Commit 4f235dd2 by Aeolus

update

parent 66ab33b3
......@@ -16,7 +16,6 @@ class AdminAccount(Base):
level = Column(INTEGER(2), nullable=False)
parent_id = Column(INTEGER(10), nullable=False)
draw = Column(INTEGER(1), nullable=False)
rate = Column(INTEGER(1), nullable=False)
status = Column(INTEGER(1), nullable=False)
_password_hash_ = Column(String(255, 'utf8mb4_unicode_ci'))
comment = Column(String(255, 'utf8mb4_unicode_ci'))
......@@ -56,6 +55,7 @@ class AdminBusiness(Base):
user_id = Column(INTEGER(11), nullable=False)
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False)
business_id = Column(INTEGER(11), nullable=False)
rate = Column(INTEGER(1), nullable=False)
status = Column(INTEGER(1), nullable=False, server_default=text("'1'"))
created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
......@@ -429,7 +429,6 @@ class SalePlanProduction(Base):
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
class TallymanAccount(Base):
__tablename__ = 'tallyman_account'
......
......@@ -113,7 +113,7 @@ def add_user():
comment = json_data.get('comment', "")
parent_id = json_data.get("parent_id", admin.id)
draw = json_data.get("draw", 0)
rate = json_data.get("rate", 0)
business_id = json_data["business_id"]
account = AdminAccount.query.filter_by(phone=phone).first()
if account:
......@@ -128,7 +128,6 @@ def add_user():
account.phone = phone
account.level = level
account.draw = draw
account.rate = rate
account.parent_id = parent_id
account.status = 1
account.comment = comment
......@@ -142,9 +141,7 @@ def add_user():
db.session.add(account)
db.session.commit()
business_ids = json_data.get("business_ids", [])
if business_ids:
AdminService.add_or_edit_admin_business(account, business_ids)
AdminService.add_or_edit_admin_business(account, [business_id, ])
return BaseResponse()
......@@ -239,9 +236,6 @@ def edit_user():
db.session.add(admin_info)
db.session.commit()
business_ids = json_data.get("business_ids", [])
if business_ids:
AdminService.add_or_edit_admin_business(admin_info, business_ids)
return BaseResponse()
......
......@@ -13,9 +13,12 @@ import logging
from flask import Blueprint, g, request, jsonify
from models.base_model import db
from models.models import AdminPlace, Place, Business, AdminBusiness
from utils.error_code import NO_PLACE_ERROR, NO_BUSINESS_ERROR
from models.models import AdminPlace, Place, Business, AdminBusiness, AdminAccount
from service.admin_service import AdminService
from utils.error_code import NO_PLACE_ERROR, NO_BUSINESS_ERROR, ADMIN_BUSINESS_NOT_EXIST, OPERATE_LEVEL_ERROR, \
ACCOUNT_NOT_EXISTS_ERROR, RATE_INVALID_ERROR
from utils.my_response import BaseResponse
from utils.mytools import json2obj
logger = logging.getLogger(__name__)
......@@ -68,7 +71,7 @@ def run_business_list():
@business_route.route("add_business", methods=["POST"])
def run_add_place():
def run_add_business():
"""
:return:
......@@ -126,3 +129,143 @@ def get_business_detail():
"status": business_model.status, "business_id": business_id})
else:
return jsonify(NO_BUSINESS_ERROR)
@business_route.route("business_account_list", methods=["POST"])
def get_business_account_list():
"""
:return:
"""
json_data = request.get_json()
page = json_data.get("page", 1)
page_size = json_data.get("pageSize", 10)
keyword = json_data.get("keyword", None)
business_id = json_data.get("business_id", None)
admin = g.user
if g.user.level != 1:
result = AdminBusiness.query.filter_by(business_id=business_id, user_id=admin.id, status=1).first()
if not result:
return jsonify(ADMIN_BUSINESS_NOT_EXIST)
select_sql = """select admin_account.id, admin_account.user_no,admin_account.user_name, admin_account.phone,
admin_account.level, admin_business.rate """
count_sql = "select count(admin_account.id) as total_count"
from_sql = """ from admin_account left join admin_business on admin_account.id = admin_business.user_id """
where_sql = """ where admin_business.business_id = {} and admin_business.status = 1
and admin_account.status = 1
""".format(business_id)
if keyword:
where_sql += """ and CONCAT(admin_account.user_name, admin_account.phone) LIKE '%{keyword}%'
""".format(keyword=keyword)
order_sql = " ORDER BY admin_account.id ASC"
limit_sql = " LIMIT {offset} , {page_size} ".format(offset=(page - 1) * page_size, page_size=page_size)
count_result = db.session.execute(count_sql + from_sql + where_sql).fetchone()
if not count_result:
return BaseResponse(data={"list": [], "page": page, "pageSize": page_size, "total_count": 0})
else:
total_count = count_result.total_count
result = db.session.execute(select_sql + from_sql + where_sql + order_sql + limit_sql).fetchall()
return_data = []
# super_admin = {"user_name": "咻咻公司", "user_id": 0, "user_no": "0",
# "phone": "0", "level": 1, "rate": 0}
for info in result:
# if info.level == 1 or info.level == 4:
# super_admin["rate"] += info.rate
# else:
return_data.append({"user_name": info.user_name, "user_id": info.id, "user_no": info.user_no,
"phone": info.phone, "level": info.level, "rate": info.rate
})
# return_data.append(super_admin)
return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count})
@business_route.route("add_admin_account", methods=["POST"])
def run_add_admin_account():
"""
:return:
"""
json_data = request.get_json()
business_id = json_data["business_id"]
phone = json_data["phone"]
rate = int(json_data["rate"])
admin = g.user
if admin.level not in (1, 2, 4, 5):
return jsonify(OPERATE_LEVEL_ERROR)
if admin.level != 1:
result = AdminBusiness.query.filter_by(business_id=business_id, user_id=admin.id, status=1).first()
if not result:
return jsonify(ADMIN_BUSINESS_NOT_EXIST)
result = AdminService.get_admin_account_list(phone=phone)
if result["total_count"] != 1:
return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR)
user_info = json2obj(result["list"][0])
result = AdminBusiness.query.filter_by(business_id=business_id, status=1).all()
total_rate = 0
for i in result:
total_rate += i.rate
if (total_rate + rate) > 100:
return jsonify(RATE_INVALID_ERROR)
admin_business = AdminBusiness()
admin_business.user_id = user_info.id
admin_business.user_no = user_info.user_no
admin_business.business_id = business_id
admin_business.rate = rate
db.session.add(admin_business)
db.session.commit()
return BaseResponse()
@business_route.route("edit_admin_account", methods=["POST"])
def run_edit_admin_account():
"""
:return:
"""
json_data = request.get_json()
business_id = json_data["business_id"]
user_id = json_data["user_id"]
rate = json_data.get("rate", None)
status = json_data.get("status", None)
admin = g.user
if admin.level not in (1, 2, 4, 5):
return jsonify(OPERATE_LEVEL_ERROR)
if admin.level != 1:
result = AdminBusiness.query.filter_by(business_id=business_id, user_id=admin.id, status=1).first()
if not result:
return jsonify(OPERATE_LEVEL_ERROR)
admin_business = AdminBusiness.query.filter_by(business_id=business_id, user_id=user_id).first()
if not admin_business:
return jsonify(ADMIN_BUSINESS_NOT_EXIST)
if rate:
result = AdminBusiness.query.filter_by(business_id=business_id, status=1).all()
total_rate = 0
for i in result:
if i.user_id != user_id:
total_rate += i.rate
if (total_rate + int(rate)) > 100:
return jsonify(RATE_INVALID_ERROR)
admin_business.rate = rate
if status:
admin_business.status = int(status)
db.session.add(admin_business)
db.session.commit()
return BaseResponse()
......@@ -42,7 +42,7 @@ def run_rent_list():
business_id = json_data.get("business_id", None)
is_pay = json_data.get("is_pay", None)
if g.user.level not in (1, 2, 4):
if g.user.level not in (1, 2, 4, 5):
return jsonify(OPERATE_LEVEL_ERROR)
select_sql = """
SELECT rent.rent_no, rent.machine_no, rent.user_id,rent.place_id,rent.is_pay,
......@@ -126,7 +126,7 @@ def get_rent_detail():
json_data = request.get_json()
rent_no = json_data.get("rent_no", None)
rent_detail_id = json_data.get("rent_detail_id", None)
if g.user.level not in (1, 2, 4):
if g.user.level not in (1, 2, 4, 5):
return jsonify(OPERATE_LEVEL_ERROR)
select_sql = """
......@@ -192,7 +192,7 @@ def get_rent_detail():
@rent_route.route('/rent_money_refund', methods=['GET', 'POST'])
def rent_money_refund_new():
if g.user.level not in (1, 2, 4):
if g.user.level not in (1, 2, 4, 5):
return jsonify(OPERATE_LEVEL_ERROR)
json_data = request.get_json()
......
......@@ -41,7 +41,7 @@ def get_account_list():
@tallyman_route.route('/edit_tallyman_account', methods=['GET', 'POST'])
def run_tallyman_edit_account():
admin = g.user
if g.user.level not in (1, 2, 4):
if g.user.level not in (1, 2, 4, 5):
return jsonify(OPERATE_LEVEL_ERROR)
json_data = request.get_json()
old_phone = json_data['old_phone']
......@@ -79,7 +79,7 @@ def run_tallyman_edit_account():
@tallyman_route.route('/add_tallyman_account', methods=['GET', 'POST'])
def run_add_tallyman_account():
admin = g.user
if g.user.level not in (1, 2, 4):
if g.user.level not in (1, 2, 4, 5):
return jsonify(OPERATE_LEVEL_ERROR)
json_data = request.get_json()
user_name = json_data['user_name'] if 'user_name' in json_data else 'SSW'
......@@ -118,7 +118,7 @@ def run_add_tallyman_account():
@tallyman_route.route('/delete_tallyman_account', methods=['GET', 'POST'])
def run_delete_tallyman_account():
json_data = request.get_json()
if g.user.level not in (1, 2, 4):
if g.user.level not in (1, 2, 4, 5):
return jsonify(OPERATE_LEVEL_ERROR)
phone = json_data['phone']
......@@ -141,7 +141,7 @@ def run_delete_tallyman_account():
@tallyman_route.route('/tallyman_account_detail', methods=["POST"])
def get_tallyman_account_detail():
json_data = request.get_json()
if g.user.level not in (1, 2, 4):
if g.user.level not in (1, 2, 4, 5):
return jsonify(OPERATE_LEVEL_ERROR)
phone = json_data["phone"]
if phone == g.user.phone:
......
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