Beispiel #1
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 )
	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)
Beispiel #2
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)
Beispiel #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:
        # 获取表中所有的book_id,联合查询
        book_ids = selectFilterObj(cart_list, "book_id")
        book_map = getDictFilterField(Book, Book.id, "id", book_ids)
        for item in cart_list:
            tmp_book_info = book_map[item.book_id]
            tmp_data = {
                "id": item.id,
                "book_id": item.book_id,
                "number": item.quantity,
                "name": tmp_book_info.name,
                "price": str(tmp_book_info.price),
                "pic_url": UrlManager.buildImageUrl(tmp_book_info.main_image),
                "active": True
            }
            data_cart_list.append(tmp_data)

    resp['data']['list'] = data_cart_list

    return jsonify(resp)
Beispiel #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()
    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,
                "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)
Beispiel #5
0
def myComment():
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values
    instructor_comment_id = req['id'] if 'id' in req else 0

    query = MemberComments.query.filter_by(
        instructor_comment_id=instructor_comment_id)

    list = query.order_by(MemberComments.id.desc()).limit(5).all()
    data_list = []
    if list:
        member_map = getDictFilterField(Member, Member.id, "id",
                                        selectFilterObj(list, 'member_id'))
        for item in list:
            if item.member_id not in member_map:
                continue
            tmp_member_info = member_map[item.member_id]
            tmp_data = {
                'score': item.score_desc,
                'date': item.created_time.strftime("%Y-%m-%d %H:%M:%S"),
                'content': item.content,
                'user': {
                    'nickname': tmp_member_info.nickname,
                    'avatar_url': tmp_member_info.avatar
                }
            }
            data_list.append(tmp_data)

    resp['data']['list'] = data_list
    resp['data']['count'] = query.count()
    return jsonify(resp)
Beispiel #6
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_dic = getDictFilterFiled(Food, Food.id, 'id', food_ids)
        for item in cart_list:
            tmp_food_info = food_dic[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)
Beispiel #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()
    # 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)
Beispiel #8
0
def myCommentList():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values
    p = int(req['p']) if 'p' in req else 0
    page_size = int(req['size']) if 'size' in req else 10

    if p < 1:
        p = 1

    offset = (p - 1) * page_size

    member_info = g.member_info
    comment_list = MemberComment.query.filter_by(member_id=member_info.id)\
     .order_by(MemberComment.id.desc()).offset(offset).limit(page_size).all()
    data_comment_list = []
    if comment_list:
        pay_order_ids = selectFilterObj(comment_list, 'pay_order_id')
        pay_order_map = getDictFilterField(PayOrder, PayOrder.id, 'id',
                                           pay_order_ids)
        for item in comment_list:
            tmp_pay_order_info = pay_order_map[item.pay_order_id]
            tmp_data = {
                "date": item.created_time.strftime("%Y-%m-%d %H:%M:%S"),
                "content": item.content,
                "order_number": tmp_pay_order_info.order_number
            }
            data_comment_list.append(tmp_data)
    resp['data']['list'] = data_comment_list
    resp['data']['has_more'] = 0 if len(data_comment_list) < page_size else 1
    return jsonify(resp)
Beispiel #9
0
def myCommentList():
	resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
	member_info = g.member_info
	if not member_info:
		resp['code']=-1
		resp['msg']="请登录后查看我的总结~"
		return jsonify(resp)
	comment_list = MemberComments.query.filter_by( member_id=member_info.id )\
		.order_by(MemberComments.id.desc()).all()

	data_comment_list = []
	if comment_list:
		pay_order_ids = selectFilterObj( comment_list,"pay_order_id" )
		pay_order_map = getDictFilterField( PayOrderItem,PayOrderItem.id,"id",pay_order_ids )
		for item in comment_list:
			tmp_pay_order_info = pay_order_map[ item.pay_order_id ]
			food_info = Food.query.filter_by( id=tmp_pay_order_info.food_id ).first()
			tmp_data = {
				"date":item.created_time.strftime("%Y-%m-%d %H:%M:%S"),
				"content":item.content,
				"speaker":tmp_pay_order_info.speaker,
				"lecture_time":tmp_pay_order_info.lecture_time,
				"name":food_info.name
			}
			data_comment_list.append( tmp_data )
	resp['data']['list'] = data_comment_list
	return jsonify(resp)
