示例#1
0
def listImage():
    resp = {
        'state': 'SUCCESS',
        'list': [],
        'start': 0,
        'total': 0
    }  # 请求拿到的动作数据。action: listimage,所以放的是list

    req = request.values

    start = int(req['start']) if 'start' in req else 0  # 初始值
    page_size = int(req['size']) if 'size' in req else 20  #每页大小

    query = Image.query
    if start > 0:
        query = query.filter(Image.id < start)  # 倒序拍的,所以id越来越小

    list = query.order_by(Image.id.desc()).limit(
        page_size).all()  #id倒序查出所有图片。offest:页面偏移量。limit:图片的数量
    images = []  # 返回的是一个数组

    if list:  #如果list存在
        for item in list:  # 进行循环
            images.append({'url': UrlManager.buildImageUrl(item.file_key)
                           })  # 字典,添加url地址
            start = item.id
    resp['list'] = images
    resp['start'] = start
    resp['total'] = len(images)
    return jsonify(resp)
示例#2
0
def listImage():
    '''
    action: listimage
    start: 0
    size: 20                返回每一页开始的ID字段 和 图片页数
    '''

    resp = {'state': 'SUCCESS', 'list': [], 'start': 0, 'total': 0}
    req = request.values
    start = int(req['start']) if 'start' in req else 0
    page_size = int(req['size']) if 'size' in req else 20

    # 分页 方法2——通过 id方式,快速查询id,跨苏查询出来结果集——更快!
    # 分页 方法1——通过 offset:
    query = Image.query
    if start > 0:
        query = query.filter(Image.id < start)  # 因为咱们是按照  降序排列进行查询的。

    # 获取对应list —— 图片路径的存储地址
    list = query.order_by(Image.id.desc()).limit(page_size).all()
    images = []

    image_id = None
    if list:
        for item in list:
            images.append({'url': UrlManager.buildImageUrl(item.file_key)})
            image_id = item.id

    resp['list'] = images
    resp['start'] = image_id
    resp['total'] = len(images)
    return jsonify(resp)
示例#3
0
def cartIndex():
    resp = {'code': 200, 'msg': '查询购物车成功~', 'data': {}}
    member_info = g.member_info  # 取出用户信息
    if not member_info:
        resp['code'] = -1
        resp['msg'] = "获取失败,伪登录~~"
        return jsonify(resp)
    cart_list = MemberCart.query.filter_by(member_id=member_info.id).all()
    data_cart_list = []
    if cart_list:
        food_ids = selectFilterObj(cart_list, "food_id")  # 获取所有的 food_id
        food_map = getDictFilterField(
            Food, Food.id, "id", food_ids)  # 到food表里面进行查询。返回map方柏霓取值,因为它有 key
        for item in cart_list:
            tmp_food_info = food_map[item.food_id]
            tmp_data = {  # 已添加的商品信息
                "id": item.id,  # 购物车商品id
                "number": item.quantity,  # 添加的数量
                "food_id": item.food_id,  # 商品id
                "name": tmp_food_info.name,  # 商品名称
                "price": str(tmp_food_info.price),
                "pic_url":
                UrlManager.buildImageUrl(tmp_food_info.main_image),  # 封面图
                "active": True  # 是否被选中
            }
            data_cart_list.append(tmp_data)

    resp['data']['list'] = data_cart_list
    return jsonify(resp)
示例#4
0
def cartIndex():
    resp = {'code':200, 'msg':'操作成功', 'data':{}}
    member_info = g.member_info
    if not member_info:
        resp['code'] = -1
        resp['msg'] = '获取失败,未登录'
        return jsonify(resp)

    cart_list = MemberCart.query.filter_by(member_id = member_info.id).all()
    # cart_list [<common.models.member.MemberCart.MemberCart object at 0x7ff44568d9b0>,
    # <common.models.member.MemberCart.MemberCart object at 0x7ff44568da90>]
    data_cart_list = []
    if cart_list:
        # 在购物车表里找food_ids,然后再筛选出对象
        food_ids = selectFilterObj(cart_list, "food_id")
        # food_ids:[17, 3]
        food_map = getDictFilterField(Food, Food.id, "id", food_ids)
        # food_map:{3: <common.models.food.Food.Food object at 0x7ff445632b70>,
        # 17: <common.models.food.Food.Food object at 0x7ff445632be0>}
        for item in cart_list:
            tmp_food_info = food_map[item.food_id]

            tmp_data = {
                "id":item.id,
                "food_id":item.food_id,
                "number":item.quantity,
                "name":tmp_food_info.name,
                "price":str(tmp_food_info.price),
                "pic_url":UrlManager.buildImageUrl(tmp_food_info.main_image),
                "active":True
            }
            data_cart_list.append(tmp_data)
    resp['data']['list'] = data_cart_list
    return jsonify(resp)
