Commit f44317f7 by Aeolus

Merge branch 'master' into yanglei

parents 1b0fb537 f4e121b6
......@@ -216,6 +216,7 @@ class RentDetail(Base):
cate_id = Column(INTEGER(10), nullable=False, comment='分类ID')
cate_name = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题')
price = Column(INTEGER(10), nullable=False, comment='价格')
rent_count = Column(INTEGER(10), nullable=False, comment='数量')
img = Column(String(200, 'utf8mb4_unicode_ci'))
tags = Column(String(255, 'utf8mb4_unicode_ci'), comment='商品标签')
content = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品内容')
......@@ -327,6 +328,7 @@ class TallyRecord(Base):
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='商品名称')
tally_count = Column(TINYINT(3), 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"))
......
#!usr/bin/.env python
# -*- coding:utf-8 _*-
"""
@version:
@author:Aeolus
@file: __init__.py
@function:
@modify:
"""
from flask import Flask
from flask_cors import CORS
from flask_log_request_id import RequestID
from dotenv import load_dotenv
from models.base_model import db
from utils.my_redis_cache import redis_client
from utils.mylogger import set_logger
def create_app(config_name):
from config.env_path_config import env_path
load_dotenv(dotenv_path=env_path, verbose=True, override=True)
set_logger()
app = Flask("management")
from config.app_config import config
app.config.from_object(config[config_name])
CORS(app)
db.init_app(app)
redis_client.init_app(app)
RequestID(app)
from utils.middlewares import jwt_authentication, log_enter_interface, log_out_interface, close_db_session, \
get_platform, all_options_pass
app.before_request(log_enter_interface)
app.before_request(all_options_pass)
app.before_request(get_platform)
app.before_request(jwt_authentication)
app.after_request(log_out_interface)
app.after_request(close_db_session)
# todo register blueprint
from myapps.management.api import register_management_blueprint
register_management_blueprint(app)
return app
#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@version:
author:Aeolus
@file: __init__.py.py
"""
from flask import Flask
from myapps.management.api.rent_query import rent_query_route
from myapps.management.api.machine_management import machine_query_route
def register_management_blueprint(app: Flask):
prefix = "/management"
app.register_blueprint(rent_query_route, url_prefix=prefix + "/rent")
app.register_blueprint(machine_query_route, url_prefix=prefix + "/machine")
\ No newline at end of file
#!usr/bin/env python
# -*- coding:utf-8 _*-
import json
import logging
import re
import time
from flask import Blueprint, request, jsonify, g
from models.base_model import db
from utils.my_response import BaseResponse
from models.models import Machine, Hatch
from utils.error_code import MACHINE_NOT_EXIST_ERROR
logger = logging.getLogger(__name__)
# 创建蓝图
machine_query_route = Blueprint('machine', __name__)
# 展示机器信息
@machine_query_route.route("show",methods=["post"])
def machine_show():
json_date = request.get_json()
page = json_date["page"]
page_size = json_date["page_size"]
# 展示机器信息
m_count = Machine.query.count()
machine_result = Machine.query.offset((page-1)*page_size).limit(page_size).all()
if not machine_result:
return BaseResponse(data=[], page=page, page_size=page_size)
result_date = []
for result in machine_result:
res = {
"machine_no": result.machine_no,
"address": result.address,
"short_address": result.short_address,
"hatch_number": result.hatch_number,
"status": result.status
}
result_date.append(res)
return BaseResponse(data=result_date, page=page, page_size=page_size,page_cout=m_count//page_size+1)
# 模糊查询到机器信息
@machine_query_route.route("query_machine",methods=["post"])
def query_machine():
json_date = request.get_json()
number = json_date["number"]
page = json_date["page"]
page_size = json_date["page_size"]
pass
# 修改机器信息
@machine_query_route.route("query_edit",methods=["post"])
def query_edit():
json_date = request.get_json()
machine_no = json_date["machine_no"]
address = json_date["address"]
short_address = json_date["short_address"]
status = json_date["status"]
machine_not = Machine.query.filter_by(machine_no=machine_no).first()
if not machine_not:
return MACHINE_NOT_EXIST_ERROR
machine_result = Machine.query.filter_by(machine_no=machine_no).update(
{"address": address, "short_address": short_address, "status": status}
)
db.session.commit()
return BaseResponse()
# 显出机柜数量
@machine_query_route.route("hatch_query",methods=["post"])
def hatch_query():
json_date = request.get_json()
machine_no = json_date["machine_no"]
machine_not = Machine.query.filter_by(machine_no=machine_no).first()
if not machine_not:
return MACHINE_NOT_EXIST_ERROR
machine_result = Hatch.query.filter_by(machine_no=machine_no).all()
result_date = []
for res in machine_result:
result_date.append(res.hatch_no)
return BaseResponse(data=result_date)
# 查询信息
@machine_query_route.route("query", methods=["post"])
def query():
json_date = request.get_json()
number = str(json_date["number"])
page = json_date["page"]
page_size = json_date["page_size"]
machine_not = Machine.query.filter(Machine.machine_no.like("%"+number+"%")).first()
if not machine_not:
add_not = Machine.query.filter(Machine.address.like("%"+number+"%")).first()
if not add_not:
return BaseResponse(data=[])
else:
add_result = Machine.query.filter(Machine.address.like("%"+number+"%")).offset((page-1)*page_size).limit(
page_size
).all()
result_date = []
for add in add_result:
date = {
"machine_no": add.machine_no,
"address": add.address,
"short_address": add.short_address,
"hatch_number": add.hatch_number,
"status": add.status
}
result_date.append(date)
return BaseResponse(data=result_date, page=page, page_size=page_size)
else:
machine_result = Machine.query.filter(Machine.machine_no.like("%"+number+"%")).offset((page-1)*page_size).\
limit(page_size).all()
result_date = []
for machine in machine_result:
date = {
"machine_no": machine.machine_no,
"address": machine.address,
"short_address": machine.short_address,
"hatch_number": machine.hatch_number,
"status": machine.status
}
result_date.append(date)
return BaseResponse(data=result_date, page=page, page_size=page_size)
#!usr/bin/env python
# -*- coding:utf-8 _*-
import json
import logging
import re
import time
from config.wechat_config import platform_appid_config_list, pay_config_list, NFC_PAY_CALLBCK_URL
from flask import Blueprint, request, jsonify, g
from models.base_model import db
from utils.my_response import BaseResponse
from utils.error_code import NO_RENT_RECORD
from models.models import Rent
from service.rent_service import RentService
from service.wechat_service import WeChatPayService
logger = logging.getLogger(__name__)
rent_query_route = Blueprint('rent', __name__) # 创建蓝图
# 查询订单
@rent_query_route.route("part",methods=["post"])
def rent_query():
json_date = request.get_json()
get_number =str(json_date["number"])
# 订单状态
is_pay = json_date["is_pay"]
add_time = json_date["add_time"]
pay_time = json_date["pay_time"]
page = json_date["page"]
page_size = json_date["page_size"]
if is_pay == 1 or is_pay == 0: # 完成或未完成订单
if add_time == "" or pay_time == "": # 没有时间筛选
machine_result = Rent.query.filter(Rent.machine_no.like("%"+get_number+"%"),is_pay=is_pay).offset((page-1)*page_size)\
.limit(page_size).all()
else: # 开始进行模糊查询以及时间筛选
query1 = "SELECT * from rent where concat(rent.machine_no,rent.user_id,rent.rent_no) like '{}' and add_time > '{}' AND pay_time < '{}' and is_pay={} limit {},{}".format(
"%"+get_number+"%", add_time, pay_time, is_pay, (page-1)*page_size, page*page_size
)
machine_result = db.session.execute(query1).fetchall()
else: # 已支付或没有支付
if add_time == "" or pay_time == "": # 没有时间筛选
machine_result = Rent.query.filter(Rent.machine_no.like("%"+get_number+"%")).offset((page-1)*page_size)\
.limit(page_size).all()
else: # 开始进行模糊查询以及时间筛选
query1 = "SELECT * from rent where concat(rent.machine_no,rent.user_id,rent.rent_no) like '{}' and add_time > '{}' AND pay_time < '{}' limit {},{}".format(
"%" + get_number + "%", add_time, pay_time,(page-1)*page_size, page*page_size
)
machine_result = db.session.execute(query1).fetchall()
result_date = []
# 将数据遍历和筛选
for i in machine_result:
date = {
"rent_no ": i.rent_no,
"machine_no": i.machine_no,
"user_id": i.user_id,
"place_id": i.place_id,
"agent_total": i.agent_total,
"is_pay": i.is_pay,
"add_time": i.add_time.strftime("%Y-%m-%d %H:%M:%S"),
"pay_time": i.pay_time.strftime("%Y-%m-%d %H:%M:%S")
}
result_date.append(date)
return BaseResponse(date=result_date, page=page, page_size=page_size)
# 点击详情按钮,显示订单信息
@rent_query_route.route("datails",methods=["post"])
def details():
# 根据订单号来获取信息
json_date = request.get_json()
rent_no = json_date["rent_no"]
rent_not = Rent.query.filter(rent_no=rent_no).first()
if not rent_not:
return BaseResponse(data=[])
rent_result = Rent.query.filter(rent_no=rent_no).all()
result_date = []
for result in rent_result:
date = {
"rent_no": result.rent_no,
"machine_no": result.machine_no,
"user_id": result.user_id,
"place_id": result.place_id,
"back_money": result.back_money,
"is_pay": result.is_pay,
"rent_pay": result.rent_pay,
"add_time": result.add_time,
"pay_time": result.pay_time,
"over_time": result.over_time
}
result_date.append(date)
return BaseResponse(date=result_date)
# 进行订单修改并进行退款
@rent_query_route.route("edit_s",methods=["post"])
def edit_s():
json_date = request.get_json()
rent_no = json_date["rent_no"]
is_pay = json_date["is_pay"]
rent = Rent.query.filter_by(rent_no=rent_no, is_pay=1)
if not rent:
return NO_RENT_RECORD
# 退款操作
data = {
"out_refund_no": RentService.create_refund_no(),
"out_trade_no": rent.rent_no,
"total_fee": rent.pay_money,
"refund_fee": rent.pay_money
}
result = WeChatPayService(app_id=platform_appid_config_list[g.user.platform],
config_name=pay_config_list[rent.mch_platform]).do_refund(data)
if result:
rent_refund = Rent()
rent_refund.refund_no = data["out_refund_no"]
rent_refund.rent_no = rent_no
rent_refund.fee = data["refund_fee"]
rent.status = 3
db.session.add(rent_refund)
db.session.commit()
return BaseResponse()
......@@ -52,10 +52,10 @@ def get_production_list():
"content": i.content,
"summary": i.summary,
"status": i.status,
"count": 1
"count": i.left_count
}
else:
tmp_dict[i.production_id]["count"] += 1
tmp_dict[i.production_id]["count"] += i.left_count
tmp_dict[i.production_id]["hatch_no"].append(i.hatch_no)
hatch_data = list(tmp_dict.values())
return BaseResponse(data=hatch_data)
......@@ -92,6 +92,7 @@ def get_production_info():
"content": hatch_info.content,
"summary": hatch_info.summary,
"status": hatch_info.status,
"count": hatch_info.left_count
}
return BaseResponse(data=hatch_data)
......@@ -113,11 +114,15 @@ def run_hatch_open():
rent_detail.is_take = 1
db.session.add(rent_detail)
# 查询到柜子中的物品 数量减一
sql = "update hatch set left_count = left_count - 1 where machine_no = '{}' and hatch_no='{}'".format(
machine_no, hatch_no)
db.session.execute(sql)
db.session.commit()
# 当数量小于等于1时,将柜子物品状态改为已售空
left_res = Hatch.query.filter(Hatch.hatch_no == hatch_no,
Hatch.machine_no == machine_no).first()
left_res.left_count = left_res.left_count - 1
# 当数量等于1时,将柜子物品状态改为已售空
if left_res.left_count == 0:
if left_res.left_count <= 0:
left_res.status = 2
# 执行语句
db.session.add(left_res)
......
......@@ -89,6 +89,6 @@ def run_get_machine_no():
machine = Machine.query.filter_by(qrcode_no=qrcode_no).first()
if machine:
return BaseResponse(data={"machine_no": machine.machine_no, "status": machine.status, "mac_no": machine.mac,
"command_time":machine.command_time})
"command_time": machine.command_time, "type": machine.type})
else:
return jsonify(MACHINE_NOT_EXIST_ERROR)
......@@ -372,6 +372,7 @@ def run_nfc_card_load_succeed():
secret = json_data["secret"]
record_nos = json_data["record_nos"]
card_no = json_data["card_no"]
money = int(json_data["money"])
if secret != NFC_PAY_LOAD_SECRET:
return jsonify(NFC_PAY_LOAD_SECRET_ERROR)
......@@ -382,10 +383,11 @@ def run_nfc_card_load_succeed():
for record_no in record_nos:
card_record = NfcCardPayRecord.query.filter_by(rent_no=record_no, status=1).first() # 查询到充值记录
if card_record:
card_result.money += card_record.pay_money
card_record.status = 2
db.session.add(card_record)
card_result.money = money
try:
db.session.add(card_result)
db.session.commit()
except SQLAlchemyError as e:
......
......@@ -184,12 +184,12 @@ def wx_pay_callback():
rent_detail.cate_id = i.cate_id
rent_detail.cate_name = i.cate_name
rent_detail.price = i.price * open_hatchs[str(i.hatch_no)]
rent_detail.rent_count = open_hatchs[str(i.hatch_no)]
rent_detail.img = i.img
rent_detail.tags = i.tags
rent_detail.content = i.content
rent_detail.summary = i.summary
db.session.add(rent_detail)
db.session.add(i)
total_fee += rent_detail.price
if total_fee != int(callback_data['total_fee']):
......
......@@ -4,6 +4,8 @@ import logging
import time
from flask import Blueprint, jsonify, request, g
from sqlalchemy import func
from config.base_config import MONGO_DATABASE_URI
from config.commen_config import LOGIN_TYPE
......@@ -238,6 +240,8 @@ def get_tallyman_hatch_list():
"production_id": i.production_id,
"name": i.name,
"status": i.status,
"left_count": i.left_count,
"total_count": i.total_count
} for i in hatch_list]
return BaseResponse(data=hatch_data)
......@@ -261,8 +265,8 @@ def run_tally_start():
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()
hatch_list = Hatch.query.filter(Hatch.machine_no == machine_no, Hatch.hatch_no.in_(hatch_nos)).order_by(
Hatch.hatch_no.asc()).all()
if not hatch_list:
return jsonify(HATCH_NOT_EXIST_ERROR)
else:
......@@ -278,6 +282,7 @@ def run_tally_start():
tally_record.hatch_no = i.hatch_no
tally_record.production_id = i.production_id
tally_record.production_name = i.name
tally_record.tally_count = i.total_count - i.left_count if i.left_count > 0 else i.total_count
tally_record.status = 1
db.session.add(tally_record)
......@@ -303,9 +308,9 @@ def run_tally_over():
if tally_record:
tally_record.status = 2
db.session.add(tally_record)
db.session.commit()
hatch = Hatch.query.filter(Hatch.machine_no == machine_no, Hatch.hatch_no.in_(hatch_no),
Hatch.status == 2).update({"status": 1})
sql = "update hatch set left_count = total_count , status=1 where machine_no = '{}' and hatch_no='{}'".format(
machine_no, i)
db.session.execute(sql)
db.session.commit()
elif tally_type == 2:
......@@ -316,9 +321,10 @@ def run_tally_over():
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()
hatch = Hatch.query.filter_by(machine_no=machine_no, hatch_no=hatch_no).first()
if hatch:
hatch.status = 1
hatch.left_count = hatch.total_count
db.session.add(hatch)
db.session.commit()
else:
......@@ -336,9 +342,9 @@ def get_tally_report():
return jsonify(MACHINE_NOT_EXIST_ERROR)
empty_number = int(machine_info["empty_number"])
over_number = TallyRecord.query.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.status == 2).count()
TallyRecord.status == 2).scalar()
return BaseResponse(data={"empty_number": empty_number, "over_number": over_number})
......
# -*- coding: utf-8 -*-
import logging
from sqlalchemy import func
from models.base_model import db
from models.models import TallymanMachine, Machine, Hatch
logger = logging.getLogger(__name__)
......@@ -45,6 +48,7 @@ class TallymanService(object):
cur_machine['short_address'] = machine_info.short_address
cur_machine['address'] = machine_info.address
cur_machine['place_id'] = machine_info.place_id
cur_machine['empty_number'] = Hatch.query.filter(Hatch.machine_no == machine_info.machine_no,
Hatch.status == 2).count()
cur_machine['empty_number'] = db.session.query(func.sum(Hatch.total_count - Hatch.left_count)).filter(
Hatch.machine_no == machine_info.machine_no,
Hatch.status == 2).scalar()
return cur_machine
#!usr/bin/.env python
# -*- coding:utf-8 _*-
"""
@version:
@author:Aeolus
"""
import os
import logging
from myapps.management 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)
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