コード例 #1
0
    def post_inventory(self, inventories, is_online=1):
        if not inventories:
            raise gen.Return(False)
        inventory_data = self.generate_inventory_data(inventories, is_online)
        track_id = self.generate_track_id(inventories[0].roomtype_id)

        params = {
            'track_id': track_id,
            'data': json_encode({'list': [inventory_data]})
        }

        Log.info("push inventory roomtype {}: {}".format(
            inventories[0].roomtype_id, params))
        if not IS_PUSH_TO_STOCK:
            raise gen.Return(True)

        url = API['STOCK'] + '/stock/update_inventory?is_async=false'
        r = yield AsyncHTTPClient().fetch(url,
                                          method='POST',
                                          body=urllib.urlencode(params))

        Log.info("push inventory roomtype {} response {}".format(
            inventories[0].roomtype_id, r.body))
        resp = json.loads(r.body)

        raise gen.Return(resp and resp['errcode'] == 0)
コード例 #2
0
ファイル: secondvalid.py プロジェクト: icyCloud/test_p_o_i
    def put(self, hotel_mapping_id):
        Log.info("Second>>Hotel {}>>Valid>> user:{}".format(hotel_mapping_id, self.current_user))
        hotel_mapping = HotelMapping.get_by_id(self.db, hotel_mapping_id)
        if hotel_mapping and hotel_mapping.status == hotel_mapping.STATUS.wait_second_valid\
                and hotel_mapping.main_hotel_id != 0:

            hotels = HotelMapping.get_by_chain_id_and_main_hotel_id(self.db, hotel_mapping.provider_id, hotel_mapping.main_hotel_id)
            for hotel in hotels:
                if hotel.id != hotel_mapping.id and hotel.status > hotel_mapping.status:
                    self.finish_json(errcode=402, errmsg=u"已有Hotel{}绑定相同基础酒店".format(hotel.provider_hotel_name))
                    return

            hotel_mapping = HotelMapping.set_secondvalid_complete(self.db, hotel_mapping_id)

            try:
                module = modules['second_valid']
                motivation = motivations['pass_hotel']
                operator = self.current_user
                poi_hotel_id = hotel_mapping.main_hotel_id
                otaId = hotel_mapping.provider_id
                hotelName = hotel_mapping.provider_hotel_name
                hotelModel = Hotel.get_by_id(self.db,id=poi_hotel_id)
                operate_content = hotelName + "<->" + hotelModel.name
                hotel_id = hotel_mapping_id
                PoiOperateLogMapping.record_log(self.db,otaId=otaId,hotelName=hotelName,module=module,motivation=motivation,operator=operator,poi_hotel_id=poi_hotel_id,operate_content=operate_content,hotel_id=hotel_id)
            except Exception,e:
                traceback.print_exc()

            self.finish_json(result=ObjectDict(
                hotel_mapping=hotel_mapping.todict(),
                ))
コード例 #3
0
ファイル: secondvalid.py プロジェクト: icyCloud/test_p_o_i
    def delete(self, roomtype_mapping_id):
        Log.info("Second>>RoomType {}>>Delete>> user:{}".format(roomtype_mapping_id, self.current_user))
        mapping = RoomTypeMapping.get_by_id(self.db, roomtype_mapping_id)
        if mapping and mapping.status == mapping.STATUS.wait_second_valid:
            mapping = RoomTypeMapping.revert_to_firstvalid(self.db, roomtype_mapping_id)

            try:
                module = modules['second_valid']
                motivation = motivations['back_roomtype']
                operator = self.current_user
                poi_hotel_id = mapping.main_hotel_id
                poi_roomtype_id = mapping.main_roomtype_id
                otaId = mapping.provider_id
                hotel_id = mapping.provider_hotel_id
                hotelModel = HotelMapping.get_by_provider_and_main_hotel(self.db,otaId,hotel_id,poi_hotel_id)
                hotelName = hotelModel.provider_hotel_name
                roomType = RoomType.get_by_id(self.db,id=poi_roomtype_id)
                operate_content = mapping.provider_roomtype_name + " <-> " + roomType.name

                PoiOperateLogMapping.record_log(self.db,otaId=otaId,hotelName=hotelName,module=module,motivation=motivation,operator=operator,
                                                poi_hotel_id=poi_hotel_id,operate_content=operate_content,hotel_id=hotel_id,poi_roomtype_id=poi_roomtype_id)
            except Exception,e:
                traceback.print_exc()

            self.finish_json(result=ObjectDict(
                roomtype_mapping=mapping.todict(),
                ))
コード例 #4
0
ファイル: sms.py プロジェクト: icyCloud/test_e_b_k
def send_order_sms(self, merchant_id, hotel_name, order_id, confirm_type):
    Log.info(u">>> send sms to merchant {} hotel {} order_id {} confirm type {}".format(merchant_id, hotel_name, order_id, confirm_type))

    order = OrderModel.get_by_id(self.session, order_id)
    breakfast_str = u'含早' if order.get_has_breakfast() else u'无早'
    customers = json.loads(order.customer_info)
    customer_str = " ".join([customer['name'] for customer in customers])


    if confirm_type == OrderModel.CONFIRM_TYPE_AUTO:
        content = u"尊敬的用户您好,系统收到编号{}自动确认订单:{},房型:{},入离日期:{}至{}( {}晚 ),入住人:{},总价:{},{}。订单号:{},请及时关注。客服联系电话:4006103330".format(merchant_id, hotel_name, order.roomtype_name, order.checkin_date, order.checkout_date, order.get_stay_days(), customer_str, order.total_price / 100, breakfast_str, order_id)
    elif confirm_type == OrderModel.CONFIRM_TYPE_MANUAL:
        content = u"尊敬的用户您好,系统收到编号{}待确认订单:{},房型:{},入离日期:{}至{}( {}晚 ),入住人:{},总价:{},{}。订单号:{},请尽快处理。客服联系电话:4006103330".format(merchant_id, hotel_name, order.roomtype_name, order.checkin_date, order.checkout_date, order.get_stay_days(), customer_str, order.total_price / 100, breakfast_str, order_id)
    send_sms_to_service(merchant_id, content)

    user =UserModel.get_user_by_merchantid_username(self.session, merchant_id, 'admin')
    if not user:
        Log.info("send sms no user(order {})".format(order_id))
        return
    phone = user.mobile
    if not phone:
        Log.info("send sms no phone(order {})".format(order_id))
        return

    Log.info(">> send sms to {}".format(phone))
    Log.info(u">> sms content: {}".format(content))
    
    send_sms([phone], content)
