Beispiel #1
0
    def post(self):
        '''
        添加计费设置
        '''
        try:
            rt_id = int(self.get_argument('rt_id'))
            args = json.loads(self.request.body.decode())
            for arg in args:
                assert (arg.get('day') or arg.get('holiday'))
                for item in arg['list']:
                    assert (utils.is_valid_time(item['st']))
                    assert (utils.is_valid_time(item['ed']))
                    assert (int(item['fee']) > 0)
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=10001)

        room_fees = ctrl.room.add_room_fees_ctl(self.current_user['store_id'],
                                                rt_id, args)

        data = {'list': []}

        if not room_fees:
            return self.send_json(data)

        FILTER = ({
            'id': 'fee_id'
        }, 'store_id', 'rt_id', 'st', 'ed', 'fee', 'day_or_holiday',
                  'update_time')

        data['list'] = [utils.dict_filter(fee, FILTER) for fee in room_fees]

        self.send_json(data)
Beispiel #2
0
    def get(self):
        '''
        获取某房型下的所有的酒水套餐
        '''
        try:
            rt_id = int(self.get_argument('rt_id'))
            is_valid = int(self.get_argument('is_valid', 0))
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=10001)

        data = {'list': []}
        FILTER = ({
            'id': 'pack_id'
        }, 'store_id', 'name', 'start_date', 'end_date', 'st', 'ed', 'price',
                  'day', 'hour', 'state', 'update_time')

        packs = ctrl.room.get_room_packs_ctl(self.current_user['store_id'],
                                             rt_id)

        if not packs:
            return self.send_json(data)

        if is_valid:
            _packs = [pack for pack in packs if utils.is_valid_pack(pack)]
            packs = _packs

        packs = [utils.dict_filter(pack, FILTER) for pack in packs]

        data['list'] = packs

        self.send_json(data)
Beispiel #3
0
    def post(self):
        '''
        往某个包房类型下添加包房
        '''
        try:
            args = json.loads(self.request.body.decode())
            rooms = {}
            for arg in args:
                rt_id = arg['rt_id']
                rooms[rt_id] = []
                for ip_name in arg['list']:
                    assert (ip_name['name'])
                    rooms[rt_id].append(ip_name)
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=10001)

        data = {'list': []}

        rooms = ctrl.room.add_rooms_ctl(self.current_user['store_id'], rooms)

        if not rooms:
            return self.send_json(data)

        FILTER = ({
            'id': 'room_id'
        }, 'store_id', 'rt_id', 'name', 'mac', 'ip', 'room_type', 'describe',
                  'update_time')
        data['list'] = [utils.dict_filter(room, FILTER) for room in rooms]

        self.send_json(data)
Beispiel #4
0
    def post(self):
        '''
        注册
        '''
        try:
            args = json.loads(self.request.body.decode())
            code = args.get('code')
            phone = args.get('phone')
            passwd = args.get('passwd')
            name = args.get('name')
            address = args.get('address')
            st = args.get('st')
            ed = args.get('ed')
            manager = args.get('manager', '')

            assert (code and phone)
            assert (utils.is_valid_time(st))
            assert (utils.is_valid_time(ed))
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=10001)

        store = ctrl.store.get_store_ctl(phone)
        if store:
            raise utils.APIError(errcode=50001, errmsg='请勿重复注册')

        try:
            data = {
                'ktype': 20,
                'name': name,
                'address': address,
                'tel': phone,
                'is_test': 0,
                'is_own': 0,
                'manager': manager
            }
            ktv = utils.common_post_api('/kinfo', data)
            store_id = ktv['store_id']
            store = ctrl.store.add_store_ctl({
                'store_id':
                store_id,
                'st':
                st,
                'ed':
                ed,
                'name':
                name,
                'phone':
                phone,
                'passwd':
                hashlib.md5(passwd.encode()).hexdigest()
            })
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=50001, errmsg='注册失败, 稍后再试')

        FILTER = ('store_id', 'phone', 'update_time', 'st', 'ed', 'name')
        store = utils.dict_filter(store, FILTER)

        self.send_json(store)
Beispiel #5
0
    def post(self):
        '''
        添加包房类型
        '''
        try:
            args = json.loads(self.request.body.decode())
            names = args['names']
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=10001)

        data = {'list': []}

        if not names:
            return self.send_json(data)

        room_types = ctrl.room.add_room_types_ctl(
            self.current_user['store_id'], names)

        if not room_types:
            return self.send_json(data)

        FILTER = ({'id': 'rt_id'}, 'store_id', 'name', 'update_time')
        data['list'] = [
            utils.dict_filter(room_type, FILTER) for room_type in room_types
        ]

        self.send_json(data)
