def post(self, hotel_id, roomtype_id): args = self.get_json_arguments() merchant_id = self.current_user.merchant_id name, meal_num, punish_type = get_and_valid_arguments( args, 'name', 'meal_num', 'punish_type') pay_type = args.get('pay_type', RatePlanModel.PAY_TYPE_PRE) ahead_days = args.get('ahead_days', None) stay_days = args.get('stay_days', None) self.valid_pay_type(pay_type) self.valid_rateplan_arguments(name, meal_num, punish_type) if pay_type == RatePlanModel.PAY_TYPE_ARRIVE: guarantee_start_time, guarantee_type = get_and_valid_arguments( args, 'guarantee_start_time', 'guarantee_type') self.valid_arrive_pay_args(guarantee_type, guarantee_start_time) rateplan, roomrate = yield self.new_rate_plan( merchant_id, hotel_id, roomtype_id, name, meal_num, punish_type, ahead_days, stay_days, pay_type, guarantee_type, guarantee_start_time) else: rateplan, roomrate = yield self.new_rate_plan( merchant_id, hotel_id, roomtype_id, name, meal_num, punish_type, ahead_days, stay_days) self.finish_json(result=dict( rateplan=rateplan.todict(), roomrate=roomrate.todict(), ))
def put(self): args = self.get_json_arguments() merchant, = get_and_valid_arguments(args, 'merchant') id, name, type = get_and_valid_arguments(merchant, 'id', 'name', 'type') admin_pwd = args.get('admin_pwd', None) root_pwd = args.get('root_pwd', None) merchant = self.modify_merchant(id, name, type, admin_pwd, root_pwd) self.finish_json(result=dict(merchant=merchant.todict(), ))
def post(self): args = self.get_json_arguments() merchant, root_pwd, admin_pwd = get_and_valid_arguments(args, 'merchant', 'root_pwd', 'admin_pwd') name, type = get_and_valid_arguments(merchant, 'name', 'type') merchant, admin, root = self.new_merchant(name, type, admin_pwd, root_pwd) self.finish_json(result=dict( merchant=merchant.todict(), admin=admin.todict(), root=root.todict(), ))
def put(self): args = self.get_json_arguments() merchant, = get_and_valid_arguments(args, 'merchant') id, name, type = get_and_valid_arguments(merchant, 'id', 'name', 'type') admin_pwd = args.get('admin_pwd', None) root_pwd = args.get('root_pwd', None) merchant = self.modify_merchant(id, name, type, admin_pwd, root_pwd) self.finish_json(result=dict( merchant=merchant.todict(), ))
def post(self): args = self.get_json_arguments() merchant, root_pwd, admin_pwd = get_and_valid_arguments( args, 'merchant', 'root_pwd', 'admin_pwd') name, type = get_and_valid_arguments(merchant, 'name', 'type') merchant, admin, root = self.new_merchant(name, type, admin_pwd, root_pwd) self.finish_json(result=dict( merchant=merchant.todict(), admin=admin.todict(), root=root.todict(), ))
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(), ))
def put(self): args = self.get_json_arguments() old_password, password, re_password = get_and_valid_arguments(args, 'old_password', 'password', 're_password') old_password = md5_password(old_password) if self.current_user.password != old_password: print u'密码不对' print self.current_user.password, old_password self.finish_json(1, u'旧密码不正确') return if (not password) or (not re_password): print u'请输入正确密码' self.finish_json(1, u'请输入正确密码') return if password != re_password: print u'两次密码不一致' self.finish_json(1, u'两次密码不一致') return if md5_password(password) == self.current_user.password: print u'新密码和旧密码相同' self.finish_json(1, u'新密码和旧密码相同') return UserModel.update_password(self.db, self.current_user.merchant_id, self.current_user.username, password) self.clear_cookie('username') self.clear_cookie('merchant_id') self.finish_json(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')
def put(self): args = self.get_json_arguments() old_password, password, re_password = get_and_valid_arguments( args, 'old_password', 'password', 're_password') old_password = md5_password(old_password) if self.current_user.password != old_password: print u'密码不对' print self.current_user.password, old_password self.finish_json(1, u'旧密码不正确') return if (not password) or (not re_password): print u'请输入正确密码' self.finish_json(1, u'请输入正确密码') return if password != re_password: print u'两次密码不一致' self.finish_json(1, u'两次密码不一致') return if md5_password(password) == self.current_user.password: print u'新密码和旧密码相同' self.finish_json(1, u'新密码和旧密码相同') return UserModel.update_password(self.db, self.current_user.merchant_id, self.current_user.username, password) self.clear_cookie('username') self.clear_cookie('merchant_id') self.finish_json(0, '修改成功')
def post(self): merchant_id = self.current_user.merchant_id args = self.get_json_arguments() hotel_ids, = get_and_valid_arguments(args, 'hotel_ids') coops = yield self.new_hotel_cooprates(merchant_id, hotel_ids) self.finish_json( result=dict(hotel_cooprate=[coop.todict() for coop in coops], ))
def post(self): merchant_id = self.current_user.merchant_id args = self.get_json_arguments() hotel_ids, = get_and_valid_arguments(args, 'hotel_ids') coops = yield self.new_hotel_cooprates(merchant_id, hotel_ids) self.finish_json(result=dict( hotel_cooprate=[coop.todict() for coop in coops], ))
def post(self): args = self.get_json_arguments() commission = None name, type, bank_name, bank_account_id, bank_account_name = get_and_valid_arguments(args, 'name', 'type', 'bank_name', 'bank_account_id', 'bank_account_name') type = int(type) if type == ContractModel.PAY_TYPE_ARRIVE: commission, = get_and_valid_arguments(args, 'commission') self.valid_args(name, type, commission, bank_name, bank_account_id, bank_account_name) contract = ContractModel.get_by_merchant_and_type(self.db, self.merchant.id, type) if contract: raise JsonException(2000, 'contract exist') contract = ContractModel.new(self.db, self.merchant.id, name, type, commission, bank_name, bank_account_id, bank_account_name) self.finish_json(result=dict( contract=contract.todict(), ))
def post(self): args = self.get_json_arguments() merchant_id, username, password, re_password, department, mobile, authority, is_valid = \ get_and_valid_arguments( args, 'merchant_id', 'username', 'password', 're_password', 'department', 'mobile', 'authority', 'is_valid') hotel_id = None if 'hotel_id' in args: hotel_id = args['hotel_id'] try: hotel_id = int(hotel_id) authority = 0 authority += PERMISSIONS.update_order authority += PERMISSIONS.view_cooperated_hotel authority += PERMISSIONS.view_order authority += PERMISSIONS.inventory authority += PERMISSIONS.pricing authority += PERMISSIONS.update_password except Exception: self.finish_json('1', u'不合法的酒店') return if merchant_id != self.current_user.merchant_id: self.finish_json(1, u'您只能管理自己的酒店') return if not username: self.finish_json(1, u'请填写用户名') return if (not password) or (not re_password): self.finish_json(1, u'请输入密码') return if password != re_password: self.finish_json(1, u'两次密码不一致') return if not department: self.finish_json(1, u'请输入部门') return if not mobile: self.finish_json(1, u'请输入手机号') return if authority & PERMISSIONS.admin or authority & PERMISSIONS.root: self.finish_json(1, u'不允许添加管理员用户') return user = UserModel.get_user_by_merchantid_username( self.db, merchant_id, username) if user: self.finish_json(1, u'用户名已被使用') else: UserModel.add_user(self.db, merchant_id, username, password, department, mobile, authority, is_valid, hotel_id) self.finish_json(0, u'添加成功')
def put(self, hotel_id, roomtype_id): merchant_id = self.current_user.merchant_id args = self.get_json_arguments() prefix_name, remark_name = get_and_valid_arguments(args, "prefix_name", "remark_name") room = self.modify_cooped_roomtype(merchant_id, hotel_id, roomtype_id, prefix_name, remark_name) self.finish_json(result=dict( cooped_roomtype=room.todict(), ))
def post(self): args = self.get_json_arguments() roomtypes, = get_and_valid_arguments(args, 'roomtypes') roomtype_mappings = self.add_roomtypes(roomtypes) self.finish_json(result=dict( roomtype_mapping=[roomtype_mapping.todict() for roomtype_mapping in roomtype_mappings] ))
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], ))
def post(self, hotel_id): merchant_id = self.current_user.merchant_id args = self.get_json_arguments() roomtype_ids, = get_and_valid_arguments(args, 'roomtype_ids') if not roomtype_ids: raise JsonException(errcode=2001, errmsg="need id") coops = yield self.new_roomtype_coops(merchant_id, hotel_id, roomtype_ids) self.finish_json(result=dict( cooped_roomtypes=[coop.todict() for coop in coops], ))
def post(self): merchant_id = self.current_user.merchant_id args = self.get_json_arguments() pay_type, ota_ids, year, month, value = get_and_valid_arguments( args, 'pay_type', 'ota_ids', 'year', 'month', 'value') remark = args.get('remark', '') self.valid_args(pay_type, ota_ids, year, month, value, remark) income = IncomeModel.new(self.db, merchant_id, pay_type, min(ota_ids), year, month, value, remark) self.finish_json(result=dict(income=income.todict(), ))
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)
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(), ))
def post(self): args = self.get_json_arguments() commission = None name, type, bank_name, bank_account_id, bank_account_name = get_and_valid_arguments( args, 'name', 'type', 'bank_name', 'bank_account_id', 'bank_account_name') type = int(type) if type == ContractModel.PAY_TYPE_ARRIVE: commission, = get_and_valid_arguments(args, 'commission') self.valid_args(name, type, commission, bank_name, bank_account_id, bank_account_name) contract = ContractModel.get_by_merchant_and_type( self.db, self.merchant.id, type) if contract: raise JsonException(2000, 'contract exist') contract = ContractModel.new(self.db, self.merchant.id, name, type, commission, bank_name, bank_account_id, bank_account_name) self.finish_json(result=dict(contract=contract.todict(), ))
def post(self): merchant_id =self.current_user.merchant_id args = self.get_json_arguments() pay_type, ota_ids, year, month, value = get_and_valid_arguments( args, 'pay_type', 'ota_ids', 'year', 'month', 'value' ) remark = args.get('remark', '') self.valid_args(pay_type, ota_ids, year, month, value, remark) income = IncomeModel.new(self.db, merchant_id, pay_type, min(ota_ids), year, month, value, remark) self.finish_json(result=dict( income=income.todict(), ))
def put(self): args = self.get_json_arguments() merchant_id, username, department, mobile, authority, is_valid = \ get_and_valid_arguments( args, 'merchant_id', 'username', 'department', 'mobile', 'authority', 'is_valid') hotel_id = None if 'hotel_id' in args: hotel_id = args['hotel_id'] try: authority = None hotel_id = int(hotel_id) except Exception: self.finish_json('1', u'不合法的酒店') return if 'email' in args: email = args['email'] else: email = None if 'password' in args: password = args['password'] else: password = None if not self.mobile_check(mobile): self.finish_json(1, u'请填写正确手机号') return if not department: self.finish_json(1, u'请填写部门') return if self.current_user.merchant_id != merchant_id: self.finish_json(1, u'您只能管理自己的酒店') return ''' 可以管理用户 ''' UserModel.update_user(self.db, merchant_id, username, password, department, mobile, email, is_valid, authority, hotel_id) ''' 修改了自己的密码 ''' if self.current_user.username == username and password: self.clear_cookie('username') self.clear_cookie('merchant_id') self.finish_json(301, self.get_login_url()) return self.finish_json(0, u'成功')
def put(self): args = self.get_json_arguments() commission = None id, name, bank_name, bank_account_id, bank_account_name = get_and_valid_arguments(args, 'id', 'name', 'bank_name', 'bank_account_id', 'bank_account_name') contract = ContractModel.get_by_id_and_merchant(self.db, id, self.merchant.id) if not contract: raise JsonException(2000, 'contract not found') contract.name = name contract.bank_name = bank_name contract.bank_account_id = bank_account_id contract.bank_account_name = bank_account_name if contract.type == ContractModel.PAY_TYPE_ARRIVE: commission, = get_and_valid_arguments(args, 'commission') contract.commission = commission self.db.commit() self.finish_json(result=dict( contract=contract.todict(), ))
def put(self): args = self.get_json_arguments() commission = None id, name, bank_name, bank_account_id, bank_account_name = get_and_valid_arguments( args, 'id', 'name', 'bank_name', 'bank_account_id', 'bank_account_name') contract = ContractModel.get_by_id_and_merchant( self.db, id, self.merchant.id) if not contract: raise JsonException(2000, 'contract not found') contract.name = name contract.bank_name = bank_name contract.bank_account_id = bank_account_id contract.bank_account_name = bank_account_name if contract.type == ContractModel.PAY_TYPE_ARRIVE: commission, = get_and_valid_arguments(args, 'commission') contract.commission = commission self.db.commit() self.finish_json(result=dict(contract=contract.todict(), ))
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(), ))
def post(self): args = self.get_json_arguments() merchant_id, username, password = get_and_valid_arguments(args, 'merchant_id', 'username', 'password') user = UserModel.get_user_by_merchantid_username_and_password(self.db, merchant_id, username, password) if user: self.set_secure_cookie("username", user.username, expires_days=0.02) self.set_secure_cookie("merchant_id", str(user.merchant_id), expires_days=0.02) self.finish_json(result={ 'user':user.todict() }) else: self.finish_json(errcode=100, errmsg=u"帐号或密码错误")
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(), ))
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(), ))
def put(self): args = self.get_json_arguments() is_online, = get_and_valid_arguments(args, 'is_online') if is_online not in [0, 1]: raise JsonException(errmsg='wrong arg is_online', errcode=2001) CooperateRoomTypeModel.set_online_by_merchant(self.db, self.merchant.id, is_online, commit=False) self.db.flush() r = yield InventoryAsyncPusher(self.db).push_inventory_by_merchant(self.merchant.id) if r: self.db.commit() self.finish_json() else: self.db.rollback() yield InventoryAsyncPusher(self.db).push_inventory_by_merchant(self.merchant.id) raise JsonException(1000, "push stock error")
def put(self, hotel_id, roomtype_id): merchant_id = self.current_user.merchant_id args = self.get_json_arguments() Log.info(u"modify inventory>> user:{} data:{}".format(self.current_user.todict(), args)) start_date, end_date, change_num, price_type = get_and_valid_arguments(args, 'start_date', 'end_date', 'change_num', 'price_type') start_date, end_date = self.valid_date(start_date, end_date) self.valid_args(price_type) change_task = yield gen.Task(Inventory.modify_inventory.apply_async, args=[merchant_id, hotel_id, roomtype_id, price_type, change_num, start_date, end_date]) inventories = change_task.result if inventories: print 'success' self.finish_json(result=dict( inventories = [inventory.todict() for inventory in inventories], )) else: raise JsonException(errcode=2002, errmsg="change fail")
def post(self): args = self.get_json_arguments() merchant_id, username, password = get_and_valid_arguments( args, 'merchant_id', 'username', 'password') user = UserModel.get_user_by_merchantid_username_and_password( self.db, merchant_id, username, password) if user: self.set_secure_cookie("username", user.username, expires_days=0.02) self.set_secure_cookie("merchant_id", str(user.merchant_id), expires_days=0.02) self.finish_json(result={'user': user.todict()}) else: self.finish_json(errcode=100, errmsg=u"帐号或密码错误")
def post(self): args = self.get_json_arguments() chain_hotel_id, chain_roomtype_id, main_roomtype_id = get_and_valid_arguments(args, 'chain_hotel_id', 'chain_roomtype_id', 'main_roomtype_id') roomtype = RoomTypeModel.get_by_id(self.db, main_roomtype_id) Log.info('args: ' + str(args)) roomtype_mapping = RoomTypeMappingModel.get_by_provider_and_main_roomtype(self.db, 6, chain_roomtype_id, main_roomtype_id,chain_hotel_id,is_delete=-1) if roomtype_mapping: Log.info('exist roomtype mapping: ' + str(args)) if roomtype_mapping.is_delete == 1: RoomTypeMappingModel.delete_mapping_by_provider_hotel_id(self.db,6,chain_hotel_id,chain_roomtype_id,is_delete=0) else: raise JsonException(errcode=1000, errmsg="already exist") else: roomtype_mapping = RoomTypeMappingModel.new_roomtype_mapping_from_ebooking(self.db, chain_hotel_id, chain_roomtype_id, roomtype.name, roomtype.hotel_id, main_roomtype_id) self.finish_json(result=dict( roomtype_mapping=roomtype_mapping.todict() ))
def put(self): args = self.get_json_arguments() merchant_id, username, department, mobile, authority, is_valid = \ get_and_valid_arguments( args, 'merchant_id', 'username', 'department', 'mobile', 'authority', 'is_valid') if 'email' in args: email = args['email'] else: email = None if 'password' in args: password = args['password'] else: password = None if not self.mobile_check(mobile): self.finish_json(1, u'请填写正确手机号') return if not department: self.finish_json(1, u'请填写部门') return if self.current_user.merchant_id != merchant_id: self.finish_json(1, u'您只能管理自己的酒店') return ''' 可以管理用户 ''' UserModel.update_user(self.db, merchant_id, username, password, department, mobile, email, authority, is_valid) ''' 修改了自己的密码 ''' if self.current_user.username == username and password: self.clear_cookie('username') self.clear_cookie('merchant_id') self.finish_json(301, self.get_login_url()) return self.finish_json(0, u'成功')
def post(self): args = self.get_json_arguments() merchant_id, username, password, re_password, department, mobile, authority, is_valid = \ get_and_valid_arguments( args, 'merchant_id', 'username', 'password', 're_password', 'department', 'mobile', 'authority', 'is_valid') if merchant_id != self.current_user.merchant_id: self.finish_json(1, u'您只能管理自己的酒店') return if not username: self.finish_json(1, u'请填写用户名') return if (not password) or (not re_password): self.finish_json(1, u'请输入密码') return if password != re_password: self.finish_json(1, u'两次密码不一致') return if not department: self.finish_json(1, u'请输入部门') return if not mobile: self.finish_json(1, u'请输入手机号') return if authority & PERMISSIONS.admin or authority & PERMISSIONS.root: self.finish_json(1, u'不允许添加管理员用户') return user = UserModel.get_user_by_merchantid_username( self.db, merchant_id, username) if user: self.finish_json(1, u'用户名已被使用') else: UserModel.add_user(self.db, merchant_id, username, password, department, mobile, authority, is_valid) self.finish_json(0, u'添加成功')
def put(self, hotel_id, roomtype_id): args = self.get_json_arguments() is_online, = get_and_valid_arguments(args, 'is_online') if is_online not in [0, 1]: raise JsonException(errmsg='wrong arg is_online', errcode=2001) roomtype = CooperateRoomTypeModel.get_by_merchant_hotel_and_id(self.db, self.merchant.id, hotel_id, roomtype_id) if not roomtype: raise JsonException(errmsg='roomtype not found', errcode=2002) roomtype.is_online = is_online self.db.flush() r = yield InventoryAsyncPusher(self.db).push_by_roomtype(roomtype) if r: self.db.commit() self.finish_json(result=dict( roomtype = roomtype.todict(), )) else: self.db.rollback() raise JsonException(1000, 'push stock fail')
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')
def put(self, hotel_id, roomtype_id): merchant_id = self.current_user.merchant_id args = self.get_json_arguments() Log.info(u"modify inventory>> user:{} data:{}".format( self.current_user.todict(), args)) start_date, end_date, change_num, price_type = get_and_valid_arguments( args, 'start_date', 'end_date', 'change_num', 'price_type') start_date, end_date = self.valid_date(start_date, end_date) self.valid_args(price_type) change_task = yield gen.Task(Inventory.modify_inventory.apply_async, args=[ merchant_id, hotel_id, roomtype_id, price_type, change_num, start_date, end_date ]) inventories = change_task.result if inventories: print 'success' self.finish_json(result=dict( inventories=[inventory.todict() for inventory in inventories], )) else: raise JsonException(errcode=2002, errmsg="change fail")