示例#5
0
def cartIndex():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    member_info = g.member_info
    if not member_info:
        resp['code'] = -1
        resp['msg'] = "获取失败,未登录~"
        return jsonify(resp)

    # 取出购物车list
    cart_list = MemberCart.query.filter_by(member_id=member_info.id).all()
    data_cart_list = []
    # 业务封装
    if cart_list:  # 重点逻辑!
        food_ids = selectFilterObj(cart_list, 'food_id')  # 获取所有的 food_id
        food_map = getDictFilterField(Food, Food.id, 'id', food_ids)

        for item in cart_list:
            tmp_food_info = food_map[item.food_id]
            tmp_data = {
                'id': item.id,
                'food_id': item.food_id,
                'number': item.quantity,
                'name': tmp_food_info.name,
                'price': str(tmp_food_info.price),
                'pic_url': UrlManager.buildImageUrl(tmp_food_info.main_image),
                'active': True  #  默认是否为选中状态
            }
            data_cart_list.append(tmp_data)
    resp['data']['list'] = data_cart_list
    return jsonify(resp)
示例#6
0
def cartIndex():
    resp = {'code': 200, 'msg': 'ok', 'data': {}}
    member_info = g.member_info
    if not member_info:
        resp['code'] = -1
        resp['msg'] = '未登录'
        return jsonify(resp)

    cart_list = MemberCart.query.filter_by(member_id=member_info.id).all()
    data_cart_list = []
    if cart_list:
        food_ids = selectFilterObj(cart_list, 'food_id')
        food_map = getDictFilterField(Food, Food.id, 'id', food_ids)

        for item in cart_list:
            tem_food_info = food_map[item.food_id]
            tmp_data = {
                "id": item.id,
                "food_id": item.food_id,
                "pic_url": UrlManager.buildImageUrl(tem_food_info.main_image),
                "name": tem_food_info.name,
                "price": str(tem_food_info.price),
                "active": True,
                "number": item.quantity
            }
            data_cart_list.append(tmp_data)
    resp['data']['list'] = data_cart_list

    return jsonify(resp)
示例#7
0
def cartIndex():
    resp = {'code': 200, 'msg': '添加购物车成功~', 'data': {}}
    member_info = g.member_info
    if not member_info:
        resp['code'] = -1
        resp['msg'] = "获取失败,未登录~~"
        return jsonify(resp)
    cart_list = MemberCart.query.filter_by(
        member_id=member_info.id).all()  # 所有的car组成列表
    data_cart_list = []
    if cart_list:
        food_ids = selectFilterObj(cart_list, "food_id")  # 从购物车列表中取出id(组成id列表)
        food_map = getDictFilterField(Food, Food.id, "id",
                                      food_ids)  # 在food表获得{'id':{food信息}}的字典
        # 传入要查询的表,表的字段,等于food_ids里面的,生成的可以值为id
        for item in cart_list:  # 组装成列表
            tmp_food_info = food_map[item.food_id]  # 取出map信息
            tmp_data = {
                "id": item.id,
                "number": item.quantity,
                "food_id": item.food_id,
                "name": tmp_food_info.name,
                "price": str(tmp_food_info.price),
                "pic_url": UrlManager.buildImageUrl(tmp_food_info.main_image),
                "active": True
            }
            data_cart_list.append(tmp_data)

    resp['data']['list'] = data_cart_list
    return jsonify(resp)
示例#8
0
文件: report.py 项目: rxwycdh/iJFv2.0
def uploadImage():
    resp = {'code': 200, 'msg': 'successfully!', 'data': {}}
    file_target = request.files
    app.logger.info(file_target)
    upfile = file_target['upfile'] if 'upfile' in file_target else None
    if upfile is None:
        resp['code'] = -1
        resp['msg'] = '上传失败'
        return jsonify(resp)
    ret = UploadService.uploadByFile(upfile)
    if ret['code'] != 200:
        resp['state'] = "上传失败" + ret['msg']
        return jsonify(resp)

    model_report = Report()
    model_report.member_id = g.member_info.id
    model_report.attribute = -1
    model_report.name = -1
    model_report.mobile = -1
    model_report.address = -1
    model_report.description = -1
    model_report.main_image = ret['data']['file_key']
    model_report.random_code = ret['data']['random_code']
    model_report.status = -1
    model_report.updated_time = getCurrentDate()
    model_report.created_time = getCurrentDate()
    db.session.add(model_report)
    db.session.commit()
    resp['data']['url'] = UrlManager.buildImageUrl(ret['data']['file_key'])
    resp['data']['random_code'] = ret['data']['random_code']
    return jsonify(resp)