Beispiel #10
0
def foodComments():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values
    id = int(req['id']) if 'id' in req else 0

    # 使用 ilike查询; 且注意这里只查询出来了五条
    query = MemberComments.query.filter(
        MemberComments.food_ids.ilike("%_{0}_%".format(id)))
    list = query.order_by(MemberComments.id.desc()).limit(5).all()
    data_list = []
    if list:
        member_map = getDictFilterField(Member, Member.id, 'id',
                                        selectFilterObj(list, "member_id"))
        for item in list:
            if item.member_id not in member_map:
                continue
            tmp_member_info = member_map[item.member_id]
            tmp_data = {
                "score": item.score_desc,
                "date": item.created_time.strftime("%Y-%m-%d %H:%M:%S"),
                "content": item.content,
                "user": {
                    "nickname": tmp_member_info.nickname,
                    "avatar_url": tmp_member_info.avatar,
                }
            }
            data_list.append(tmp_data)

    resp['data']['list'] = data_list
    resp['data']['count'] = query.count()
    return jsonify(resp)
Beispiel #11
0
def myIndex():
    resp = {'code': 200, 'msg': '展示成功', 'data': {}}
    comment_list = InstructorComment.query.order_by(
        InstructorComment.id.desc()).all()
    data_comment_list = []
    if comment_list:
        course_ids = selectFilterObj(comment_list, "course_id")
        course_map = getDictFilterField(Course, Course.id, "id", course_ids)
        for item in comment_list:
            tmp_course_info = course_map[item.course_id]
            tmp_data = {
                #comment表中的数据
                "id": item.id,
                "instructor_id": item.instructor_id,
                "title": item.title,
                "instructor_course_summary": item.instructor_course_summary,
                "updated_date": item.updated_time.strftime("%Y-%m-%d"),
                "pic_url": UrlManager.buildImageUrl(item.main_image),
                #mapping到course表中的数据
                "name": tmp_course_info.name,
                "course_date": tmp_course_info.course_date,
                "tags": tmp_course_info.tags,
                "active": True
            }
            data_comment_list.append(tmp_data)

    resp['data']['list'] = data_comment_list
    return jsonify(resp)
Beispiel #12
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)
Beispiel #13
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)
Beispiel #14
0
def info():
    resp_data = {}
    req = request.args
    id = int(req.get("id", 0))
    reback_url = UrlManager.buildUrl("/food/index")

    if id < 1:
        return redirect(reback_url)

    info = Food.query.filter_by(id=id).first()
    if not info:
        return redirect(reback_url)


#    stock_change_list = FoodStockChangeLog.query.filter( FoodStockChangeLog.food_id == id )\
#        .order_by( FoodStockChangeLog.id.desc() ).all()
    mem_comments = MemberComments.query.filter_by(food_ids=id).all()
    data_member_comments_list = []
    if mem_comments:
        member_ids = selectFilterObj(mem_comments, "member_id")
        member_map = getDictFilterField(Member, Member.id, "id", member_ids)
        mem_com = {}
        for item in mem_comments:
            tmp_mem_com = member_map[item.member_id]
            data_member_comments_list.append({
                'nickname': tmp_mem_com.nickname,
                'comment': item.content
            })
    print("!!!!!!")
    print(data_member_comments_list)

    resp_data['info'] = info
    resp_data['comment'] = data_member_comments_list
    resp_data['current'] = 'index'
    return ops_render("food/info.html", resp_data)
Beispiel #15
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_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,
                # "number":item.quantity,
                "food_id": item.food_id,
                "name": tmp_food_info.name,
                "speaker": tmp_food_info.speaker,
                "speaker_address": tmp_food_info.speaker_address,
                "lecture_time": tmp_food_info.lecture_time,
                "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)
Beispiel #16
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:
        product_ids = selectFilterObj(cart_list, 'product_id')
        product_map = getDictFilterField(Product, Product.id, 'id',
                                         product_ids)
        for item in cart_list:
            tmp_product_info = product_map[item.product_id]
            tmp_data = {
                'id': item.id,
                'product_id': item.product_id,
                'number': item.quantity,
                'name': tmp_product_info.name,
                'price': str(tmp_product_info.price),
                'pic_url':
                UrlManager.buildImageUrl(tmp_product_info.main_image),
                'active': True
            }
            data_cart_list.append(tmp_data)

    resp['data']['list'] = data_cart_list
    return jsonify(resp)