コード例 #5
0
def start_order(self, order_id):
    session = self.session
    order = get_order(session, order_id)
    if not order:
        Log.info("query order {} is None".format(order_id))
        return None
    if order.status != 0:
        return order

    # valid is roomtype online
    roomtype = CooperateRoomTypeModel.get_by_id(self.session,
                                                order.roomtype_id)
    if roomtype.is_online != 1:
        Log.info('roomtype is not online')
        order.status = 200
        order.exception_info = 'roomtype is not online'
        session.commit()
        OrderHistoryModel.set_order_status_by_server(session, order, 0, 200)
        return order

    order = modify_inventory(session, order)
    if order.status != 0:
        OrderHistoryModel.set_order_status_by_server(session, order, 0,
                                                     order.status)

    return order
コード例 #6
0
ファイル: polymer.py プロジェクト: icyCloud/test_p_o_i
    def put(self):
        req = ObjectDict(json_decode(self.request.body))
        Log.info("Polymer>>Hotel>>Online>> user:{} req:{}".format(self.current_user, req))
        hotel_mapping_id = req.hotel_mapping_id
        is_online = req.is_online


        hotel_mapping = HotelMapping.get_by_id(self.db, hotel_mapping_id)
        if hotel_mapping and hotel_mapping.status == hotel_mapping.STATUS.valid_complete:
            hotel_mapping = HotelMapping.set_online(self.db, hotel_mapping_id, is_online)
            if hotel_mapping.is_online in [0, -1]:
                RoomTypeMapping.disable_by_provider_hotel_id(self.db, hotel_mapping.provider_hotel_id)

            try:
                redisClient.put('poi_online',hotel_mapping.main_hotel_id)
            except Exception,e:
                traceback.print_exc()
            yield self.notify_stock(hotel_mapping.provider_id, hotel_mapping.provider_hotel_id)
            try:
                module = modules['merge']
                motivation = None
                if is_online in [0, -1]:
                    motivation = motivations['offline_hotel']
                else:
                    motivation = motivations['online_hotel']
                operator = self.current_user
                poi_hotel_id = hotel_mapping.main_hotel_id
                otaId = hotel_mapping.provider_id
                hotelName = hotel_mapping.provider_hotel_name
                hotelModel = Hotel.get_by_id(self.db,id=poi_hotel_id)
                operate_content = hotelName + "<->" + hotelModel.name
                hotel_id = hotel_mapping_id
                PoiOperateLogMapping.record_log(self.db,otaId=otaId,hotelName=hotelName,module=module,motivation=motivation,operator=operator,poi_hotel_id=poi_hotel_id,operate_content=operate_content,hotel_id=hotel_id)
            except Exception,e:
                traceback.print_exc()
コード例 #7
0
ファイル: hotel_mapping.py プロジェクト: icyCloud/test_p_o_i
    def post(self):
        args = self.get_json_arguments()
        chain_hotel_id, main_hotel_id, merchant_id, merchant_name = get_and_valid_arguments(args,
                'chain_hotel_id', 'main_hotel_id', 'merchant_id', 'merchant_name')
        hotel = HotelModel.get_by_id(self.db, main_hotel_id)

        hotel_mapping = HotelMappingModel.get_by_provider_hotel(self.db, 6, chain_hotel_id,is_delete=-1)
        if hotel_mapping:
            Log.info(">>> modify exist ebooking hotel {}".format(hotel_mapping.todict()))
            hotel_mapping.merchant_id = merchant_id
            hotel_mapping.merchant_name = merchant_name
            hotel_mapping.info = 'update by ebooking'
            hotel_mapping.status = hotel_mapping.STATUS.valid_complete
            hotel_mapping.city_id = hotel.city_id
            hotel_mapping.provider_hotel_name = hotel.name
            hotel_mapping.provider_hotel_address = hotel.address
            hotel_mapping.main_hotel_id = hotel.id
            hotel_mapping.is_delete = 0
            self.db.commit()
        else:
            hotel_mapping = HotelMappingModel.new_hotel_mapping_from_ebooking(self.db,
                    chain_hotel_id, hotel.name, hotel.address, hotel.city_id, main_hotel_id, merchant_id, merchant_name)

        self.finish_json(result=dict(
            hotel_mapping=hotel_mapping.todict(),
            ))
コード例 #8
0
ファイル: submit_order.py プロジェクト: Hackforid/Ebooking
    def pre_check_order(self, order_entity):

        order = self.create_order(order_entity)
        if not order:
            raise JsonException(1, 'create order fail')

        if order.status != 0:
            return order

        # valid is roomtype online
        roomtype = CooperateRoomTypeModel.get_by_id(self.db, order.roomtype_id)
        if roomtype.is_online != 1:
            Log.info('roomtype is not online')
            order.status = 200
            order.exception_info = 'roomtype is not online'
            self.db.commit()
            OrderHistoryModel.set_order_status_by_server(
                self.db, order, 0, 200)
            return order

        # valid is inventory enough
        if not self.valid_inventory(order_entity):
            Log.info('more room please')
            order.status = 200
            order.exception_info = 'inventory not enough'
            self.db.commit()

            OrderHistoryModel.set_order_status_by_server(
                self.db, order, 0, 200)
            return order

        return order
