def CartIndex(): ret = {'code': 200, 'msg': '操作成功~~', 'data': {}} member_info = g.member_info if not member_info: ret['code'] = -1 ret['msg'] = "未登录~" return jsonify(ret) cart_list = MemberCart.query.filter_by(member_id=member_info.id).all() data_cart_list = [] if cart_list: food_ids = select_filter_from_obj(cart_list, 'food_id') food_map = get_dict_by_field(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) ret['data']['list'] = data_cart_list return jsonify(ret)
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) 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(StatDailyFood.id.desc()).offset(offset).limit( app.config['PAGE_SIZE']).all() date_list = [] if list: food_map = get_dict_by_field(Food, Food.id, "id", select_filter_from_obj(list, "food_id")) for item in 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)
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) 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: food_ids = select_filter_from_obj(pay_order_items, "food_id") food_map = get_dict_by_field(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)
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 = get_dict_by_field( Food, Food.id, "id", select_filter_from_obj(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)
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 = get_dict_by_field(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)
def myCommentList(): resp = {'code': 200, 'msg': '操作成功~', 'data': {}} member_info = g.member_info comment_list = MemberComment.query.filter_by(member_id=member_info.id)\ .order_by(MemberComment.id.desc()).all() data_comment_list = [] if comment_list: pay_order_ids = select_filter_from_obj(comment_list, "pay_order_id") pay_order_map = get_dict_by_field(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)
def index(): resp_data = {} req = request.values page = int(req['p']) if ('p' in req and req['p']) else 1 query = PayOrder.query if 'status' in req and int(req['status']) > -1: query = query.filter(PayOrder.status == int(req['status'])) 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'] pay_list = query.order_by(PayOrder.id.desc()).offset(offset).limit( app.config['PAGE_SIZE']).all() data_list = [] if pay_list: pay_order_ids = select_filter_from_obj(pay_list, "id") pay_order_items_map = getDictListFilterField(PayOrderItem, PayOrderItem.pay_order_id, "pay_order_id", pay_order_ids) food_mapping = {} if pay_order_items_map: food_ids = [] for item in pay_order_items_map: tmp_food_ids = select_filter_from_obj( pay_order_items_map[item], "food_id") tmp_food_ids = {}.fromkeys(tmp_food_ids).keys() food_ids = food_ids + list(tmp_food_ids) # food_ids里面会有重复的,要去重 food_mapping = get_dict_by_field(Food, Food.id, "id", food_ids) for item in pay_list: tmp_data = { "id": item.id, "status_desc": item.status_desc, "order_number": item.order_number, "price": item.total_price, "pay_time": item.pay_time, "created_time": item.created_time.strftime("%Y%m%d%H%M%S") } tmp_foods = [] tmp_order_items = pay_order_items_map[item.id] for tmp_order_item in tmp_order_items: tmp_food_info = food_mapping[tmp_order_item.food_id] tmp_foods.append({ 'name': tmp_food_info.name, 'quantity': tmp_order_item.quantity }) tmp_data['foods'] = tmp_foods data_list.append(tmp_data) resp_data['list'] = data_list resp_data['pages'] = pages resp_data['search_con'] = req resp_data['pay_status_mapping'] = app.config['PAY_STATUS_MAPPING'] resp_data['current'] = 'index' return ops_render("finance/index.html", resp_data)
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 = select_filter_from_obj(pay_order_list, "id") pay_order_item_list = PayOrderItem.query.filter( PayOrderItem.pay_order_id.in_(pay_order_ids)).all() food_ids = select_filter_from_obj(pay_order_item_list, "food_id") food_map = get_dict_by_field(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)