예제 #1
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)
예제 #2
0
    def post(self, order_id):
        merchant_id = self.current_user.merchant_id
        args = self.get_json_arguments()
        reason, = get_and_valid_arguments(args, 'reason')
        if not reason:
            raise JsonException(200, 'invalid reason')

        order = OrderModel.get_by_id(self.db, order_id)

        pre_status = order.status

        if order.merchant_id != merchant_id:
            raise JsonException(300, 'merchant invalid')
        if order.status not in [0, 100]:
            raise JsonException(400, 'illegal status')

        if not (yield self.callback_order_server(order)):
            raise JsonException(1000, 'callback order server error')

        task = yield gen.Task(Cancel.cancel_order_by_user.apply_async,
                              args=[order_id, reason])

        if task.status == 'SUCCESS':
            order = task.result
            if order.status != pre_status:
                OrderHistoryModel.set_order_status_by_user(
                    self.db, self.current_user, order, pre_status,
                    order.status)
            self.finish_json(result=dict(order=order.todict(), ))
        else:
            if isinstance(task.result, CeleryException):
                raise JsonException(1000, task.result.errmsg)
            else:
                raise JsonException(1000, 'network error')
예제 #3
0
def cancel_order_by_user(self, user, order_id, reason):
    session = self.session
    order = OrderModel.get_by_id(session, order_id)

    pre_status = order.status

    if order.merchant_id != user.merchant_id:
        raise CeleryException(100, 'merchant invalid')
    if order.status not in [0, 100]:
        raise CeleryException(1000, 'illegal status')

    if not callback_order_server(order_id):
        raise CeleryException(1000, 'callback order server error')

    task = Cancel.cancel_order_by_user.delay(order_id, reason)
    result = task.get()

    if task.status == 'SUCCESS':
        if result.status != pre_status:
            OrderHistoryModel.set_order_status_by_user(session, user, result,
                                                       pre_status,
                                                       result.status)
        PushInventoryTask().push_inventory.delay(order.roomtype_id)
        return result
    else:
        if isinstance(result, Exception):
            raise result
예제 #4
0
def cancel_order_by_user(self, user, order_id, reason):
    session = self.session
    order = OrderModel.get_by_id(session, order_id)

    pre_status = order.status

    if order.merchant_id != user.merchant_id:
        raise CeleryException(100, 'merchant invalid')
    if order.status not in [0, 100]:
        raise CeleryException(1000, 'illegal status')

    if not callback_order_server(order_id):
        raise CeleryException(1000, 'callback order server error')


    task = Cancel.cancel_order_by_user.delay(order_id, reason)
    result = task.get()
    
    if task.status == 'SUCCESS':
        if result.status != pre_status:
            OrderHistoryModel.set_order_status_by_user(session, user, result, pre_status, result.status)
        PushInventoryTask().push_inventory.delay(order.roomtype_id)
        return result
    else:
        if isinstance(result, Exception):
            raise result
예제 #5
0
def confirm_order_by_user(self, user, order_id):
    session = self.session
    order = OrderModel.get_by_id(session, order_id)
    pre_status = order.status
    if order.merchant_id != user.merchant_id:
        raise CeleryException(100, 'merchant not valid')
    if order.status != 100:
        raise CeleryException(200, 'illegal status')

    if callback_order_server(order_id):
        order.confirm_by_user(session)
        if order.status != pre_status:
            OrderHistoryModel.set_order_status_by_user(session, user, order, pre_status, order.status)
        return order
    else:
        raise CeleryException(1000, 'callback order server fail')
예제 #6
0
    def post(self, order_id):

        order = OrderModel.get_by_id(self.db, order_id)
        pre_status = order.status
        if order.merchant_id != self.merchant.id:
            raise JsonException(100, 'merchant not valid')
        if order.status != 100:
            raise JsonException(200, 'illegal status')

        if (yield self.callback_order_server(order)):
            order.confirm_by_user(self.db)
            if order.status != pre_status:
                OrderHistoryModel.set_order_status_by_user(
                    self.db, self.current_user, order, pre_status,
                    order.status)
        else:
            raise JsonException(1000, 'callback order server fail')

        self.finish_json(result=dict(order=order.todict(), ))
예제 #7
0
    def cancel_order_by_server(self, order_id):
        order = OrderModel.get_by_id(self.db, order_id)
        if not order:
            raise JsonException(2000, 'no order')

        pre_status = order.status

        if order.status == 0 or order.status == 100:
            _order = yield self.cancel_before_user_confirm(order.id)
        elif order.status == 300:
            _order = yield self.cancel_after_user_confirm(order.id)
        elif order.status in [400, 500, 600]:
            raise gen.Return(order)
        else:
            raise JsonException(1000, 'illegal status')

        if _order.status != pre_status:
            OrderHistoryModel.set_order_status_by_server(
                self.db, _order, pre_status, _order.status)
        raise gen.Return(_order)