コード例 #9
0
ファイル: hotel.py プロジェクト: icyCloud/test_p_o_i
    def query(cls, session, name=None, star=None, city_id=None, district_id=None, start=0, limit=10, filter_ids=None, within_ids=None, count_total=True):
        query = session.query(HotelModel)\
                .filter(HotelModel.is_valid == 1)
        if within_ids:
            query = query.filter(HotelModel.id.in_(within_ids))
        if filter_ids:
            query = query.filter(~HotelModel.id.in_(filter_ids))
        if name:
            query = query.filter(HotelModel.name.like(u'%{}%'.format(name)))
        if star:
            query = query.filter(HotelModel.star == star)
        if city_id:
            query = query.filter(HotelModel.city_id == city_id)
        if district_id:
            query = query.filter(HotelModel.district_id == district_id)

        Log.info("=" * 30)
        t0 = time.time()
        r = query.offset(start).limit(limit).all()
        t1 = time.time()
        if count_total:
            total = query.count()
            return r, total
            t2 = time.time()
            Log.info(">>HotelSearch query cost:{} query total cost:{}".format(t1 - t0, t2-t1))
        else:
            return r
コード例 #10
0
ファイル: submit_order.py プロジェクト: icyCloud/test_e_b_k
    def pre_check_order(self, order_entity):

        order = self.create_order(order_entity)
        if not order:
            raise JsonException(1, 'create order fail')

        if order.status != 0:
            return order

        # valid is roomtype online
        roomtype = CooperateRoomTypeModel.get_by_id(self.db, order.roomtype_id)
        if roomtype.is_online != 1:
            Log.info('roomtype is not online')
            order.status = 200
            order.exception_info = 'roomtype is not online'
            self.db.commit()
            OrderHistoryModel.set_order_status_by_server(self.db, order, 0, 200)
            return order

        # valid is inventory enough
        if not self.valid_inventory(order_entity):
            Log.info('more room please')
            order.status = 200
            order.exception_info = 'inventory not enough'
            self.db.commit()

            OrderHistoryModel.set_order_status_by_server(self.db, order, 0, 200)
            return order

        return order
コード例 #11
0
ファイル: efs.py プロジェクト: alpha-jacobshih/pyjects
 def generate_html_report(self, report_in_js=True):
     self.generate_report_path()
     reportjs = self.report_path + '/' + 'report.js'
     reporttemplate = self.html_path + '/' + 'report.html'
     reporthtml = self.report_path + '/' + self.dict_all["project"]["name"] + '.html'
     if report_in_js:
         shutil.copy(reporttemplate, reporthtml)
         with open(reportjs, 'w') as f:
             try:
                 d = Log.beautify_json(self.dict_all).encode('utf8').decode('utf8')
                 f.writelines(["report = ", "\n", d, ";", "\n"])
             except UnicodeDecodeError as e:
                 print(e)
     else:
         reporthtml = self.report_path + '/' + self.dict_all["project"]["name"] + '_report.html'
         with open(reporttemplate, 'r') as src, open(reporthtml, 'w') as dst:
             for line in src:
                 if "<script" in line and "src" in line and "report.js" in line:
                     d = Log.beautify_json(self.dict_all)
                     dst.writelines(["<script type='text/javascript' charset='utf-8'>", "\n"])
                     dst.writelines(["var report = ", "\n"])
                     dst.writelines([d.encode("utf8").decode("utf8"), ";", "\n"])
                     dst.writelines(["</script>", "\n"])
                 else:
                     dst.write(line)
     pass
コード例 #12
0
ファイル: hotel.py プロジェクト: icyCloud/test_e_b_k
 def fetch_base_hotel_and_roomtypes(self, hotel_id):
     url = API['POI'] + "/api/hotel/" + str(hotel_id) + "/roomtype/"
     try:
         r = yield AsyncHTTPClient().fetch(url)
         result = json.loads(r.body)
     except Exception, e:
         Log.exception(e)
         raise gen.Return((None, None))
コード例 #13
0
 def fetch_base_hotel_and_roomtypes(self, hotel_id):
     url = API['POI'] + "/api/hotel/" + str(hotel_id) + "/roomtype/"
     try:
         r = yield AsyncHTTPClient().fetch(url)
         result = json.loads(r.body)
     except Exception, e:
         Log.exception(e)
         raise gen.Return((None, None))
コード例 #14
0
ファイル: base.py プロジェクト: icyCloud/test_p_o_i
 def _handle_request_exception(self, e):
     self.db.rollback()
     if isinstance(e, JsonException):
         Log.error(e.tojson)
         self.finish_json(errcode=e.errcode, errmsg=e.errmsg)
     else:
         Log.error(traceback.format_exc())
         super(BtwBaseHandler, self)._handle_request_exception(e)
コード例 #15
0
ファイル: hotel.py プロジェクト: icyCloud/test_e_b_k
 def push_hotel_by_id(self, hotel_id):
     Log.info("<<push hotel by id {}>>".format(hotel_id))
     hotel = CooperateHotelModel.get_by_id(self.db, hotel_id, with_delete=True)
     if not hotel:
         Log.info("<<push hotel {}>> error hotel not exist".format(hotel_id))
         raise gen.Return(False)
     r = yield self.push_hotel(hotel)
     raise gen.Return(r)