示例#9
0
def foodSearch():
	resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
	req = request.values
	cat_id = int(req['cat_id']) if 'cat_id' in req else 0
	p = int(req['p']) if 'p' in req else 0
	mix_kw = str(req['mix_kw']) if 'mix_kw' in req else ''
	query = Food.query.filter_by(status=1)
	if p < 1:
		p = 1

	page_size = 10
	offset = (p - 1) * page_size
	if cat_id > 0:
		query = query.filter(Food.cat_id == cat_id)

	if 'mix_kw' in req and req['mix_kw']:
		rule = or_(Food.name.ilike("%{0}%".format(mix_kw)), Food.tags.ilike("%{0}%".format(mix_kw)))
		query = query.filter(rule)

	food_list = query.order_by(Food.total_count.desc(), Food.id.desc()).offset(offset).limit(page_size).all()
	data_food_list = []
	if food_list:
		for item in food_list:
			tmp_data = {
				'id': item.id,
				'name': item.name,
				'price': str(item.price),
				'min_price': str(item.price),
				'pic_url': UrlManager.buildImageUrl(item.main_image),
			}
			data_food_list.append((tmp_data))
	resp['data']['list'] = data_food_list
	resp['data']['has_more'] = 0 if len(data_food_list) < page_size else 1
	return jsonify(resp)
示例#10
0
def foodIndex():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    cat_list = FoodCat.query.filter_by(status=1).order_by(
        FoodCat.weight.desc()).all()
    data_cat_list = []
    data_cat_list.append({'id': 0, 'name': "全部"})
    if cat_list:
        for item in cat_list:
            tmp_data = {'id': item.id, 'name': item.name}
            data_cat_list.append(tmp_data)
    resp['data']['cat_list'] = data_cat_list

    food_list = Food.query.filter_by( status = 1 )\
        .order_by( Food.total_count.desc(),Food.id.desc() ).limit(3).all()

    data_food_list = []
    if food_list:
        for item in food_list:
            tmp_data = {
                'id': item.id,
                'pic_url': UrlManager.buildImageUrl(item.main_image)
            }
            data_food_list.append(tmp_data)

    resp['data']['banner_list'] = data_food_list
    return jsonify(resp)
示例#11
0
def food_index():
    """美食页面展示"""
    res = {'code': 200, 'msg': '操作成功', 'data': {}}
    data_cat_list = []
    cat_list = FoodCat.query.filter_by(status=1).order_by(
        FoodCat.weight.desc()).all()
    data_cat_list.append({'id': 0, 'name': '全部'})
    if cat_list:
        for item in cat_list:
            data_cat_list.append({'id': item.id, 'name': item.name})
    res['data']['cat_list'] = data_cat_list

    food_list = Food.query.filter_by(status=1).order_by(
        Food.total_count.desc(), Food.id.desc()).limit(3).all()
    data_food_list = []
    if food_list:
        for item in food_list:
            data_food_list.append({
                'id':
                item.id,
                'pic_url':
                UrlManager.buildImageUrl(item.main_image)
            })
    res['data']['banner_list'] = data_food_list
    return jsonify(res)
示例#12
0
def courseIndex():
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}

    #类别
    cat_list = CourseCat.query.filter_by(status=1).order_by(
        CourseCat.weight.desc()).all()
    #数据重构是为了把'全部'这个类型加到目录中去
    data_cat_list = []
    data_cat_list.append({'id': 0, 'name': '全部'})
    if cat_list:
        for item in cat_list:
            tmp_data = {'id': item.id, 'name': item.name}
            data_cat_list.append(tmp_data)
    resp['data']['cat_list'] = data_cat_list
    #banner
    banner_list = Course.query.filter_by(status=1).order_by(
        Course.total_count.desc(), Course.id.desc()).limit(3).all()
    data_banner_list = []
    if banner_list:
        for item in banner_list:
            tmp_data = {
                'id': item.id,
                'pic_url': UrlManager.buildImageUrl(item.main_image)
            }
            data_banner_list.append(tmp_data)
    resp['data']['banner_list'] = data_banner_list

    return jsonify(resp)
示例#13
0
def quantIndex():
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    cat_list = QuantCat.query.filter_by(status=1).order_by(QuantCat.weight.desc()).all()
    data_cat_list = []
    data_cat_list.append({
        'id': 0,
        'name': '全部'
    })
    if cat_list:
        for item in cat_list:
            tmp_data = {
                "id": item.id,
                "name": item.name
            }
            data_cat_list.append(tmp_data)
    resp['data']['cat_list'] = data_cat_list

    quant_list = Quant.query.filter_by(status=1)\
        .order_by(Quant.total_count.desc(), Quant.id.desc()).limit(3).all()
    data_quant_list = []
    if quant_list:
        for item in quant_list:
            tmp_data = {
                "id": item.id,
                "pic_url": UrlManager.buildImageUrl(item.main_image)
            }
            data_quant_list.append(tmp_data)
    resp['data']['banner_list'] = data_quant_list
    return jsonify(resp)
