def get(self): ret = {} user_id = self.get_argument('user_id', '') address_index = self.get_argument('address_index', '') self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') try: userdao = UserDAO() address, size, kind, rooms, baths = userdao.get_user_address_full_detail_by_index(user_id, address_index) address_info = {} address_info['rooms'] = rooms address_info['size'] = size address_info['kind'] = kind address_info['baths'] = baths address_info['address'] = address ret['response'] = address_info 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)
def notify_10mins_ahead(self): try: userdao = UserDAO() current_time = dt.datetime.now() print '-' * 40 print 'push before 10 minutes' print 'current_time :', current_time hour = current_time.hour if current_time.minute >= 20 and current_time.minute <= 29: minute = 30 elif current_time.minute >= 50 and current_time.minute <= 59: hour += 1 minute = 0 else: minute = 0 cron_time = current_time.replace(hour=hour, minute=minute, second=0, microsecond=0) print 'cron_time :', cron_time print '-' * 40 session = Session() result = session.query(Booking, Master, User, UserPushKey) \ .join(Master, Booking.master_id == Master.id) \ .join(User, Booking.user_id == User.id) \ .outerjoin(UserPushKey, User.id == UserPushKey.user_id) \ .filter(or_(Booking.cleaning_status == BC.BOOKING_UPCOMMING, Booking.cleaning_status == BC.BOOKING_STARTED)) \ .filter(func.date(Booking.start_time) == cron_time.date()) \ .filter(func.HOUR(Booking.start_time) == cron_time.time().hour) \ .filter(func.MINUTE(Booking.start_time) == cron_time.time().minute) \ .all() for row in result: key = userdao.get_user_salt_by_id(row.User.id)[:16] crypto = aes.MyCrypto(key) booking_id = row.Booking.id pushkey = row.UserPushKey.pushkey if row.UserPushKey != None else '' user_name = crypto.decodeAES(row.User.name) phone = crypto.decodeAES(row.User.phone) master_name = row.Master.name devicetype = row.User.devicetype print 'push to', user_name, master_name, booking_id print pushkey if devicetype != 'android': pushkey = crypto.decodeAES(row.User.phone) send_10mins_ahead_notification(devicetype, [pushkey], booking_id) send_alimtalk(phone, 'noti_10', user_name, master_name) except Exception, e: print_err_detail(e)
def post(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') ret = {} user_id = self.get_argument('user_id', '') new_pwd = self.get_argument('new_pwd', 'hm123') try: userdao = UserDAO() session = Session() user_row = session.query(User).filter(User.id == user_id).one() salt = userdao.get_user_salt_by_id(user_id) hash_obj = hashlib.sha256(salt + new_pwd) user_row.password = hash_obj.hexdigest() session.commit() ret['response'] = Response.SUCCESS self.set_status(Response.RESULT_OK) except Exception, e: print_err_detail(e) self.set_status(Response.RESULT_SERVERERROR) add_err_message_to_response(ret, err_dict['err_mysql'])
def get(self): self.set_header("Content-Type", "application/json") ret = {} try: session = Session() userdao = UserDAO() bookingdao = BookingDAO() # get last saturday now = dt.datetime.now() if week != 0: offset = ((now.weekday() - FRIDAY) % 7) + (week - 1) * 7 now -= dt.timedelta(days=offset) offset = (now.weekday() - SATURDAY) % 7 last_saturday = (now - dt.timedelta(days=offset)).date() now = now.date() # rating # 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") booking_id = self.get_argument('booking_id', '') ret = {} try: session = Session() userdao = UserDAO() try: row = session.query(Booking).filter( Booking.id == booking_id).one() except NoResultFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_no_record']) return except MultipleResultsFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_multiple_record']) return
def get(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') user_id = self.get_argument('user_id', '') ret = {} try: addresses = [] session = Session() userdao = UserDAO() addresses = userdao.get_all_user_addresses(user_id) name = userdao.get_user_name(user_id) default_index = userdao.get_user_default_address_index(user_id) ret['response'] = { 'name': name, 'addresses': addresses, 'user_id': user_id, 'default_index': default_index } 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 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") ret = {} email = self.get_argument('email', '') pwd = self.get_argument('pwd', '') print 'login', email, pwd mongo_logger = get_mongo_logger() mix = get_mixpanel() try: session = Session() userdao = UserDAO() try: row = session.query(User) \ .filter(User.email == email, User.password == pwd, User.active == 1) \ .one() except NoResultFound, e: try: if len(email) == 11 and email.startswith('010'): row = session.query(User) \ .filter(func.aes_decrypt(func.from_base64(User.phone), \ func.substr(User.salt, 1, 16)) == email, \ User.password == pwd, \ User.active == 1) \ .one() else: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response( ret, err_dict['err_login_no_match']) mongo_logger.error('%s failed to logined' % email, extra={'err': str(e)}) return except NoResultFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_login_no_match']) mongo_logger.error('%s failed to logined' % email, extra={'err': str(e)}) return except MultipleResultsFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_dup_phone2']) mongo_logger.error('%s failed to logined' % email, extra={'err': str(e)}) return
class ManualChargeHandler(tornado.web.RequestHandler): def post(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') booking_id = self.get_argument('booking_id', '') price = self.get_argument('price', '') product_name = self.get_argument('product_name', '') price = int(price) ret = {} try: session = Session() try: row = session.query(Booking, User) \ .join(User, Booking.user_id == User.id) \ .filter(Booking.id == booking_id) \ .one() except NoResultFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_login_no_record']) return except MultipleResultsFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_multiple_record']) return userdao = UserDAO() user_id = row.User.id key = userdao.get_user_salt_by_id(user_id)[:16] crypto = aes.MyCrypto(key) user_name = crypto.decodeAES(row.User.name) appointment_type = row.Booking.appointment_type if row.User.devicetype == 'None': try: record = UserPaymentRecordForIOS(booking_id, user_id, price, dt.datetime.now()) session.add(record) session.commit() ret_code = True except Exception, e: ret_code = False value = str(e)
def post(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') user_id = self.get_argument('id', '') tid = self.get_argument('tid', '') amount = self.get_argument('amount', 0) partial = self.get_argument('partial', 1) cancel_msg = self.get_argument('cancel_msg', '') amount = int(amount) if cancel_msg == '': cancel_msg = '취소' ret = {} try: mongo_logger = get_mongo_logger() mix = get_mixpanel() userdao = UserDAO() request_url = '%s:%d/homemaster_payment/cancel_payment' % ( PAYMENT_HOST, PAYMENT_PORT) params = {} params['id'] = user_id params['tid'] = tid params['amount'] = amount params['partial'] = partial params['cancel_msg'] = cancel_msg response = requests.post(request_url, data=params) result = json.loads(response.text) if response.status_code == 200 and result['response'] != "": mix.track(user_id, 'cancel payment', {'time': dt.datetime.now()}) mongo_logger.debug('cancel payment', extra={'user_id': user_id}) ret['response'] = result['response'] self.set_status(Response.RESULT_OK) else: print 'An error occurred while register card' print result['err_msg'] add_err_ko_message_to_response(ret, result['err_msg']) mix.track(user_id, 'cannot cancel payment', {'time': dt.datetime.now()}) mongo_logger.error('failed to cancel payment', extra={'user_id': user_id}) except Exception, e: print_err_detail(e) self.set_status(Response.RESULT_SERVERERROR) add_err_message_to_response(ret, err_dict['err_mysql'])
def notify(self): try: userdao = UserDAO() current_time = dt.datetime.now() print '-' * 40 print 'push before 2 hours' print 'current_time :', current_time hour = current_time.hour minute = 30 if current_time.minute >= 30 else 0 #current_time = current_time + dt.timedelta(hours=2) cron_time = current_time.replace(hour=hour+2, minute=minute, second = 0, microsecond=0) print 'cron_time :', cron_time print '-' * 40 session = Session() result = session.query(Booking, Master, MasterPushKey, User) \ .join(Master, Booking.master_id == Master.id) \ .join(MasterPushKey, Master.id == MasterPushKey.master_id) \ .join(User, Booking.user_id == User.id) \ .filter(Booking.cleaning_status == BC.BOOKING_UPCOMMING) \ .filter(func.date(Booking.start_time) == cron_time.date()) \ .filter(func.HOUR(Booking.start_time) == cron_time.time().hour) \ .filter(func.MINUTE(Booking.start_time) == cron_time.time().minute) \ .all() for row in result: key = userdao.get_user_salt_by_id(row.User.id)[:16] crypto = aes.MyCrypto(key) if row.Master.id == 'da2a1f50-fd36-40bf-8460-55b3e1b2c459': continue booking_id = row.Booking.id pushkey = row.MasterPushKey.pushkey if row.MasterPushKey != None else '' master_name = row.Master.name start_time = row.Booking.start_time time_str = convert_datetime_format4(start_time) print 'push to', master_name, booking_id print pushkey send_master_ahead_notification('android', [pushkey], booking_id, master_name, time_str) except Exception, e: print_err_detail(e)
def post(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') ret = {} booking_id = self.get_argument('booking_id', '') uid = self.get_argument('uid', '') date = self.get_argument('date', dt.datetime.strftime(dt.datetime.now(), '%Y%m%d')) time = self.get_argument('time', '08:00') master_ids = self.get_argument('master_ids', []) apply_to_all_behind = self.get_argument('apply_to_all_behind', 0) by_manager = self.get_argument('by_manager', 0) # convert parameters apply_to_all_behind = int(apply_to_all_behind) selected_date_str = date time_str = time selected_date = dt.datetime.strptime(date, '%Y%m%d') master_ids = master_ids.split(',') by_manager = int(by_manager) # logging part mix = get_mixpanel() mongo_logger = get_mongo_logger() print 'update schedule' print selected_date_str, time_str, apply_to_all_behind print '*' * 100 try: session = Session() booking_info = {} userdao = UserDAO() masterdao = MasterDAO() holder = IntermediateValueHolder() try: row = session.query(Booking).filter(Booking.id == booking_id).one() except NoResultFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_no_record']) return except MultipleResultsFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_multiple_record']) return
def get(self): self.set_header("Content-Type", "application/json") ret = {} try: session = Session() ratings = [] userdao = UserDAO() result = session.query(Rating, Booking, User, Master) \ .join(Booking, Rating.booking_id == Booking.id) \ .join(Master, Rating.master_id == Master.id) \ .join(User, Booking.user_id == User.id) \ .order_by(desc(Rating.review_time)) \ .all() for row in result: key = userdao.get_user_salt(row.User.email)[:16] crypto = aes.MyCrypto(key) rating = {} rating['user_name'] = crypto.decodeAES(row.User.name) rating['master_name'] = row.Master.name rating['appointment_type'] = row.Booking.appointment_type rating['start_time'] = dt.datetime.strftime( row.Booking.start_time, '%Y-%m-%d %H:%M') rating['estimated_end_time'] = dt.datetime.strftime( row.Booking.estimated_end_time, '%Y-%m-%d %H:%M') rating['end_time'] = dt.datetime.strftime( row.Booking.end_time, '%Y-%m-%d %H:%M') rating['clean_rating'] = float(row.Rating.rate_clean) rating['clean_review'] = row.Rating.review_clean rating['master_rating'] = float(row.Rating.rate_master) rating['master_review'] = row.Rating.review_master rating['review_time'] = dt.datetime.strftime( row.Rating.review_time, '%Y-%m-%d %H:%M') ratings.append(rating) ret['response'] = ratings 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") 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 get(self): self.set_header("Content-Type", "application/json") ret = {} master_id = self.get_argument('master_id', '') try: session = Session() userdao = UserDAO() result = session.query(Master, Booking, User) \ .join(Booking, Master.id == Booking.master_id) \ .join(User, Booking.user_id == User.id) \ .filter(Booking.master_id == master_id) \ .filter(or_(Booking.cleaning_status == BC.BOOKING_UPCOMMING, Booking.cleaning_status == BC.BOOKING_STARTED, Booking.cleaning_status == BC.BOOKING_COMPLETED)) \ .order_by(desc(Booking.start_time)) \ .all() booking_list = [] for row in result: key = userdao.get_user_salt_by_id(row.Booking.user_id)[:16] crypto = aes.MyCrypto(key) booking = {} booking['booking_id'] = row.Booking.id booking['name'] = crypto.decodeAES(row.User.name) booking['start_time'] = convert_datetime_format2( row.Booking.start_time) booking['additional_task'] = row.Booking.additional_task booking['price'] = row.Booking.price_with_task booking['status'] = row.Booking.status booking['cleaning_status'] = row.Booking.cleaning_status booking['payment_status'] = row.Booking.payment_status booking_list.append(booking) ret['response'] = booking_list 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 get(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') ret = {} print "test-intro" try: session = Session() result = session.query(UserClaim, Booking, User, Master) \ .join(Booking, UserClaim.booking_id == Booking.id) \ .join(Master, Master.id == Booking.master_id) \ .join(User, User.id == Booking.user_id) \ .all() claims = [] Userdao = UserDAO() print result for record in result: key = Userdao.get_user_salt(record.User.email)[:16] if key == None or key == '': continue crypto = aes.MyCrypto(key) claim_info = {} claim_info['cleanning_date'] = dt.datetime.strftime( record.Booking.start_time, '%Y-%m-%d %H:%M') claim_info['user_name'] = crypto.decodeAES(record.User.name) claim_info['user_phone'] = crypto.decodeAES(record.User.phone) claim_info['master_name'] = record.Master.name claim_info['claim_comment'] = record.UserClaim.comment claim_info['claim_reg_time'] = dt.datetime.strftime( record.UserClaim.register_time, '%Y-%m-%d %H:%M') claims.append(claim_info) ret['response'] = claims 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): ret = {} guid = self.get_argument('id', '') address = self.get_argument('address', '') index = self.get_argument('index', 0) size = self.get_argument('size', 0) kind = self.get_argument('kind', 1) rooms = self.get_argument('rooms', 1) baths = self.get_argument('baths', 1) self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') index = int(index) print address, index mongo_logger = get_mongo_logger() mix = get_mixpanel() try: session = Session() userdao = UserDAO() try: row = session.query(UserAddress) \ .filter(and_(UserAddress.user_id == guid, UserAddress.user_addr_index == index)) \ .one() except NoResultFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_no_record']) mongo_logger.error('%s failed to find address, no record' % email, extra={'err': str(e)}) return except MultipleResultsFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_multiple_record']) mongo_logger.error( '%s failed to find address, multiple record' % email, extra={'err': str(e)}) return
class ManualUnpaidChargeHandler(tornado.web.RequestHandler): def post(self): self.set_header("Content-Type", "application/json") user_id = self.get_argument('user_id', '') amount = self.get_argument('amount', '') interest = self.get_argument('interest', '0') quota = self.get_argument('quota', '00') amount = int(amount) ret = {} try: session = Session() try: row = session.query(User) \ .filter(User.id == user_id) \ .one() except NoResultFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_login_no_record']) return except MultipleResultsFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_multiple_record']) return userdao = UserDAO() user_id = row.id key = userdao.get_user_salt_by_id(user_id)[:16] crypto = aes.MyCrypto(key) user_name = crypto.decodeAES(row.name) ret_code, value = request_unpaid_charge(user_id, user_name, amount, interest, quota) if ret_code == True: ret['response'] = Response.SUCCESS else: add_err_ko_message_to_response(ret, value) self.set_status(Response.RESULT_OK)
def get(self): self.set_header("Content-Type", "application/json") manager_id = self.get_argument('manager_id', '') ret = {} try: session = Session() userdao = UserDAO() payment_records = [] result = session.query(UserPaymentRecord, User) \ .join(User, UserPaymentRecord.user_id == User.id) \ .order_by(UserPaymentRecord.user_id, desc(UserPaymentRecord.auth_date)) \ .all() for row in result: payment = {} key = userdao.get_user_salt_by_id(row.User.id)[:16] crypto = aes.MyCrypto(key) payment['tid'] = row.UserPaymentRecord.tid payment['booking_id'] = row.UserPaymentRecord.booking_id payment['user_id'] = row.UserPaymentRecord.user_id payment['price'] = row.UserPaymentRecord.price payment['auth_date'] = row.UserPaymentRecord.auth_date payment[ 'canceled_amount'] = row.UserPaymentRecord.canceled_amount payment['canceled_date'] = row.UserPaymentRecord.canceled_date payment['status'] = row.UserPaymentRecord.status payment['user_name'] = crypto.decodeAES(row.User.name) payment['user_phone'] = crypto.decodeAES(row.User.phone) payment_records.append(payment) ret['response'] = payment_records 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', '*') cleaning_id = self.get_argument('cleaning_id', '') 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', '') ret = {} try: mongo_logger = get_mongo_logger() mix = get_mixpanel() userdao = UserDAO() doc = self.db.find_one_and_update( {'cleaning_id': cleaning_id}, {'$set': { 'payment': '선결제' }}, return_document=ReturnDocument.AFTER) if doc == None: self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_no_cleaning_id']) return print cno try: uid = doc['user_id'] except Exception, e: self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_no_user_id']) return try: amount = int(doc['total_price']) except Exception, e: self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_invalid_amount']) return
def post(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') ret = {} user_id = self.get_argument('user_id', '') email = self.get_argument('email', '') name = self.get_argument('name', '') phone = self.get_argument('phone', '') devicetype = self.get_argument('devicetype', 'None') gender = self.get_argument('gender', 0) birthdate = self.get_argument('birthdate', '') self.set_header("Content-Type", "application/json") gender = int(gender) mongo_logger = get_mongo_logger() mix = get_mixpanel() try: session = Session() userdao = UserDAO() try: row = session.query(User) \ .filter(User.id == user_id) \ .one() except NoResultFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_no_record']) mongo_logger.error('%s failed to find user, no record' % user_id, extra={'err': str(e)}) return except MultipleResultsFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_multiple_record']) mongo_logger.error('%s failed to find user, multiple record' % user_id, extra={'err': str(e)}) return
def post(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') ret = {} booking_id = self.get_argument('booking_id', '') additional_task = self.get_argument('additional_task', '') # convert parameters additional_task = int(additional_task) # logging part mix = get_mixpanel() mongo_logger = get_mongo_logger() print 'modify additional task' print '*' * 100 try: session = Session() booking_info = {} userdao = UserDAO() masterdao = MasterDAO() try: row = session.query(Booking, UserAddress) \ .join(UserAddress, Booking.user_id == UserAddress.user_id) \ .filter(Booking.addr_idx == UserAddress.user_addr_index) \ .filter(Booking.id == booking_id) \ .one() except NoResultFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_no_record']) return except MultipleResultsFound, e: session.close() self.set_status(Response.RESULT_OK) 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', '*') phone = self.get_argument('phone', '') print 'phone', phone mongo_logger = get_mongo_logger() ret = {} try: session = Session() userdao = UserDAO() try: result = session.query(User) \ .filter(func.aes_decrypt(func.from_base64(User.phone), \ func.substr(User.salt, 1, 16)) == phone, \ User.active == 1) \ .all() except NoResultFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_login_no_match']) mongo_logger.error('%s failed to get registerinfo' % phone, extra={'err': str(e)}) return usersinfo = [] for row in result: userinfo = {} userinfo['id'] = row.id userinfo['name'] = userdao.get_user_name(row.id) userinfo['phone'] = userdao.get_user_phone(row.id) userinfo['email'] = row.email usersinfo.append(userinfo) mongo_logger.debug('user registered info') ret['response'] = usersinfo self.set_status(Response.RESULT_OK)
def get(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') user_id = self.get_argument('user_id', '') ret = {} try: session = Session() userdao = UserDAO() payment_histories = [] result = session.query(UserPaymentRecord, Booking, User) \ .join(Booking, UserPaymentRecord.booking_id == Booking.id) \ .join(User, UserPaymentRecord.user_id == User.id) \ .filter(UserPaymentRecord.user_id == user_id) \ .order_by(desc(UserPaymentRecord.auth_date)) \ .all() for row in result: try: auth_date = '20' + row.UserPaymentRecord.auth_date auth_date = dt.datetime.strptime(auth_date, '%Y%m%d%H%M%S') except Exception, e: auth_date = None try: canceled_date = row.UserPaymentRecord.canceled_date if canceled_date != None: canceled_date = dt.datetime.strptime(canceled_date, '%Y%m%d%H%M%S') except Exception, e: canceled_date = None payment_info = {} payment_info['tid'] = row.UserPaymentRecord.tid payment_info['booking_id'] = row.UserPaymentRecord.booking_id payment_info['start_time'] = convert_datetime_format3(row.Booking.start_time) payment_info['charged_price'] = row.UserPaymentRecord.price payment_info['canceled_price'] = row.UserPaymentRecord.canceled_amount payment_info['status'] = row.UserPaymentRecord.status payment_info['auth_date'] = convert_datetime_format2(auth_date) if auth_date != None else '' payment_info['canceled_date'] = convert_datetime_format2(canceled_date) if canceled_date != None else '' payment_histories.append(payment_info)
def get(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') user_id = self.get_argument('user_id', '') ret = {} try: session = Session() userdao = UserDAO() payment_histories = [] result = session.query(UserChargeRecord, User) \ .join(User, UserChargeRecord.user_id == User.id) \ .filter(UserChargeRecord.user_id == user_id) \ .order_by(desc(UserChargeRecord.auth_date)) \ .all() for row in result: try: auth_date = '20' + row.UserChargeRecord.auth_date auth_date = dt.datetime.strptime(auth_date, '%Y%m%d%H%M%S') except Exception, e: auth_date = None payment_info = {} payment_info['tid'] = row.UserChargeRecord.tid payment_info['amount'] = row.UserChargeRecord.amount payment_info['auth_date'] = convert_datetime_format2( auth_date) if auth_date != None else '' payment_histories.append(payment_info) user_name = userdao.get_user_name(user_id) user_phone = userdao.get_user_phone(user_id) ret['response'] = { 'user_id': user_id, 'name': user_name, 'phone': user_phone, 'payment_histories': payment_histories } self.set_status(Response.RESULT_OK)
def get(self): self.set_header("Content-Type", "application/json") ret = {} try: session = Session() users = [] userdao = UserDAO() for row in session.query(User, UserAddress) \ .outerjoin(UserDefaultAddress, UserDefaultAddress.user_id == User.id) \ .outerjoin(UserAddress, and_(UserDefaultAddress.user_id == UserAddress.user_id, UserDefaultAddress.address_idx == UserAddress.user_addr_index)) \ .order_by(desc(User.dateofreg)) \ .all(): key = userdao.get_user_salt(row.User.email)[:16] crypto = aes.MyCrypto(key) user_info = {} user_info['user_id'] = row.User.id user_info['dateofreg'] = dt.datetime.strftime(row.User.dateofreg, '%Y-%m-%d %H:%M') user_info['devicetype'] = row.User.devicetype user_info['name'] = crypto.decodeAES(row.User.name) user_info['email'] = row.User.email user_info['phone'] = crypto.decodeAES(row.User.phone) user_info['gender'] = row.User.gender user_info['birthdate'] = crypto.decodeAES(row.User.dateofbirth) user_info['default_address'] = crypto.decodeAES(row.UserAddress.address) if row.UserAddress != None else '' user_info['default_address_size'] = row.UserAddress.size if row.UserAddress != None else '' user_info['default_address_kind'] = row.UserAddress.kind if row.UserAddress != None else '' users.append(user_info) ret['response'] = users 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 login(self, name, phone): session = Session() userdao = UserDAO() result = session.query(User) \ .filter(User.email == name + phone + '@11st.co.kr') \ .filter(User.authsource == '11st') \ .all() for row in result: key = userdao.get_user_salt_by_id(row.id)[:16] crypto = aes.MyCrypto(key) decrypted_name = crypto.decodeAES(row.name) decrypted_phone = crypto.decodeAES(row.phone) if name == decrypted_name and phone == decrypted_phone: # 동명이인 고려, 일치하게 된다면 id 반환 return row.id, True return '', False
def get(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') ret = {} try: session = Session() result = session.query(Booking, User) \ .join(User, and_(Booking.user_id == User.id, and_(or_(Booking.cleaning_status == 1, Booking.cleaning_status == 2), or_(Booking.payment_status == 0, Booking.payment_status == -3)))) \ .filter(not_(User.email.like('*****@*****.**'))) \ .all() unpaid_datas = [] Userdao = UserDAO() for record in result: key = Userdao.get_user_salt(record.User.email)[:16] if key == None or key == '': continue crypto = aes.MyCrypto(key) unpaid_info = {} unpaid_info['booking_id'] = record.Booking.id unpaid_info[ 'appointment_type'] = record.Booking.appointment_type unpaid_info['cleanning_date'] = dt.datetime.strftime( record.Booking.start_time, '%Y-%m-%d %H:%M') unpaid_info['user_name'] = crypto.decodeAES(record.User.name) unpaid_info['user_phone'] = crypto.decodeAES(record.User.phone) unpaid_info['price_with_task'] = record.Booking.price_with_task unpaid_datas.append(unpaid_info) ret['response'] = unpaid_datas 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") uid = self.get_argument('uid', '') price = self.get_argument('price', '') ret = {} try: mongo_logger = get_mongo_logger() mix = get_mixpanel() userdao = UserDAO() request_url = '%s:%d/homemaster_payment/request_payment' % (PAYMENT_HOST, PAYMENT_PORT) params = {} params['id'] = uid params['name'] = userdao.get_user_name(uid) params['price'] = price params['product_name'] = 'moving' response = requests.post(request_url, data = params) result = json.loads(response.text) if response.status_code == 200 and result['response'] == "SUCCESS": mix.track(uid, 'request mc payment', {'time' : dt.datetime.now(), 'tid' : result['tid'], 'authdate' : result['authdate']}) mongo_logger.debug('%s request mc payment' % uid, extra = {'user_id' : uid, 'tid' : result['tid'], 'authdate' : result['authdate']}) ret['response'] = result['response'] self.set_status(Response.RESULT_OK) else: print 'An error occurred when paying moving clean' print result['err_code'], result['err_msg'] add_err_ko_message_to_response(ret, result['err_msg']) mix.track(uid, 'cannot request mc payment', {'time' : dt.datetime.now(), 'code' : result['err_code']}) mongo_logger.error('%s failed to request mc payment' % uid, extra = {'err' : result['err_msg']}) except Exception, e: 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") ret = {} uid = self.get_argument('user_id', '') master_gender = self.get_argument('master_gender', 1) mongo_logger = get_mongo_logger() master_gender = int(master_gender) if master_gender == 2: # 남자일 경우 남자코드인 0으로 변경 master_gender = 0 try: session = Session() userdao = UserDAO() addressdao = AddressDAO() address = userdao.get_user_address(uid)[0] gu_id = addressdao.get_gu_id(address) master_count_by_gender = session.query(MasterPreferedArea, Master) \ .join(Master, MasterPreferedArea.master_id == Master.id) \ .filter(MasterPreferedArea.prefered_gu == gu_id) \ .filter(Master.gender == master_gender) \ .filter(Master.active == 1) \ .count() ret['response'] = {'master_count_by_gender' : master_count_by_gender} self.set_status(Response.RESULT_OK) print uid, 'request master gender, value of ', master_gender, master_count_by_gender mongo_logger.debug('%s request master gender count' % uid, extra={'user_id' : uid, 'master_gender' : master_gender}) 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']) mongo_logger.error('%s failed to posted memo' % uid, extra = {'err' : str(e)})