Commit 5a4f9857 by Aeolus

Merge remote-tracking branch 'origin/master'

parents 8065bc35 9aa1cb99
[uWSGI] getting INI configuration from /data/www/automat/automat_app_uwsgi.ini
*** Starting uWSGI 2.0.20 (64bit) on [Thu Jan 20 12:05:17 2022] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-44) on 20 January 2022 04:01:54
os: Linux-3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018
nodename: iZ2ze4tbzlpw7nv35r9zudZ
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /data/www/automat
detected binary path: /root/.pyenv/versions/3.7.5/envs/env4automat/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
chdir() to /data/www/automat
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 30125
your memory page size is 4096 bytes
detected max file descriptor number: 65535
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address 127.0.0.1:8893 fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.7.5 (default, Jan 20 2022, 11:57:50) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
Python main interpreter initialized at 0xc137f0
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 584448 bytes (570 KB) for 32 cores
*** Operational MODE: preforking+threaded ***
2022-01-20 12:05:17 - automat_app.py - <module> -[line:13] - INFO - request_id=None: run server
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xc137f0 pid: 1182 (default app)
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (pid: 1182, cores: 8)
spawned uWSGI worker 2 (pid: 1185, cores: 8)
spawned uWSGI worker 3 (pid: 1189, cores: 8)
spawned uWSGI worker 4 (pid: 1193, cores: 8)
...@@ -22,9 +22,9 @@ XX_PAY_CONFIG = { ...@@ -22,9 +22,9 @@ XX_PAY_CONFIG = {
"pay_key": os.getenv("XX_PAY_KEY"), "pay_key": os.getenv("XX_PAY_KEY"),
"cert_path": os.getenv("XX_PAY_SSL_CERT_PATH"), "cert_path": os.getenv("XX_PAY_SSL_CERT_PATH"),
"key_path": os.getenv("XX_PAY_SSL_KEY_PATH"), "key_path": os.getenv("XX_PAY_SSL_KEY_PATH"),
'callback_url': '/rent/wx_pay_callback', 'callback_url': '/automat/rent/wx_pay_callback',
'refund_callback_url': '/rent/refund_callback', 'refund_callback_url': '/automat/rent/refund_callback',
'domain': 'https://automat.ssw-htzn.com/sukang' 'domain': os.getenv("DOMAIN")
} }
pay_config_list = ["", "xx"] pay_config_list = ["", "xx"]
......
...@@ -116,6 +116,7 @@ def run_create_machine_no(): ...@@ -116,6 +116,7 @@ def run_create_machine_no():
machine_model.machine_no = machine_no machine_model.machine_no = machine_no
machine_model.mac = mac machine_model.mac = mac
machine_model.hatch_number = hatch_number machine_model.hatch_number = hatch_number
machine_model.status = 1
db.session.add(machine_model) db.session.add(machine_model)
db.session.commit() db.session.commit()
return BaseResponse(data={"machine_no": machine_no}) return BaseResponse(data={"machine_no": machine_no})
...@@ -130,7 +131,7 @@ def run_bind_serial_num(): ...@@ -130,7 +131,7 @@ def run_bind_serial_num():
machine = Machine.query.filter_by(machine_no=machine_no).first() machine = Machine.query.filter_by(machine_no=machine_no).first()
if not machine: if not machine:
return jsonify(MACHINE_NOT_EXIST_ERROR) return jsonify(MACHINE_NOT_EXIST_ERROR)
machine.device_id = serial_num machine.qrcode_no = serial_num
db.session.add(machine) db.session.add(machine)
db.session.commit() db.session.commit()
return BaseResponse(data={"machine_no": machine_no, "serial_num": serial_num}) return BaseResponse(data={"machine_no": machine_no, "serial_num": serial_num})
...@@ -42,7 +42,8 @@ def get_discount_info(): ...@@ -42,7 +42,8 @@ def get_discount_info():
return jsonify(MACHINE_NOT_EXIST_ERROR) return jsonify(MACHINE_NOT_EXIST_ERROR)
is_used = 1 is_used = 1
if machine.discounts_id == 1: if machine.discounts_id == 1:
rent = Rent.query.filter(db.cast(Rent.created_at, db.DATE) == db.cast(datetime.datetime.now(), db.DATE)).first() rent = Rent.query.filter(db.cast(Rent.created_at, db.DATE) == db.cast(datetime.datetime.now(), db.DATE),
Rent.user_id == g.user.id).first()
if rent: if rent:
is_used = 1 is_used = 1
else: else:
...@@ -67,7 +68,8 @@ def create_rent(): ...@@ -67,7 +68,8 @@ def create_rent():
return jsonify(MACHINE_NOT_EXIST_ERROR) return jsonify(MACHINE_NOT_EXIST_ERROR)
if machine.discounts_id == 1: if machine.discounts_id == 1:
rent = Rent.query.filter(db.cast(Rent.created_at, db.DATE) == db.cast(datetime.datetime.now(), db.DATE)).first() rent = Rent.query.filter(db.cast(Rent.created_at, db.DATE) == db.cast(datetime.datetime.now(), db.DATE),
Rent.user_id == g.user.id).first()
if not rent: if not rent:
if len(productions) != 1: if len(productions) != 1:
return jsonify(HATCH_COUNT_ERROR) return jsonify(HATCH_COUNT_ERROR)
...@@ -243,11 +245,12 @@ def wx_pay_callback(): ...@@ -243,11 +245,12 @@ def wx_pay_callback():
rent.user_id = user_id rent.user_id = user_id
rent.place_id = machine.place_id rent.place_id = machine.place_id
rent.total = int(callback_data["total_fee"]) rent.total = int(callback_data["total_fee"])
rent.real_total = int(callback_data["total_fee"])
rent.add_time = datetime.datetime.now() rent.add_time = datetime.datetime.now()
rent.is_pay = 1 rent.is_pay = 1
rent.pay_time = datetime.datetime.strptime(callback_data["time_end"], "%Y%m%d%H%M%S") rent.pay_time = datetime.datetime.strptime(callback_data["time_end"], "%Y%m%d%H%M%S")
rent.rent_type = type rent.rent_type = type
rent.mch_platform = platform rent.mch_platform = rent_data["platform"]
prepay_id = redis_client.get(USER_RENT_PREPAY_ID + str(user_id) + rent_no) prepay_id = redis_client.get(USER_RENT_PREPAY_ID + str(user_id) + rent_no)
if prepay_id: if prepay_id:
rent.prepay_id = prepay_id rent.prepay_id = prepay_id
...@@ -271,6 +274,7 @@ def wx_pay_callback(): ...@@ -271,6 +274,7 @@ def wx_pay_callback():
rent_detail.production_type_id = i.production_type_id rent_detail.production_type_id = i.production_type_id
rent_detail.production_type_name = i.production_type_name rent_detail.production_type_name = i.production_type_name
rent_detail.price = i.price rent_detail.price = i.price
rent_detail.original_price = i.original_price
rent_detail.total = i.price * open_hatchs[str(i.hatch_no)] rent_detail.total = i.price * open_hatchs[str(i.hatch_no)]
rent_detail.rent_count = open_hatchs[str(i.hatch_no)] rent_detail.rent_count = open_hatchs[str(i.hatch_no)]
rent_detail.img = i.img rent_detail.img = i.img
...@@ -278,7 +282,7 @@ def wx_pay_callback(): ...@@ -278,7 +282,7 @@ def wx_pay_callback():
rent_detail.content = i.content rent_detail.content = i.content
rent_detail.summary = i.summary rent_detail.summary = i.summary
db.session.add(rent_detail) db.session.add(rent_detail)
total_fee += rent_detail.price total_fee += rent_detail.total
if total_fee != int(callback_data['total_fee']): if total_fee != int(callback_data['total_fee']):
return xmltodict.unparse({'xml': error_data}, pretty=True), header return xmltodict.unparse({'xml': error_data}, pretty=True), header
...@@ -287,6 +291,7 @@ def wx_pay_callback(): ...@@ -287,6 +291,7 @@ def wx_pay_callback():
db.session.commit() db.session.commit()
except Exception as e: except Exception as e:
logger.info(e)
return xmltodict.unparse({'xml': error_data}, pretty=True), header return xmltodict.unparse({'xml': error_data}, pretty=True), header
return xmltodict.unparse({'xml': response_data}, pretty=True), header return xmltodict.unparse({'xml': response_data}, pretty=True), header
...@@ -363,7 +368,7 @@ def get_user_detail_record(): ...@@ -363,7 +368,7 @@ def get_user_detail_record():
tmp_data["hatch_no"] = i.hatch_no tmp_data["hatch_no"] = i.hatch_no
tmp_data["production_id"] = i.production_id tmp_data["production_id"] = i.production_id
tmp_data["is_take"] = i.is_take tmp_data["is_take"] = i.is_take
tmp_data["name"] = i.name tmp_data["name"] = i.production_name
tmp_data["title"] = i.title tmp_data["title"] = i.title
tmp_data["brand_id"] = i.brand_id tmp_data["brand_id"] = i.brand_id
tmp_data["brand_name"] = i.brand_name tmp_data["brand_name"] = i.brand_name
...@@ -402,7 +407,7 @@ def get_user_rent_detail(): ...@@ -402,7 +407,7 @@ def get_user_rent_detail():
tmp_data["hatch_no"] = i.hatch_no tmp_data["hatch_no"] = i.hatch_no
tmp_data["production_id"] = i.production_id tmp_data["production_id"] = i.production_id
tmp_data["is_take"] = i.is_take tmp_data["is_take"] = i.is_take
tmp_data["name"] = i.name tmp_data["name"] = i.production_name
tmp_data["title"] = i.title tmp_data["title"] = i.title
tmp_data["price"] = i.price tmp_data["price"] = i.price
tmp_data["img"] = i.img tmp_data["img"] = i.img
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import datetime import datetime
import logging import logging
import time import time
...@@ -238,7 +238,7 @@ def get_tallyman_hatch_list(): ...@@ -238,7 +238,7 @@ def get_tallyman_hatch_list():
"machine_no": i.machine_no, "machine_no": i.machine_no,
"hatch_no": i.hatch_no, "hatch_no": i.hatch_no,
"production_id": i.production_id, "production_id": i.production_id,
"name": i.name, "name": i.production_name,
"status": i.status, "status": i.status,
"left_count": i.left_count, "left_count": i.left_count,
"total_count": i.total_count "total_count": i.total_count
...@@ -281,7 +281,7 @@ def run_tally_start(): ...@@ -281,7 +281,7 @@ def run_tally_start():
tally_record.machine_no = i.machine_no tally_record.machine_no = i.machine_no
tally_record.hatch_no = i.hatch_no tally_record.hatch_no = i.hatch_no
tally_record.production_id = i.production_id tally_record.production_id = i.production_id
tally_record.production_name = i.name tally_record.production_name = i.production_name
tally_record.tally_count = i.total_count - i.left_count if i.left_count > 0 else i.total_count tally_record.tally_count = i.total_count - i.left_count if i.left_count > 0 else i.total_count
tally_record.status = 1 tally_record.status = 1
db.session.add(tally_record) db.session.add(tally_record)
...@@ -340,13 +340,12 @@ def get_tally_report(): ...@@ -340,13 +340,12 @@ def get_tally_report():
machine_info = TallymanService.get_machine_info(g.user, machine_no) machine_info = TallymanService.get_machine_info(g.user, machine_no)
if not machine_info: if not machine_info:
return jsonify(MACHINE_NOT_EXIST_ERROR) return jsonify(MACHINE_NOT_EXIST_ERROR)
empty_number = int(machine_info["empty_number"]) empty_number = machine_info["empty_number"]
over_number = db.session.query(func.sum(TallyRecord.tally_count)).filter(TallyRecord.user_no == g.user.user_no, over_number = db.session.query(func.sum(TallyRecord.tally_count)).filter(TallyRecord.user_no == g.user.user_no,
TallyRecord.machine_no == machine_no, TallyRecord.machine_no == machine_no,
TallyRecord.status == 2).scalar() TallyRecord.status == 2).scalar()
return BaseResponse(data={"empty_number": empty_number, "over_number": over_number}) return BaseResponse(data={"empty_number": empty_number, "over_number": over_number if over_number else 0})
@tallyman_route.route('machine_activate', methods=["post"]) @tallyman_route.route('machine_activate', methods=["post"])
......
...@@ -134,7 +134,7 @@ def add_user(): ...@@ -134,7 +134,7 @@ def add_user():
account.comment = comment account.comment = comment
account.created_at = datetime.datetime.now() account.created_at = datetime.datetime.now()
account.updated_at = datetime.datetime.now() account.updated_at = datetime.datetime.now()
if password: if password is not None:
account.password = password account.password = password
db.session.add(account) db.session.add(account)
db.session.commit() db.session.commit()
...@@ -196,13 +196,13 @@ def get_account_detail(): ...@@ -196,13 +196,13 @@ def get_account_detail():
@admin_route.route('/edit_account', methods=['GET', 'POST']) @admin_route.route('/edit_account', methods=['GET', 'POST'])
def edit_user(): def edit_user():
json_data = request.get_json() json_data = request.get_json()
old_phone = json_data['old_phone'] if 'old_phone' in json_data else '' old_phone = json_data['old_phone'] if 'old_phone' in json_data else None
new_phone = json_data['new_phone'] if 'new_phone' in json_data else '' new_phone = json_data['new_phone'] if 'new_phone' in json_data else None
user_name = json_data['user_name'] if 'user_name' in json_data else 'XX' user_name = json_data['user_name'] if 'user_name' in json_data else None
password = json_data['password'] if 'password' in json_data else '' password = json_data['password'] if 'password' in json_data else None
comment = json_data['comment'] if 'comment' in json_data else '' comment = json_data['comment'] if 'comment' in json_data else None
level = json_data['level'] if 'level' in json_data else '' level = json_data['level'] if 'level' in json_data else None
status = json_data['status'] if 'status' in json_data else '' status = json_data['status'] if 'status' in json_data else None
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')
...@@ -224,16 +224,16 @@ def edit_user(): ...@@ -224,16 +224,16 @@ def edit_user():
return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR) return BaseResponse(**ACCOUNT_NOT_EXISTS_ERROR)
if level and level > g.user.level: if level and level > g.user.level:
admin_info.level = level admin_info.level = level
if status: if status is not None:
admin_info.status = status admin_info.status = status
if comment: if comment is not None:
admin_info.comment = comment admin_info.comment = comment
if user_name: if user_name is not None:
admin_info.user_name = user_name admin_info.user_name = user_name
if new_phone: if new_phone is not None:
admin_info.phone = new_phone admin_info.phone = new_phone
if password: if password is not None:
admin_info.password = password admin_info.password = password
db.session.add(admin_info) db.session.add(admin_info)
...@@ -248,7 +248,7 @@ def edit_user(): ...@@ -248,7 +248,7 @@ def edit_user():
@admin_route.route('/delete_account', methods=['GET', 'POST']) @admin_route.route('/delete_account', methods=['GET', 'POST'])
def delete_user(): def delete_user():
json_data = request.get_json() json_data = request.get_json()
phone = json_data['phone'] if 'phone' in json_data else '' phone = json_data['phone'] if 'phone' in json_data else None
if not phone: if not phone:
return BaseResponse(**PHONE_NOT_NULL_ERROR) return BaseResponse(**PHONE_NOT_NULL_ERROR)
......
...@@ -102,9 +102,9 @@ def run_edit_business(): ...@@ -102,9 +102,9 @@ def run_edit_business():
status = json_data.get("status", None) status = json_data.get("status", None)
business_model = Business.query.filter_by(id=business_id).first() business_model = Business.query.filter_by(id=business_id).first()
if business_name: if business_name is not None:
business_model.business_name = business_name business_model.business_name = business_name
if status: if status is not None:
business_model.status = status business_model.status = status
db.session.add(business_model) db.session.add(business_model)
db.session.commit() db.session.commit()
......
...@@ -45,11 +45,14 @@ def run_hatch_list(): ...@@ -45,11 +45,14 @@ def run_hatch_list():
""" """
count_sql = "select count(hatch.id) as total_count" count_sql = "select count(hatch.id) as total_count"
from_sql = """ from hatch from_sql = """ from hatch
where hatch.machine_no in ( select machine_no from admin_machine where
admin_machine.user_id = {user_id} and admin_machine.status = 1) """
""".format(user_id=admin.id) if g.user.level == 1:
where_sql = " where 0=0"
where_sql = " " else:
where_sql = """ where hatch.machine_no in ( select machine_no from admin_machine where
admin_machine.user_id = '{user_id}' and admin_machine.status = 1)
""".format(user_id=admin.id)
if keyword: if keyword:
where_sql += """ where_sql += """
and CONCAT(hatch.machine_no,ifnull(hatch.brand_name,''), ifnull(hatch.production_type_name,''), and CONCAT(hatch.machine_no,ifnull(hatch.brand_name,''), ifnull(hatch.production_type_name,''),
...@@ -99,9 +102,10 @@ def run_add_machine(): ...@@ -99,9 +102,10 @@ def run_add_machine():
""" """
json_data = request.get_json() json_data = request.get_json()
machine_no = json_data["machine_no"] machine_no = json_data["machine_no"]
admin_machine = AdminMachine.query.filter_by(machine_no=machine_no, user_id=g.user.id, status=1).first() if g.user.level != 1:
if not admin_machine: admin_machine = AdminMachine.query.filter_by(machine_no=machine_no, user_id=g.user.id, status=1).first()
return jsonify(MACHINE_NOT_EXIST_ERROR) if not admin_machine:
return jsonify(MACHINE_NOT_EXIST_ERROR)
machine = Machine.query.filter(Machine.machine_no == machine_no, Machine.status != -1).first() machine = Machine.query.filter(Machine.machine_no == machine_no, Machine.status != -1).first()
if not machine: if not machine:
return jsonify(MACHINE_NOT_EXIST_ERROR) return jsonify(MACHINE_NOT_EXIST_ERROR)
...@@ -178,10 +182,10 @@ def run_edit_hatch(): ...@@ -178,10 +182,10 @@ def run_edit_hatch():
hatch = Hatch.query.filter_by(id=hatch_id).first() hatch = Hatch.query.filter_by(id=hatch_id).first()
if not hatch: if not hatch:
return jsonify(HATCH_NOT_EXIST_ERROR) return jsonify(HATCH_NOT_EXIST_ERROR)
if g.user.level != 1:
admin_machine = AdminMachine.query.filter_by(machine_no=hatch.machine_no, user_id=g.user.id, status=1).first() admin_machine = AdminMachine.query.filter_by(machine_no=hatch.machine_no, user_id=g.user.id, status=1).first()
if not admin_machine: if not admin_machine:
return jsonify(MACHINE_NOT_EXIST_ERROR) return jsonify(MACHINE_NOT_EXIST_ERROR)
machine = Machine.query.filter(Machine.machine_no == hatch.machine_no, Machine.status != -1).first() machine = Machine.query.filter(Machine.machine_no == hatch.machine_no, Machine.status != -1).first()
if not machine: if not machine:
return jsonify(MACHINE_NOT_EXIST_ERROR) return jsonify(MACHINE_NOT_EXIST_ERROR)
...@@ -208,44 +212,44 @@ def run_edit_hatch(): ...@@ -208,44 +212,44 @@ def run_edit_hatch():
left_count = json_data.get("left_count", None) left_count = json_data.get("left_count", None)
total_count = json_data.get("total_count", None) total_count = json_data.get("total_count", None)
if production_id: if production_id is not None:
hatch.production_id = production_id hatch.production_id = production_id
hatch.production_name = production_name hatch.production_name = production_name
if title: if title is not None:
hatch.title = title hatch.title = title
if brand_id: if brand_id is not None:
hatch.brand_id = brand_id hatch.brand_id = brand_id
hatch.brand_name = brand_name hatch.brand_name = brand_name
if production_type_id: if production_type_id is not None:
hatch.production_type_id = production_type_id hatch.production_type_id = production_type_id
hatch.production_type_name = production_type_name hatch.production_type_name = production_type_name
if price: if price is not None:
hatch.price = price hatch.price = price
if original_price: if original_price is not None:
hatch.original_price = original_price hatch.original_price = original_price
if weight: if weight is not None:
hatch.weight = weight hatch.weight = weight
if weight_unit: if weight_unit is not None:
hatch.weight_unit = weight_unit hatch.weight_unit = weight_unit
if weight_error: if weight_error is not None:
hatch.weight_error = weight_error hatch.weight_error = weight_error
if expiration_date: if expiration_date is not None:
hatch.expiration_date = expiration_date hatch.expiration_date = expiration_date
if expiration_date_unit: if expiration_date_unit is not None:
hatch.expiration_date_unit = expiration_date_unit hatch.expiration_date_unit = expiration_date_unit
if is_expiration_date: if is_expiration_date is not None:
hatch.is_expiration_date = is_expiration_date hatch.is_expiration_date = is_expiration_date
if img: if img is not None:
hatch.img = img hatch.img = img
if tags: if tags is not None:
hatch.tags = tags hatch.tags = tags
if content: if content is not None:
hatch.content = content hatch.content = content
if summary: if summary is not None:
hatch.summary = summary hatch.summary = summary
if left_count: if left_count is not None:
hatch.left_count = left_count hatch.left_count = left_count
if total_count: if total_count is not None:
hatch.total_count = total_count hatch.total_count = total_count
db.session.add(hatch) db.session.add(hatch)
db.session.commit() db.session.commit()
......
...@@ -45,12 +45,14 @@ def run_machine_list(): ...@@ -45,12 +45,14 @@ def run_machine_list():
from_sql = """ from machine from_sql = """ from machine
left join place on machine.place_id = place.id left join place on machine.place_id = place.id
left join business on machine.business_id = business.id left join business on machine.business_id = business.id
where machine.machine_no in ( select machine_no from admin_machine where
admin_machine.user_id = {user_id} and admin_machine.status = 1) """
""".format(user_id=admin.id) if g.user.level == 1:
where_sql = " where 0=0 "
where_sql = " " else:
if keyword: where_sql = """ where machine.machine_no in ( select machine_no from admin_machine where
admin_machine.user_id = '{user_id}' and admin_machine.status = 1)""".format(user_id=admin.id)
if keyword is not None:
where_sql += """ where_sql += """
and CONCAT(machine.machine_no,ifnull(machine.qrcode_no,'')) LIKE '%{keyword}%' and CONCAT(machine.machine_no,ifnull(machine.qrcode_no,'')) LIKE '%{keyword}%'
...@@ -87,16 +89,17 @@ def run_add_machine(): ...@@ -87,16 +89,17 @@ def run_add_machine():
:return: :return:
""" """
json_data = request.get_json() json_data = request.get_json()
machine_no = json_data["machine_no"] machine_no = json_data.get("machine_no", None)
address = json_data.get("address", None) address = json_data.get("address", None)
device_id = json_data.get("device_id", None) device_id = json_data.get("device_id", None)
qrcode_no = json_data.get("qrcode_no", None) qrcode_no = json_data.get("qrcode_no", None)
mac = json_data.get("mac", None) mac = json_data["mac"]
power = json_data.get("power", None) power = json_data.get("power", None)
hatch_number = json_data.get("hatch_number", None) hatch_number = json_data.get("hatch_number", None)
place_id = json_data.get("place_id", None) place_id = json_data.get("place_id", None)
type = json_data.get("type", 1) type = json_data.get("type", 1)
discounts_id = json_data.get("type", 0) discounts_id = json_data.get("discounts_id", 0)
status = int(json_data.get("status", 1))
machine_model = Machine() machine_model = Machine()
machine_model.machine_no = machine_no machine_model.machine_no = machine_no
...@@ -110,6 +113,7 @@ def run_add_machine(): ...@@ -110,6 +113,7 @@ def run_add_machine():
machine_model.hatch_number = hatch_number machine_model.hatch_number = hatch_number
machine_model.type = type machine_model.type = type
machine_model.discounts_id = discounts_id machine_model.discounts_id = discounts_id
machine_model.status = status
db.session.add(machine_model) db.session.add(machine_model)
admin_machine = AdminMachine() admin_machine = AdminMachine()
...@@ -145,25 +149,25 @@ def run_edit_machine(): ...@@ -145,25 +149,25 @@ def run_edit_machine():
if not machine_model: if not machine_model:
return jsonify(MACHINE_NOT_EXIST_ERROR) return jsonify(MACHINE_NOT_EXIST_ERROR)
if device_id: if device_id is not None:
machine_model.device_id = device_id machine_model.device_id = device_id
if qrcode_no: if qrcode_no is not None:
machine_model.qrcode_no = qrcode_no machine_model.qrcode_no = qrcode_no
if mac: if mac is not None:
machine_model.mac = mac machine_model.mac = mac
if power: if power is not None:
machine_model.power = power machine_model.power = power
if place_id: if place_id is not None:
machine_model.place_id = place_id machine_model.place_id = place_id
if address: if address is not None:
machine_model.address = address machine_model.address = address
if hatch_number: if hatch_number is not None:
machine_model.hatch_number = hatch_number machine_model.hatch_number = hatch_number
if type: if type is not None:
machine_model.type = type machine_model.type = type
if status: if status is not None:
machine_model.status = status machine_model.status = status
if discounts_id: if discounts_id is not None:
machine_model.discounts_id = discounts_id machine_model.discounts_id = discounts_id
db.session.add(machine_model) db.session.add(machine_model)
...@@ -188,11 +192,15 @@ def get_machine_detail(): ...@@ -188,11 +192,15 @@ def get_machine_detail():
from_sql = """ from machine from_sql = """ from machine
left join place on machine.place_id = place.id left join place on machine.place_id = place.id
left join business on machine.business_id = business.id left join business on machine.business_id = business.id
where machine.machine_no in ( select machine_no from admin_machine where """
admin_machine.user_id = {user_id} and admin_machine.status = 1)
""".format(user_id=admin.id)
where_sql = " and machine.machine_no = {}".format(machine_no) if g.user.level == 1:
where_sql = " where 0=0 "
else:
where_sql = """ where machine.machine_no in ( select machine_no from admin_machine where
admin_machine.user_id = '{user_id}' and admin_machine.status = 1) """.format(user_id=admin.id)
where_sql += " and machine.machine_no = '{}'".format(machine_no)
result = db.session.execute(select_sql + from_sql + where_sql).fetchall() result = db.session.execute(select_sql + from_sql + where_sql).fetchall()
if not result or len(result) != 1: if not result or len(result) != 1:
...@@ -230,9 +238,10 @@ def run_distribute_machine(): ...@@ -230,9 +238,10 @@ def run_distribute_machine():
return_machine_no = [] return_machine_no = []
for i in machine_nos: for i in machine_nos:
admin_machines = AdminMachine.query.filter_by(user_id=g.user.id, machine_no=i, status=1).first() if g.user.level != 1:
if not admin_machines: admin_machines = AdminMachine.query.filter_by(user_id=g.user.id, machine_no=i, status=1).first()
continue if not admin_machines:
continue
machine = Machine.query.filter_by(machine_no=i).first() machine = Machine.query.filter_by(machine_no=i).first()
if not machine: if not machine:
continue continue
...@@ -267,9 +276,10 @@ def run_distribute_tallyman_machine(): ...@@ -267,9 +276,10 @@ def run_distribute_tallyman_machine():
return_machine_no = [] return_machine_no = []
for i in machine_nos: for i in machine_nos:
admin_machines = AdminMachine.query.filter_by(user_id=g.user.id, machine_no=i, status=1).first() if g.user.level != 1:
if not admin_machines: admin_machines = AdminMachine.query.filter_by(user_id=g.user.id, machine_no=i, status=1).first()
continue if not admin_machines:
continue
machine = Machine.query.filter_by(machine_no=i).first() machine = Machine.query.filter_by(machine_no=i).first()
if not machine: if not machine:
continue continue
......
...@@ -36,10 +36,14 @@ def run_place_list(): ...@@ -36,10 +36,14 @@ def run_place_list():
admin = g.user admin = g.user
select_sql = "select place.place_name, place.address, place.parent_id,place.status, place.id " select_sql = "select place.place_name, place.address, place.parent_id,place.status, place.id "
count_sql = "select count(place.id) as total_count" count_sql = "select count(place.id) as total_count"
from_sql = " from place where place.id in ( select place_id from admin_place where admin_place.user_id = {} and admin_place.status = 1) ".format( from_sql = " from place"
admin.id)
if g.user.level == 1:
where_sql = " where 0=0 "
else:
where_sql = """ where place.id in ( select place_id from admin_place where
admin_place.user_id = '{}' and admin_place.status = 1) """.format(admin.id)
where_sql = " "
if keyword: if keyword:
where_sql += """ where_sql += """
and CONCAT(place.place_name, place.address) LIKE '%{keyword}%' and CONCAT(place.place_name, place.address) LIKE '%{keyword}%'
...@@ -107,10 +111,14 @@ def run_edit_place(): ...@@ -107,10 +111,14 @@ def run_edit_place():
status = json_data.get("status", None) status = json_data.get("status", None)
place_model = Place.query.filter_by(id=id).first() place_model = Place.query.filter_by(id=id).first()
place_model.place_name = place_name if place_name is not None:
place_model.address = address place_model.place_name = place_name
place_model.parent_id = parent_id if address is not None:
place_model.status = status place_model.address = address
if parent_id is not None:
place_model.parent_id = parent_id
if status is not None:
place_model.status = status
db.session.add(place_model) db.session.add(place_model)
db.session.commit() db.session.commit()
return BaseResponse() return BaseResponse()
...@@ -126,7 +134,7 @@ def get_place_detail(): ...@@ -126,7 +134,7 @@ def get_place_detail():
id = json_data["id"] id = json_data["id"]
place_model = Place.query.filter_by(id=id).first() place_model = Place.query.filter_by(id=id).first()
if place_model: if place_model is not None:
return BaseResponse(data={"place_name": place_model.place_name, return BaseResponse(data={"place_name": place_model.place_name,
"address": place_model.address, "address": place_model.address,
"parent_id": place_model.parent_id, "parent_id": place_model.parent_id,
......
...@@ -66,21 +66,21 @@ def run_rent_list(): ...@@ -66,21 +66,21 @@ def run_rent_list():
""" """
where_sql = " WHERE 0=0 " where_sql = " WHERE 0=0 "
if keyword: if keyword is not None:
where_sql += """ where_sql += """
and CONCAT(rent.rent_no, and CONCAT(rent.rent_no,
wx_user.phone) LIKE '%{keyword}%' wx_user.phone) LIKE '%{keyword}%'
""".format(keyword=keyword) """.format(keyword=keyword)
if start_date: if start_date is not None:
where_sql += " and rent.created_at > '{}'".format(start_date) where_sql += " and rent.created_at > '{}'".format(start_date)
if end_date: if end_date is not None:
where_sql += " and rent.created_at <= '{}'".format(end_date) where_sql += " and rent.created_at <= '{}'".format(end_date)
if is_pay: if is_pay is not None:
where_sql += " and rent.is_pay = '{}'".format(is_pay) where_sql += " and rent.is_pay = '{}'".format(is_pay)
if business_id: if business_id is not None:
where_sql += " and rent.business_id = '{}'".format(business_id) where_sql += " and rent.business_id = '{}'".format(business_id)
if g.user.level != 1: if g.user.level != 1:
...@@ -154,7 +154,7 @@ def get_rent_detail(): ...@@ -154,7 +154,7 @@ def get_rent_detail():
""" """
where_sql = " where rent.rent_no = '{}'".format(rent_no) where_sql = " where rent.rent_no = '{}'".format(rent_no)
if rent_detail_id: if rent_detail_id is not None:
where_sql += " and rent_detail.id = '{}'".format(rent_detail_id) where_sql += " and rent_detail.id = '{}'".format(rent_detail_id)
if g.user.level != 1: if g.user.level != 1:
where_sql += """ and rent.business_id in ( where_sql += """ and rent.business_id in (
......
...@@ -159,6 +159,7 @@ def get_tallyman_account_detail(): ...@@ -159,6 +159,7 @@ def get_tallyman_account_detail():
"phone": admin_info.phone, "phone": admin_info.phone,
"level": admin_info.level, "level": admin_info.level,
"business_id": admin_info.business_id, "business_id": admin_info.business_id,
"business_name": admin_info.business_name,
"status": admin_info.status, "status": admin_info.status,
"comment": admin_info.comment "comment": admin_info.comment
} }
......
...@@ -18,6 +18,9 @@ flask-redis = "^0.4.0" ...@@ -18,6 +18,9 @@ flask-redis = "^0.4.0"
PyJWT = "^2.2.0" PyJWT = "^2.2.0"
pycryptodome = "^3.11.0" pycryptodome = "^3.11.0"
cryptography = "^36.0.1" cryptography = "^36.0.1"
uwsgi = "^2.0.20"
pymongo = "^4.0.1"
qcloudsms-py = "^0.1.4"
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
......
...@@ -127,11 +127,11 @@ class AdminService(object): ...@@ -127,11 +127,11 @@ class AdminService(object):
select_sql = """select tallyman_account.user_name, tallyman_account.phone, tallyman_account.level, select_sql = """select tallyman_account.user_name, tallyman_account.phone, tallyman_account.level,
tallyman_account.status,tallyman_account.created_at, tallyman_account.updated_at, tallyman_account.status,tallyman_account.created_at, tallyman_account.updated_at,
tallyman_account.id, tallyman_account.user_no, tallyman_account.comment, tallyman_account.id, tallyman_account.user_no, tallyman_account.comment,
tallyman_account.business_id tallyman_account.business_id, business.business_name
""" """
count_sql = "select count(tallyman_account.id) as total_count" count_sql = "select count(tallyman_account.id) as total_count"
from_sql = " from tallyman_account " from_sql = " from tallyman_account left join business on tallyman_account.business_id = business.id"
if g.user.level == 1: if g.user.level == 1:
where_sql = " where 0=0 " where_sql = " where 0=0 "
else: else:
...@@ -171,8 +171,9 @@ class AdminService(object): ...@@ -171,8 +171,9 @@ class AdminService(object):
for info in result: for info in result:
return_data.append( return_data.append(
{"user_name": info.user_name, "phone": info.phone, "level": info.level, "status": info.status, {"user_name": info.user_name, "phone": info.phone, "level": info.level, "status": info.status,
"comment": info.comment, "id": info.id, "user_no": info.user_no, "business_id": info.business_id, "comment": info.comment, "id": info.id, "user_no": info.user_no,
"create_time": info.created_at.strftime("%Y-%m-%d %H:%M:%S"), "create_time": info.created_at.strftime("%Y-%m-%d %H:%M:%S"),
"update_time": info.updated_at.strftime("%Y-%m-%d %H:%M:%S"), "update_time": info.updated_at.strftime("%Y-%m-%d %H:%M:%S"),
"business_id": info.business_id, "business_name": info.business_name,
}) })
return {"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count} return {"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count}
...@@ -48,7 +48,8 @@ class TallymanService(object): ...@@ -48,7 +48,8 @@ class TallymanService(object):
cur_machine['short_address'] = machine_info.short_address cur_machine['short_address'] = machine_info.short_address
cur_machine['address'] = machine_info.address cur_machine['address'] = machine_info.address
cur_machine['place_id'] = machine_info.place_id cur_machine['place_id'] = machine_info.place_id
cur_machine['empty_number'] = db.session.query(func.sum(Hatch.total_count - Hatch.left_count)).filter( empty_number = db.session.query(func.sum(Hatch.total_count - Hatch.left_count)).filter(
Hatch.machine_no == machine_info.machine_no, Hatch.machine_no == machine_info.machine_no,
Hatch.status == 2).scalar() Hatch.status.in_([1, 2])).scalar()
cur_machine['empty_number'] = empty_number if empty_number else 0
return cur_machine return cur_machine
#!usr/bin/.env python # -*- coding:utf-8 _*- """ @version: author:Aeolus @time: 2021/03/30 @file: jwt_util.py @function: @modify: """ import jwt from flask import current_app def generate_jwt(payload, expiry, secret=None): """ 生成jwt :param payload: dict 载荷 :param expiry: datetime 有效期 :param secret: 密钥 :return: jwt """ _payload = {'exp': expiry} _payload.update(payload) if not secret: secret = current_app.config['SECRET_KEY'] token = jwt.encode(_payload, secret, algorithm='HS256') return token def verify_jwt(token, secret=None): """ 检验jwt :param token: jwt :param secret: 密钥 :return: dict: payload """ if not secret: secret = current_app.config['SECRET_KEY'] try: payload = jwt.decode(token, secret, algorithms=['HS256']) except jwt.PyJWTError: payload = None return payload if __name__ == '__main__': import time from config.env_path_config import env_path from dotenv import load_dotenv load_dotenv(dotenv_path=env_path, verbose=True, override=True) import os SECRET_KEY = os.getenv('SECRET_KEY') token = generate_jwt({"user_id": 10}, time.time() + 6000, SECRET_KEY) # token = generate_jwt({"user_no": 'SK000007'}, time.time() + 6000, SECRET_KEY) print(token) # for i in range(10): # result = verify_jwt(token, 'secret') # print(result) # print(time.time()) # time.sleep(1) #!usr/bin/.env python # -*- coding:utf-8 _*- """ @version: author:Aeolus @time: 2021/03/30 @file: jwt_util.py @function: @modify: """ import jwt from flask import current_app def generate_jwt(payload, expiry, secret=None): """ 生成jwt :param payload: dict 载荷 :param expiry: datetime 有效期 :param secret: 密钥 :return: jwt """ _payload = {'exp': expiry} _payload.update(payload) if not secret: secret = current_app.config['SECRET_KEY'] token = jwt.encode(_payload, secret, algorithm='HS256') return token def verify_jwt(token, secret=None): """ 检验jwt :param token: jwt :param secret: 密钥 :return: dict: payload """ if not secret: secret = current_app.config['SECRET_KEY'] try: payload = jwt.decode(token, secret, algorithms=['HS256']) except jwt.PyJWTError: payload = None return payload if __name__ == '__main__': import time from config.env_path_config import env_path from dotenv import load_dotenv load_dotenv(dotenv_path=env_path, verbose=True, override=True) import os SECRET_KEY = os.getenv('SECRET_KEY') token = generate_jwt({"user_id": 1}, time.time() + 6000, SECRET_KEY) # token = generate_jwt({"user_no": 'XXTM000015'}, time.time() + 6000, SECRET_KEY) print(token) # for i in range(10): # result = verify_jwt(token, 'secret') # print(result) # print(time.time()) # time.sleep(1)
\ No newline at end of file \ No newline at end of file
......
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