示例#14
0
def cartIndex():
    resp = {'code': 200, 'msg': "操作成功", 'data': {}}
    req = request.values
    member_info = g.member_info

    if not member_info:
        resp['code'] = -1
        resp['msg'] = "未登录"
        return jsonify(resp)

    cart_list = MemberCart.query.filter_by(member_id=member_info.id).all()

    data_cart_list = []
    if cart_list:
        food_ids = selectFilterObj(cart_list, "food_id")
        food_map = getDictFilterField(Food, Food.id, "id", food_ids)
        for item in cart_list:
            tmp_food_info = food_map[item.food_id]
            tmp_data = {
                'id': item.id,
                'food_id': item.food_id,
                'number': item.quantity,
                'name': tmp_food_info.name,
                'price': str(tmp_food_info.price),
                'pic_url': UrlManager.buildImageUrl(tmp_food_info.main_image),
                'active': True
            }
            data_cart_list.append(tmp_data)

    resp['data']['list'] = data_cart_list
    return jsonify(resp)
示例#15
0
def listImage():
    resp = {'state': 'SUCCESS', 'list': [], 'total': 0, 'start': 0}

    req = request.values
    start = int(req['start']) if 'start' in req else 0
    page_size = int(req['size']) if 'size' in req else 0

    query = Image.query
    if start > 0:
        query = query.filter(Image.id < start)
    list = query.order_by(Image.id.desc()).limit(page_size).all()
    # 这里是通过id 来处理加载
    # 也可以使用offset 进行分页处理
    images = []
    if list:
        for item in list:
            images.append({
                'url': UrlManager.buildImageUrl(item.file_key),
            })
            start = item.id

    resp['start'] = start
    resp['list'] = images
    resp['total'] = len(images)
    return jsonify(resp)
示例#16
0
文件: Cart.py 项目: xzxedu/quant_demo
def cartIndex():
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    member_info = g.member_info
    if not member_info:
        resp['code'] = -1
        resp['msg'] = "获取失败,未登录"
        return jsonify(resp)
    cart_list = MemberCart.query.filter_by(member_id=member_info.id).all()
    data_cart_list = []
    if cart_list:
        quant_ids = selectFilterObj(cart_list, "quant_id")
        quant_map = getDictFilterField(Quant, Quant.id, "id", quant_ids)
        for item in cart_list:
            tmp_quant_info = quant_map[item.quant_id]
            tmp_data = {
                "id": item.id,
                "quant_id": item.quant_id,
                "number": item.quantity,
                "name": tmp_quant_info.name,
                "price": str(tmp_quant_info.price),
                "pic_url": UrlManager.buildImageUrl(tmp_quant_info.main_image),
                "active": True
            }
            data_cart_list.append(tmp_data)
    resp['data']['list'] = data_cart_list
    return jsonify(resp)
示例#17
0
文件: Course.py 项目: starqing/webapp
def course_search():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values
    p = int(req['p']) if 'p' in req else 1
    if p < 1:
        p = 1

    page_size = 10
    offset = (p - 1) * page_size
    query = Food.query.filter_by(status=1)
    food_list = query.order_by(Food.total_count.desc(), Food.id.desc()) \
        .offset(offset).limit(page_size).all()
    data_food_list = []
    if food_list:
        for item in food_list:
            tmp_data = {
                'id': item.id,
                'name': "%s" % (item.name),
                'pic_url': UrlManager.buildImageUrl(item.main_image),
                'totle': item.total_count
            }
            data_food_list.append(tmp_data)
    resp['data']['list'] = data_food_list
    resp['data']['has_more'] = 0 if len(data_food_list) < page_size else 1
    return jsonify(resp)
