Beispiel #1
0
    def get(self, *args, **kwargs):
        resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
        member_info = self.member_info
        status = int(self.get_argument('status',0))
        query = session.query(PayOrder).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 = session.query(PayOrderItem).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
        self.finish(resp)
Beispiel #2
0
    def get(self, *args, **kwargs):
        resp_data = {}
        status = self.get_argument('status', None)
        if status:
            query = session.query(PayOrder).filter_by(status=int(status))
        else:
            query = session.query(PayOrder)
        pay_list = query.order_by(PayOrder.id.desc()).all()
        data_list = []
        if pay_list:
            pay_order_ids = selectFilterObj(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 = selectFilterObj(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 = getDictFilterField(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['pay_status_mapping'] = PAY_STATUS_MAPPING
        resp_data['search_con'] = status
        resp_data['current'] = 'index'

        self.render("finance/index.html", **resp_data)
Beispiel #3
0
    def get(self, *args, **kwargs):
        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 = {}
        date_from = self.get_argument('date_from', default_date_from)
        date_to = self.get_argument('date_to',default_date_to)
        query = session.query(StatDailyMember).filter(StatDailyMember.date >= date_from) \
            .filter(StatDailyMember.date <= date_to)
        list = query.order_by(StatDailyMember.id.desc()).limit(100).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['current'] = 'member'
        resp_data['search_con'] = {
            'date_from': date_from,
            'date_to': date_to
        }
        self.render("stat/member.html", **resp_data)
Beispiel #4
0
 def get(self, *args, **kwargs):
     resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
     id = int(self.get_argument('id', 0))
     query = session.query(MemberComments).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()
     self.finish(resp)
Beispiel #5
0
    def get(self, *args, **kwargs):
        resp = {'code': 200, 'msg': '添加购物车成功~', 'data': {}}
        member_info = self.member_info
        if not member_info:
            resp['code'] = -1
            resp['msg'] = "获取失败,伪登录~~"
            self.write(resp)
            return
        cart_list = session.query(MemberCart).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
        self.finish(resp)
Beispiel #6
0
    def get(self, *args, **kwargs):
        resp_data = {}
        id = int(self.get_argument('id', 0))
        reback_url = UrlManager.buildUrl("/finance/index")

        if id < 1:
            self.redirect(reback_url)

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

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

        order_item_list = session.query(PayOrderItem).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'
        self.render("finance/pay_info.html", **resp_data)
Beispiel #7
0
    def get(self, *args, **kwargs):
        resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
        member_info = self.member_info
        order_sn = self.get_argument('order_sn','')
        pay_order_info = session.query(PayOrder).filter_by(member_id=member_info.id, order_sn=order_sn).first()
        if not pay_order_info:
            resp['code'] = -1
            resp['msg'] = "系统繁忙,请稍后再试~~"
            self.write(resp)
            return

        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 = session.query(PayOrderItem).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
        self.finish(resp)
Beispiel #8
0
 def get(self, *args, **kwargs):
     resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
     member_info = self.member_info
     comment_list = session.query(MemberComments).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
     self.finish(resp)
    def get(self, *args, **kwargs):
        resp_data = {}
        query = session.query(MemberComments)
        comment_list = query.order_by(
            MemberComments.id.desc()).limit(100).all()
        data_list = []
        if comment_list:
            member_map = getDictFilterField(
                Member, Member.id, "id",
                selectFilterObj(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 = getDictFilterField(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['current'] = 'comment'

        self.render("member/comment.html", **resp_data)
Beispiel #10
0
    def post(self, *args, **kwargs):
        resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
        member_info = self.member_info
        order_sn = self.get_argument('order_sn','')
        score = self.get_argument('score',10)
        content = self.get_argument('content','')

        pay_order_info = session.query(PayOrder).filter_by(member_id=member_info.id, order_sn=order_sn).first()
        if not pay_order_info:
            resp['code'] = -1
            resp['msg'] = "系统繁忙,请稍后再试~~"
            self.write(resp)
            return

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

        pay_order_items = session.query(PayOrderItem).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
        session.add(model_comment)

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

        session.commit()
        self.finish(resp)