Beispiel #17
0
def comment():
    resp_data = {}
    req = request.args
    page = int(req['p']) if ('p' in req and req['p']) else 1
    query = MemberComment.query

    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']

    comment_list = query.order_by(
        MemberComment.id.desc()).offset(offset).limit(
            app.config['PAGE_SIZE']).all()
    data_list = []
    if comment_list:
        member_map = getDictFilterField(
            Member, Member.id, "id", selectFilterObj(comment_list,
                                                     "member_id"))
        product_ids = []
        for item in comment_list:
            tmp_product_ids = (item.product_ids[1:-1]).split("_")
            tmp_product_ids = {}.fromkeys(tmp_product_ids).keys()
            product_ids = product_ids + list(tmp_product_ids)

        product_map = getDictFilterField(Product, Product.id, "id",
                                         product_ids)

        for item in comment_list:
            tmp_member_info = member_map[item.member_id]
            tmp_products = []
            tmp_product_ids = (item.product_ids[1:-1]).split("_")
            for tmp_product_id in tmp_product_ids:
                tmp_product_info = product_map[int(tmp_product_id)]
                tmp_products.append({
                    'name': tmp_product_info.name,
                })

            tmp_data = {
                "content": item.content,
                "score": item.score,
                "member_info": tmp_member_info,
                "products": tmp_products
            }
            data_list.append(tmp_data)
    resp_data['list'] = data_list
    resp_data['pages'] = pages
    resp_data['current'] = 'comment'

    return ops_render("member/comment.html", resp_data)
Beispiel #18
0
def comment():
    resp_data = {}
    req = request.values
    page = int(req['page']) if ('page' in req and req['page']) else 1
    query = MemberComments.query

    # 开始分页
    page_params = {
        'total': query.count(),
        'page_size': app.config['PAGE_SIZE'],
        'page': page,
        'display': app.config['PAGE_DISPLAY'],
        'url': request.full_path.replace("&p={0}".format(page), "")
    }

    pages = iPagination(page_params)
    offset = (page - 1) * app.config['PAGE_SIZE']
    # 查找 分页评论表
    comment_list = query.order_by(
        MemberComments.member_id.asc()).offset(offset).limit(
            app.config['PAGE_SIZE']).all()
    # 待完成     selectFilterObj

    data_comment_list = []
    if comment_list:
        # 寻找foods_id
        foods_id = selectCommentFoodIDs(comment_list, 'food_ids')
        foods_map = getDictFilterField(Food, Food.id, 'id', foods_id)
        # print( "foods_id:{0} foods_map:{1}".format( foods_id, foods_map) )
        # 寻找 member_id
        member_ids = selectFilterObj(comment_list, 'member_id')
        member_ids_map = getDictFilterField(Member, Member.id, 'id',
                                            member_ids)
        # print( "member_ids:{0} member_ids_map:{1}".format( member_ids, member_ids_map) )

        # pay_order_ids = selectFilterObj( comment_list,"pay_order_id" )
        # pay_order_map = getDictFilterField( PayOrder,PayOrder.id,"id",pay_order_ids )
        for item in comment_list:
            tmp_member_info = member_ids_map[item.member_id]
            data_foods = []
            for i in item.food_ids.split('_'):
                if i != '':
                    data_foods.append(foods_map[int(i)])

            tmp_data = {
                "member_info": tmp_member_info,
                "foods": data_foods,
                "content": item.content,
                "score": item.score,
                "date": item.created_time.strftime("%Y-%m-%d %H:%M:%S"),
            }
            data_comment_list.append(tmp_data)
    resp_data['list'] = data_comment_list
    resp_data['pages'] = pages
    resp_data['current'] = 'comment'
    return ops_render("member/comment.html", resp_data)