示例#18
0
def myIndex():
    resp = {'code': 200, 'msg': "操作成功", 'data': {}}
    req = request.values
    member_info = g.member_info

    status = int(req['status']) if 'status' in req else 0
    query = PayOrder.query.filter_by(member_id=member_info.Id)

    if status == -8:
        query = query.filter(PayOrder.status == -8)
    elif status == -7:  # 待发货
        query = query.filter(PayOrder.status == 1, PayOrder.express_status == -7, PayOrder.comment_status == 0)
    elif status == -6:  # 待确认
        query = query.filter(PayOrder.status == 1, PayOrder.express_status == -6, PayOrder.comment_status == 0)
    elif status == -5:
        query = query.filter(PayOrder.status == 1, PayOrder.express_status == 1, PayOrder.comment_status == 0)
    elif status == 1:
        query = query.filter(PayOrder.status == 1, PayOrder.express_status == 1)
    else:
        query = query.filter(PayOrder.status == 0)

    pay_order_list = query.order_by(PayOrder.id.desc()).all()
    data_pay_order_list = []
    if pay_order_list:
        pay_order_ids = selectFilterObj(pay_order_list, "id")
        pay_order_item_list = PayOrderItem.query.filter(PayOrderItem.pay_order_id.in_(pay_order_ids)).all()
        food_ids = selectFilterObj(pay_order_item_list, "food_id")
        food_map = getDictFilterField(Shop_Info, Shop_Info.Id, "Id", food_ids)
        pay_order_item_map = {}
        if pay_order_item_list:
            for item in pay_order_item_list:
                if item.pay_order_id not in pay_order_item_map:
                    pay_order_item_map[item.pay_order_id] = []

                tmp_food_info = food_map[item.food_id]
                pay_order_item_map[item.pay_order_id].append({
                    'id': item.id,
                    'food_id': item.food_id,
                    'quantity': item.quantity,
                    'pic_url': UrlManager.buildImageUrl(tmp_food_info.ShopImageUrl),
                    'name': tmp_food_info.ShopName
                })

        for item in pay_order_list:
            tmp_data = {
                'status': item.pay_status,
                'status_desc': item.status_desc,
                'date': item.created_time.strftime("%Y-%m-%d %H:%M:%S"),
                'order_number': item.order_number,
                'order_sn': item.order_sn,
                'note': item.note,
                'total_price': str(item.total_price),
                'goods_list': pay_order_item_map[item.id]
            }

            data_pay_order_list.append(tmp_data)

    resp['data']['pay_order_list'] = data_pay_order_list
    return jsonify(resp)
示例#19
0
def myOrderList():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    member_info = g.member_info  # 获取用户对象
    req = request.values
    status = int(req['status']) if 'status' in req else 0
    query = PayOrder.query.filter_by(member_id=member_info.id)  # 查询id查询订单信息

    if status == -8:  # 等待付款
        query = query.filter(PayOrder.status == -8)
    elif status == -7:  # 待发货,已付款
        query = query.filter(PayOrder.status == 1, PayOrder.express_status == -7, PayOrder.comment_status == 0)
    elif status == -6:  # 待确认
        query = query.filter(PayOrder.status == 1, PayOrder.express_status == -6, PayOrder.comment_status == 0)
    elif status == -5:  # 待评价
        query = query.filter(PayOrder.status == 1, PayOrder.express_status == 1, PayOrder.comment_status == 0)
    elif status == 1:  # 已完成
        query = query.filter(PayOrder.status == 1, PayOrder.express_status == 1, PayOrder.comment_status == 1)
    else:
        query = query.filter(PayOrder.status == 0)  # 已关闭

    pay_order_list = query.order_by(PayOrder.id.desc()).all()  # 取出所有订单
    data_pay_order_list = []
    if pay_order_list:
        pay_order_ids = selectFilterObj(pay_order_list, "id")
        pay_order_item_list = PayOrderItem.query.filter(PayOrderItem.pay_order_id.in_(pay_order_ids)).all()
        food_ids = selectFilterObj(pay_order_item_list, "food_id")
        food_map = getDictFilterField(Food, Food.id, "id", food_ids)
        pay_order_item_map = {}
        if pay_order_item_list:
            for item in pay_order_item_list:
                if item.pay_order_id not in pay_order_item_map:
                    pay_order_item_map[item.pay_order_id] = []

                tmp_food_info = food_map[item.food_id]
                pay_order_item_map[item.pay_order_id].append({
                    'id': item.id,
                    'food_id': item.food_id,
                    'quantity': item.quantity,
                    'price': str(item.price),
                    'pic_url': UrlManager.buildImageUrl(tmp_food_info.main_image),
                    'name': tmp_food_info.name
                })

        for item in pay_order_list:
            tmp_data = {
                'status': item.pay_status,
                'status_desc': item.status_desc,
                'date': item.created_time.strftime("%Y-%m-%d %H:%M:%S"),
                'order_number': item.order_number,
                'order_sn': item.order_sn,
                'note': item.note,
                'total_price': str(item.total_price),
                'goods_list': pay_order_item_map[item.id]
            }

            data_pay_order_list.append(tmp_data)
    resp['data']['pay_order_list'] = data_pay_order_list
    return jsonify(resp)