Beispiel #6
0
    def get(self):
        '''
        登录
        '''
        try:
            phone = self.get_argument('phone')
            passwd = self.get_argument('passwd')
            assert (phone and passwd)
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=10001)

        try:
            store = ctrl.store.get_store_ctl(phone)
            assert (store)
            assert (store['passwd'] == hashlib.md5(
                passwd.encode()).hexdigest())
            token = self._login(store)
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=50001, errmsg='登录失败,请检查您的账号或密码')

        data = {}
        FILTER = ('store_id', 'phone', 'update_time', 'st', 'ed', 'name')
        data['store'] = utils.dict_filter(store, FILTER)
        data['token'] = token

        self.send_json(data)
Beispiel #7
0
    def get(self):
        '''
        获取分类下的酒水列表
        '''
        try:
            cate_id = int(self.get_argument('cate_id'))
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=10001)

        FILTER = ({
            'id': 'product_id'
        }, 'store_id', 'cate_id', 'name', 'pic', 'price', 'unit', 'spec',
                  'stock', 'discount', 'state', 'order', 'update_time')
        data = {'list': []}
        products = ctrl.cate.get_cate_products_ctl(
            self.current_user['store_id'], cate_id)

        if not products:
            return self.send_json(data)

        data['list'] = [
            utils.dict_filter(product, FILTER) for product in products
        ]
        self.send_json(data)
Beispiel #8
0
    def get(self):
        '''
        获取某房型下周几/假期内的所有计费设置
        '''
        try:
            rt_id = int(self.get_argument('rt_id'))
            md = self.get_argument('md', 'day')
            day_or_holiday = self.get_argument('day_or_holiday', '')
            assert (md in ('day', 'holiday'))
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=10001)

        data = {'list': []}

        room_fees = ctrl.room.get_room_fees_ctl(self.current_user['store_id'],
                                                rt_id, day_or_holiday, md)

        if not room_fees:
            return self.send_json(data)

        FILTER = ({
            'id': 'fee_id'
        }, 'store_id', 'rt_id', 'st', 'ed', 'fee', 'day_or_holiday',
                  'update_time')

        room_fees = [utils.dict_filter(fee, FILTER) for fee in room_fees]
        data['list'] = room_fees

        self.send_json(data)
Beispiel #9
0
    def get(self):
        store = ctrl.store.get_store_ctl(self.current_user['phone'])
        if not store:
            raise utils.APIError(errcode=50001, errmsg='没有门店')

        FILTER = ('store_id', 'phone', 'update_time', 'st', 'ed', 'name')
        store = utils.dict_filter(store, FILTER)
        ktv = utils.common_api('/kinfo/%s' % store['store_id'])
        store.update({'address': ktv.get('address', '')})
        self.send_json(dict(store=store))
Beispiel #10
0
    def get_rt_rooms(self, store_id, rt_id):
        rooms = ctrl.room.get_rt_rooms_ctl(store_id, rt_id)

        if not rooms:
            return rooms

        FILTER = ({
            'id': 'room_id'
        }, 'store_id', 'rt_id', 'name', 'ip', 'mac', 'update_time')
        rooms = [utils.dict_filter(room, FILTER) for room in rooms]
        return rooms
Beispiel #11
0
    def get(self):
        '''
        获取所有的酒水分类
        '''
        cates = ctrl.cate.get_cates_ctl(self.current_user['store_id'])

        data = {'list': []}
        if not cates:
            return self.send_json(data)

        FILTER = ({'id': 'cate_id'}, 'store_id', 'name', 'update_time')
        data['list'] = [utils.dict_filter(cate, FILTER) for cate in cates]
        self.send_json(data)
Beispiel #12
0
    def get_store_rooms(self):
        store_id = self.current_user['store_id']
        rooms = ctrl.room.get_store_rooms_ctl(store_id)

        if not rooms:
            return rooms

        using_states = (ROOM_TYPE['using'], ROOM_TYPE['timeout'])
        using_rooms = [
            room for room in rooms if room['room_type'] in using_states
        ]
        FILTER = ({
            'id': 'room_id'
        }, 'store_id', 'rt_id', 'rt_name', 'name', 'mac', 'room_type', 'st',
                  'ed', 'minute', 'order_no', 'prepay', 'pay_md', 'state',
                  'pay_type', 'describe', 'pay_state')

        if not using_rooms:
            rooms = [utils.dict_filter(room, FILTER) for room in rooms]
            return rooms

        room_ids = [room['id'] for room in using_rooms]
        orders = ctrl.order.get_using_orders_ctl(store_id, room_ids)
        # 开台后 有 没有订单的情况
        orders = list(filter(bool, orders))
        orders_dict = dict((order['room_id'], order) for order in orders)

        for room in rooms:
            if room['room_type'] in using_states and room['id'] in orders_dict:
                order = orders_dict[room['id']]
                order.pop('id')
                order.update({'pay_state': order['state']})
                order.pop('state')
                room.update(order)

        rooms = [utils.dict_filter(room, FILTER) for room in rooms]
        return rooms
