Commit ee4fd48f by Aeolus

update

parent 9c59730d
...@@ -48,7 +48,7 @@ class Hatch(Base): ...@@ -48,7 +48,7 @@ class Hatch(Base):
content = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品内容') content = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品内容')
summary = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品描述') summary = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品描述')
status = Column(TINYINT(3), nullable=False, server_default=text("'1'"), status = Column(TINYINT(3), nullable=False, server_default=text("'1'"),
comment='充电宝状态1在仓库2在机柜可用3在机柜占用4出货成功5永久锁 7未清洁 8手动弹出') comment='1可售2售空')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP")) created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
...@@ -260,6 +260,24 @@ class TallymanLoginRecord(Base): ...@@ -260,6 +260,24 @@ class TallymanLoginRecord(Base):
login_type = Column(INTEGER, nullable=False, server_default=FetchedValue(), comment='1:验证码登录 2:token 3:发送验证码 4:密码') login_type = Column(INTEGER, nullable=False, server_default=FetchedValue(), comment='1:验证码登录 2:token 3:发送验证码 4:密码')
class TallyRecord(Base):
__tablename__ = 'tally_record'
__table_args__ = (
Index('hatch_machine_UNIQUE', 'machine_no', 'hatch_no', unique=True),
)
id = Column(INTEGER(10), primary_key=True, unique=True)
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False, unique=True)
user_name = Column(String(255, 'utf8mb4_unicode_ci'), nullable=False)
machine_no = Column(String(20, 'utf8mb4_unicode_ci'), nullable=False, comment='机柜id')
hatch_no = Column(TINYINT(3), nullable=False, comment='机柜仓口号')
production_id = Column(INTEGER(10), nullable=False, comment='商品id')
production_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
status = Column(TINYINT(3), nullable=False, server_default=text("'1'"), comment='1指令已下发(等待开仓) 2指令上报(补货完成)')
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
class WxUser(Base): class WxUser(Base):
__tablename__ = 'wx_user' __tablename__ = 'wx_user'
__table_args__ = {'comment': '微信用户表'} __table_args__ = {'comment': '微信用户表'}
......
#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@version:
author:Aeolus
@file: hatch_portal.py
"""
import logging
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.my_response import BaseResponse
logger = logging.getLogger(__name__)
machine_route = Blueprint('machine', __name__)
@machine_route.route('list', methods=["post"])
def get_production_list():
json_data = request.get_json()
machine_no = json_data["machine_no"]
machine_info = Machine.query.filter_by(machine_no=machine_no, status=1).first()
if not machine_info:
return jsonify(MACHINE_NOT_EXIST_ERROR)
hatch_list = Hatch.query.filter_by(machine_no=machine_no, status=1).order_by(Hatch.hatch_no.asc()).all()
if not hatch_list:
return jsonify(HATCH_NOT_EXIST_ERROR)
tmp_dict = {}
for i in hatch_list:
if tmp_dict.get(i.production_id, None) is None:
tmp_dict[i.production_id] = {
"machine_no": i.machine_no,
"hatch_no": [i.hatch_no],
"production_id": i.production_id,
"name": i.name,
"title": i.title,
"brand_id": i.brand_id,
"brand_name": i.brand_name,
"cate_id": i.cate_id,
"cate_name": i.cate_name,
"price": i.price,
"original_price": i.original_price,
"img": i.img,
"tags": i.tags,
"content": i.content,
"summary": i.summary,
"status": i.status,
"count": 1
}
else:
tmp_dict[i.production_id]["count"] += 1
tmp_dict[i.production_id]["hatch_no"].append(i.hatch_no)
hatch_data = list(tmp_dict.values())
return BaseResponse(data=hatch_data)
@machine_route.route('info', methods=["post"])
def get_production_info():
json_data = request.get_json()
machine_no = json_data["machine_no"]
hatch_no = json_data["hatch_no"]
machine_info = Machine.query.filter_by(machine_no=machine_no, status=1).first()
if not machine_info:
return jsonify(MACHINE_NOT_EXIST_ERROR)
hatch_info = Hatch.query.filter_by(machine_no=machine_no, hatch_no=hatch_no).first()
if not hatch_info:
return jsonify(HATCH_NOT_EXIST_ERROR)
hatch_data = {
"machine_no": hatch_info.machine_no,
"hatch_no": hatch_info.hatch_no,
"production_id": hatch_info.production_id,
"name": hatch_info.name,
"title": hatch_info.title,
"brand_id": hatch_info.brand_id,
"brand_name": hatch_info.brand_name,
"cate_id": hatch_info.cate_id,
"cate_name": hatch_info.cate_name,
"price": hatch_info.price,
"original_price": hatch_info.original_price,
"img": hatch_info.img,
"tags": hatch_info.tags,
"content": hatch_info.content,
"summary": hatch_info.summary,
"status": hatch_info.status,
}
return BaseResponse(data=hatch_data)
@machine_route.route("/hatch_open", methods=["POST"])
def run_hatch_open():
json_data = request.get_json()
machine_no = json_data['machine_no']
hatch_no = json_data['hatch_no']
user_id = g.user.id
rent_detail = RentDetail.query.filter(RentDetail.user_id == user_id, RentDetail.machine_no == machine_no,
RentDetail.hatch_no == hatch_no,
RentDetail.status != -1,
RentDetail.is_take == 0).order_by(RentDetail.id.desc()).first()
if rent_detail:
rent_detail.is_take = 1
db.session.add(rent_detail)
db.session.commit()
return BaseResponse()
...@@ -8,10 +8,10 @@ from config.base_config import MONGO_DATABASE_URI ...@@ -8,10 +8,10 @@ from config.base_config import MONGO_DATABASE_URI
from config.commen_config import LOGIN_TYPE from config.commen_config import LOGIN_TYPE
from models.base_model import db from models.base_model import db
from models.models import TallymanAccount, TallymanMachine, TallymanLoginRecord, Machine from models.models import TallymanAccount, TallymanMachine, TallymanLoginRecord, Machine, Hatch, TallyRecord
from service.tallyman_service import TallymanService from service.tallyman_service import TallymanService
from utils.error_code import TALLYMAN_ACCOUNT_EXIST, PHONE_NOT_VALID_ERROR, TOKEN_NOT_VALID_ERROR, PASSWORD_ERROR, \ from utils.error_code import TALLYMAN_ACCOUNT_EXIST, PHONE_NOT_VALID_ERROR, TOKEN_NOT_VALID_ERROR, PASSWORD_ERROR, \
TALLYMAN_ACCOUNT_NOT_EXIST TALLYMAN_ACCOUNT_NOT_EXIST, MACHINE_NOT_EXIST_ERROR, HATCH_NOT_EXIST_ERROR
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
...@@ -216,3 +216,92 @@ def get_agent_module_list(): ...@@ -216,3 +216,92 @@ def get_agent_module_list():
machine_info = TallymanService.get_machine_info(g.user, machine_no) machine_info = TallymanService.get_machine_info(g.user, machine_no)
return BaseResponse(data=machine_info) return BaseResponse(data=machine_info)
@tallyman_route.route('hatch_list', methods=["post"])
def get_tallyman_hatch_list():
json_data = request.get_json()
machine_no = json_data["machine_no"]
machine_info = TallymanService.get_machine_info(g.user, machine_no)
if not machine_info:
return jsonify(MACHINE_NOT_EXIST_ERROR)
hatch_list = Hatch.query.filter_by(machine_no=machine_no).order_by(Hatch.hatch_no.asc()).all()
if not hatch_list:
return jsonify(HATCH_NOT_EXIST_ERROR)
hatch_data = [{
"machine_no": i.machine_no,
"hatch_no": i.hatch_no,
"production_id": i.production_id,
"name": i.name,
"status": i.status,
} for i in hatch_list]
return BaseResponse(data=hatch_data)
@tallyman_route.route("/tally_start", methods=["POST"])
def run_tally_start():
json_data = request.get_json()
machine_no = json_data['machine_no']
tally_type = json_data["type"] # 补货类型 1打开缺货锁 2打开指定仓号
machine_info = TallymanService.get_machine_info(g.user, machine_no)
if not machine_info:
return jsonify(MACHINE_NOT_EXIST_ERROR)
if tally_type == 1:
hatch_list = Hatch.query.filter_by(machine_no=machine_no, status=2).order_by(Hatch.hatch_no.asc()).all()
if not hatch_list:
return jsonify(HATCH_NOT_EXIST_ERROR)
elif tally_type == 2:
hatch_nos = json_data['hatch_nos']
hatch_list = Hatch.query.filter(Hatch.machine_no == machine_no, Hatch.status == 2,
Hatch.hatch_no.in_(hatch_nos)).order_by(Hatch.hatch_no.asc()).all()
if not hatch_list:
return jsonify(HATCH_NOT_EXIST_ERROR)
else:
return BaseResponse()
hatch_nos = []
for i in hatch_list:
hatch_nos.append(i.hatch_no)
tally_record = TallyRecord()
tally_record.user_no = g.user.user_no
tally_record.user_name = g.user.user_name
tally_record.machine_no = i.machine_no
tally_record.hatch_no = i.hatch_no
tally_record.production_id = i.production_id
tally_record.production_name = i.name
tally_record.status = 1
db.session.add(tally_record)
db.session.commit()
return BaseResponse(data={"hatch_nos": hatch_nos})
@tallyman_route.route("/tally_over", methods=["POST"])
def run_tally_over():
json_data = request.get_json()
machine_no = json_data['machine_no']
hatch_no = json_data['hatch_no']
user_id = g.user.id
tally_record = TallyRecord.query.filter(TallyRecord.user_no == g.user.user_no, TallyRecord.machine_no == machine_no,
TallyRecord.hatch_no == hatch_no,
TallyRecord.status == 1).order_by(TallyRecord.id.desc()).first()
if tally_record:
tally_record.status = 2
db.session.add(tally_record)
hatch = Hatch.query.filter_by(machine_no=machine_no, hatch_no=hatch_no, status=2).first()
if hatch:
hatch.status = 1
db.session.add(hatch)
db.session.commit()
return BaseResponse()
...@@ -40,4 +40,4 @@ class TallymanService(object): ...@@ -40,4 +40,4 @@ class TallymanService(object):
).first() ).first()
if not machine_info: if not machine_info:
return None return None
return machine_info
#!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) #!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 \ 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