示例#20
0
def foodSearch():
    # 分页搜索与简单搜索
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values
    '''
    注意是要在 对应的分类里面进行复合查询
    '''
    cat_id = int(req['cat_id']) if 'cat_id' in req else 0
    mix_kw = str(req['mix_kw']) if 'mix_kw' in req else ''
    p = int(req['p']) if 'p' in req else 1
    if p < 1:
        p = 1
    page_size = 10
    offset = (p - 1) * page_size

    # 修改catid
    query = Food.query.filter(Food.status == 1, Food.cat_id != shop_cat_id)
    if 'cat_id' in req and int(req['cat_id']) > 0:
        query = query.filter(Food.cat_id == int(req['cat_id']))
    if mix_kw:
        rule = or_(Food.name.ilike("%{0}%".format(mix_kw)),
                   Food.tags.ilike("%{0}%".format(mix_kw)))
        query = query.filter(rule)

    food_list = query.order_by(
        Food.total_count.desc(),
        Food.id.desc()).offset(offset).limit(page_size).all()

    # # 修改
    # # 初始化购物车的数量
    # member_info = g.member_info
    # if not member_info:
    #     resp['code'] = -1
    #     resp['msg'] = "获取失败,未登录~"
    #     return jsonify( resp )
    # cart_list = MemberCart.query.filter_by( member_id = member_info.id ).all()
    # cart_foods_id = selectFilterObj( cart_list, 'food_id' )
    # cart_map = getDictFilterField( MemberCart, None, 'food_id', [])

    # 转化为前端需要的list结构
    data_food_list = []
    if food_list:
        for item in food_list:
            tmp_data = {
                'id': item.id,
                'name': item.name,
                'price': str(item.price),  # 出问题了为什么?因为json 传出去decimal!
                'min_price': str(item.price),
                'sales': item.total_count,
                'pic_url': UrlManager.buildImageUrl(item.main_image)
            }
            data_food_list.append(tmp_data)

    resp['data']['list'] = data_food_list
    # 判断是否还需要发送数据
    resp['data']['has_more'] = 0 if len(data_food_list) < page_size else 1

    return jsonify(resp)
示例#21
0
def upload_img():
    response = {'status': 1, 'message': '文件上传成功'}
    image = request.files['file']
    file_path = os.path.join('Images/', image.filename)
    save_path = os.path.join(app.config["ABS_UPLOAD_FOLDER"], image.filename)
    image.save(save_path)
    result = UrlManager.buildImageUrl(file_path)
    response['img'] = result
    return jsonify(response)
示例#22
0
def orderInfo():

    resp = {'code': 200, 'msg': "操作成功", 'data': {}}
    req = request.values
    params_goods = req['goods'] if 'goods' in req else None

    member_info = g.member_info
    goods_list = []
    if params_goods:
        goods_list = json.loads(params_goods)

    food_dic = {}
    for item in goods_list:
        food_dic[item['id']] = item['number']

    food_ids = food_dic.keys()
    food_list = Food.query.filter(Food.id.in_(food_ids)).all()
    data_food_list = []

    yun_price = pay_price = decimal.Decimal(0.00)
    if food_list:
        for item in food_list:
            tmp_data = {
                'id': item.id,
                'name': item.name,
                'price': str(item.price),
                'pic_url': UrlManager.buildImageUrl(item.main_image),
                'number': food_dic[item.id]
            }
            pay_price = pay_price + item.price * int(food_dic[item.id])
            data_food_list.append(tmp_data)

    # 获取地址
    address_info = MemberAddress.query.filter_by(is_default=1,
                                                 member_id=member_info.id,
                                                 status=1).first()
    default_address = ''
    if address_info:
        default_address = {
            "id":
            address_info.id,
            "name":
            address_info.nickname,
            "mobile":
            address_info.mobile,
            "address":
            "%s%s%s%s" % (address_info.province_str, address_info.city_str,
                          address_info.area_str, address_info.address)
        }
    resp['data']['food_list'] = data_food_list
    resp['data']['pay_price'] = str(pay_price)
    resp['data']['yun_price'] = str(yun_price)
    resp['data']['total_price'] = str(pay_price + yun_price)
    resp['data']['default_address'] = default_address
    return jsonify(resp)