예제 #8
0
def cancel_order_by_server(self, order_id):
    session = self.session
    order = OrderModel.get_by_id(session, order_id)

    pre_status = order.status

    if order.status == 0 or order.status == 100:
        _order = cancel_before_user_confirm(session, order.id)
    elif order.status == 200:
        raise CeleryException(1000, 'illegal status')
    elif order.status == 300:
        _order = cancel_after_user_confirm(session, order.id)
    elif order.status in [400, 500, 600]:
        return order
    else:
        raise CeleryException(1000, 'illegal status')


    if _order.status != pre_status:
        OrderHistoryModel.set_order_status_by_server(session, _order, pre_status, _order.status)
    return _order
예제 #9
0
def cancel_order_by_server(self, order_id):
    session = self.session
    order = OrderModel.get_by_id(session, order_id)

    pre_status = order.status

    if order.status == 0 or order.status == 100:
        _order = cancel_before_user_confirm(session, order.id)
    elif order.status == 200:
        raise CeleryException(1000, 'illegal status')
    elif order.status == 300:
        _order = cancel_after_user_confirm(session, order.id)
    elif order.status in [400, 500, 600]:
        return order
    else:
        raise CeleryException(1000, 'illegal status')

    if _order.status != pre_status:
        OrderHistoryModel.set_order_status_by_server(session, _order,
                                                     pre_status, _order.status)
    return _order
예제 #10
0
    def post(self, order_id):

        order = OrderModel.get_by_id(self.db, order_id)
        pre_status = order.status
        if order.merchant_id != self.merchant.id:
            raise JsonException(100, 'merchant not valid')
        if order.status != 100:
            raise JsonException(200, 'illegal status')
        if self.current_user.type == UserModel.TYPE_SUB and order.hotel_id != self.current_user.hotel_id:
            raise JsonException(500, 'illegal hotel')

        if (yield self.callback_order_server(order)):
            order.confirm_by_user(self.db)
            if order.status != pre_status:
                OrderHistoryModel.set_order_status_by_user(
                    self.db, self.current_user, order, pre_status, order.status)
        else:
            raise JsonException(1000, 'callback order server fail')

        self.finish_json(result=dict(
            order=order.todict(),
        ))
예제 #11
0
    def cancel_order_by_server(self, order_id):
        order = OrderModel.get_by_id(self.db, order_id)
        if not order:
            raise JsonException(2000, 'no order')

        pre_status = order.status

        if order.status == 0 or order.status == 100:
            _order = yield self.cancel_before_user_confirm(order.id)
        elif order.status == 300:
            _order = yield self.cancel_after_user_confirm(order.id)
        elif order.status in [400, 500, 600]:
            raise gen.Return(order)
        elif self.current_user.type == UserModel.TYPE_SUB and order.hotel_id != self.current_user.hotel_id:
            raise JsonException(500, 'illegal hotel')
        else:
            raise JsonException(1000, 'illegal status')


        if _order.status != pre_status:
            OrderHistoryModel.set_order_status_by_server(self.db, _order, pre_status, _order.status)
        raise gen.Return(_order)
예제 #12
0
파일: sms.py 프로젝트: Hackforid/Ebooking
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)
예제 #13
0
    def post(self, order_id):
        merchant_id = self.current_user.merchant_id
        args = self.get_json_arguments()
        reason, = get_and_valid_arguments(args, 'reason')
        if not reason:
            raise JsonException(200, 'invalid reason')

        order = OrderModel.get_by_id(self.db, order_id)

        pre_status = order.status

        if order.merchant_id != merchant_id:
            raise JsonException(300, 'merchant invalid')
        if order.status not in [0, 100]:
            raise JsonException(400, 'illegal status')
        if self.current_user.type == UserModel.TYPE_SUB and order.hotel_id != self.current_user.hotel_id:
            raise JsonException(500, 'illegal hotel')

        if not (yield self.callback_order_server(order)):
            raise JsonException(1000, 'callback order server error')

        task = yield gen.Task(Cancel.cancel_order_by_user.apply_async,
                              args=[order_id, reason])

        if task.status == 'SUCCESS':
            order = task.result
            if order.status != pre_status:
                OrderHistoryModel.set_order_status_by_user(
                    self.db, self.current_user, order, pre_status, order.status)
            self.finish_json(result=dict(
                order=order.todict(),
            ))
        else:
            if isinstance(task.result, CeleryException):
                raise JsonException(1000, task.result.errmsg)
            else:
                raise JsonException(1000, 'network error')
예제 #14
0
def get_order(session, order_id):
    return OrderModel.get_by_id(session, order_id)
예제 #15
0
def get_order(session, order_id):
    return OrderModel.get_by_id(session, order_id)