Beispiel #13
0
    def get(self):
        '''
        获取某酒水套餐下的所有酒水列表
        '''
        try:
            pack_id = int(self.get_argument('pack_id'))
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=10001)

        pack, products = ctrl.pack.get_pack_info_ctl(
            self.current_user['store_id'], pack_id)

        data = {'detail': {}}

        if not pack:
            return self.send_json(data)

        PACK_FILTER = ({
            'id': 'pack_id'
        }, 'store_id', 'name', 'start_date', 'end_date', 'pic', 'price', 'day',
                       'rt_ids', 'st', 'ed', 'state', 'hour', 'md',
                       'update_time')
        PRODUCT_FILTER = ({
            'id': 'product_id'
        }, 'store_id', 'cate_id', 'name', 'pic', 'price', 'unit', 'spec',
                          'stock', 'discount', 'state', 'order', 'count',
                          'update_time')
        pack = utils.dict_filter(pack, PACK_FILTER)
        products = [
            utils.dict_filter(product, PRODUCT_FILTER) for product in products
        ]
        data['detail'] = pack
        data['detail']['list'] = products

        self.send_json(data)
Beispiel #14
0
    def post(self):
        '''
        添加酒水套餐
        '''
        try:
            args = json.loads(self.request.body.decode())
            name = args['name']
            start_date = args['start_date']
            end_date = args['end_date']
            price = int(args['price'])
            pic = args.get('pic', '')
            day = args['day']
            rt_ids = args['rt_ids']
            st = args['st']
            ed = args['ed']
            products = args.get('list', [])

            assert (utils.is_valid_day_value(day))
            assert (utils.is_valid_rt_ids_value(rt_ids))
            assert (utils.is_valid_time(st))
            assert (utils.is_valid_time(ed))
            assert (price > 0)
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=10001)

        FILTER = ({
            'id': 'pack_id'
        }, 'name', 'start_date', 'end_date', 'pic', 'price', 'day', 'rt_ids',
                  'st', 'ed', 'state', 'update_time')
        data = {'detail': {}}
        pack = ctrl.pack.add_store_pack_ctl(
            self.current_user['store_id'], products, {
                'name': name,
                'start_date': start_date,
                'end_date': end_date,
                'price': price,
                'pic': pic,
                'day': day,
                'rt_ids': rt_ids,
                'st': st,
                'ed': ed
            })
        data['detail'] = utils.dict_filter(pack, FILTER)

        self.send_json(data)
Beispiel #15
0
    def post(self):
        '''
        给某房型添加酒水套餐
        '''
        try:
            rt_id = int(self.get_argument('rt_id'))
            args = json.loads(self.request.body.decode())
            name = args['name']
            start_date = args['start_date']
            end_date = args['end_date']
            price = int(args['price'])
            day = args['day']
            st = args['st']
            ed = args['ed']
            hour = int(args['hour'])
            products = args.get('list', [])

            assert (utils.is_valid_day_value(day))
            assert (utils.is_valid_time(st))
            assert (utils.is_valid_time(ed))
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=10001)

        pack = ctrl.room.add_room_pack_ctl(
            self.current_user['store_id'], rt_id, products, {
                'name': name,
                'start_date': start_date,
                'end_date': end_date,
                'price': price,
                'day': day,
                'st': st,
                'ed': ed,
                'hour': hour,
                'md': 'room'
            })

        data = {'detail': {}}
        FILTER = ({
            'id': 'pack_id'
        }, 'store_id', 'name', 'start_date', 'end_date', 'st', 'ed', 'price',
                  'day', 'hour', 'state', 'update_time')
        data['detail'] = utils.dict_filter(pack, FILTER)

        self.send_json(data)