コード例 #16
0
ファイル: submit_order.py プロジェクト: Hackforid/Ebooking
 def call_weixin(self, order):
     if order.confirm_type == OrderModel.CONFIRM_TYPE_AUTO:
         raise gen.Return()
     url = API['WEIXIN'] + "/webchart/ebkOrderPush"
     body = urllib.urlencode(order.todict())
     try:
         yield AsyncHTTPClient().fetch(url, method='POST', body=body)
     except Exception, e:
         Log.exception(e)
コード例 #17
0
ファイル: submit_order.py プロジェクト: Hackforid/Ebooking
    def create_order(self, order_entity):
        order = OrderModel.get_by_main_order_id(self.db, order_entity.id)
        if order:
            # callback 订单已存在
            Log.info('order exist')
            return order

        order = OrderModel.new_order(self.db, order_entity)
        return order
コード例 #18
0
ファイル: stockmixin.py プロジェクト: icyCloud/test_p_o_i
    def notify_stock(self, chain_id, chain_hotel_id):
        if not IS_PUSH_TO_STOCK:
            raise gen.Return()

        url = '{}/stock2/internal/hotel/update_time?chainId={}&chainHotelId={}'.format(API['STOCK'], chain_id, chain_hotel_id)
        time.sleep(2)
        resp = yield AsyncHTTPClient().fetch(url)
        Log.info(resp.body)
        raise gen.Return()
コード例 #19
0
ファイル: wechat_mixin.py プロジェクト: Hackforid/Ebooking
 def logout(self):
     Log.info("valid weixin fail")
     clear_domain_cookie(self, "open_id", domain=".betterwood.com")
     clear_domain_cookie(self, "username", domain=".betterwood.com")
     clear_domain_cookie(self, "merchant_id", domain=".betterwood.com")
     clear_domain_cookie(self, "open_id")
     clear_domain_cookie(self, "username")
     clear_domain_cookie(self, "merchant_id")
     raise JsonException(500, "weixin login valid fai")
コード例 #20
0
ファイル: inventory.py プロジェクト: icyCloud/test_e_b_k
    def push_inventory_by_merchant(self, merchant_id):
        Log.info(">> push inventories by merchant {}".format(merchant_id))
        roomtypes = CooperateRoomTypeModel.get_by_merchant_id(self.db, merchant_id)

        for roomtype in roomtypes:
            r = yield self.push_by_roomtype(roomtype)
            if not r:
                raise gen.Return(False)
        raise gen.Return(True)
コード例 #21
0
    def put(self):
        req = ObjectDict(json_decode(self.request.body))
        Log.info("RoomTypeMapping>> user:{}, req:{}".format(self.current_user, req))

        r = RoomTypeMappingModel.update_main_hotel_id(self.db, req.id, req.main_roomtype_id)

        self.finish_json(result=ObjectDict(
                roomtype_mapping=r.todict(),
            ))
コード例 #22
0
ファイル: submit_order.py プロジェクト: icyCloud/test_e_b_k
    def create_order(self, order_entity):
        order = OrderModel.get_by_main_order_id(self.db, order_entity.id)
        if order:
            # callback 订单已存在
            Log.info('order exist')
            return order

        order = OrderModel.new_order(self.db, order_entity)
        return order
コード例 #23
0
    def push_inventory_by_merchant(self, merchant_id):
        Log.info(">> push inventories by merchant {}".format(merchant_id))
        roomtypes = CooperateRoomTypeModel.get_by_merchant_id(
            self.db, merchant_id)

        for roomtype in roomtypes:
            r = yield self.push_by_roomtype(roomtype)
            if not r:
                raise gen.Return(False)
        raise gen.Return(True)
コード例 #24
0
 def push_hotel_by_id(self, hotel_id):
     Log.info("<<push hotel by id {}>>".format(hotel_id))
     hotel = CooperateHotelModel.get_by_id(self.db,
                                           hotel_id,
                                           with_delete=True)
     if not hotel:
         Log.info(
             "<<push hotel {}>> error hotel not exist".format(hotel_id))
         raise gen.Return(False)
     r = yield self.push_hotel(hotel)
     raise gen.Return(r)
コード例 #25
0
ファイル: base.py プロジェクト: icyCloud/test_p_o_i
 def get_user_permission(self, username):
     url = Login.PERMISSION_URL.format(username)
     Log.info(url)
     resp = yield AsyncHTTPClient().fetch(url)
     Log.info(resp.body)
     r = json.loads(resp.body)
     resources = r['result']['resources']
     permissions = [p['id'] for p in resources]
     print '=' * 10
     print permissions
     raise gen.Return(mapping_permission(permissions))
コード例 #26
0
ファイル: hotel_mapping.py プロジェクト: icyCloud/test_p_o_i
 def add_hotels(self, hotels):
     hotel_mappings = []
     for hotel in hotels:
         try:
             hotel_mapping = self.add_hotel_mapping(hotel)
             hotel_mappings.append(hotel_mapping)
         except:
             Log.info(">>> push ebooking hotel {} fail !!!".format(hotel))
             Log.error(traceback.format_exc())
             self.db.rollback()
     return hotel_mappings
コード例 #27
0
ファイル: poi.py プロジェクト: icyCloud/test_e_b_k
    def push_roomtype(self, roomtype_id):
        Log.info("<<POI push room mapping {}>> start".format(roomtype_id))

        room = CooperateRoomTypeModel.get_by_id(self.db, roomtype_id)
        if not room:
            Log.error("<<POI push room mapping {}>> no roomtype".format(roomtype_id))
            raise gen.Return(False)

        room_data = self.generate_data(room)
        r = yield self.post_room(room_data)
        raise gen.Return(r)
