def get(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') user_id = self.get_argument('user_id', '') havepet = self.get_argument('havepet', '') master_gender = self.get_argument('master_gender', '') havepet = int(havepet) master_gender = int(master_gender) ret = {} try: session = Session() userdao = UserDAO() addressdao = AddressDAO() masters = [] row = session.query(UserDefaultAddress) \ .filter(UserDefaultAddress.user_id == user_id) \ .one() address, _, _ = userdao.get_user_address_by_index( user_id, row.address_idx) gu_id = addressdao.get_gu_id(address) pet_filter = 2 if havepet == 1: pet_filter = 1 gender_filter = 2 if master_gender == 1: gender_filter = 0 result = session.query(Master, MasterPreferedArea) \ .join(MasterPreferedArea, Master.id == MasterPreferedArea.master_id) \ .filter(Master.active == 1) \ .filter(Master.pet_alergy != pet_filter) \ .filter(Master.gender != gender_filter) \ .filter(MasterPreferedArea.prefered_gu == gu_id) \ .order_by(Master.name) \ .all() for row in result: masters.append({'id': row.Master.id, 'name': row.Master.name}) ret['response'] = masters self.set_status(Response.RESULT_OK) except Exception, e: session.rollback() print_err_detail(e) self.set_status(Response.RESULT_SERVERERROR) add_err_message_to_response(ret, err_dict['err_mysql'])
def post(self): self.set_header("Content-Type", "application/json") booking_id = self.get_argument('booking_id', '') new_master_id = self.get_argument('new_master_id', '') ret = {} try: session = Session() userdao = UserDAO() addrdao = AddressDAO() masterdao = MasterDAO() holder = IntermediateValueHolder() row = session.query(Booking).filter(Booking.id == booking_id).one() uid = row.user_id master_id_to_change = row.master_id org_start_time = row.start_time org_end_time = row.estimated_end_time appointment_type = 0 # 여기서는 1회 청소로 한다. 편집이기 때문에 have_pet = row.havepet master_gender = row.master_gender addr_idx = row.addr_idx taking_time_in_minutes = time_to_minutes(timedelta_to_time(org_end_time - org_start_time)) address, geohash5, geohash6 = userdao.get_user_address_by_index(uid, addr_idx) gu_id = addrdao.get_gu_id(address) dates = [int(dt.datetime.strftime(org_start_time, '%Y%m%d'))] time_range_begin = org_start_time.hour time_range_begin_min = org_start_time.minute time_range_end = org_start_time.hour time_range_end_min = org_start_time.minute print gu_id, dates print time_range_begin print time_range_begin_min print time_range_end print time_range_end_min print taking_time_in_minutes schedule_by_date_list = masterdao.get_master_schedule_by_dates(gu_id, have_pet, master_gender, dates, new_master_id) print schedule_by_date_list success, msg, store_key, search_keys, result = masterdao.find_master_by_score(schedule_by_date_list, \ gu_id, \ uid, \ appointment_type, \ dates, \ time_range_begin, \ time_range_begin_min, \ time_range_end, \ time_range_end_min, \ taking_time_in_minutes, \ geohash6) if success != 'SUCCESS': session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_no_hm_at_that_time']) #self.write(json.dumps(ret)) print booking_id, ' WAS NOT ... successfully updated to master_id : ', new_master_id return else: row.master_id = result[0]['mid'] if master_id_to_change != row.master_id: row.is_master_changed = 1 session.commit() holder.remove(store_key) for sk in search_keys: holder.remove(sk) ret['response'] = Response.SUCCESS self.set_status(Response.RESULT_OK) print booking_id, ' was successfully updated to master_id : ', new_master_id except Exception, e: session.rollback() print_err_detail(e) self.set_status(Response.RESULT_SERVERERROR) add_err_message_to_response(ret, err_dict['err_mysql'])
def post(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') ret = {} uid = self.get_argument('uid', '') appointment_type = self.get_argument('appointment_type', BC.ONE_TIME) taking_time = self.get_argument('taking_time', 25) first_added_time = self.get_argument('first_added_time', 0) additional_time = self.get_argument('additional_time', 0) have_pet = self.get_argument('have_pet', 0) master_gender = self.get_argument('master_gender', 0) isdirty = self.get_argument('isdirty', 0) for_manager = self.get_argument('for_manager', '') # for b2b appointment user_address_idx = self.get_argument('user_address_idx', -1) b2b = self.get_argument('b2b', '') # convert parameters appointment_type = int(appointment_type) taking_time = int(taking_time) first_added_time = int(first_added_time) additional_time = int(additional_time) taking_time_in_minutes = taking_time * 6 first_added_time_in_minutes = first_added_time * 6 additional_time_in_minutes = additional_time * 6 total_taking_time_in_minutes = taking_time_in_minutes + first_added_time_in_minutes + additional_time_in_minutes have_pet = int(have_pet) master_gender = int(master_gender) # 0 dont care 1 women isdirty = int(isdirty) # logging part mix = get_mixpanel() mongo_logger = get_mongo_logger() try: if self.is_user_block(ret, uid) == True: return if appointment_type == BC.ONE_TIME_A_MONTH and b2b != 'b2b': self.set_status(Response.RESULT_OK) add_err_ko_message_to_response(ret, '4주 1회 서비스는 신규 예약을 지원하지 않습니다.') mongo_logger.debug('not booking one time a month', extra = { 'user_id' : uid }) ret['err_code'] = '4038' # 임시 처리 return if total_taking_time_in_minutes >= 600: self.set_status(Response.RESULT_OK) add_err_ko_message_to_response(ret, '클리닝 가능 시간을 초과하였습니다. (최대 10시간) 이전 화면으로 돌아가 추가사항을 2개이하로 줄여주세요.') ret['err_code'] = '4036' # 임시 처리 return scheduler = HMScheduler() userdao = UserDAO() addrdao = AddressDAO() if user_address_idx == -1: # default_address address, geohash5, geohash6 = userdao.get_user_address(uid) _, size, kind = userdao.get_user_address_detail(uid) else: # address selection address, geohash5, geohash6 = userdao.get_user_address_by_index(uid, user_address_idx) _, size, kind = userdao.get_user_address_detail_by_index(uid, user_address_idx) gu_id = addrdao.get_gu_id(address) if gu_id == '': raise Exception('gu id is incorrect') available_schedules = scheduler.get_available_slots(gu_id = gu_id, geohash = geohash6, appointment_type = appointment_type, taking_time = total_taking_time_in_minutes, prefer_women = True if master_gender == 1 else False, have_pet = True if have_pet == 1 else False, isdirty = True if isdirty == 1 else False, user_id = uid) now = dt.datetime.now() if now.hour >= 17: # 7시 이후 라면 -> 5시로 변경 2016.06.03 if for_manager == '': # 사용자 앱에서는 내일 예약 불가능 tomorrow = now + dt.timedelta(days=1) tomorrow = dt.datetime.strftime(tomorrow, '%Y%m%d') if tomorrow in available_schedules: del available_schedules[tomorrow] for day in available_schedules: print '[', day, ']' print available_schedules[day]['by_time'] # log to mixpanel mix.track(uid, 'request available schedule', {'time' : dt.datetime.now(), 'taking_time' : taking_time, 'additional_time' : additional_time, 'appointment_type' : appointment_type, 'have_pet' : have_pet, 'master_gender' : master_gender,'isdirty' : isdirty}) # log to mongo mongo_logger.debug('request available schedule', extra = {'log_time' : dt.datetime.now(), 'user_id' : uid, 'taking_time' : taking_time, 'additional_time' : additional_time, 'appointment_type' : appointment_type, 'have_pet' : have_pet, 'master_gender' : master_gender,'isdirty' : isdirty}) if len(available_schedules) > 0: # 가능한 날짜가 있다면 ret['response'] = {'schedule' : available_schedules, 'first_date' : available_schedules.keys()[0] } else: add_err_message_to_response(ret, err_dict['err_not_available']) mongo_logger.debug('no masters', extra = {'log_time' : dt.datetime.now(), 'user_id' : uid, 'taking_time' : total_taking_time_in_minutes, 'gu_id' : gu_id, 'address' : address}) user_name = userdao.get_user_name(uid) user_phone = userdao.get_user_phone(uid) send_jandi('BOOKING_NOT_AVAILABE', '예약 불가능 알림', '고객 : {} 전번 : {}'.format(user_name, user_phone), '주기 : {}, 주소 : {}'.format(appointment_type, address)) self.set_status(Response.RESULT_OK) except Exception, e: add_err_message_to_response(ret, err_dict['err_mysql']) self.set_status(Response.RESULT_SERVERERROR) print_err_detail(e) mongo_logger.error('error request available schedules', extra = {'user_id' : uid, 'err' : str(e)})