示例#23
0
def orderInfo():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values
    params_goods = req[
        'goods'] if 'goods' in req else None  # 用户传回的 goods 是一个json数据
    member_info = g.member_info
    params_goods_list = []  # 遍历存放
    if params_goods:
        params_goods_list = json.loads(params_goods)  # 反解信息,放到 list列表里面

    food_dic = {}  #字典,因为要取出想购买的份数
    for item in params_goods_list:
        food_dic[item['id']] = item['number']

    food_ids = food_dic.keys()  # 到字典里,取出所有的 key值
    food_list = Food.query.filter(Food.id.in_(food_ids)).all()
    data_food_list = []  # 将上面的 food_list结果集,进行统一格式化
    yun_price = pay_price = decimal.Decimal(0.00)  # 运费
    if food_list:
        for item in food_list:
            tmp_data = {  # 进行格式化
                "id": item.id,
                "name": item.name,
                "price": str(item.price),
                'pic_url': UrlManager.buildImageUrl(item.main_image),
                'number': food_dic[item.id]
            }
            pay_price = pay_price + item.price * int(
                food_dic[item.id])  # 付的钱 = 当前价格 + 商品价格 * 下单数量
            data_food_list.append(tmp_data)

    # 获取地址
    # address_info = MemberAddres.query.filter_by(is_default=1, member_id=member_info.id, status=1).first()
    # default_address = ''
    default_address = {
        "name": "王伟",
        "mobile": 18501490003,
        "address": "江苏省苏州市苏州工业园区服务外包职业学院"
    }
    # if address_info:
    #     default_address = {
    #         "id": address_info.id,
    #         "name": address_info.nickname,
    #         "mobile": address_info.mobile,
    #         "address": "%s%s%s%s" % (
    #         address_info.province_str, address_info.city_str, address_info.area_str, address_info.address)
    #     }
    #
    resp['data']['food_list'] = data_food_list
    resp['data']['pay_price'] = str(
        pay_price)  # 商品应付。因为json无法将Decimal转化成json对象
    resp['data']['yun_price'] = str(yun_price)  # 运费
    resp['data']['total_price'] = str(pay_price + yun_price)  # 总价格
    resp['data']['default_address'] = default_address  # 地址
    return jsonify(resp)
示例#24
0
def courseInfo():
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values
    id = int(req['id']) if 'id' in req else 0,

    course_info = Course.query.filter_by(id=id).first()
    if not course_info or not course_info.status:
        resp['code'] = -1
        resp['msg'] = '课程已经下架'
        return jsonify(resp)

    #课程登记信息一同返回前台,计算共登记了几门课程
    member_info = session.member_info
    cart_number = 0
    if member_info:
        cart_number = MemberCart.query.filter_by(member_id=member_info.id,
                                                 register_status=1).count()

    #该课有几人报名
    course_id = id
    register_number = 0
    if course_id:
        register_number = MemberCart.query.filter_by(
            course_id=course_id, register_status=1).count()

    resp['data']['info'] = {
        'id': course_info.id,
        'name': course_info.name,
        'course_date': course_info.course_date,
        'location': course_info.location,
        'summary': course_info.summary,
        'total_count': course_info.total_count,
        'main_image': UrlManager.buildImageUrl(course_info.main_image),
        'price': int(course_info.price),
        'stock': int(course_info.stock),
        'pics': [UrlManager.buildImageUrl(course_info.main_image)],
        'register_number': register_number
    }

    resp['data']['cart_number'] = cart_number

    return jsonify(resp)
示例#25
0
def upload_img():
    resp = {'status': 1, 'message': '文件上传成功'}
    image = request.files['file']
    file_path = os.path.join('Images/', image.filename)
    save_path = os.path.join(app.config["ABS_UPLOAD_FOLDER"], image.filename)
    image.save(save_path)
    result = UrlManager.buildImageUrl(file_path)
    resp['img'] = result
    response = jsonify(resp)
    response.headers['Access-Control-Allow-Origin'] = '*'
    return response
示例#26
0
def orderInfo():
    resp = {"code": 200, "msg": "添加成功", "data": {}}
    req = request.values
    # order_sn = str(req.get('order_sn', ''))
    member_info = g.member_info
    # print(order_sn)
    # order_info = PayOrder.query.filter_by(order_sn=order_sn).first()
    # print(order_info)
    #
    # data_product_list = []
    # pay_price = decimal.Decimal(0.00)
    # if order_info:
    #     goods_list = PayOrderItem.query.filter_by(id=order_info.id).all()
    #     for item in goods_list:
    #         tmp_data = {
    #             'id': item.id,
    #             'name': item.name,
    #             'price': str(item.price),
    #             'pic_url': UrlManager.buildImageUrl(item.main_image),
    #             'number': item.quantity
    #         }
    #         pay_price = pay_price + item.price * int(item.quantity)
    #         data_product_list.append(tmp_data)
    #     print(data_product_list)

    params_goods = req['goods'] if 'goods' in req else None
    params_goods_list = []
    if params_goods:
        params_goods_list = json.loads(params_goods)

    product_dic = {}
    for item in params_goods_list:
        product_dic[item['id']] = item['number']

    product_ids = product_dic.keys()
    product_list = Product.query.filter(Product.id.in_(product_ids)).all()
    pay_price = decimal.Decimal(0.00)
    data_product_list = []
    if product_list:
        for item in product_list:
            tmp_data = {
                'id': item.id,
                'name': item.name,
                'price': str(item.price),
                'pic_url': UrlManager.buildImageUrl(item.main_image),
                'number': product_dic[item.id]
            }
            pay_price = pay_price + item.price * int(product_dic[item.id])
            data_product_list.append(tmp_data)

    resp['data']['product_list'] = data_product_list
    resp['data']['pay_price'] = str(pay_price)
    resp['data']['total_price'] = str(pay_price)
    return jsonify(resp)