コード例 #28
0
ファイル: submit_order.py プロジェクト: icyCloud/test_e_b_k
def callback_order_server(order_id):
    url = API['ORDER'] + '/order/ebooking/update'
    params = {'orderId': order_id, 'msgType': 0, 'success': True,
            'trackId': generate_track_id(order_id)}
    r = requests.post(url, data=params)
    Log.info(r.text)
    if r.status_code == 200:
        j = r.json()
        if j['errcode'] == 0:
            return True
    return False
コード例 #29
0
    def add_roomtypes(self, roomtypes):
        roomtype_mappings = []
        for roomtype in roomtypes:
            try:
                roomtype_mapping = self.add_roomtype(roomtype)
                roomtype_mappings.append(roomtype_mapping)
            except:
                Log.info(">>> push ebooking room {} fail !!!".format(roomtype))
                Log.error(traceback.format_exc())
                self.db.rollback()

        return roomtype_mappings 
コード例 #30
0
ファイル: sms.py プロジェクト: icyCloud/test_e_b_k
def send_sms(phones, content):
    if not content:
        return

    url = "http://10.200.11.119:8090/member/send_sms"

    for phone in phones:
        obj = {}
        obj['mobile'] = phone
        obj['content'] = content
        r = requests.post(url, json=obj)
        Log.info(">> send sms resp {}".format(r.text))
コード例 #31
0
    def push_all(self):
        Log.info("<<POI push all>> start")
        if not IS_PUSH_TO_POI:
            return

        from models.merchant import MerchantModel
        merchants = MerchantModel.get_all(self.session)
        for merchant in merchants:
            try:
                self.push_by_merchant(merchant)
            except Exception as e:
                Log.debug(traceback.format_exc())
コード例 #32
0
ファイル: poi.py プロジェクト: icyCloud/test_e_b_k
    def push_all(self):
        Log.info("<<POI push all>> start")
        if not IS_PUSH_TO_POI:
            return

        from models.merchant import MerchantModel
        merchants = MerchantModel.get_all(self.session)
        for merchant in merchants:
            try:
                self.push_by_merchant(merchant)
            except Exception as e:
                Log.debug(traceback.format_exc())
コード例 #33
0
    def push_roomtype(self, roomtype_id):
        Log.info("<<POI push room mapping {}>> start".format(roomtype_id))

        room = CooperateRoomTypeModel.get_by_id(self.db, roomtype_id)
        if not room:
            Log.error(
                "<<POI push room mapping {}>> no roomtype".format(roomtype_id))
            raise gen.Return(False)

        room_data = self.generate_data(room)
        r = yield self.post_room(room_data)
        raise gen.Return(r)
コード例 #34
0
ファイル: sms.py プロジェクト: Hackforid/Ebooking
def send_sms(phones, content):
    if not content:
        return

    url = "http://10.200.11.119:8090/member/send_sms"

    for phone in phones:
        obj = {}
        obj['mobile'] = phone
        obj['content'] = content
        r = requests.post(url, json=obj)
        Log.info(">> send sms resp {}".format(r.text))
コード例 #35
0
ファイル: hotel_mapping.py プロジェクト: icyCloud/test_p_o_i
    def post(self):
        Log.info("start push ebooking hotel")
        print self.request.body
        args = self.get_json_arguments()

        hotels, = get_and_valid_arguments(args, 'hotels')
        hotel_mappings = self.add_hotels(hotels)

        Log.info("end push ebooking hotel")
        self.finish_json(result=dict(
            hotel_mapping=[hotel_mapping.todict() for hotel_mapping in hotel_mappings],
            ))
コード例 #36
0
ファイル: submit_order.py プロジェクト: icyCloud/test_e_b_k
def create_order(session, submit_order):
    order = OrderModel.get_by_main_order_id(session, submit_order.id)
    if order:
        # callback 订单已存在
        Log.info('order exist')
        return order

    order = OrderModel.new_order(session, submit_order)
    if order:
        return order
    else:
        # callback 创建失败
        pass
コード例 #37
0
    def push_roomtype(self, roomtype_id):
        Log.info("<<POI push room mapping {}>> start".format(roomtype_id))
        if not IS_PUSH_TO_POI:
            return
        from models.cooperate_roomtype import CooperateRoomTypeModel

        room = CooperateRoomTypeModel.get_by_id(self.session, roomtype_id)
        if not room:
            Log.error("no roomtype")
            return

        room_data = self.generate_data(room)
        self.post_room(room_data)
コード例 #38
0
ファイル: poi.py プロジェクト: icyCloud/test_e_b_k
    def push_roomtype(self, roomtype_id):
        Log.info("<<POI push room mapping {}>> start".format(roomtype_id))
        if not IS_PUSH_TO_POI:
            return
        from models.cooperate_roomtype import CooperateRoomTypeModel

        room = CooperateRoomTypeModel.get_by_id(self.session, roomtype_id)
        if not room:
            Log.error("no roomtype")
            return

        room_data = self.generate_data(room)
        self.post_room(room_data)
コード例 #39
0
ファイル: hotel_mapping.py プロジェクト: icyCloud/test_p_o_i
    def put(self):
        req = ObjectDict(json_decode(self.request.body))
        Log.info("HotelMapping>> user:{} req:{}".format(self.current_user, req))
        mapping = HotelMappingModel.change_main_hotel_id(self.db, req.hotel_mapping_id, req.main_hotel_id)
        RoomTypeMappingModel.reset_mapping_by_provider_hotel_id(self.db, mapping.provider_hotel_id, req.main_hotel_id)
        room_types = RoomTypeModel.gets_by_hotel_id(self.db, req.main_hotel_id)
        room_types = [room_type.todict() for room_type in room_types]


        self.finish_json(result=dict(
            hotel_mapping=mapping.todict(),
            room_types=room_types,
            ))