Beispiel #19
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)
Beispiel #20
0
def food():
    now = datetime.datetime.now()
    date_before_30days = now + datetime.timedelta(days=-30)
    default_date_from = getFormatDate(date=date_before_30days,
                                      format="%Y-%m-%d")
    default_date_to = getFormatDate(date=now, format="%Y-%m-%d")

    resp_data = {}
    req = request.values
    page = int(req['p']) if ('p' in req and req['p']) else 1
    date_from = req['date_from'] if 'date_from' in req else default_date_from
    date_to = req['date_to'] if 'date_to' in req else default_date_to
    query = StatDailyFood.query.filter(StatDailyFood.date >= date_from) \
        .filter(StatDailyFood.date <= date_to)

    app_config = current_app.config

    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']

    res_list = query.order_by(StatDailyFood.id.desc()).offset(offset).limit(
        app_config['PAGE_SIZE']).all()
    date_list = []
    if res_list:
        food_map = getDictFilterField(Food, Food.id, "id",
                                      selectFilterObj(res_list, "food_id"))
        for item in res_list:
            tmp_food_info = food_map[
                item.food_id] if item.food_id in food_map else {}
            tmp_data = {
                "date": item.date,
                "total_count": item.total_count,
                "total_pay_money": item.total_pay_money,
                'food_info': tmp_food_info
            }
            date_list.append(tmp_data)

    resp_data['list'] = date_list
    resp_data['pages'] = pages
    resp_data['current'] = 'food'
    resp_data['search_con'] = {'date_from': date_from, 'date_to': date_to}
    return ops_render("stat/food.html", **resp_data)
Beispiel #21
0
def myCommentAdd():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    member_info = g.member_info
    req = request.values
    order_sn = req['order_sn'] if 'order_sn' in req else ''
    score = req['score'] if 'score' in req else 10
    content = req['content'] if 'content' 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)

    if pay_order_info.comment_status:
        resp['code'] = -1
        resp['msg'] = "已经评价过了~~"
        return jsonify(resp)

    pay_order_items = PayOrderItem.query.filter_by(
        pay_order_id=pay_order_info.id).all()
    food_ids = selectFilterObj(pay_order_items, "food_id")
    tmp_food_ids_str = '_'.join(str(s) for s in food_ids if s not in [None])
    model_comment = MemberComments()
    model_comment.food_ids = "_%s_" % tmp_food_ids_str
    model_comment.member_id = member_info.id
    model_comment.pay_order_id = pay_order_info.id
    model_comment.score = score
    model_comment.content = content
    db.session.add(model_comment)

    pay_order_info.comment_status = 1
    pay_order_info.updated_time = getCurrentDate()
    db.session.add(pay_order_info)

    db.session.commit()

    #更新对应商品评论数量
    for tmp_food_id in food_ids:
        tmp_food_info = Food.query.filter_by(id=tmp_food_id).first()
        if not tmp_food_info:
            continue
        tmp_food_info.comment_count += 1
        db.session.add(tmp_food_info)
        db.session.commit()
    return jsonify(resp)
Beispiel #22
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)

    express_info = {}
    if pay_order_info.express_info:
        express_info = json.loads(pay_order_info.express_info)
        # print(express_info)

    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": express_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:
        book_ids = selectFilterObj(pay_order_items, "book_id")
        book_map = getDictFilterField(Book, Book.id, "id", book_ids)
        for item in pay_order_items:
            tmp_book_info = book_map[item.book_id]
            tmp_data = {
                "name": tmp_book_info.name,
                "price": str(item.price),
                "unit": item.quantity,
                "pic_url": UrlManager.buildImageUrl(tmp_book_info.main_image),
            }
            info['goods'].append(tmp_data)
    resp['data']['info'] = info
    return jsonify(resp)
Beispiel #23
0
def info():
    resp_data = {}
    req = request.values
    id = int(req['id']) if 'id' in req else 0

    reback_url = UrlManager.buildUrl("/finance/index")

    # 重定向
    if id < 1:
        return redirect(reback_url)

    pay_order_info = PayOrder.query.filter_by(id=id).first()
    if not pay_order_info:
        return redirect(reback_url)

    member_info = Member.query.filter_by(id=pay_order_info.member_id).first()
    if not member_info:
        return redirect(reback_url)

    # 同样通过item 查找,food name。不如新建一个view。
    order_item_list = PayOrderItem.query.filter_by(
        pay_order_id=pay_order_info.id).all()
    data_order_item_list = []
    if order_item_list:
        food_map = getDictFilterField(
            Food, Food.id, "id", selectFilterObj(order_item_list, "food_id"))
        for item in order_item_list:
            tmp_food_info = food_map[item.food_id]
            tmp_data = {
                "quantity": item.quantity,
                "price": item.price,
                "name": tmp_food_info.name
            }
            data_order_item_list.append(tmp_data)

    address_info = {}
    if pay_order_info.express_info:
        address_info = json.loads(pay_order_info.express_info)

    resp_data['pay_order_info'] = pay_order_info
    resp_data['pay_order_items'] = data_order_item_list
    resp_data['member_info'] = member_info
    resp_data['address_info'] = address_info
    resp_data['current'] = 'index'
    return ops_render("finance/pay_info.html", resp_data)