示例#27
0
def myOrderInfo():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    member_info = g.member_info
    req = request.values
    order_sn = req['order_sn'] if 'order_sn' in req else ''
    pay_order_info = PayOrder.query.filter_by(member_id=member_info.id,
                                              order_sn=order_sn).first()
    if not pay_order_info:
        resp['code'] = -1
        resp['msg'] = "系统繁忙,请稍后再试~~"
        return jsonify(resp)

    address_info = MemberAddress.query.filter_by(
        id=pay_order_info.express_address_id).first()
    if address_info:
        address_info = {
            'mobile':
            address_info.mobile,
            'nickname':
            address_info.nickname,
            "address":
            "%s%s%s%s" % (address_info.province_str, address_info.city_str,
                          address_info.area_str, address_info.address)
        }
    tmp_deadline = pay_order_info.created_time + datetime.timedelta(minutes=30)
    info = {
        "order_sn": pay_order_info.order_sn,
        "status": pay_order_info.pay_status,
        "status_desc": pay_order_info.status_desc,
        "pay_price": str(pay_order_info.pay_price),
        "yun_price": str(pay_order_info.yun_price),
        "total_price": str(pay_order_info.total_price),
        "address": address_info,
        "goods": [],
        "deadline": tmp_deadline.strftime("%Y-%m-%d %H:%M")
    }

    pay_order_items = PayOrderItem.query.filter_by(
        pay_order_id=pay_order_info.id).all()
    if pay_order_items:
        food_ids = selectFilterObj(pay_order_items, "food_id")
        food_map = getDictFilterField(Food, Food.id, "id", food_ids)
        for item in pay_order_items:
            tmp_food_info = food_map[item.food_id]
            tmp_data = {
                "name": tmp_food_info.name,
                "price": str(item.price),
                "unit": item.quantity,
                "pic_url": UrlManager.buildImageUrl(tmp_food_info.main_image),
            }
            info['goods'].append(tmp_data)
    resp['data']['info'] = info
    return jsonify(resp)
示例#28
0
文件: Upload.py 项目: FitzWHU/order
def uploadImage():
    resp = {'state': 'SUCCESS', 'url': '', 'title': '', 'original': ''}
    file_target = request.files
    upfile = file_target.get('upfile', None)
    if upfile is None:
        resp['state'] = '上传失败'
        return jsonify(resp)
    ret = UploadService.uploadByFile(upfile)
    if ret['code'] != 200:
        resp['state'] = '上传失败' + ret['msg']
        return jsonify(resp)
    resp['url'] = UrlManager.buildImageUrl(ret['data']['file_key'])
    return jsonify(resp)
示例#29
0
def myInfo():
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values
    id = int(req['id']) if 'id' in req else 0

    comment_info = InstructorComment.query.filter_by(id=id).first()
    if not comment_info:
        resp['code'] = -1
        resp['msg'] = '没有老师评论'
        return jsonify(resp)

    course_info = Course.query.filter_by(id=comment_info.course_id).first()

    course_id = comment_info.course_id
    register_number = 0
    if course_id:
        register_number = MemberCart.query.filter_by(
            course_id=course_id).count()

    resp['data']['info'] = {
        # comment表中的数据
        "id": comment_info.id,
        "instructor_id": comment_info.instructor_id,
        "course_id": comment_info.course_id,
        "title": comment_info.title,
        "instructor_course_summary": comment_info.instructor_course_summary,
        "updated_date": comment_info.updated_time.strftime("%Y-%m-%d"),
        "pic_url": UrlManager.buildImageUrl(comment_info.main_image),

        # mapping到course表中的数据
        "name": course_info.name,
        "price": str(course_info.price),
        "course_date": course_info.course_date,
        "tags": course_info.tags,
        "active": True,

        #MemberCart 的数据,本课程一共几个人报名
        'register_number': register_number
    }

    # 课程登记信息一同返回前台,计算共登记了几门课程
    member_info = session.member_info
    cart_number = 0
    if member_info:
        cart_number = MemberCart.query.filter_by(
            member_id=member_info.id).count()

    resp['data']['course_id'] = comment_info.course_id
    resp['data']['cart_number'] = cart_number

    return jsonify(resp)
示例#30
0
def uploadImage():
    resp = {'state': 'SUCCESS', 'url': '', 'title': '', 'original': ''}
    target_file = request.files
    upfile = target_file['upfile'] if 'upfile' in target_file else None
    if upfile is None:
        resp['state'] = '上传失败'
        return jsonify(resp)
    ret = UploadService.uploadByFile(upfile)
    print(ret)
    if ret['code'] != 200:
        resp['state'] = '上传失败:' + ret['msg']
        return jsonify(resp)
    resp['url'] = UrlManager.buildImageUrl(ret['data']['file_key'])
    return jsonify(resp)