コード例 #40
0
    def post(self):
        args = self.get_json_arguments()
        Log.info('args: ' + str(args))
        chain_hotel_id, chain_roomtype_id = get_and_valid_arguments(args,
                'chain_hotel_id', 'chain_roomtype_id')

        if chain_hotel_id and chain_roomtype_id:

            RoomTypeMappingModel.delete_mapping_by_provider_hotel_id(self.db,6, chain_hotel_id, chain_roomtype_id)

            self.finish_json()
        else:
            self.finish_json(errcode=1)
コード例 #41
0
ファイル: ota.py プロジェクト: Hackforid/Ebooking
def change_ota(hotel_id, ota_ids):
    Log.info("change ota>>hotel {}>>ota {}".format(hotel_id, ota_ids))
    url =  API['STOCK'] + '/stock/switch_ota'
    track_id = generate_track_id(hotel_id)
    if not ota_ids:
        ota_ids_str = '-1'
    else:
        ota_ids_str = '|'.join([str(id) for id in ota_ids])
    data = {
            'track_id': track_id,
            'chain_id': CHAIN_ID,
            'chain_hotel_id': hotel_id,
            'ota_ids': ota_ids_str,
            }
    body = urllib.urlencode(data)
    Log.info("change ota>>hotel {}>>ota {}:req {}".format(hotel_id, ota_ids, body))

    if not IS_PUSH_TO_STOCK:
        raise gen.Return(True)

    try:
        r = yield AsyncHTTPClient().fetch(url, method='POST', body=body)
        Log.info("change ota>>hotel {}>>ota {}:resp {}".format(hotel_id, ota_ids, r.body))
        resp = json.loads(r.body)
    except Exception, e:
        Log.exception(e)
        raise gen.Return(False)
コード例 #42
0
ファイル: order.py プロジェクト: icyCloud/test_e_b_k
    def callback_order_server(self, order):
        url = API['ORDER'] + '/order/ebooking/update'
        params = {'orderId': order.id, 'msgType': 0, 'success': True,
                  'btwOrderId': order.main_order_id,
                  'trackId': self.generate_track_id(order.id)}
        r = yield AsyncHTTPClient().fetch(url, method='POST',
                                          body=urllib.urlencode(params)
        )
        Log.info(r.body)
        resp = json.loads(r.body)

        if resp and resp['errcode'] == 0:
            raise gen.Return(True)
        raise gen.Return(False)
コード例 #43
0
    def update_rateplans_valid_status(self, rateplan_ids):
        Log.info("<< push rateplans {} update rateplan valid>>".format(
            rateplan_ids))
        if not IS_PUSH_TO_STOCK:
            raise gen.Return(True)

        rateplans = RatePlanModel.get_by_ids(self.db,
                                             rateplan_ids,
                                             with_delete=True)
        rateplan_datas = [{
            "chain_id": CHAIN_ID,
            "hotel_id": rateplan.hotel_id,
            "rate_plan_id": rateplan.id,
            "is_valid": self.cal_rateplan_isvalid(rateplan)
        } for rateplan in rateplans]

        track_id = self.generate_track_id(rateplan_ids)
        data = {'list': rateplan_datas, 'type': 3}
        params = {'track_id': track_id, 'data': json.dumps(data)}
        body = urllib.urlencode(params)
        url = API['STOCK'] + '/stock/update_state?is_async=false'

        Log.info(
            "<< push rateplan {} update rateplan valid request {}>>".format(
                rateplan_ids, params))
        try:
            r = yield AsyncHTTPClient().fetch(url, method='POST', body=body)
            Log.info("<< push rateplan {} update rateplan valid response {}>>".
                     format(rateplan_ids, r.body))
            resp = json.loads(r.body)
        except Exception, e:
            Log.exception(e)
            raise gen.Return(False)
コード例 #44
0
ファイル: finance.py プロジェクト: icyCloud/test_e_b_k
    def valid_order_from_server(self, orders):
        order_ids = [order.id for order in orders]
        url = API['ORDER_VALID'] + '/order/settleApi/ebooking/settleStatus'
        resp = yield AsyncHTTPClient().fetch(url, method='POST', headers = {'Content-Type': 'application/json; charset=UTF-8'}, body = json.dumps({'order_ids': order_ids}))
        r = json.loads(resp.body)

        if r and r['errcode'] == 0:
            Log.info("load orders {}".format(order_ids))
            Log.info("fetch valid orders {}".format(r))
            valid_order_ids = r['result']['order_ids']
            orders = [order for order in orders if str(order.id) in valid_order_ids]
            raise gen.Return(orders)
        else:
            raise JsonException(1002, 'order valid server error')
コード例 #45
0
ファイル: roomrate.py プロジェクト: Hackforid/Ebooking
    def put(self):
        args = self.get_json_arguments()
        Log.info(u"<<modify roomrate>>  data: {}".format(args))
        merchant_id, roomrate_id, start_date, end_date, price = get_and_valid_arguments(
            args, 'merchant_id', 'roomrate_id', 'start_date', 'end_date',
            'price')
        weekdays = args.get('weekdays', None)

        self.valid_price(price)
        start_date, end_date = self.valid_date(start_date, end_date, weekdays)

        roomrate = yield self.set_price(merchant_id, roomrate_id, price,
                                        start_date, end_date, weekdays)
        self.finish_json(result=dict(roomrate=roomrate.todict(), ))
