Commit daa64669 by Aeolus

Merge branch 'aeolus'

parents deb0e035 a77e82d0
......@@ -131,18 +131,22 @@ class Hatch(Base):
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')
name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
production_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题')
left_count = Column(TINYINT(3), nullable=False, comment='剩余数量')
total_count = Column(TINYINT(3), nullable=False, comment='总数')
brand_id = Column(INTEGER(10), nullable=False, comment='品牌ID')
left_count = Column(INTEGER(10), nullable=False, comment='余额')
total_count = Column(INTEGER(10), nullable=False, comment='总数')
brand_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
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='价格')
original_price = Column(INTEGER(10), nullable=False, comment='商品原价')
weight = Column(INTEGER(10), server_default=text("'0'"))
weight_unit = Column(String(10, 'utf8mb4_unicode_ci'), server_default=text("'g'"))
weight_error = Column(INTEGER(10), server_default=text("'0'"))
expiration_date = Column(INTEGER(10), server_default=text("'0'"))
expiration_date_unit = Column(String(10, 'utf8mb4_unicode_ci'), server_default=text("'月'"))
is_expiration_date = Column(TINYINT(1), server_default=text("'0'"))
img = Column(String(200, 'utf8mb4_unicode_ci'))
tags = Column(String(255, 'utf8mb4_unicode_ci'), comment='商品标签')
content = Column(Text(collation='utf8mb4_unicode_ci'), comment='商品内容')
......
......@@ -40,6 +40,7 @@ def get_discount_info():
machine = Machine.query.filter_by(machine_no=machine_no).first()
if not machine:
return jsonify(MACHINE_NOT_EXIST_ERROR)
is_used = 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()
if rent:
......
......@@ -14,8 +14,8 @@ 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 models.models import AdminMachine, Machine, Hatch
from utils.error_code import MACHINE_NOT_EXIST_ERROR, HATCH_COUNT_MAX_ERROR, HATCH_NO_DUPLICATE_ERROR
from utils.my_response import BaseResponse
logger = logging.getLogger(__name__)
......@@ -35,23 +35,26 @@ def run_hatch_list():
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
select_sql = """select hatch.machine_no, hatch.hatch_no,hatch.production_id,hatch.production_name,hatch.title,hatch.left_count,
hatch.total_count,hatch.brand_id,hatch.brand_name,hatch.production_type_id,hatch.production_type_name,
hatch.price,hatch.original_price, hatch.weight,hatch.weight_unit,hatch.weight_error,
hatch.expiration_date,hatch.expiration_date_unit,hatch.is_expiration_date,
hatch.img, hatch.tags, hatch.content,hatch.summary,hatch.status
"""
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
count_sql = "select count(hatch.id) as total_count"
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)
where_sql = " "
if keyword:
where_sql += """
and CONCAT(machine.machine_no,ifnull(machine.qrcode_no,'')) LIKE '%{keyword}%'
and CONCAT(hatch.machine_no,ifnull(hatch.brand_name,''), ifnull(hatch.production_type_name,''))
LIKE '%{keyword}%'
""".format(keyword=keyword)
order_sql = " ORDER BY machine.id ASC, machine.status ASC"
order_sql = " ORDER BY hatch.id ASC, hatch.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()
......@@ -66,17 +69,26 @@ def run_hatch_list():
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), "无此优惠"),
{"production_name": info.production_name, "production_id": info.production_id,
"machine_no": info.machine_no,
"hatch_no": info.hatch_no,
"left_count": info.left_count,
"total_count": info.total_count,
"title": info.title, "brand_id": info.brand_id, "brand_name": info.brand_name,
"production_type_id": info.production_type_id, "production_type_name": info.production_type_name,
"price": info.price, "original_price": info.original_price, "weight": info.weight,
"weight_unit": info.weight_unit,
"expiration_date": info.expiration_date, "expiration_date_unit": info.expiration_date_unit,
"is_expiration_date": info.is_expiration_date,
"weight_error": info.weight_error,
"img": info.img, "tags": info.tags, "content": info.content,
"summary": info.summary, "status": info.status,
})
return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count})
@hatch_route.route("add_machine", methods=["POST"])
@hatch_route.route("add_hatch", methods=["POST"])
def run_add_machine():
"""
......@@ -84,36 +96,60 @@ def run_add_machine():
"""
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)
admin_machine = AdminMachine.query.filter_by(machine_no=machine_no, user_id=g.user.id, status=1).first()
if not admin_machine:
return jsonify(MACHINE_NOT_EXIST_ERROR)
machine = Machine.query.filter_by(machine_no=machine_no, status=1).first()
if not machine:
return jsonify(MACHINE_NOT_EXIST_ERROR)
hatch_num = machine.hatch_number
hatchs = Hatch.query.filter_by(machine_no=machine_no).all()
if len(hatchs) >= hatch_num:
return jsonify(HATCH_COUNT_MAX_ERROR)
hatch_no = json_data["hatch_no"]
for i in hatchs:
if i.hatch_no == hatch_no:
return jsonify(HATCH_NO_DUPLICATE_ERROR)
production_id = json_data["production_id"]
production_name = json_data["production_name"]
title = json_data.get("title", "")
brand_id = json_data.get("brand_id", 0)
production_type_id = json_data.get("production_type_id", 0)
price = json_data.get("price", 0)
original_price = json_data.get("original_price", 0)
weight = json_data.get("weight", 0)
weight_unit = json_data.get("weight_unit", "g")
weight_error = json_data.get("weight_error", 0)
expiration_date = json_data.get("expiration_date", 0)
expiration_date_unit = json_data.get("expiration_date_unit", "月")
is_expiration_date = json_data.get("is_expiration_date", 0)
img = json_data.get("img", None)
tags = json_data.get("tags", None)
content = json_data.get("content", None)
summary = json_data.get("summary", None)
hatch_model = Hatch()
hatch_model.production_id = production_id
hatch_model.production_name = production_name
hatch_model.title = title
hatch_model.brand_id = brand_id
hatch_model.production_type_id = production_type_id
hatch_model.price = price
hatch_model.original_price = original_price
hatch_model.weight = weight
hatch_model.weight_unit = weight_unit
hatch_model.weight_error = weight_error
hatch_model.expiration_date = expiration_date
hatch_model.expiration_date_unit = expiration_date_unit
hatch_model.is_expiration_date = is_expiration_date
hatch_model.img = img
hatch_model.tags = tags
hatch_model.content = content
hatch_model.summary = summary
db.session.add(hatch_model)
db.session.commit()
return BaseResponse()
......
......@@ -14,8 +14,8 @@ 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 models.models import AdminMachine, Machine, AdminAccount
from utils.error_code import MACHINE_NOT_EXIST_ERROR, ACCOUNT_NOT_EXISTS_ERROR
from utils.my_response import BaseResponse
logger = logging.getLogger(__name__)
......@@ -145,8 +145,7 @@ def run_edit_machine():
machine_model.device_id = device_id
if qrcode_no:
machine_model.qrcode_no = qrcode_no
if mac:
machine_model.mac = mac
if mac: machine_model.mac = mac
if power:
machine_model.power = power
if place_id:
......@@ -200,3 +199,37 @@ def get_machine_detail():
"discounts_name": DISCOUNTS_TYPES.get(int(info.discounts_id), "无此优惠"),
})
@machine_route.route("distribute_machine", methods=["POST"])
def run_distribute_machine():
"""
:return:
"""
json_data = request.get_json()
machine_nos = json_data["machine_nos"]
user_id = json_data["user_id"]
user = AdminAccount.query.filter_by(id=user_id, parent_id=g.user.id, status=1).first()
if not user:
return jsonify(ACCOUNT_NOT_EXISTS_ERROR)
admin_machines = AdminMachine.query.filter_by(user_id=g.user.id, status=1).all()
if not admin_machines:
return jsonify(MACHINE_NOT_EXIST_ERROR)
admin_machine_nos = [x.machine_no for x in admin_machines]
right_machine_nos = list(set(machine_nos).intersection(set(admin_machine_nos)))
if not right_machine_nos:
return jsonify(MACHINE_NOT_EXIST_ERROR)
insert_sql = " insert into admin_machine (user_id, user_no, machine_no) values "
for i in right_machine_nos:
insert_sql += "('{}','{}','{}'),".format(user.id, user.user_no, i)
insert_sql = insert_sql[:-1]
insert_sql += " ON DUPLICATE KEY UPDATE status = 1"
print(insert_sql)
db.session.execute(insert_sql)
db.session.commit()
return BaseResponse(data={"add_machine_nos": right_machine_nos})
......@@ -370,7 +370,7 @@ def get_brand_detail():
brand_id = json_data["brand_id"]
admin = g.user
select_sql = """select b.id,b.brand_name,b.status
select_sql = """select b.id,b.brand_name,b.status, b.img
"""
from_sql = """ from brand b """
......@@ -384,7 +384,7 @@ def get_brand_detail():
return BaseResponse(
data={"brand_id": info.id, "brand_name": info.brand_name,
"status": info.status,
"status": info.status, "img": info.img
})
......
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