Esempio n. 1
0
    def get(self, *args, **kwargs):
        resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
        id = int(self.get_argument('id', 0))
        food_info = session.query(Food).filter_by(id=id).first()
        if not food_info or not food_info.status:
            resp['code'] = -1
            resp['msg'] = "美食已下架"
            self.write(resp)
            return

        member_info = self.member_info
        cart_number = 0
        if member_info:
            cart_number = session.query(MemberCart).filter_by(
                member_id=member_info.id).count()
        resp['data']['info'] = {
            "id": food_info.id,
            "name": food_info.name,
            "summary": food_info.summary,
            "total_count": food_info.total_count,
            "comment_count": food_info.comment_count,
            'main_image': UrlManager.buildImageUrl(food_info.main_image),
            "price": str(food_info.price),
            "stock": food_info.stock,
            "pics": [UrlManager.buildImageUrl(food_info.main_image)]
        }
        resp['data']['cart_number'] = cart_number
        self.finish(resp)
Esempio n. 2
0
    def get(self, *args, **kwargs):
        resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
        cat_list = session.query(FoodCat).filter_by(status=1).order_by(
            FoodCat.weight.desc()).all()
        data_cat_list = []
        data_cat_list.append({'id': 0, 'name': "全部"})
        if cat_list:
            for item in cat_list:
                tmp_data = {'id': item.id, 'name': item.name}
                data_cat_list.append(tmp_data)
        resp['data']['cat_list'] = data_cat_list
        food_list = session.query(Food).filter_by(status=1) \
            .order_by(Food.total_count.desc(), Food.id.desc()).limit(3).all()

        data_food_list = []
        if food_list:
            for item in food_list:
                tmp_data = {
                    'id': item.id,
                    'pic_url': UrlManager.buildImageUrl(item.main_image)
                }
                data_food_list.append(tmp_data)

        resp['data']['banner_list'] = data_food_list
        self.finish(resp)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
0
    def post(self, *args, **kwargs):
        resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
        params_goods = self.get_argument('goods',None)
        member_info = self.member_info
        params_goods_list = []
        if params_goods:
            params_goods_list = json.loads(params_goods)

        food_dic = {}
        for item in params_goods_list:
            food_dic[item['id']] = item['number']

        food_ids = food_dic.keys()
        food_list = session.query(Food).filter(Food.id.in_(food_ids)).all()
        data_food_list = []
        yun_price = pay_price = decimal.Decimal(0.00)
        if food_list:
            for item in food_list:
                tmp_data = {
                    "id": item.id,
                    "name": item.name,
                    "price": str(item.price),
                    'pic_url': UrlManager.buildImageUrl(item.main_image),
                    'number': food_dic[item.id]
                }
                pay_price = pay_price + item.price * int(food_dic[item.id])
                data_food_list.append(tmp_data)

        # 获取地址
        address_info = session.query(MemberAddress).filter_by(is_default=1, member_id=member_info.id, status=1).first()
        default_address = ''
        if address_info:
            default_address = {
                "id": address_info.id,
                "name": address_info.nickname,
                "mobile": address_info.mobile,
                "address": "%s%s%s%s" % (
                address_info.province_str, address_info.city_str, address_info.area_str, address_info.address)
            }

        resp['data']['food_list'] = data_food_list
        resp['data']['pay_price'] = str(pay_price)
        resp['data']['yun_price'] = str(yun_price)
        resp['data']['total_price'] = str(pay_price + yun_price)
        resp['data']['default_address'] = default_address
        self.finish(resp)
Esempio n. 6
0
def uploadImage(self):
    resp = {'state': 'SUCCESS', 'url': '', 'title': '', 'original': ''}
    # file_target 是一个字典
    file_target = self.request.files
    upfile = file_target['upfile']
    if upfile is None or len(upfile) == 0:
        resp['state'] = "上传失败"
        self.finish(resp)
        return

    ret = UploadService.uploadByFile(upfile[0])
    if ret['code'] != 200:
        resp['state'] = "上传失败:" + ret['msg']
        self.finish(resp)
        return

    resp['url'] = UrlManager.buildImageUrl(ret['data']['file_key'])
    return resp
Esempio n. 7
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)
Esempio n. 8
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)
Esempio n. 9
0
def listImage(self):
    resp = {'state': 'SUCCESS', 'list': [], 'start': 0, 'total': 0}
    start = int(self.get_argument('start', 0))
    page_size = int(self.get_argument('size', 20))

    query = session.query(Image)
    if start > 0:
        query = query.filter(Image.id < start)

    list = query.order_by(Image.id.desc()).limit(page_size).all()
    images = []

    if list:
        for item in list:
            images.append({'url': UrlManager.buildImageUrl(item.file_key)})
            start = item.id
    resp['list'] = images
    resp['start'] = start
    resp['total'] = len(images)
    return resp
Esempio n. 10
0
    def get(self, *args, **kwargs):
        resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
        cat_id = int(self.get_argument('cat_id', 0))
        mix_kw = str(self.get_argument('mix_kw', ''))
        p = int(self.get_argument('p', 1))
        if p < 1:
            p = 1

        page_size = 10
        offset = (p - 1) * page_size
        query = session.query(Food).filter_by(status=1)
        if cat_id > 0:
            query = query.filter_by(cat_id=cat_id)

        if mix_kw:
            rule = or_(Food.name.ilike("%{0}%".format(mix_kw)),
                       Food.tags.ilike("%{0}%".format(mix_kw)))
            query = query.filter(rule)

        food_list = query.order_by(Food.total_count.desc(), Food.id.desc()) \
            .offset(offset).limit(page_size).all()

        data_food_list = []
        if food_list:
            for item in food_list:
                tmp_data = {
                    'id': item.id,
                    'name': "%s" % (item.name),
                    'price': str(item.price),
                    'min_price': str(item.price),
                    'pic_url': UrlManager.buildImageUrl(item.main_image)
                }
                data_food_list.append(tmp_data)
        resp['data']['list'] = data_food_list
        resp['data']['has_more'] = 0 if len(data_food_list) < page_size else 1
        self.finish(resp)