コード例 #46
0
    def push_hotel(self, hotel_id):
        Log.info("<<POI push hotel mapping {}>> start".format(hotel_id))
        if not IS_PUSH_TO_POI:
            raise gen.Return(True)

        hotel = CooperateHotelModel.get_by_id(self.db, hotel_id)
        if not hotel:
            raise gen.Return(False)
        merchant = MerchantModel.get_by_id(self.db, hotel.merchant_id)
        if not merchant:
            raise gen.Return(False)

        hotel_data = self.generate_data(hotel, merchant)
        r = yield self.post_hotel(hotel_data)
        raise gen.Return(r)
コード例 #47
0
ファイル: roomrate.py プロジェクト: Hackforid/Ebooking
    def put(self, hotel_id, roomtype_id, roomrate_id):
        args = self.get_json_arguments()
        Log.info(u"<<modify roomrate {}>> user:{} data: {}".format(
            roomrate_id, self.current_user.todict(), args))
        start_date, end_date, price = get_and_valid_arguments(
            args, 'start_date', 'end_date', 'price')
        weekdays = args.get('weekdays', None)
        merchant_id = self.merchant.id

        self.valid_price(price)
        start_date, end_date = self.valid_date(start_date, end_date, weekdays)

        roomrate = yield self.set_price(merchant_id, roomrate_id, price,
                                        start_date, end_date, weekdays)
        self.finish_json(result=dict(roomrate=roomrate.todict(), ))
コード例 #48
0
ファイル: wechat_mixin.py プロジェクト: Hackforid/Ebooking
 def check_open_id(self, open_id, merchant_id, username):
     if API.get('WEIXIN') is None:
         raise gen.Return(False)
     url = "{}/webchart/user/ebk/has_bind_wechat?merchantId={}&username={}&openId={}".format(
         API['WEIXIN'], merchant_id, username, open_id)
     resp = yield AsyncHTTPClient().fetch(url)
     Log.info(resp.body)
     if resp.code == 200:
         r = json.loads(resp.body)
         if r and r['errcode'] == 0:
             raise gen.Return(True)
         else:
             self.logout()
             raise gen.Return(False)
     else:
         raise JsonException(500, 'call weixin server error')
コード例 #49
0
    def push_hotel(self, hotel_id):
        Log.info("<<POI push hotel mapping {}>> start".format(hotel_id))
        if not IS_PUSH_TO_POI:
            return

        from models.cooperate_hotel import CooperateHotelModel
        from models.merchant import MerchantModel

        hotel = CooperateHotelModel.get_by_id(self.session, hotel_id)
        if not hotel:
            return
        merchant = MerchantModel.get_by_id(self.session, hotel.merchant_id)
        if not merchant:
            return

        hotel_data = self.generate_data(hotel, merchant)
        self.post_hotel(hotel_data)
コード例 #50
0
    def put(self, hotel_id):
        Log.info(self.request.body)
        args = self.get_json_arguments()
        ota_ids, = get_and_valid_arguments(args, 'ota_ids')
        yield self.valid_ota_ids(ota_ids)

        ota_channel = OtaChannelModel.set_ota_ids(self.db,
                                                  hotel_id,
                                                  ota_ids,
                                                  commit=False)
        r = yield change_ota(hotel_id, ota_ids)
        if not r:
            self.db.rollback()
            raise JsonException(1000, 'fail')
        else:
            self.db.commit()
            self.finish_json(result=dict(ota_channel=ota_channel.todict(), ))
コード例 #51
0
    def callback_order_server(self, order):
        url = API['ORDER'] + '/order/ebooking/update'
        params = {
            'orderId': order.id,
            'msgType': 0,
            'success': False,
            'btwOrderId': order.main_order_id,
            'trackId': self.generate_track_id(order.id)
        }
        r = yield AsyncHTTPClient().fetch(url,
                                          method='POST',
                                          body=urllib.urlencode(params))
        Log.info(r.body)
        resp = json.loads(r.body)

        if resp and resp['errcode'] == 0:
            raise gen.Return(True)
        raise gen.Return(False)
コード例 #52
0
def modify_inventory(session, order):
    stay_days = get_stay_days(order.checkin_date, order.checkout_date)
    year_months = [(day.year, day.month) for day in stay_days]
    year_months = {}.fromkeys(year_months).keys()

    inventories = InventoryModel.get_by_merchant_hotel_roomtype_dates(
        session, order.merchant_id, order.hotel_id, order.roomtype_id,
        year_months)

    if not valid_inventory(inventories, stay_days, order.room_num):
        Log.info('valid inventory fail')
        order.exception_info = 'valid inventory fail'
        order.status = 200
        session.commit()
        return order

    room_num_record = []
    is_auto = True

    for day in stay_days:
        inventory = get_inventory_by_date(inventories, day.year, day.month)
        num_auto, num_manual = inventory.deduct_val_by_day(
            day.day, order.room_num)
        if num_manual > 0:
            is_auto = False
        room_num_record.append((num_auto, num_manual))

    if is_auto:
        order.status = 300
        order.confirm_type = OrderModel.CONFIRM_TYPE_AUTO
    else:
        order.status = 100
        order.confirm_type = OrderModel.CONFIRM_TYPE_MANUAL

    order.room_num_record = generate_room_num_record(room_num_record)

    r = InventoryPusher(session).push_by_roomtype_id(order.roomtype_id)
    if r:
        session.commit()
        return order
    else:
        session.rollback()
        raise Exception("push stock fail")
