def my_comment_add(): member_info = g.user form = CommentForm().validate_for_api() order_sn = form.order_sn.data score = form.score.data content = form.content.data pay_order_info = PayOrder.query.filter_by(member_id=member_info.uid, order_sn=order_sn).first() if not pay_order_info: return ParameterException('系统繁忙,请稍后再试') if pay_order_info.comment_status: return ParameterException('已经评价过了') 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.uid model_comment.pay_order_id = pay_order_info.id model_comment.score = score model_comment.content = content with db.auto_commit(): db.session.add(model_comment) pay_order_info.comment_status = 1 pay_order_info.updated_time = get_current_date() with db.auto_commit(): pay_order_info return Success()
def cart_index(): member_info = g.user if not member_info: return AuthFailed('请先登录') cart_list = MemberCart.query.filter_by(member_id=member_info.uid).all() data_cart_list = [] resp = {} 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'] = data_cart_list return jsonify(resp)
def food_comments(): form = IdForm().validate_for_api() id = form.id.data 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 = {} resp['list'] = data_list resp['count'] = query.count() return jsonify(resp)
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': current_app.config['PAGE_SIZE'], 'page': page, 'display': current_app.config['PAGE_DISPLAY'], 'url': request.full_path.replace("&p={}".format(page), "") } pages = i_pagination(page_params) offset = (page - 1) * current_app.config['PAGE_SIZE'] list = query.order_by(StatDailyFood.id.desc()).offset(offset).limit( current_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 render_template("stat/food.html", **resp_data)
def my_comment_list(): member_info = g.user comment_list = MemberComments.query.filter_by(member_id=member_info.uid)\ .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) return jsonify(data_comment_list)
def pay_info(): resp_data = {} req = request.values id = int(req['id']) if 'id' in req else 0 back_url = UrlManager.build_url("/finance/index") if id < 1: return redirect(back_url) pay_order_info = PayOrder.query.filter_by( id = id ).first() if not pay_order_info: return redirect(back_url) member_info = Member.query.filter_by(id=pay_order_info.member_id).first() if not member_info: return redirect(back_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 render_template("finance/pay_info.html", **resp_data)
def my_order_info(): form = PayForm().validate_for_api() member_info = g.user pay_order_info = PayOrder.query.filter_by( member_id=member_info.uid, order_sn=form.order_sn.data).first_or_404() 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) return jsonify(info)
def my_order_list(): member_info = g.user form = MyOrderForm().validate_for_api() status = form.status.data query = PayOrder.query.filter_by(member_id=member_info.uid) if status == OrderStatusEnum.WAIT: # 等待付款 query = query.filter(PayOrder.status == -8) elif status == OrderStatusEnum.SEND: # 待发货 query = query.filter(PayOrder.status == 1, PayOrder.express_status == -7, PayOrder.comment_status == 0) elif status == OrderStatusEnum.CONFIRM: # 待确认 query = query.filter(PayOrder.status == 1, PayOrder.express_status == -6, PayOrder.comment_status == 0) elif status == OrderStatusEnum.SAY: # 待评价 query = query.filter(PayOrder.status == 1, PayOrder.express_status == 1, PayOrder.comment_status == 0) elif status == OrderStatusEnum.OK: # 已完成 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 = {} resp['pay_order_list'] = data_pay_order_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': current_app.config['PAGE_SIZE'], 'page': page, 'display': current_app.config['PAGE_DISPLAY'], 'url': request.full_path.replace("&p={}".format(page), "") } pages = i_pagination(page_params) offset = (page - 1) * current_app.config['PAGE_SIZE'] pay_list = query.order_by(PayOrder.id.desc()).offset(offset).limit(current_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'] = current_app.config['PAY_STATUS_MAPPING'] resp_data['current'] = 'index' return render_template("finance/index.html", **resp_data)