Beispiel #24
0
def info():
    resp_data = {}
    req = request.values
    id = int(req['id']) if 'id' in req else 0

    reback_url = UrlManager.buildUrl("/finance/index")

    if id < 1:
        return redirect( reback_url )

    pay_order_info = PayOrder.query.filter_by( id = id ).first()
    if not pay_order_info:
        return redirect(reback_url)

    member_info = Member.query.filter_by( id = pay_order_info.member_id ).first()
    if not member_info:
        return redirect(reback_url)

    order_item_list = PayOrderItem.query.filter_by( pay_order_id = pay_order_info.id ).all()
    data_order_item_list = []
    if order_item_list:
        food_map = getDictFilterField(Food, Food.id, "id", selectFilterObj(order_item_list, "food_id"))
        for item in order_item_list:
            tmp_food_info = food_map[ item.food_id ]
            tmp_data = {
                "quantity":item.quantity,
                "price":item.price,
                "name":tmp_food_info.name
            }
            data_order_item_list.append( tmp_data )

    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)
        }
    resp_data['pay_order_info'] = pay_order_info
    resp_data['pay_order_items'] = data_order_item_list
    resp_data['member_info'] = member_info
    resp_data['address_info'] = address_info
    resp_data['current'] = 'index'
    return render_template_ops( "finance/pay_info.html",resp_data )
Beispiel #25
0
def memebr():
    resp_data = {}
    now = datetime.datetime.now()
    date_before_30days = now + datetime.timedelta(days=-30)
    default_date_from = getFormatDate(date=date_before_30days,
                                      format="%Y-%m-%d")
    default_date_to = getFormatDate(date=now, format="%Y-%m-%d")
    req = request.values
    page = req['p'] if 'p' in req and req['p'] else 1
    date_from = req['date_from'] if 'date_from' in req else default_date_from
    date_to = req['date_to'] if 'date_to' in req else default_date_to

    query = StatDailyMember.query.filter(StatDailyMember.date >= date_from)\
        .filter(StatDailyMember.date <= date_to)
    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(StatDailyMember.id.desc()).offset(offset).limit(
        app.config['PAGE_SIZE']).all()
    date_list = []
    if list:
        member_map = getDictFilterField(Member, Member.id, 'id',
                                        selectFilterObj(list, 'member_id'))
        for item in list:
            tmp_member_info = member_map[
                item.member_id] if item.member_id in member_map else {}
            tmp_data = {
                'date': item.date,
                'total_pay_money': item.total_pay_money,
                'total_shared_count': item.total_shared_count,
                'member_info': tmp_member_info
            }
            date_list.append(tmp_data)
    resp_data['list'] = date_list
    resp_data['pages'] = pages
    resp_data['current'] = 'member'
    resp_data['search_con'] = {'date_from': date_from, 'date_to': date_to}
    return ops_render("stat/member.html", resp_data)
Beispiel #26
0
def myCommentList():
	resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
	member_info = g.member_info
	comment_list = MemberComments.query.filter_by( member_id=member_info.id )\
		.order_by(MemberComments.id.desc()).all()
	data_comment_list = []
	if comment_list:
		pay_order_ids = selectFilterObj( comment_list,"pay_order_id" )
		pay_order_map = getDictFilterField( PayOrder,PayOrder.id,"id",pay_order_ids )
		for item in comment_list:
			tmp_pay_order_info = pay_order_map[ item.pay_order_id ]
			tmp_data = {
				"date":item.created_time.strftime("%Y-%m-%d %H:%M:%S"),
				"content":item.content,
				"order_number":tmp_pay_order_info.order_number
			}
			data_comment_list.append( tmp_data )
	resp['data']['list'] = data_comment_list
	return jsonify(resp)
