Commit 4a3dd0f4 by Aeolus

Merge branch 'aeolus'

parents d351ecd1 92264414
......@@ -56,5 +56,10 @@ AGENT_STATUS = {
ACCOUNT_STATUS = {
'on_use': 1,
'delete': 2
'delete': -1
}
DISCOUNTS_TYPES = {
0: "暂无折扣",
1: "每日首单免费",
}
......@@ -12,6 +12,11 @@ SK_CONFIG = {
"app_secret": os.getenv("SK_MINI_PROGRAM_APPSECRET"),
}
XXZN_CONFIG = {
"app_id": os.getenv("XXZN_MINI_PROGRAM_APPID"),
"app_secret": os.getenv("XXZN_MINI_PROGRAM_APPSECRET"),
}
XX_PAY_CONFIG = {
"mch_id": os.getenv("XX_MCHID"),
"pay_key": os.getenv("XX_PAY_KEY"),
......@@ -28,19 +33,22 @@ pay_config_dict = {
"xx": XX_PAY_CONFIG,
}
platform_config_list = ["", "sukang24h", ]
platform_config_list = ["", "sukang24h", "xxzn"]
platform_config_dict = {
"sukang24h": SK_CONFIG,
"xxzn": XXZN_CONFIG
}
platform_appid_config_list = [
"",
SK_CONFIG["app_id"], # 苏康24H 平台序号 ==>1
XXZN_CONFIG["app_id"]
]
platform_appid_config_dict = {
"sukang24h": SK_CONFIG["app_id"],
"xxzn": XXZN_CONFIG["app_id"]
}
......
......@@ -57,7 +57,7 @@ class AdminMachine(Base):
user_id = Column(INTEGER(11), nullable=False)
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False)
machine_no = Column(INTEGER(11), nullable=False)
status = Column(INTEGER(1), nullable=False)
status = Column(INTEGER(1), default=1, nullable=False)
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"))
......@@ -69,7 +69,7 @@ class AdminPlace(Base):
user_id = Column(INTEGER(11), nullable=False)
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False)
place_id = Column(INTEGER(11), nullable=False)
status = 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"))
......@@ -130,9 +130,10 @@ class Machine(Base):
id = Column(INTEGER(10), primary_key=True)
machine_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False, unique=True, comment='机柜编号')
qrcode_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False, unique=True, comment='二维码编号')
mac = Column(String(30, 'utf8mb4_unicode_ci'), nullable=False, unique=True, comment='mac')
power = Column(TINYINT(3), nullable=False, server_default=text("'0'"), comment='电量')
device_id = Column(String(45, 'utf8mb4_unicode_ci'), unique=True)
qrcode_no = Column(String(20, 'utf8mb4_unicode_ci'), unique=True, comment='二维码编号')
mac = Column(String(30, 'utf8mb4_unicode_ci'), unique=True, comment='mac')
power = Column(TINYINT(3), server_default=text("'0'"), comment='电量')
short_address = Column(VARCHAR(45))
address = Column(String(191, 'utf8mb4_unicode_ci'), comment='机柜位置')
place_id = Column(INTEGER(10), nullable=False)
......@@ -140,10 +141,11 @@ class Machine(Base):
position = Column(String(20, 'utf8mb4_unicode_ci'), comment='机柜位置坐标')
hatch_number = Column(TINYINT(3), nullable=False, server_default=text("'0'"), comment='机柜的仓口数量')
type = Column(TINYINT(3), nullable=False, server_default=text("'1'"), comment='机柜类型1正常')
status = Column(TINYINT(1), server_default=text("'1'"), comment='状态: 1正常-1删除')
status = Column(TINYINT(1), default=text("'0'"), comment='状态: 0未激活 1正常-1删除')
created_at = Column(TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
command_time = Column(INTEGER(1), nullable=False)
command_time = Column(INTEGER(1), nullable=False, server_default=text("'1'"))
discounts_id = Column(INTEGER(11), nullable=False, server_default=text("'0'"), comment="折扣活动")
class MachineProduction(Base):
......@@ -208,14 +210,16 @@ class Place(Base):
__tablename__ = 'place'
id = Column(INTEGER(10), primary_key=True)
parent_id = Column(INTEGER(10), server_default=FetchedValue(), nullable=False)
place_name = Column(VARCHAR(191), nullable=False, index=True, comment='场所名')
img = Column(VARCHAR(191), comment='展示界面的图片')
logo = Column(VARCHAR(191), nullable=False, comment='微型头像')
address = Column(VARCHAR(255), nullable=False, server_default=text("''"))
logo = Column(VARCHAR(191), comment='微型头像')
address = Column(VARCHAR(255), server_default=text("''"))
position = Column(String(20, 'utf8mb4_unicode_ci'))
open_time = Column(VARCHAR(191), nullable=False, comment='开始时间')
close_time = Column(VARCHAR(191), nullable=False, comment='结束时间')
open_week = Column(VARCHAR(255), nullable=False, server_default=text("''"))
open_time = Column(VARCHAR(191), comment='开始时间')
close_time = Column(VARCHAR(191), comment='结束时间')
open_week = Column(VARCHAR(255), server_default=text("''"))
status = Column(INTEGER(1), nullable=False, server_default=text("'1'"))
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
......
#!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)
......@@ -22,7 +22,7 @@ def create_app(config_name):
load_dotenv(dotenv_path=env_path, verbose=True, override=True)
set_logger()
app = Flask("sukang24h")
app = Flask("automat")
from config.app_config import config
app.config.from_object(config[config_name])
CORS(app)
......@@ -40,6 +40,6 @@ def create_app(config_name):
app.after_request(close_db_session)
# todo register blueprint
from myapps.sukang24h.api import register_sukang_blueprint
from myapps.automat.api import register_sukang_blueprint
register_sukang_blueprint(app)
return app
......@@ -7,17 +7,17 @@ author:Aeolus
"""
from flask import Flask
from myapps.sukang24h.api.wx_auth_portal import wx_auth_route
from myapps.sukang24h.api.hatch_portal import hatch_route
from myapps.sukang24h.api.rent_portal import rent_route
from myapps.sukang24h.api.tallyman_portal import tallyman_route
from myapps.sukang24h.api.machine_portal import machine_route
from myapps.sukang24h.api.nfc_card_portal import nfc_card_route
from myapps.sukang24h.api.card_edit_portal import card_edit_route
from myapps.automat.api.wx_auth_portal import wx_auth_route
from myapps.automat.api.hatch_portal import hatch_route
from myapps.automat.api.rent_portal import rent_route
from myapps.automat.api.tallyman_portal import tallyman_route
from myapps.automat.api.machine_portal import machine_route
from myapps.automat.api.nfc_card_portal import nfc_card_route
from myapps.automat.api.card_edit_portal import card_edit_route
def register_sukang_blueprint(app: Flask):
prefix = "/sukang"
prefix = "/automat"
app.register_blueprint(wx_auth_route, url_prefix=prefix + "/wx_auth")
app.register_blueprint(hatch_route, url_prefix=prefix + "/hatch")
app.register_blueprint(rent_route, url_prefix=prefix + "/rent")
......
......@@ -6,12 +6,14 @@ author:Aeolus
@file: hatch_portal.py
"""
import logging
import time
from flask import Blueprint, request, jsonify, g
from models.base_model import db
from models.models import Machine, Production, Hatch, RentDetail
from utils.error_code import MACHINE_NOT_EXIST_ERROR, HATCH_NOT_EXIST_ERROR
from utils.error_code import MACHINE_NOT_EXIST_ERROR, HATCH_NOT_EXIST_ERROR, MACHINE_NO_CREATE_ERROR, \
MACHINE_MAC_DUPLICATE_ERROR
from utils.my_response import BaseResponse
logger = logging.getLogger(__name__)
......@@ -92,3 +94,43 @@ def run_get_machine_no():
"command_time": machine.command_time, "type": machine.type})
else:
return jsonify(MACHINE_NOT_EXIST_ERROR)
@machine_route.route('create_machine_no', methods=["post"])
def run_create_machine_no():
json_data = request.get_json()
mac = json_data["iMEI"]
hatch_number = json_data["slotCount"]
machine = Machine.query.filter_by(mac=mac).first()
if machine:
return jsonify(MACHINE_MAC_DUPLICATE_ERROR)
for i in range(3):
machine_no = int(time.time())
machine = Machine.query.filter_by(machine_no=machine_no).first()
if not machine:
break
return jsonify(MACHINE_NO_CREATE_ERROR)
machine_model = Machine()
machine_model.machine_no = machine_no
machine_model.mac = mac
machine_model.hatch_number = hatch_number
db.session.add(machine_model)
db.session.commit()
return BaseResponse(data={"machine_no": machine_no})
@machine_route.route('bind_serial_num', methods=["post"])
def run_bind_serial_num():
json_data = request.get_json()
machine_no = json_data["machine_no"]
serial_num = json_data["serial_num"]
machine = Machine.query.filter_by(machine_no=machine_no).first()
if not machine:
return jsonify(MACHINE_NOT_EXIST_ERROR)
machine.device_id = serial_num
db.session.add(machine)
db.session.commit()
return BaseResponse(data={"machine_no": machine_no, "serial_num": serial_num})
......@@ -15,7 +15,7 @@ from functools import reduce
from flask import Blueprint, request, jsonify, g
from sqlalchemy import func
from config.commen_config import USER_RENT_PREPAY_ID, RENT_SALE_LOCK
from config.commen_config import USER_RENT_PREPAY_ID, RENT_SALE_LOCK, DISCOUNTS_TYPES
from config.wechat_config import platform_appid_config_list, pay_config_list
from models.base_model import db
from models.models import Machine, Hatch, Rent, WxUser, RentDetail
......@@ -31,6 +31,28 @@ logger = logging.getLogger(__name__)
rent_route = Blueprint('rent', __name__)
@rent_route.route("discounts_info", methods=["POST"])
def get_discount_info():
json_data = request.get_json()
machine_no = json_data["machine_no"]
user = g.user
# 验证机柜是否存在
machine = Machine.query.filter_by(machine_no=machine_no).first()
if not machine:
return jsonify(MACHINE_NOT_EXIST_ERROR)
if machine.discounts_id == 1:
rent = Rent.query.filter(db.cast(Rent.created_at, db.DATE) == db.cast(datetime.datetime.now(), db.DATE)).first()
if rent:
is_used = 1
else:
is_used = 0
return_data = {"discounts_id": machine.discounts_id,
"discounts_name": DISCOUNTS_TYPES[int(machine.discounts_id)],
"is_used": is_used}
return BaseResponse(data=return_data)
@rent_route.route("rent", methods=["POST"])
def create_rent():
json_data = request.get_json()
......@@ -43,6 +65,67 @@ def create_rent():
if not machine:
return jsonify(MACHINE_NOT_EXIST_ERROR)
if machine.discounts_id == 1:
rent = Rent.query.filter(db.cast(Rent.created_at, db.DATE) == db.cast(datetime.datetime.now(), db.DATE)).first()
if not rent:
if len(productions) != 1:
return jsonify(HATCH_COUNT_ERROR)
total_fee = 0
for id, count in productions.items():
count = int(count)
if count != 1:
return jsonify(HATCH_COUNT_ERROR)
id = int(id)
# 根据给的仓号去获取商品信息
open_hatch = Hatch.query.filter(Hatch.machine_no == machine_no, Hatch.production_id == id,
Hatch.left_count >= 1).order_by(func.random()).first()
if not open_hatch:
print("....")
return jsonify(HATCH_NOT_EXIST_ERROR)
break
rent_no = RentService.create_order_no()
rent = Rent()
rent.rent_no = rent_no
rent.machine_no = machine.machine_no
rent.user_id = g.user.id
rent.place_id = machine.place_id
rent.total = total_fee
rent.add_time = datetime.datetime.now()
rent.is_pay = 1
rent.pay_time = datetime.datetime.now()
rent.rent_type = type
rent.mch_platform = machine.mch_platform
rent_detail = RentDetail()
rent_detail.rent_no = rent_no
rent_detail.user_id = rent.user_id
rent_detail.machine_no = rent.machine_no
rent_detail.hatch_no = open_hatch.hatch_no
rent_detail.production_id = open_hatch.production_id
rent_detail.name = open_hatch.name
rent_detail.title = open_hatch.title
rent_detail.brand_id = open_hatch.brand_id
rent_detail.brand_name = open_hatch.brand_name
rent_detail.cate_id = open_hatch.cate_id
rent_detail.cate_name = open_hatch.cate_name
rent_detail.price = 0
rent_detail.rent_count = 1
rent_detail.img = open_hatch.img
rent_detail.tags = open_hatch.tags
rent_detail.content = open_hatch.content
rent_detail.summary = open_hatch.summary
open_hatch.left_count -= 1
if open_hatch.left_count <= 0:
open_hatch.status = 2
db.session.add(rent)
db.session.add(rent_detail)
db.session.commit()
return BaseResponse(data={"out_trade_no": rent_no, "free_order": True})
total_fee = 0
open_hatchs = {}
for id, count in productions.items():
......
......@@ -12,8 +12,12 @@ author:Aeolus
from flask import Flask
from myapps.pc_management.api.admin_portal import admin_route
from myapps.pc_management.api.place_portal import place_route
from myapps.pc_management.api.machine_portal import machine_route
def register_sukang_blueprint(app: Flask):
prefix = "/pc_management"
app.register_blueprint(admin_route, url_prefix=prefix + "/admin")
app.register_blueprint(place_route, url_prefix=prefix + "/place")
app.register_blueprint(machine_route, url_prefix=prefix + "/machine")
#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@version:
author:Aeolus
@time: 2022/01/12
@file: machine_portal.py
@function:
@modify:
"""
import logging
from flask import Blueprint, g, request, jsonify
from config.commen_config import DISCOUNTS_TYPES
from models.base_model import db
from models.models import AdminMachine, Machine
from utils.error_code import MACHINE_NOT_EXIST_ERROR
from utils.my_response import BaseResponse
logger = logging.getLogger(__name__)
machine_route = Blueprint('machine', __name__)
@machine_route.route("machine_list", methods=["POST"])
def run_machine_list():
"""
:return:
"""
json_data = request.get_json()
page = json_data.get("page", None)
page_size = json_data.get("pageSize", None)
keyword = json_data.get("keyword", None)
admin = g.user
select_sql = """select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status,
machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id,
place.place_name, machine.discounts_id
"""
count_sql = "select count(machine.id) as total_count"
from_sql = """ from machine left join place on machine.place_id = place.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 = " "
if keyword:
where_sql += """
and CONCAT(machine.machine_no,ifnull(machine.qrcode_no,'')) LIKE '%{keyword}%'
""".format(keyword=keyword)
order_sql = " ORDER BY machine.id ASC, machine.status 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
print(select_sql + from_sql + where_sql + order_sql + limit_sql)
result = db.session.execute(select_sql + from_sql + where_sql + order_sql + limit_sql).fetchall()
return_data = []
for info in result:
return_data.append(
{"machine_no": info.machine_no, "device_id": info.device_id, "place_name": info.place_name,
"mac": info.mac, "power": info.power, "hatch_number": info.hatch_number, "type": info.type,
"status": info.status, "place_id": info.place_id,
"discounts_id": info.discounts_id,
"discounts_name": DISCOUNTS_TYPES.get(int(info.discounts_id), "无此优惠"),
})
return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count})
@machine_route.route("add_machine", methods=["POST"])
def run_add_machine():
"""
:return:
"""
json_data = request.get_json()
machine_no = json_data["machine_no"]
address = json_data.get("address", None)
device_id = json_data.get("device_id", None)
qrcode_no = json_data.get("qrcode_no", None)
mac = json_data.get("mac", None)
power = json_data.get("power", None)
hatch_number = json_data.get("hatch_number", None)
place_id = json_data.get("place_id", None)
type = json_data.get("type", 1)
discounts_id = json_data.get("type", 0)
machine_model = Machine()
machine_model.machine_no = machine_no
machine_model.device_id = device_id
machine_model.qrcode_no = qrcode_no
machine_model.mac = mac
machine_model.power = power
machine_model.place_id = place_id
machine_model.address = address
machine_model.mch_platform = 1
machine_model.hatch_number = hatch_number
machine_model.type = type
machine_model.discounts_id = discounts_id
db.session.add(machine_model)
admin_machine = AdminMachine()
admin_machine.user_id = g.user.id
admin_machine.user_no = g.user.user_no
admin_machine.machine_no = machine_model.machine_no
db.session.add(admin_machine)
db.session.commit()
return BaseResponse()
@machine_route.route("edit_machine", methods=["POST"])
def run_edit_machine():
"""
:return:
"""
json_data = request.get_json()
machine_no = json_data["machine_no"]
address = json_data.get("address", None)
device_id = json_data.get("device_id", None)
qrcode_no = json_data.get("qrcode_no", None)
mac = json_data.get("mac", None)
power = json_data.get("power", None)
hatch_number = json_data.get("hatch_number", None)
place_id = json_data.get("place_id", None)
type = json_data.get("type", None)
status = json_data.get("status", None)
discounts_id = json_data.get("discounts_id", None)
machine_model = Machine.query.filter_by(machine_no=machine_no).first()
if not machine_model:
return jsonify(MACHINE_NOT_EXIST_ERROR)
if device_id:
machine_model.device_id = device_id
if qrcode_no:
machine_model.qrcode_no = qrcode_no
if mac:
machine_model.mac = mac
if power:
machine_model.power = power
if place_id:
machine_model.place_id = place_id
if address:
machine_model.address = address
if hatch_number:
machine_model.hatch_number = hatch_number
if type:
machine_model.type = type
if status:
machine_model.status = status
if discounts_id:
machine_model.discounts_id = discounts_id
db.session.add(machine_model)
db.session.commit()
return BaseResponse()
@machine_route.route("machine_detail", methods=["POST"])
def get_machine_detail():
"""
:return:
"""
json_data = request.get_json()
machine_no = json_data["machine_no"]
admin = g.user
select_sql = """select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status,
machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id,
place.place_name, machine.discounts_id
"""
from_sql = """ from machine left join place on machine.place_id = place.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)
result = db.session.execute(select_sql + from_sql + where_sql).fetchall()
if not result or len(result) != 1:
return jsonify(MACHINE_NOT_EXIST_ERROR)
info = result[0]
return BaseResponse(data={"machine_no": info.machine_no, "device_id": info.device_id, "place_name": info.place_name,
"mac": info.mac, "power": info.power, "hatch_number": info.hatch_number,
"type": info.type, "status": info.status, "place_id": info.place_id,
"discounts_id": info.discounts_id,
"discounts_name": DISCOUNTS_TYPES.get(int(info.discounts_id), "无此优惠"),
})
#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@version:
author:Aeolus
@time: 2022/01/12
@file: place_portal.py
@function:
@modify:
"""
import logging
from flask import Blueprint, g, request, jsonify
from models.base_model import db
from models.models import AdminPlace, Place
from utils.error_code import NO_PLACE_ERROR
from utils.my_response import BaseResponse
logger = logging.getLogger(__name__)
place_route = Blueprint('place', __name__)
@place_route.route("place_list", methods=["POST"])
def run_place_list():
"""
:return:
"""
json_data = request.get_json()
page = json_data.get("page", None)
page_size = json_data.get("pageSize", None)
keyword = json_data.get("keyword", None)
admin = g.user
select_sql = "select place.place_name, place.address, place.parent_id,place.status, place.id "
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(
admin.id)
where_sql = " "
if keyword:
where_sql += """
and CONCAT(place.place_name, place.address) LIKE '%{keyword}%'
""".format(keyword=keyword)
order_sql = " ORDER BY place.id ASC, place.status 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 = []
for info in result:
return_data.append(
{"place_name": info.place_name, "place_id": info.id, "address": info.address, "parent_id": info.parent_id,
"status": info.status
})
return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count})
@place_route.route("add_place", methods=["POST"])
def run_add_place():
"""
:return:
"""
json_data = request.get_json()
place_name = json_data["place_name"]
address = json_data.get("address", "")
parent_id = json_data.get("parent_id", 0)
place_model = Place()
place_model.place_name = place_name
place_model.address = address
place_model.parent_id = parent_id
db.session.add(place_model)
db.session.commit()
admin_place = AdminPlace()
admin_place.user_id = g.user.id
admin_place.user_no = g.user.user_no
admin_place.place_id = place_model.id
db.session.add(admin_place)
db.session.commit()
return BaseResponse()
@place_route.route("edit_place", methods=["POST"])
def run_edit_place():
"""
:return:
"""
json_data = request.get_json()
id = json_data["id"]
place_name = json_data.get("place_name", "")
address = json_data.get("address", "")
parent_id = json_data.get("parent_id", 0)
status = json_data.get("status", None)
place_model = Place.query.filter_by(id=id).first()
place_model.place_name = place_name
place_model.address = address
place_model.parent_id = parent_id
place_model.status = status
db.session.add(place_model)
db.session.commit()
return BaseResponse()
@place_route.route("place_detail", methods=["POST"])
def get_place_detail():
"""
:return:
"""
json_data = request.get_json()
id = json_data["id"]
place_model = Place.query.filter_by(id=id).first()
if place_model:
return BaseResponse(data={"place_name": place_model.place_name,
"address": place_model.address,
"parent_id": place_model.parent_id,
"status": place_model.status, })
else:
return jsonify(NO_PLACE_ERROR)
......@@ -6,11 +6,11 @@
"""
import os
import logging
from myapps.sukang24h import create_app
from myapps.automat import create_app
logger = logging.getLogger(__name__)
app = create_app(os.getenv('RUN_ENV', 'prod'))
logger.info("run server")
if __name__ == '__main__':
app.run('127.0.0.1', 8893, debug=False)
app.run('127.0.0.1', 8893, debug=True)
......@@ -13,4 +13,4 @@ app = create_app('prod')
logger.info("run server")
if __name__ == '__main__':
app.run('127.0.0.1', 8893, debug=False)
app.run('127.0.0.1', 8893, debug=True)
#!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": '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)
\ No newline at end of file
#!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": 4}, 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)
\ 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