コード例 #53
0
    def post_hotels(self, hotel_datas):
        hotel_ids = [hotel_data['id'] for hotel_data in hotel_datas]
        track_id = self.generate_track_id(id(hotel_ids))
        data = {'list': hotel_datas}
        params = {'track_id': track_id, 'data': json.dumps(data)}
        Log.info(u"<<push hotels {}>> push data {}".format(hotel_ids, params))
        url = API['STOCK'] + '/stock/update_hotel?is_async=false'

        body = urllib.urlencode(params)

        if not IS_PUSH_TO_STOCK:
            raise gen.Return(True)

        try:
            r = yield AsyncHTTPClient().fetch(url, method='POST', body=body)
            resp = json.loads(r.body)
        except Exception, e:
            Log.exception(e)
            raise gen.Return(False)
コード例 #54
0
ファイル: finance.py プロジェクト: Hackforid/Ebooking
    def valid_order_from_server(self, orders):
        order_ids = [order.id for order in orders]
        url = API['ORDER_VALID'] + '/order/settleApi/ebooking/settleStatus'
        resp = yield AsyncHTTPClient().fetch(
            url,
            method='POST',
            headers={'Content-Type': 'application/json; charset=UTF-8'},
            body=json.dumps({'order_ids': order_ids}))
        r = json.loads(resp.body)

        if r and r['errcode'] == 0:
            Log.info("load orders {}".format(order_ids))
            Log.info("fetch valid orders {}".format(r))
            valid_order_ids = r['result']['order_ids']
            orders = [
                order for order in orders if str(order.id) in valid_order_ids
            ]
            raise gen.Return(orders)
        else:
            raise JsonException(1002, 'order valid server error')
コード例 #55
0
ファイル: submit_order.py プロジェクト: Hackforid/Ebooking
    def format_order(self, order_json):
        Log.info(order_json)
        try:
            order_entity = SubmitOrder(order_json)
        except ValueError as e:
            raise JsonException(errcode=1, errmsg=e.message)
        Log.info(order_entity)

        rate_plan = RatePlanModel.get_by_id(self.db, order_entity.rateplan_id)
        if not rate_plan:
            raise JsonException(1, 'no rate plan')

        order_entity.pay_type = rate_plan.pay_type
        order_entity.merchant_id = rate_plan.merchant_id
        order_entity.cancel_type = rate_plan.cancel_type
        order_entity.punish_type = rate_plan.punish_type
        order_entity.punish_value = rate_plan.punish_value
        order_entity.guarantee_type = rate_plan.guarantee_type
        order_entity.guarantee_start_time = rate_plan.guarantee_start_time

        return order_entity
コード例 #56
0
    def post_rateplan(self, rateplan):

        rateplan_data = self.generate_rateplan_data(rateplan)

        track_id = self.generate_track_id(rateplan_data['rate_plan_id'])
        data = {'list': [rateplan_data]}
        params = {'track_id': track_id, 'data': json_encode(data)}
        Log.info('push rateplan {} : {}'.format(rateplan.id, params))

        if not IS_PUSH_TO_STOCK:
            raise gen.Return(True)

        url = API['STOCK'] + '/stock/update_rate_plan?is_async=false'
        body = urllib.urlencode(params)
        r = yield AsyncHTTPClient().fetch(url, method="POST", body=body)
        resp = json.loads(r.body)
        Log.info("<<push rateplan {}>> response:{}".format(rateplan.id, resp))
        if resp and resp['errcode'] == 0:
            raise gen.Return(True)
        else:
            raise gen.Return(False)
コード例 #57
0
def browser_param(browser: str, email: str, pw: str):
    log = Log(error_path='error.log',
              debug_path='normal.log',
              json_path='info.log')
    log.set_level(Log.stdout_level)
    # for test
    log.debug('test ' + browser + '_' + email)
    start = time.time()
    crawler = FacebookCrawler(user_name=email,
                              password=pw,
                              log=log,
                              browser=browser)
    crawler.init()
    crawler.login_facebook()
    # crawler.get_browser().save_screenshot('login.png')
    crawler.set_sleep(1)
    user_url = 'https://www.facebook.com/app_scoped_user_id/1758044224504993/'
    user_info = crawler.open_homepage_by_url(user_homepage=user_url)
    log.debug(user_info)
    end = time.time()
    log.debug('time cost:' + str(end - start) + ' s')
コード例 #58
0
    def post_inventory(self, inventories, is_online=1):
        if not inventories:
            return True
        inventory_data = self.generate_inventory_data(inventories, is_online)
        track_id = self.generate_track_id(inventories[0].roomtype_id)

        params = {
            'track_id': track_id,
            'data': json_encode({'list': [inventory_data]})
        }

        Log.info("push inventory roomtype {}: {}".format(
            inventories[0].roomtype_id, params))
        if not IS_PUSH_TO_STOCK:
            return True

        url = API['STOCK'] + '/stock/update_inventory?is_async=false'
        r = requests.post(url, data=params)
        Log.info("push inventory roomtype {} response {}".format(
            inventories[0].roomtype_id, r.text))

        return r.status_code == 200 and r.json()['errcode'] == 0
コード例 #59
0
    def post_roomrate(self, merchant_id, roomrate):
        roomrate_datas = self.generate_roomrate_datas(merchant_id, roomrate)
        track_id = self.generate_track_id(roomrate.id)
        data = {
            'track_id': track_id,
            'data': json_encode({'list': roomrate_datas})
        }
        Log.info("<<push roomrate {}>>: {}".format(roomrate.id, data))

        if not IS_PUSH_TO_STOCK:
            raise gen.Return(True)

        url = API['STOCK'] + '/stock/update_room_rate?is_async=false'
        body = urllib.urlencode(data)
        r = yield AsyncHTTPClient().fetch(url, method="POST", body=body)
        resp = json.loads(r.body)
        Log.info("<<push roomrate {}>> response:{}".format(
            roomrate.id, r.body))
        if resp and resp['errcode'] == 0:
            raise gen.Return(True)
        else:
            raise gen.Return(False)