def post(self): self.set_header("Content-Type", "application/json") user_id = self.get_argument('user_id', '') ret = {} try: session = Session() userdao = UserDAO() addr_idx = userdao.get_user_default_address_index(user_id) booking = MovingCleaningBooking(user_id=user_id, addr_idx=addr_idx, datetime=dt.datetime.now()) session.add(booking) session.commit() # send sms sms_sender = SMS_Sender() name = str(userdao.get_user_name(user_id)) phone = str(userdao.get_user_phone(user_id)) address, size, kind = userdao.get_user_address_detail(user_id) address = str(address) if kind == 0: kind = '오피스텔' elif kind == 1: kind = '주택' elif kind == 2: kind = '아파트' text = '입주청소 예약 문의\n이름: %s\n번호: %s\n주소: %s\n종류: %s\n평수:%d' % ( name, phone, address, kind, size) #print sms_sender.send_for_manager(sender = MAIN_CALL, mtype = 'lms', to = JAMES_CALL, text = str(text)) # jandi notification send_jandi('MOVING_IN_CLEANING', "이사청소 문의", name + ' 고객님 이사청소 문의', text) ret['response'] = Response.SUCCESS 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") 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', 10) 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 address parameter address = self.get_argument('address', '') size = self.get_argument('size', 25) kind = self.get_argument('kind', 0) size = int(size) kind = int(kind) # 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: print uid if self.is_user_block(ret, uid) == True: return if appointment_type == BC.ONE_TIME_A_MONTH: 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 <= 0 or taking_time_in_minutes <= 0: self.set_status(Response.RESULT_OK) add_err_ko_message_to_response(ret, '클리닝 시간이 잘못 설정되었습니다.') ret['err_code'] = '9999' # 임시 처리 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() session = Session() userdao = UserDAO() addrdao = AddressDAO() # add user address latlng = get_latlng_from_address(address) if len(latlng) > 1: latitude = latlng[0] longitude = latlng[1] geohash5 = get_geohash(latitude, longitude, 5) geohash6 = get_geohash(latitude, longitude, 6) else: latitude = 0.0 longitude = 0.0 geohash5 = '' geohash6 = '' key = userdao.get_user_salt_by_id(uid)[:16] crypto = aes.MyCrypto(key) encrypted_address = crypto.encodeAES(str(address)) count = session.query(UserAddress).filter(UserAddress.user_id == uid).count() last_index = session.query(UserAddress).filter(UserAddress.user_id == uid).order_by(desc(UserAddress.user_addr_index)).first() index = 0 if last_index != None: index = last_index.user_addr_index + 1 new_address = UserAddress(user_id = uid, address = encrypted_address, size = size, kind = kind, user_addr_index = index, latitude = latitude, longitude = longitude, geohash5 = geohash5, geohash6 = geohash6) session.add(new_address) session.commit() # set default address index if count == 0: new_default_address = UserDefaultAddress(user_id=uid, address_idx=index) session.add(new_default_address) else: record = session.query(UserDefaultAddress).filter(UserDefaultAddress.user_id == uid).one() record.address_idx = index session.commit() address, geohash5, geohash6 = userdao.get_user_address(uid) _, size, kind = userdao.get_user_address_detail(uid) gu_id = addrdao.get_gu_id(address) if gu_id == '': raise Exception('gu id is incorrect') return 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)})
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) additional_task = self.get_argument('additional_task', 0) temp_additional_task = self.get_argument('addtional_task', 0) # deal with typo date = self.get_argument( 'date', dt.datetime.strftime(dt.datetime.now(), '%Y%m%d')) time = self.get_argument('time', '08:00') 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', 10) have_pet = self.get_argument('have_pet', 0) master_gender = self.get_argument('master_gender', 0) isdirty = self.get_argument('isdirty', 0) master_ids = self.get_argument('master_ids', []) # convert parameters selected_date_str = date selected_date = dt.datetime.strptime(date, '%Y%m%d') master_ids = master_ids.split(',') appointment_type = int(appointment_type) additional_task = int(additional_task) taking_time = int(taking_time) first_added_time = int(first_added_time) additional_time = int(additional_time) if have_pet == '': have_pet = 0 have_pet = int(have_pet) if master_gender == '': master_gender = 0 master_gender = int(master_gender) # 0 dont care 1 women if isdirty == '': isdirty = 0 isdirty = int(isdirty) print have_pet, master_gender, isdirty print taking_time, additional_time print temp_additional_task, type(temp_additional_task) print additional_task, type(additional_task) if temp_additional_task > 0: # ios typo bug temporary fix additional_task = str(temp_additional_task) additional_task = int(additional_task, 2) if additional_task >= 64: additional_task -= 64 if additional_task > 64: # ios typo bug temporary fix additional_task = str(additional_task) additional_task = int(additional_task, 2) if additional_task >= 64: additional_task -= 64 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 if isdirty == 1: total_taking_time_in_minutes += 120 # logging part mix = get_mixpanel() mongo_logger = get_mongo_logger() try: booking_info = {} masterdao = MasterDAO() userdao = UserDAO() holder = IntermediateValueHolder() # 가격 정보 address, house_size, house_type = userdao.get_user_address_detail( uid) _, _, price, _ = get_time_price(appointment_type, house_type, house_size) _, additional_price = get_additional_task_time_price( additional_task, house_type, house_size) total_price = price + additional_price print price print additional_price print total_price cal_appointment_type = appointment_type if cal_appointment_type == BC.ONE_TIME_BUT_CONSIDERING: cal_appointment_type = BC.ONE_TIME count_of_iteration = cal_appointment_type * 2 + 1 # 2 months date_list = [] if cal_appointment_type == BC.ONE_TIME: week_const = 0 else: week_const = 4 / cal_appointment_type for i in xrange(count_of_iteration): date = selected_date + dt.timedelta(weeks=week_const * i) date = dt.datetime.strftime(date, '%Y%m%d') date_list.append(date) booking_info['dates'] = date_list booking_info['time'] = time booking_info['appointment_type'] = appointment_type booking_info['additional_task'] = additional_task booking_info['have_pet'] = have_pet booking_info['master_gender'] = master_gender booking_info['isdirty'] = isdirty booking_info['user_id'] = uid booking_info['taking_time'] = taking_time_in_minutes booking_info['first_added_time'] = first_added_time_in_minutes booking_info['additional_time'] = additional_time_in_minutes booking_info['total_time'] = total_taking_time_in_minutes booking_info[ 'additional_task_prices'] = get_additional_tasks_and_prices( additional_task, house_type, house_size) booking_info['price'] = price booking_info['total_price'] = total_price # 각 마스터별로 예약이 가능한지 메모리에서 다시 한번 확인. # 선택한 값을 메모리에 키로 저장하여 중복되는 예약 방지. # 선택 했으면 선택된 정보를 가지고 있어야 함 master_num = len(master_ids) i = 0 while i < master_num: # 랭킹이 높은 홈마스터별로 확인 mid = master_ids[i] if not masterdao.is_valid_master(mid): self.set_status(Response.RESULT_OK) add_err_message_to_response( ret, err_dict['err_not_valid_master']) return master_date_keys = [] name, img_url, avg_rating = masterdao.get_master_name_img_and_average_rating( mid) booking_info['master_id'] = mid booking_info['name'] = name booking_info['img_url'] = img_url booking_info['avg_rating'] = avg_rating # 날짜별 키 생성 for date in date_list: key = '%s_%s' % (mid, date) master_date_keys.append(key) # 저장할 키 생성 booking_item_key = '%s_%s_%d' % (uid, master_date_keys[0], appointment_type) # 가능 일정을 미리 호출한 고객과, 그 바로 직후 휴무 신청을 한 홈마스터의 경우, 예약이 불가 하기 때문에 체크하도록 함 if holder.store_keys( master_date_keys) and not masterdao.is_master_off_date( mid, selected_date.date() ): # 메모리에 키가 하나도 없을 때, 즉 예약이 가능할 때 holder.store(booking_item_key, booking_info) master_date_keys = ','.join(master_date_keys) booking_info['search_keys'] = master_date_keys booking_info['store_key'] = booking_item_key ret['response'] = booking_info self.set_status(Response.RESULT_OK) # log to mixpanel mix.track( uid, 'select schedule', { 'time': dt.datetime.now(), 'user_id': uid, 'master_id': mid, 'sel_date': selected_date_str, 'sel_time': time, '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('select schedule', extra={ 'log_time': dt.datetime.now(), 'user_id': uid, 'master_id': mid, 'sel_date': selected_date_str, 'sel_time': time, 'taking_time': taking_time, 'additional_time': additional_time, 'appointment_type': appointment_type, 'have_pet': have_pet, 'master_gender': master_gender, 'isdirty': isdirty }) return i += 1 # when not available # log to mixpanel mix.track( uid, 'cannot select schedule', { 'time': dt.datetime.now(), 'user_id': uid, 'sel_date': selected_date_str, 'sel_time': time, '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('cannot select schedule', extra={ 'user_id': uid, 'sel_date': selected_date_str, 'sel_time': time, 'taking_time': taking_time, 'additional_time': additional_time, 'appointment_type': appointment_type, 'have_pet': have_pet, 'master_gender': master_gender, 'isdirty': isdirty }) # other users preempt homemasters, so no homemaster available self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_homemaster_occupied']) return 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 select schedules', extra={ 'user_id': uid, 'err': str(e) })
def post(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') ret = {} uid = self.get_argument('uid', '') search_keys = self.get_argument('search_keys', '') store_key = self.get_argument('store_key', '') #price = self.get_argument('price', 0) #price_with_task = self.get_argument('price_with_task', 0) #discounted_price = self.get_argument('discounted_price', 0) promotion_code = self.get_argument('promotion_code', '') laundry_apply_all = self.get_argument( 'laundry_apply_all', 0) # -1 - 없앰, 0 - one time, 1 - all time has_card = self.get_argument('has_card', 0) # ---------- card paremeters ------------ cno = self.get_argument('cno', '') expy = self.get_argument('expy', '') expm = self.get_argument('expm', '') ssnf = self.get_argument('ssnf', '') cpftd = self.get_argument('cpftd', '') calias = self.get_argument('calias', '') # register card request_url = '%s:%d/homemaster_payment/register_card' % (PAYMENT_HOST, PAYMENT_PORT) params = {} params['id'] = uid params['cno'] = cno params['expy'] = expy params['expm'] = expm params['ssnf'] = ssnf params['cpftd'] = cpftd params['calias'] = calias has_card = int(has_card) mongo_logger = get_mongo_logger() mix = get_mixpanel() # 카드가 없는 경우에만 카드 등록하고 진행, 있다면 바로 진행 if has_card == 0: response = requests.post(request_url, data=params) result = json.loads(response.text) if response.status_code != 200 or result['response'] == "": print 'An error occurred while register card' print result['err_code'], result['err_msg'] add_err_ko_message_to_response(ret, result['err_msg']) mongo_logger.error('register card failed', extra={'uid': uid}) return laundry_apply_all = int(laundry_apply_all) search_keys = search_keys.split(',') try: session = Session() userdao = UserDAO() masterdao = MasterDAO() promotiondao = PromotionDAO() addressdao = AddressDAO() holder = IntermediateValueHolder() # request id to group each individual bookings request_id = str(uuid.uuid4()) obj = holder.retrieve(store_key) print obj if obj == None: self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_booking_timeout']) mix.track(uid, 'request timeout', {'time': dt.datetime.now()}) mongo_logger.error('%s got timed out' % uid) return # retrieve all stored values uid = obj['user_id'] mid = obj['master_id'] dates = obj['dates'] time = obj['time'] appointment_type = obj['appointment_type'] additional_task = obj['additional_task'] org_additional_task = additional_task taking_time = obj['taking_time'] first_added_time = obj['first_added_time'] additional_time = obj['additional_time'] total_time = obj['total_time'] master_gender = obj['master_gender'] have_pet = obj['have_pet'] isdirty = obj['isdirty'] # price # price_with_task # discounted_price address, house_size, house_type = userdao.get_user_address_detail( uid) _, _, price, _ = get_time_price(appointment_type, house_type, house_size) _, additional_price = get_additional_task_time_price( additional_task, house_type, house_size) discounted_price = 0 if promotion_code != '': discounted_price = promotiondao.get_discount_price( promotion_code) price_with_task = price + additional_price if 0 < discounted_price <= 100: price_with_task *= (float(100 - discounted_price) / 100) else: price_with_task -= discounted_price price_with_task = int(price_with_task) print '-' * 30 print price, additional_price print promotion_code, price_with_task print '##' * 20 # hasids to generate unique booking id now = dt.datetime.strftime(dt.datetime.now(), '%Y%m%d%H%M%S') hashids = Hashids(min_length=16, salt=now + uid) # set tool info havetools = 1 if additional_task >= 64: havetools = 0 card_idx = 0 addr_idx = 0 # get card and address idx addr_idx = userdao.get_user_default_address_index(uid) card_idx = userdao.get_user_default_card_index(uid) i = 1 booking_ids = [] start_time_list = [] for date in dates: # print date, time booking_id = hashids.encode(int(date + time.replace(':', ''))) print 'key', booking_id master_id = mid date = dt.datetime.strptime(date, '%Y%m%d') dow = date.date().weekday() booking_time = dt.time(hour=int(time.split(':')[0]), minute=int(time.split(':')[1])) start_time = dt.datetime.combine(date, booking_time) estimated_end_time = start_time + dt.timedelta( minutes=total_time) cleaning_duration = taking_time actual_price = 0 if i == 1: # 1 번째 클리닝 actual_price = price_with_task # 할인은 1회만 적용됨 else: # 나머지 actual_price = price if havetools == 1: additional_task = 0 else: additional_task = 64 if laundry_apply_all == 1: additional_task += 4 # 빨래 isdirty = 0 # 첫째 이후에는 is dirty는 0 estimated_end_time = estimated_end_time - dt.timedelta( minutes=additional_time + first_added_time) booking = Booking( id=booking_id, request_id=request_id, user_id=uid, master_id=mid, appointment_type=appointment_type, appointment_index=i, dow=dow, booking_time=dt.datetime.now(), org_start_time=start_time, start_time=start_time, estimated_end_time=estimated_end_time, end_time= estimated_end_time, # update after homemaster finish their job cleaning_duration=cleaning_duration, additional_task=additional_task, price=price, price_with_task=actual_price, charging_price=0, card_idx=card_idx, addr_idx=addr_idx, havetools=havetools, havepet=have_pet, laundry_apply_all=laundry_apply_all, is_dirty=isdirty, master_gender=master_gender, status=BC.BOOKING_UPCOMMING, cleaning_status=BC.BOOKING_UPCOMMING, payment_status=BC.BOOKING_UNPAID_YET) i += 1 session.add(booking) booking_ids.append(booking_id) start_time_list.append(start_time) #print 'booking_id', booking_id, 'was added..' # charge for first appointment date user_name = userdao.get_user_name(uid) if price_with_task <= 0: ret_code = True msg = '' else: ret_code, msg = request_payment(uid, user_name, booking_ids[0], price_with_task, appointment_type) # 결제 정보 출력 print user_name, ret_code, msg if ret_code: session.commit() # remove store_key and related_keys holder.remove(store_key) for sk in search_keys: holder.remove(sk) # promotion code 와 연결 if promotion_code != '': promotiondao.set_promotion_code_status( promotion_code, 1, booking_ids[0], price_with_task) # change status to paid try: first_booking = session.query(Booking, User, MasterPushKey) \ .join(User, Booking.user_id == User.id) \ .outerjoin(MasterPushKey, Booking.master_id == MasterPushKey.master_id) \ .filter(Booking.id == booking_ids[0]) \ .one() except NoResultFound, e: session.close() self.set_status(Response.RESULT_OK) mongo_logger.debug('no first booking record', extra={ 'uid': uid, 'mid': mid, 'appointment_type': appointment_type, 'have_pet': have_pet, 'master_gender': master_gender, 'isdirty': isdirty }) add_err_message_to_response(ret, err_dict['err_no_record']) return except MultipleResultsFound, e: session.close() self.set_status(Response.RESULT_OK) mongo_logger.debug('multiple first booking record', extra={ 'uid': uid, 'mid': mid, 'appointment_type': appointment_type, 'have_pet': have_pet, 'master_gender': master_gender, 'isdirty': isdirty }) add_err_message_to_response( ret, err_dict['err_multiple_record']) return
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)})