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_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_obj(pay_order_item_list, "food_id") food_map = get_dict_filter_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.build_image_url(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)
def foodComments(): resp = {'code': 200, 'msg': '操作成功~', 'data': {}} req = request.values id = int(req['id']) if 'id' in req else 0 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 = get_dict_filter_field( Member, Member.id, "id", select_filter_obj(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)
def cart_index(): 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 = select_filter_obj(cart_list, "food_id") food_map = get_dict_filter_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, 'food_id': item.food_id, 'number': item.quantity, 'name': tmp_food_info.name, 'price': str(tmp_food_info.price), 'pic_url': UrlManager.build_image_url(tmp_food_info.main_image), 'active': True } data_cart_list.append(tmp_data) resp['data']['list'] = data_cart_list return jsonify(resp)
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 = select_filter_obj(cart_list, "food_id") food_map = get_dict_filter_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.build_image_url(tmp_food_info.main_image), "active": True } data_cart_list.append(tmp_data) resp['data']['list'] = data_cart_list return jsonify(resp)
def comment(): resp_data = {} req = request.args page = int(req['p']) if ('p' in req and req['p']) 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={}".format(page), "") } pages = i_pagination(page_params) offset = (page - 1) * app.config['PAGE_SIZE'] comment_list = query.order_by( MemberComments.id.desc()).offset(offset).limit( app.config['PAGE_SIZE']).all() data_list = [] if comment_list: member_map = get_dict_filter_field( Member, Member.id, "id", select_filter_obj(comment_list, "member_id")) food_ids = [] for item in comment_list: tmp_food_ids = (item.food_ids[1:-1]).split("_") tmp_food_ids = {}.fromkeys(tmp_food_ids).keys() food_ids = food_ids + list(tmp_food_ids) food_map = get_dict_filter_field(Food, Food.id, "id", food_ids) for item in comment_list: tmp_member_info = member_map[item.member_id] tmp_foods = [] tmp_food_ids = (item.food_ids[1:-1]).split("_") for tmp_food_id in tmp_food_ids: tmp_food_info = food_map[int(tmp_food_id)] tmp_foods.append({ 'name': tmp_food_info.name, }) tmp_data = { "content": item.content, "score": item.score, "member_info": tmp_member_info, "foods": tmp_foods } 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)
def food(): now = datetime.datetime.now() date_before_30days = now + datetime.timedelta(days=-30) default_date_from = get_format_date(date=date_before_30days, format="%Y-%m-%d") default_date_to = get_format_date(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 = i_pagination(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_filter_field(Food, Food.id, "id", select_filter_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_obj(pay_order_items, "food_id") food_map = get_dict_filter_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.build_image_url(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.build_url("/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_filter_field( Food, Food.id, "id", select_filter_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 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 = select_filter_obj(comment_list, "pay_order_id") pay_order_map = get_dict_filter_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 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 = select_filter_obj(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 = get_current_date() db.session.add(pay_order_info) db.session.commit() 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 = i_pagination(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_obj(pay_list, "id") pay_order_items_map = get_dict_list_filter_field( 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_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_filter_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)