Beispiel #27
0
def myCommentAdd():
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    member_info = g.member_info
    req = request.values
    order_sn = req['order_sn'] if 'order_sn' in req else ''
    score = req['score'] if 'score' in req else 10
    content = req['content'] if 'content' in req else 10

    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)
    if pay_order_info.comment_status:
        resp['code'] = -1
        resp['msg'] = '已经评级过了'
        return jsonify(resp)

    pay_order_items = PayOrderItem.query.filter_by(
        pay_order_id=pay_order_info.id)
    food_ids = selectFilterObj(pay_order_items, 'food_id')

    tmp_food_ids_str = '_'.join(str(s) for s in food_ids if s not in [None])

    model_comment = MemberComments()
    model_comment.food_ids = '_%s_' % tmp_food_ids_str
    model_comment.member_id = member_info.id
    model_comment.pay_order_id = pay_order_info.id
    model_comment.score = score
    model_comment.content = content
    model_comment.created_time = getCurrentDate()
    db.session.add(model_comment)

    pay_order_info.comment_status = 1
    pay_order_info.updated_time = getCurrentDate()
    db.session.add(pay_order_info)

    db.session.commit()

    return jsonify(resp)
Beispiel #28
0
    def addComments(self, params):
        try:
            order_sn = params['order_sn'] if 'order_sn' in params else ''
            score = params['score'] if 'score' in params else 10
            content = params['content'] if 'content' in params else ''
            member_id = params['member_id'] if 'member_id' in params else 0
            print("member_id is:{0}".format(member_id))

            pay_order_info = PayOrder.query.filter_by(
                member_id=member_id, order_sn=order_sn).first()
            if not pay_order_info:
                return False

            if pay_order_info.comment_status:
                return True

            pay_order_items = PayOrderItem.query.filter_by(
                pay_order_id=pay_order_info.id).all()
            food_ids = selectFilterObj(pay_order_items, "food_id")
            tmp_food_ids_str = '_'.join(
                str(s) for s in food_ids if s not in [None])
            model_comment = MemberComments()
            model_comment.food_ids = "_%s_" % tmp_food_ids_str
            model_comment.member_id = pay_order_info.member_id
            model_comment.pay_order_id = pay_order_info.id
            model_comment.score = score
            model_comment.content = content
            db.session.add(model_comment)

            pay_order_info.comment_status = 1
            pay_order_info.updated_time = getCurrentDate()
            db.session.add(pay_order_info)
            db.session.commit()

        except Exception as e:
            db.session.rollback()
            print("exception is :%s" % e)
            app.logger.info("exception")
            return False
        return True
Beispiel #29
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)
    #通过用户的id查找该用户在购物车的所有操作
    cart_list = MemberCart.query.filter_by(member_id=member_info.id).all()
    # print('cart_list',cart_list)

    data_cart_list = []
    if cart_list:
        #该用户在购物车所有商品的id
        food_ids = selectFilterObj(cart_list, "food_id")
        # print('food_ids',food_ids)
        #得到{商品id:商品}
        food_map = getDicFilterField(Food, Food.id, 'id', food_ids)
        # print('food_map',food_map)
        #对购物车里的商品进行遍历
        for item in cart_list:
            #遍历到哪个商品使用哪个商品
            tmp_food_info = food_map[item.food_id]
            # print('tmp_food_info',tmp_food_info)
            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)
    # print('data_cart_list',data_cart_list)
    resp['data']['list'] = data_cart_list
    return jsonify(resp)
Beispiel #30
0
def info():
    resp_data = {}
    req = request.values
    id = int(req['id']) if 'id' in req else 0

    reback_url = UrlManager.buildUrl("/finance/index")

    if id < 1:
        return redirect(reback_url)

    pay_order_info = PayOrder.query.filter_by(id=id).first()
    if not pay_order_info:
        return redirect(reback_url)

    member_info = Member.query.filter_by(id=pay_order_info.member_id).first()
    if not member_info:
        return redirect(reback_url)

    order_item_list = PayOrderItem.query.filter_by(
        pay_order_id=pay_order_info.id).all()
    data_order_item_list = []
    if order_item_list:
        product_map = getDictFilterField(
            Product, Product.id, "id",
            selectFilterObj(order_item_list, "product_id"))
        for item in order_item_list:
            tmp_product_info = product_map[item.product_id]
            tmp_data = {
                "quantity": item.quantity,
                "price": item.price,
                "name": tmp_product_info.name
            }
            data_order_item_list.append(tmp_data)

    resp_data['pay_order_info'] = pay_order_info
    resp_data['pay_order_items'] = data_order_item_list
    resp_data['member_info'] = member_info
    resp_data['current'] = 'index'
    return ops_render("finance/pay_info.html", resp_data)