Commit aa14c113 by Aeolus

Merge branch 'aeolus'

parents 21fdc72c 3441538c
......@@ -334,8 +334,8 @@ class RentDetail(Base):
title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题')
brand_id = Column(INTEGER(10), nullable=False, comment='品牌ID')
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='商品标题')
production_type_id = Column(INTEGER(10), nullable=False, comment='分类ID')
production_type_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'))
......
......@@ -16,6 +16,7 @@ from myapps.pc_management.api.place_portal import place_route
from myapps.pc_management.api.machine_portal import machine_route
from myapps.pc_management.api.file_protal import file_route
from myapps.pc_management.api.production_portal import production_route
from myapps.pc_management.api.hatch_portal import hatch_route
def register_sukang_blueprint(app: Flask):
......@@ -25,3 +26,4 @@ def register_sukang_blueprint(app: Flask):
app.register_blueprint(machine_route, url_prefix=prefix + "/machine")
app.register_blueprint(file_route, url_prefix=prefix + "/file")
app.register_blueprint(production_route, url_prefix=prefix + "/production")
app.register_blueprint(hatch_route, url_prefix=prefix + "/hatch")
......@@ -15,7 +15,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, Hatch
from utils.error_code import MACHINE_NOT_EXIST_ERROR, HATCH_COUNT_MAX_ERROR, HATCH_NO_DUPLICATE_ERROR
from utils.error_code import MACHINE_NOT_EXIST_ERROR, HATCH_COUNT_MAX_ERROR, HATCH_NO_DUPLICATE_ERROR, \
HATCH_NOT_EXIST_ERROR
from utils.my_response import BaseResponse
logger = logging.getLogger(__name__)
......@@ -30,8 +31,8 @@ def run_hatch_list():
:return:
"""
json_data = request.get_json()
page = json_data.get("page", None)
page_size = json_data.get("pageSize", None)
page = json_data.get("page", 1)
page_size = json_data.get("pageSize", 10)
keyword = json_data.get("keyword", None)
admin = g.user
......@@ -99,7 +100,7 @@ def run_add_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()
machine = Machine.query.filter(Machine.machine_no == machine_no, Machine.status != -1).first()
if not machine:
return jsonify(MACHINE_NOT_EXIST_ERROR)
......@@ -174,107 +175,76 @@ def run_edit_hatch():
hatch_id = json_data["hatch_id"]
hatch = Hatch.query.filter_by(id=hatch_id).first()
if not hatch:
return jsonify()
return jsonify(HATCH_NOT_EXIST_ERROR)
machine_no = json_data["machine_no"]
admin_machine = AdminMachine.query.filter_by(machine_no=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:
return jsonify(MACHINE_NOT_EXIST_ERROR)
machine = Machine.query.filter_by(machine_no=machine_no, status=1).first()
machine = Machine.query.filter(Machine.machine_no == hatch.machine_no, Machine.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 = int(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)
brand_name = json_data.get("brand_name", 0)
production_type_id = json_data.get("production_type_id", 0)
production_type_name = json_data.get("production_type_name", 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)
production_id = json_data.get("production_id", None)
production_name = json_data.get("production_name", None)
title = json_data.get("title", None)
brand_id = json_data.get("brand_id", None)
brand_name = json_data.get("brand_name", None)
production_type_id = json_data.get("production_type_id", None)
production_type_name = json_data.get("production_type_name", None)
price = json_data.get("price", None)
original_price = json_data.get("original_price", None)
weight = json_data.get("weight", None)
weight_unit = json_data.get("weight_unit", None)
weight_error = json_data.get("weight_error", None)
expiration_date = json_data.get("expiration_date", None)
expiration_date_unit = json_data.get("expiration_date_unit", None)
is_expiration_date = json_data.get("is_expiration_date", None)
img = json_data.get("img", None)
tags = json_data.get("tags", None)
content = json_data.get("content", None)
summary = json_data.get("summary", None)
left_count = json_data.get("left_count", 0)
total_count = json_data.get["total_count"]
hatch_model = Hatch()
hatch_model.machine_no = machine_no
hatch_model.hatch_no = hatch_no
hatch_model.production_id = production_id
hatch_model.production_name = production_name
hatch_model.title = title
hatch_model.left_count = left_count
hatch_model.total_count = total_count
hatch_model.brand_id = brand_id
hatch_model.brand_name = brand_name
hatch_model.production_type_id = production_type_id
hatch_model.production_type_name = production_type_name
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)
left_count = json_data.get("left_count", None)
total_count = json_data.get("total_count", None)
if production_id:
hatch.production_id = production_id
hatch.production_name = production_name
if title:
hatch.title = title
if brand_id:
hatch.brand_id = brand_id
hatch.brand_name = brand_name
if production_type_id:
hatch.production_type_id = production_type_id
hatch.production_type_name = production_type_name
if price:
hatch.price = price
if original_price:
hatch.original_price = original_price
if weight:
hatch.weight = weight
if weight_unit:
hatch.weight_unit = weight_unit
if weight_error:
hatch.weight_error = weight_error
if expiration_date:
hatch.expiration_date = expiration_date
if expiration_date_unit:
hatch.expiration_date_unit = expiration_date_unit
if is_expiration_date:
hatch.is_expiration_date = is_expiration_date
if img:
hatch.img = img
if tags:
hatch.tags = tags
if content:
hatch.content = content
if summary:
hatch.summary = summary
if left_count:
hatch.left_count = left_count
if total_count:
hatch.total_count = total_count
db.session.add(hatch)
db.session.commit()
return BaseResponse()
@hatch_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), "无此优惠"),
})
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