# -*- coding: utf-8 -*-
from flask import Blueprint, request, jsonify, redirect
from decimal import Decimal
from sqlalchemy import or_
from common.libs.Helper import ops_render, getCurrentDate, iPagination, getDictFilterField
from common.libs.UrlManager import UrlManager
from common.libs.food.FoodService import FoodService
from common.models.food.FoodCat import FoodCat
from common.models.food.Food import Food
from common.models.food.FoodStockChangeLog import FoodStockChangeLog
from application import app, db
route_food = Blueprint('food_page', __name__)
@route_food.route("/index")
def index():
resp_data = {}
req = request.values
page = int(req["p"]) if ("p" in req and req["p"]) else 1
query = Food.query
# 食品名称或标签查询
if "mix_kw" in req:
rule = or_(Food.name.ilike("%{0}%".format(req["mix_kw"])),
Food.tags.ilike("%{0}%".format(req["mix_kw"])))
query = query.filter(rule)
# 状态查询
if "status" in req and int(req["status"]) > -1:
query = query.filter(Food.status == int(req["status"]))
# 菜系分类查询
if 'cat_id' in req and int(req['cat_id']) > 0:
query = query.filter(Food.cat_id == int(req['cat_id']))
page_params = {
"total": query.count(),
"page_size": app.config["PAGE_SIZE"],
"page": page,
"display": app.config["PAGE_DISPLAY"],
"url": request.full_path.replace("&p={}".format(page), "")
}
pages = iPagination(page_params)
offset = (page - 1) * app.config["PAGE_SIZE"]
list = query.order_by(Food.id.desc()).offset(offset).limit(app.config["PAGE_SIZE"]).all()
cat_mapping = getDictFilterField(FoodCat, FoodCat.id, "id", [])
resp_data["list"] = list
resp_data["pages"] = pages
resp_data["search_con"] = req
resp_data["status_mapping"] = app.config["STATUS_MAPPING"]
resp_data["cat_mapping"] = cat_mapping
resp_data["current"] = "index"
return ops_render("food/index.html", resp_data)
@route_food.route("/info")
def info():
resp_data = {}
req = request.args
id = int(req.get("id", 0))
if id < 1:
return redirect(UrlManager.buildUrl("/food/index"))
food_info = Food.query.filter_by(id=id).first()
if not food_info:
return redirect(UrlManager.buildUrl("/food/index"))
stock_change_list = FoodStockChangeLog.query.filter(FoodStockChangeLog.food_id == id).order_by(
FoodStockChangeLog.id.desc()).all()
resp_data["food_info"] = food_info
resp_data["stock_change_list"] = stock_change_list
resp_data["current"] = "index"
return ops_render("food/info.html", resp_data)
@route_food.route("/set", methods=["GET", "POST"])
def set():
if request.method == "GET":
resp_data = {}
req = request.args
id = int(req.get("id", 0))
food_info = Food.query.filter_by(id=id).first()
if food_info and food_info.status != 1:
return redirect(UrlManager.buildUrl("/food/index"))
cat_list = FoodCat.query.all()
resp_data["food_info"] = food_info
resp_data["cat_list"] = cat_list
resp_data["current"] = "index"
return ops_render("food/set.html", resp_data)
resp = {"code": 200, "msg": "操作成功~", "data": {}}
req = request.values
id = int(req['id']) if 'id' in req and req['id'] else 0
cat_id = int(req['cat_id']) if 'cat_id' in req else 0
name = req['name'] if 'name' in req else ''
price = req['price'] if 'price' in req else ''
main_image = req['main_image'] if 'main_image' in req else ''
summary = req['summary'] if 'summary' in req else ''
stock = int(req['stock']) if 'stock' in req else ''
tags = req['tags'] if 'tags' in req else ''
price = Decimal(price).quantize(Decimal('0.00'))
if cat_id < 1:
resp['code'] = -1
resp['msg'] = "请选择分类~~"
return jsonify(resp)
if name is None or len(name) < 1:
resp['code'] = -1
resp['msg'] = "请输入符合规范的名称~~"
return jsonify(resp)
if price <= 0:
resp['code'] = -1
resp['msg'] = "请输入符合规范的售卖价格~~"
return jsonify(resp)
if main_image is None or len(main_image) < 3:
resp['code'] = -1
resp['msg'] = "请上传封面图~~"
return jsonify(resp)
if summary is None or len(summary) < 3:
resp['code'] = -1
resp['msg'] = "请输入图书描述,并不能少于10个字符~~"
return jsonify(resp)
if stock < 1:
resp['code'] = -1
resp['msg'] = "请输入符合规范的库存量~~"
return jsonify(resp)
if tags is None or len(tags) < 1:
resp['code'] = -1
resp['msg'] = "请输入标签,便于搜索~~"
return jsonify(resp)
food_info = Food.query.filter_by(id=id).first()
before_stock = 0
if food_info:
model_food = food_info
before_stock = model_food.stock
else:
model_food = Food()
model_food.status = 1
model_food.created_time = getCurrentDate()
model_food.cat_id = cat_id
model_food.name = name
model_food.price = price
model_food.main_image = main_image
model_food.summary = summary
model_food.stock = stock
model_food.tags = tags
model_food.updated_time = getCurrentDate()
db.session.add(model_food)
ret = db.session.commit()
FoodService.setStockChangeLog(model_food.id, int(stock) - int(before_stock), "后台修改")
return jsonify(resp)
@route_food.route("/cat")
def cat():
resp_data = {}
req = request.values
query = FoodCat.query
if "status" in req and int(req["status"]) > -1:
query = query.filter(FoodCat.status == int(req["status"]))
list = query.order_by(FoodCat.weight.desc(), FoodCat.id.desc()).all()
resp_data["list"] = list
resp_data["status_mapping"] = app.config["STATUS_MAPPING"]
resp_data["search_con"] = req
resp_data["current"] = "cat"
return ops_render("food/cat.html", resp_data)
@route_food.route("/cat-set", methods=["GET", "POST"])
def catSet():
if request.method == "GET":
resp_data = {}
req = request.args
id = int(req.get("id", 0))
food_cat_info = None
if id:
food_cat_info = FoodCat.query.filter_by(id=id).first()
resp_data["food_cat_info"] = food_cat_info
resp_data["current"] = "cat"
return ops_render("food/cat_set.html", resp_data)
resp = {"code": 200, "msg": "操作成功~", "data": {}}
req = request.values
id = req["id"] if "id" in req else 0
name = req["name"] if "name" in req else ""
weight = int(req["weight"]) if ("weight" in req and int(req["weight"]) > 0) else 1
if name is None or len(name) < 1:
resp["code"] = -1
resp["msg"] = "请输入符合规范的分类名称~~"
return jsonify(resp)
food_cat_info = FoodCat.query.filter_by(id=id).first()
if food_cat_info:
model_food_cat = food_cat_info
else:
model_food_cat = FoodCat()
model_food_cat.created_time = getCurrentDate()
model_food_cat.name = name
model_food_cat.weight = weight
model_food_cat.updated_time = getCurrentDate()
db.session.add(model_food_cat)
db.session.commit()
return jsonify(resp)
@route_food.route("/cat-ops", methods=["POST"])
def catOps():
resp = {"code": 200, "msg": "操作成功~", "data": {}}
req = request.values
id = req["id"] if "id" in req else 0
act = req["act"] if "act" in req else ""
if not id:
resp["code"] = -1
resp["msg"] = "请选择要操作的账号~~"
return jsonify(resp)
if act not in ["remove", "recover"]:
resp["code"] = -1
resp["msg"] = "操作有误,请重试~~"
return jsonify(resp)
food_cat_info = FoodCat.query.filter_by(id=id).first()
if not food_cat_info:
resp["code"] = -1
resp[
没有合适的资源?快使用搜索试试~ 我知道了~
基于Flask框架的微信小程序订餐系统.zip
共684个文件
gif:184个
js:121个
png:118个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 131 浏览量
2024-09-15
15:05:28
上传
评论
收藏 5.44MB ZIP 举报
温馨提示
该项目是一个使用Python Flask框架构建的基于微信小程序的订餐系统。通过微信小程序,用户可以浏览菜单、点餐、下单等操作。项目提供了系统的基本结构和逻辑实现,并且包括了一些常见的功能和页面,如登录、注册、菜单展示、订单管理等。在开发过程中,使用了微信小程序的开发工具和flask框架进行开发,实现了前后端的交互和数据管理。项目中还可能包含了一些错误处理机制和其他特定的功能实现。从项目的README文件和描述中,可以看出该项目具有一定的实用性和商业价值。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
资源推荐
资源详情
资源评论
收起资源包目录
基于Flask框架的微信小程序订餐系统.zip (684个子文件)
style.css 165KB
bootstrap.min.css 118KB
bootstrap.min.css 118KB
ueditor.css 44KB
ueditor.min.css 34KB
font-awesome.css 28KB
font-awesome.min.css 23KB
video-js.css 21KB
image.css 19KB
jquery.datetimepicker.min.css 16KB
select2.min.css 16KB
video.css 15KB
attachment.css 15KB
layer.css 14KB
video-js.min.css 11KB
shCoreDefault.css 7KB
layer.css 5KB
scrawl.css 4KB
codemirror.css 3KB
charts.css 3KB
background.css 2KB
emotion.css 2KB
dialogbase.css 2KB
music.css 2KB
edittable.css 1KB
template.css 1KB
jquery.tagsinput.min.css 770B
webuploader.css 515B
help.css 395B
iframe.css 42B
fontawesome-webfont.eot 59KB
vjs.eot 3KB
loading.gif 82KB
wface.gif 49KB
jxface2.gif 40KB
yface.gif 28KB
bface.gif 27KB
icons.gif 20KB
file-icons.gif 20KB
file-icons.gif 20KB
tface.gif 19KB
fface.gif 18KB
35.gif 13KB
42.gif 13KB
40.gif 10KB
cface.gif 8KB
18.gif 8KB
19.gif 8KB
11.gif 8KB
32.gif 7KB
49.gif 6KB
29.gif 6KB
loading-0.gif 6KB
97.gif 5KB
65.gif 5KB
31.gif 5KB
46.gif 5KB
57.gif 5KB
45.gif 5KB
08.gif 5KB
43.gif 4KB
33.gif 4KB
68.gif 4KB
26.gif 4KB
14.gif 4KB
07.gif 4KB
icons-all.gif 4KB
51.gif 4KB
10.gif 4KB
47.gif 4KB
72.gif 4KB
06.gif 3KB
94.gif 3KB
84.gif 3KB
41.gif 3KB
17.gif 3KB
09.gif 3KB
28.gif 3KB
50.gif 3KB
95.gif 3KB
22.gif 3KB
27.gif 3KB
67.gif 3KB
90.gif 3KB
60.gif 3KB
58.gif 3KB
74.gif 2KB
25.gif 2KB
101.gif 2KB
54.gif 2KB
99.gif 2KB
24.gif 2KB
12.gif 2KB
73.gif 2KB
104.gif 2KB
103.gif 2KB
34.gif 2KB
88.gif 2KB
53.gif 2KB
04.gif 2KB
共 684 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
sec0nd_
- 粉丝: 6432
- 资源: 2069
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Esercizi di informatica!执行计划,metti alla prova!.zip
- Eloquent JavaScript 翻译 - 2ª edição .zip
- Eclipse Paho Java MQTT 客户端库 Paho 是一个 Eclipse IoT 项目 .zip
- disconf 的 Java 应用程序.zip
- cloud.google.com 上使用的 Java 和 Kotlin 代码示例.zip
- 未命名3(3).cpp
- fluent 流体动力学CFD
- Azure Pipelines 文档引用的示例 Java 应用程序.zip
- Apereo Java CAS 客户端.zip
- RAW文件的打开方法与专业处理工具推荐
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功