Beispiel #16
0
    def get(self):
        '''
        获取歌厅所有的酒水套餐
        '''
        packs = ctrl.pack.get_store_packs_ctl(self.current_user['store_id'])

        data = {'list': []}

        if not packs:
            return self.send_json(data)

        FILTER = ({
            'id': 'pack_id'
        }, 'name', 'start_date', 'end_date', 'pic', 'price', 'day', 'rt_ids',
                  'st', 'ed', 'state', 'update_time')

        data['list'] = [utils.dict_filter(pack, FILTER) for pack in packs]
        self.send_json(data)
Beispiel #17
0
    def get(self):
        '''
        获取所有的包房类型
        '''
        data = {'list': []}

        room_types = ctrl.room.get_room_types_ctl(
            self.current_user['store_id'])

        if not room_types:
            return self.send_json(data)

        FILTER = ({
            'id': 'rt_id'
        }, 'store_id', 'name', 'pic', 'min_man', 'max_man', 'update_time')
        data['list'] = [
            utils.dict_filter(room_type, FILTER) for room_type in room_types
        ]

        self.send_json(data)
Beispiel #18
0
    def post(self):
        '''
        分类下添加酒水
        '''
        try:
            cate_id = int(self.get_argument('cate_id'))
            args = json.loads(self.request.body.decode())
            name = args['name']
            pic = args.get('pic', '')
            spec = args.get('spec', '')
            price = int(args['price'])
            unit = args['unit']
            stock = int(args['stock'])
            discount = int(args['discount'])

            assert (name and unit and discount in (0, 1))
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=10001)

        FILTER = ({
            'id': 'product_id'
        }, 'store_id', 'cate_id', 'name', 'pic', 'price', 'unit', 'spec',
                  'stock', 'discount', 'state', 'order', 'update_time')
        data = {'detail': {}}
        product = ctrl.cate.add_cate_product_ctl(
            self.current_user['store_id'], {
                'cate_id': cate_id,
                'name': name,
                'pic': pic,
                'price': price,
                'unit': unit,
                'spec': spec,
                'stock': stock,
                'discount': discount
            })

        data['detail'] = utils.dict_filter(product, FILTER)
        self.send_json(data)
Beispiel #19
0
    def post(self):
        '''
        添加酒水分类
        '''
        try:
            args = json.loads(self.request.body.decode())
            names = args['names']
            assert (names)
        except Exception as e:
            logging.error(e)
            raise utils.APIError(errcode=10001)

        data = {'cates': []}

        if not names:
            return self.send_json(data)

        cates = ctrl.cate.add_cates_ctl(self.current_user['store_id'], names)

        FILTER = ({'id': 'cate_id'}, 'store_id', 'name', 'update_time')
        data['cates'] = [utils.dict_filter(cate, FILTER) for cate in cates]

        self.send_json(data)
Beispiel #20
0
    def get_order_detail(self, store_id, order_no):
        '''结完帐后要打单,所以不判断订单状态'''
        order = self.get_order_ctl(store_id, order_no)
        if not order:
            raise utils.APIError(errcode=50001, errmsg='订单不存在')

        order_id = order['id']
        room_id = order['room_id']

        room = self.ctrl.room.get_room_ctl(room_id)

        if not room:
            raise utils.APIError(errcode=50001, errmsg='此包房不存在')

        order.update({'room_name': room['name']})

        bills = self.get_order_bills_ctl(store_id, order_id)
        bills = list(
            filter(lambda x: x['pay_state'] != BILL_PAY_STATE['cancel'],
                   bills))

        if not bills:
            return order

        brs = self.get_order_bills_room_ctl(store_id, order_id)
        bps = self.get_bills_product_detail_ctl(store_id, order_id)

        for bill in bills:
            service_type = bill['service_type']

            if service_type == SERVICE_TYPE['prepay']:
                continue

            if service_type == SERVICE_TYPE['room']:
                blist = brs
                B_FILTER = BILL_RO_FILTER
            else:
                blist = bps
                B_FILTER = BILL_PRO_FILTER

            blist = list(filter(lambda bl: bl['bill_id'] == bill['id'], blist))

            # bill里的商品,有的有套餐(pack), pack里加上商品list
            for product in blist:
                if not product['pack_id']:
                    continue
                _, products = self.ctrl.pack.get_pack_info_ctl(
                    store_id, product['pack_id'])
                products = [
                    utils.dict_filter(p, PRODUCT_FILTER) for p in products
                ]
                product.update({'list': products})

            bill.update(
                {'list': [utils.dict_filter(bl, B_FILTER) for bl in blist]})

        order['bills'] = [
            utils.dict_filter(bill, BILL_FILTER) for bill in bills
        ]

        return order