def put(self, request, hub_id): self.logger_info.info('[UserAddressHubSelector][put][' + str(hub_id) + ']') auth_info = header_parser.parse_auth_info(request) lang_info = parse_language_v2(request.META) try: check_auth_info_v2(auth_info.open_id, auth_info.access_token) address_manager = AddressManagerV2(self.logger_info, self.logger_error) address_list = address_manager.select_hub(auth_info.open_id, lang_info.cn_header, int(hub_id)) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('user_addresses', address_list) return Response(result.get_response(), result.get_code())
def get(self, request): language_info = header_parser.parse_language_v2(request.META) referral_manager = ReferralManager(self.logger_info, self.logger_error) try: referral_info = referral_manager.get_referral_information( language_info.accept_lang) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('friend_coupon_status', referral_info['friend_coupon_status']) result.set('first_coupon_status', referral_info['first_coupon_status']) return Response(result.get_response(), result.get_code())
def get(self, request): auth_info = header_parser.parse_auth_info(request) self.logger_info.info('[CurationPageAdmin][get][' + str(auth_info.open_id) + str(auth_info.access_token) + ']') status = int(request.GET.get('status', self.VISIBLE)) curation_manager = CurationAdminManager(self.logger_info, self.logger_error) try: # Admin token validate get_admin_token_validate_v2(auth_info.access_token) page_list = curation_manager.read_curation_page_list( status, self.LAYOUT_TYPE) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('curation_pages', page_list) return Response(result.get_response(), result.get_code())
def get(self, request, operator_id): # Response object result = ResultResponse(code.ARIES_200_SUCCESS, 'success') # Get access token try: open_id = request.META['HTTP_OPEN_ID'] access_token = str( request.META['HTTP_AUTHORIZATION']).split(' ')[1] logger_info.info(open_id + ':' + access_token) except Exception as e: logger_error.error(str(e)) result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Token or user not found') return Response(result.get_response(), result.get_code()) # Get account object try: account = Operator.objects.get(id=operator_id) serializer = AccountSerializer(account) account_data = serializer.data del account_data['password'] result.set('account', account_data) except ObjectDoesNotExist: result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Object not found') except Exception as e: print(e) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Request data error') return Response(result.get_response(), result.get_code())
def post(self, request): request_data = request.data self.logger_info.info('[ReferralValidation][post][' + str(request_data) + ']') referral_manager = ReferralManager(self.logger_info, self.logger_error) try: share_id_param_validation(request_data) share_id = request_data['share_id'] validation_result = referral_manager.get_open_id_from_unique_id( share_id) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('open_id', validation_result['open_id']) return Response(result.get_response(), result.get_code())
def get(self, request): auth_info = header_parser.parse_auth_info(request) lang_info = parse_language_v2(request.META) if auth_info.open_id is not None: logger_info.info('[HubGeoInformation][get][' + str(auth_info.open_id) + ']') try: hub_manager = HubManagerV2(logger_info, logger_error) hub_list = hub_manager.get_hub_list(self.DEFAULT_HUB, lang_info.cn_header, lang_info.target_db) except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, self.SUCCESS_MSG) result.set('hub_list', hub_list) return Response(result.get_response(), result.get_code())
def get(self, request, hub_id): lang_info = parse_language_v2(request.META) date_info = get_date_information_v3(hub_id) target_db = lang_info.target_db cn_header = lang_info.cn_header os_type = lang_info.os_type time_type = date_info.time_type try: # Get product list from specific hub product_manager = ProductManagerV3(self.logger_info, self.logger_error) product_list = product_manager.get_product_list( hub_id, date_info.current_date) menu_manager = MenuManagerV2(self.logger_info, self.logger_error) for product in product_list: menu_manager.get_menu_data_for_list(product, target_db, cn_header, product['sales_time']) # Check the current available time bomb time_bomb_manager = TimeBombManager(self.logger_info, self.logger_error) time_bomb_id = time_bomb_manager.get_time_bomb_now(hub_id, os_type, has_after=False) if time_bomb_id is not None: # Discount information add discount_map = product_manager.get_all_discount_info( time_bomb_id, cn_header) for product in product_list: if product['id'] in discount_map: discount_info = discount_map[product['id']] add_discount_information(product, discount_info) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('hub_id', hub_id) result.set('current_time_type', time_type) result.set('phase_next_day', date_info.phase_next_day) result.set('phase_date', date_info.current_date.isoformat()) result.set('products', product_list) return Response(result.get_response(), status=result.get_code())
def get(self, request): result = ResultResponse(code.ARIES_200_SUCCESS, 'success') # Request data parsing try: open_id = request.META['HTTP_OPEN_ID'] access_token = str( request.META['HTTP_AUTHORIZATION']).split(' ')[1] logger_info.info(open_id + ':' + access_token) except Exception as e: print(e) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Request data invalid(Token or Open id)') return Response(result.get_response(), result.get_code()) # Get usable coupon count and upcoming order count try: today = date.today() coupon_count = CustomerCoupon.objects.filter( open_id=open_id, status=0, end_date__gte=today).count() upcoming_order_count = Order.objects.filter( open_id=open_id, order_status__lt=3).count() result.set('coupon_count', coupon_count) result.set('upcoming_order_count', upcoming_order_count) return Response(result.get_response(), result.get_code()) except Exception as e: print(e) result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) return Response(result.get_response(), result.get_code())
def get(self, request, address_id): self.logger_info.info('[UserAddressDetail][get][' + str(address_id) + ']') auth_info = header_parser.parse_auth_info(request) try: address_req_validation(auth_info.open_id, auth_info.access_token) check_auth_info_v2(auth_info.open_id, auth_info.access_token) # Read specific address address_manager = AddressManagerV2(self.logger_info, self.logger_error) user_address = address_manager.get_address(auth_info.open_id, int(address_id)) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('user_address', user_address) return Response(result.get_response(), result.get_code())
def get(self, request, product_id): result = ResultResponse(code.ARIES_200_SUCCESS, self.SUCCESS_MSG) lang_info = parse_language_v2(request.META) target_db = lang_info.target_db os_type = lang_info.os_type cn_header = lang_info.cn_header product_manager = ProductManagerV3(logger_info, logger_error) menu_manager = MenuManagerV2(logger_info, logger_error) # Get product data product = product_manager.get_product_data(product_id) menu_manager.get_menu_data(product, target_db, cn_header) hub_id = product['hub'] # Check the current available time bomb time_bomb_manager = TimeBombManager(logger_info, logger_error) time_bomb_id = time_bomb_manager.get_time_bomb_now(hub_id, os_type) if time_bomb_id is not None: discount_map = product_manager.get_all_discount_info(time_bomb_id, cn_header) # Time bomb information parsing if product['id'] in discount_map: discount_info = discount_map[product['id']] add_discount_information(product, discount_info) result.set('product', product) return Response(result.get_response(), result.get_code())
def post(self, request): request_data = request.data self.logger_info.info('[UserReceiptList][post][' + str(request_data) + ']') auth_info = header_parser.parse_auth_info(request) lang_info = parse_language_v2(request.META) try: check_auth_info_v2(auth_info.open_id, auth_info.access_token) receipt_util.request_validation(auth_info.open_id, request_data) receipt_manager = ReceiptManager(self.logger_info, self.logger_error) receipt_list = receipt_manager.create_user_receipt( auth_info.open_id, request_data, lang_info.cn_header) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('user_receipts', receipt_list) return Response(result.get_response(), result.get_code())
def get(self, request): result = ResultResponse(code.ARIES_200_SUCCESS, 'success') try: # Get access token open_id = request.META['HTTP_OPEN_ID'] access_token = str( request.META['HTTP_AUTHORIZATION']).split(' ')[1] user = User.objects.get(access_token=access_token, open_id=open_id) user_notify_info = UserNotifyInfo.objects.get(user=user) # Check event playable has_event = check_has_event(open_id, access_token) user_notify_info.has_event = has_event user_notify_info.save() except Exception as e: logger_error.error(str(e)) result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Auth token or user not found') return Response(result.get_response(), result.get_code()) serializer = UserNotifyInfoSerializer(user_notify_info) notify_info_data = serializer.data del notify_info_data['id'] del notify_info_data['user'] result.set('notification_info', notify_info_data) return Response(result.get_response(), result.get_code())
def get(self, request, order_id): result = ResultResponse(code.ARIES_200_SUCCESS, 'success') auth_info = header_parser.parse_auth_info(request) self.logger_info.info(auth_info.access_token) dada_manager = DadaManager(self.logger_info, self.logger_error) try: # Read dada detail dada_order_data = dada_manager.read_order_detail(order_id) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result.set('shipping_order_detail', dada_order_data) return Response(result.get_response(), result.get_code())
def post(self, request): print(request.data) request_data = request.data try: open_id = request_data['open_id'] title = request_data['title'] content = request_data['content'] custom = request_data['custom'] except Exception as e: print(e) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Parameter invalid') return Response(result.get_response(), result.get_code()) try: msg = build_ios_notification(title, content, custom) print(msg.GetMessageObject()) push_app = XingeApp(self.AccessId, self.SecretKey) ret = push_app.PushSingleAccount(0, open_id, msg, self.environment) # ret = push_app.PushSingleDevice(open_id, msg, 2) result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('ret', ret) return Response(result.get_response(), result.get_code()) except Exception as e: print(e) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Parameter invalid') return Response(result.get_response(), result.get_code())
def post(self, request, time_bomb_id): auth_info = header_parser.parse_auth_info(request) request_data = request.data try: get_admin_token_validate_v2(auth_info.access_token) # Request data validation time_bomb_activation_validation(request_data) # Get activate value activate = request_data['activate'] time_bomb_manager = TimeBombManager(self.logger_info, self.logger_error) activate_result = time_bomb_manager.set_time_bomb_activate_with_id(time_bomb_id, activate) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: self.logger_error.error(str(e)) result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e), None) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('result', activate_result) return Response(result.get_response(), result.get_code())
def post(self, request): result = ResultResponse(code.ARIES_200_SUCCESS, 'success') request_data = request.data try: open_id = request_data['open_id'] product_list = request_data['product_list'] order_id = request_data['order_id'] hub_id = request_data['hub_id'] except Exception as e: logger_info.info(str(e)) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Request data invalid(Token or Open id)') return Response(result.get_response(), result.get_code()) language_info = header_parser.parse_language(request.META) date_info = product_util.get_date_information(hub_id, product_util.get_sales_time_str()) product_manager = ProductManager(logger_info, logger_error, language_info, date_info) review_manager = ReviewManager(logger_info, logger_error) product_list = [product_manager.get_product(product['product_id']) for product in product_list] response_list = [review_manager.get_personal_review(language_info[2], open_id, order_id, product) for product in product_list] result.set('reviews', response_list) result.set('review_items', review_manager.review_items) return Response(result.get_response(), result.get_code())
def post(self, request): request_data = request.data self.logger_info.info(request_data) dada_manager = DadaManager(self.logger_info, self.logger_error) try: # Request data validation dada_util.dada_new_order_validation(request_data) # Request data parsing order_id = request_data['order_id'] # Make a new order dada_manager.re_add_order(request_data) # Read dada detail dada_order_data = dada_manager.update_order_detail(order_id) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('shipping_order_detail', dada_order_data) return Response(result.get_response(), result.get_code())
def put(self, request, address_id): self.logger_info.info('[UserAddressSelector][put][' + str(address_id) + ']') auth_info = header_parser.parse_auth_info(request) try: check_auth_info_v2(auth_info.open_id, auth_info.access_token) # Get address data address_manager = AddressManagerV2(self.logger_info, self.logger_error) address_data = address_manager.get_address(auth_info.open_id, address_id) # Check delivery area address_select_validation(address_data['delivery_area']) # Select address address_list = address_manager.select_address(auth_info.open_id, int(address_id)) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('user_addresses', address_list) return Response(result.get_response(), result.get_code())
def post(self, request): language_info = header_parser.parse_language_v2(request.META) request_data = request.data logger_info.info('[views_coupon][CouponInformation][post][' + str(request.data) + ']') try: coupon_manager = CouponManagerV3(logger_info, logger_error) coupon_info_list = coupon_manager.read_coupon_information( request_data, language_info.target_db) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('coupon_info', coupon_info_list) return Response(result.get_response(), result.get_code())
def get(self, request, hub_id): result = ResultResponse(code.ARIES_200_SUCCESS, 'success') auth_info = header_parser.parse_authentication(request) lang_info = header_parser.parse_language_v2(request.META) promotion_manager = PromotionManager(logger_info, logger_error, lang_info.target_db) promotion_manager.update_notification_count(auth_info) page = int(request.GET.get('page', 1)) limit = int(request.GET.get('limit', 10)) os_type = int(request.GET.get('os_type', 2)) try: # Get promotion list promotion_list_result = promotion_manager.get_promotion_list( page, limit, hub_id, os_type) promotion_count = promotion_list_result[0] promotion_list = promotion_list_result[1] result.set('total_count', promotion_count) result.set('promotions', promotion_list) except Exception as e: logger_info.info(str(e)) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Request data error') return Response(result.get_response(), result.get_code()) return Response(result.get_response(), result.get_code())
def get(self, request, open_id): result = ResultResponse(code.ARIES_200_SUCCESS, 'success') # Get access token try: access_token = str( request.META['HTTP_AUTHORIZATION']).split(' ')[1] user_instance = User.objects.get(access_token=access_token, open_id=open_id) except Exception as e: logger_error.error(str(e)) result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Token not found') return Response(result.get_response(), result.get_code()) user_serializer = UserAccountSerializer(user_instance) user_data = user_serializer.data user_grade = UserGrade.objects.get(user=user_instance) user_grade_serializer = UserGradeSerializer(user_grade) user_data['grade'] = user_grade_serializer.data result.set('user', user_data) return Response(result.get_response(), result.get_code())
def post(self, request, hub_id, time): result = ResultResponse(code.ARIES_200_SUCCESS, self.SUCCESS) logger_info.info(str(time)) lang_info = header_parser.parse_language_v2(request.META) cn_header = lang_info.cn_header target_db = lang_info.target_db os_type = lang_info.os_type try: product_list = request.data['product_list'] except Exception as e: print(e) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Request data invalid') return Response(result.get_response(), result.get_code()) product_manager = ProductManagerV3(logger_info, logger_error) menu_manager = MenuManager(logger_info, logger_error) restaurant_manager = RestaurantManager(logger_info, logger_error) hub_manager = HubManagerV2(logger_info, logger_error) product_list = hub_manager.get_product_list(product_list, hub_id) stock_list = hub_manager.get_stock_list(hub_id, product_list, target_db, os_type) for product in stock_list: # Get product data product_data = product_manager.get_product_for_valid( product['product_id'], cn_header) # Set time bomb information if 'time_bomb_info' in product: product['time_bomb_info']['stock'] = product['stock'] product['time_bomb_info']['has_stock'] = True product_data['price_discount'] = product['price_discount'] product_data['event_product'] = product['event_product'] product_data['price_discount_event'] = True product['product'] = product_data # Get menu data menu_id = product_data['menu'] menu_data = menu_manager.get_menu_data(target_db, menu_id, product_data['sales_time'], cn_header) menu_data['review_statics'] = menu_manager.get_menu_statics( menu_id) menu_data['restaurant'] = restaurant_manager.get_restaurant_data( menu_data['restaurant'], target_db) product['product']['menu'] = menu_data result.set('product_list', stock_list) return Response(result.get_response(), result.get_code())
def post(self, request, hub_id): auth_info = header_parser.parse_auth_info(request) request_data = request.data try: # Request data validation create_time_bomb_validation(request_data) time_bomb = request_data['time_bomb'] tb_content_en = time_bomb['time_bomb_content_en'] tb_content_cn = time_bomb['time_bomb_content_cn'] del time_bomb['time_bomb_content_en'] del time_bomb['time_bomb_content_cn'] if 'time_bomb_discount_info' in time_bomb: discount_info = time_bomb['time_bomb_discount_info'] del time_bomb['time_bomb_discount_info'] else: discount_info = [] # Admin token check get_admin_token_validate_v2(auth_info.access_token) # Product available check product_manager = ProductManagerV3(self.logger_info, self.logger_error) product_manager.get_product_validation(discount_info) # Get target hub instance hub_manager = HubManagerV2(self.logger_info, self.logger_error) time_bomb['hub'] = hub_manager.get_hub_instance(int(time_bomb['hub'])) # Create time bomb time_bomb_manager = TimeBombManager(self.logger_info, self.logger_error) time_bomb_manager.create_time_bomb(time_bomb, tb_content_en, tb_content_cn, discount_info) # Get time bomb list time_bomb_list = time_bomb_manager.get_time_bomb_list(hub_id) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except AuthInfoError: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: self.logger_error.error(str(e)) result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e), None) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('time_bomb_list', time_bomb_list) return Response(result.get_response(), result.get_code())
def do_sign_in(self): token_result = self.get_token() if token_result[0]: token = token_result[1] else: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, 'Token validation fail') return result self.user.access_token = token self.user.save() user_serializer = UserAccountSerializer(self.user) user_data = user_serializer.data user_grade = UserGrade.objects.get(user=self.user) user_grade_serializer = UserGradeSerializer(user_grade) user_data['grade'] = user_grade_serializer.data user_data['connection_account'] = json.loads( user_data['connection_account']) # User notify data notify_info = UserNotifyInfo.objects.get(user=self.user) # User notify information update user_news_count = UserNews.objects.filter(user=self.user, has_read=False).count() notify_info.news_count = user_news_count self.update_notification_info(user_data['open_id'], user_data['access_token'], notify_info) notify_info_serializer = UserNotifyInfoSerializer(notify_info) notify_info_data = notify_info_serializer.data del notify_info_data['id'] del notify_info_data['user'] user_data['notification_info'] = notify_info_data result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('user', user_data) result.set('auto_registration', self.auto_registration) # Member promotion coupon issue section if self.auto_registration: member_promo_result = request_member_promotion( self.user.open_id, 0, self.accept_lang) result.set_map(member_promo_result) if member_promo_result['has_member_promotion']: notify_info.has_new_coupon = True notify_info.coupon_count = 1 notify_info.save() return result
def post(self, request): lang_info = header_parser.parse_language_v2(request.META) request_data = request.data logger_info.info('[views_referral_coupon][PromotionCoupon][post][' + str(request_data) + ']') try: member_coupon_issue_validation(request_data) open_id = request_data['open_id'] promotion_type = request_data['promotion_type'] promotion_manager = PromotionManager(logger_info, logger_error, lang_info) lang_type = 1 if lang_info.cn_header else 0 member_promotion = promotion_manager.get_promotion_list_with_latest( promotion_type, lang_type) if member_promotion is None: has_member_promotion = False member_promotion = {} else: has_member_promotion = True coupon_id = member_promotion['coupon_id'] coupon_days = member_promotion['coupon_days'] coupon_code = member_promotion['coupon_code'] sender_id = member_promotion['sender_id'] coupon_manager = CouponManagerV3(logger_info, logger_error) coupon_manager.create_coupon_with_promotion( open_id, coupon_id, coupon_days, coupon_code, sender_id) member_promotion = member_promotion_filtering(member_promotion) except DataValidationError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_400_BAD_REQUEST, message, err_code) except BusinessLogicError as instance: message, err_code, data_set = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message, err_code) result.set_map(data_set) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, self.SUCCESS_MSG) result.set('has_member_promotion', has_member_promotion) result.set('member_promotion', member_promotion) return Response(result.get_response(), result.get_code())
def get(self, request): auth_info = header_parser.parse_authentication(request) language_info = header_parser.parse_language(request.META) event_manager = EventManager(self.logger_info, self.logger_error) try: # Get event manager event_object = event_manager.get_event_status( auth_info, None, language_info[0]) event = event_object['event'] if event['need_auth']: user_util.check_auth_info(auth_info) # Check game play condition event_util.check_play_condition(event, language_info[0]) # Play the game reward_result = event_manager.draw_event(event['id'], language_info[0]) reward_id = reward_result[0] random_number = reward_result[1] # Make the history create_result = event_manager.create_event_history( event['id'], auth_info[0], reward_id, random_number, language_info[0]) # Reward interface to purchase server reward_tuple = create_result[2] event_manager.create_coupon(auth_info[0], reward_tuple.target_id, language_info[0]) # Coupon count increase event_manager.increase_coupon_count(auth_info[0], auth_info[1]) except AuthInfoError as e: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, str(e)) except BusinessLogicError as instance: message, err_code = instance.args result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, message) result.set_error(err_code) except Exception as e: result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) else: result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('event_reward', create_result[1]) return Response(result.get_response(), result.get_code())
def post(self, request): print(request.data) request_data = request.data try: open_id = request_data['open_id'] action_type = request_data['action_type'] action = ClickAction() if action_type == 0: action = None elif action_type == 1: action.actionType = 1 action.activity = request_data['activity'] action.intentFlag = request_data['if'] action.pendingFlag = request_data['pf'] elif action_type == 2: action.actionType = 2 action.url = request_data['browser'] else: action.actionType = 3 action.intent = request_data['intent'] except Exception as e: print(e) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Parameter invalid') return Response(result.get_response(), result.get_code()) try: msg = build_android_notification_api('Custom push test', 'Test content!') if action_type != 0: msg.action = action if 'custom' in request_data: msg.custom = request_data['custom'] push_app = XingeApp(self.AccessId, self.SecretKey) ret = push_app.PushSingleAccount(0, open_id, msg) result = ResultResponse(code.ARIES_200_SUCCESS, 'success') result.set('ret', ret) return Response(result.get_response(), result.get_code()) except Exception as e: print(e) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Parameter invalid') return Response(result.get_response(), result.get_code())
def get(self, request, order_id): result = ResultResponse(code.ARIES_200_SUCCESS, 'success') try: access_token = str( request.META['HTTP_AUTHORIZATION']).split(' ')[1] api_request_util.get_admin_token_validate_v2(access_token) except Exception as e: logger_error.error(str(e)) result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Authentication error') return Response(result.get_response(), result.get_code()) try: order_manager = OrderManager(logger_info, logger_error) order_data = order_manager.get_order_detail(order_id) open_id = order_data['open_id'] address_id = order_data['address_id'] # Get user information user_data = api_request_util.get_user_info(open_id, access_token, address_id) if len(user_data['user_address']) >= 5: order_data['user_address'] = user_data['user_address'] else: order_data['user_address'] = get_user_address_data( order_data['delivery_recipient_name'], order_data['delivery_address_lat'], order_data['delivery_address_lng'], order_data['delivery_address']) order_data['user'] = user_data['user'] order_data['user_info'] = user_data['user_info'] # Dada service dada_service = DadaService(logger_info, logger_error) order_data[ 'shipping_order_detail'] = dada_service.read_dada_order_detail( order_id) result.set('order', order_data) result.set('result', order_data) except Exception as e: logger_error.error(str(e)) result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, str(e)) return Response(result.get_response(), result.get_code())
def post(self, request): result = ResultResponse(code.ARIES_200_SUCCESS, 'success') request_data = request.data logger_info.info(request_data) try: user_open_id = request_data['user_open_id'] except KeyError as e: print(e) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Request data invalid') return Response(result.get_response(), result.get_code()) # create platform & platform check while True: auth_token = binascii.hexlify(os.urandom(24)).decode() token_count = AuthToken.objects.filter( access_token=auth_token).count() if token_count == 0: break auth_token = auth_token.upper() # complete auth_token data request_data['access_token'] = auth_token request_data['scope'] = self.scope prev_token_count = AuthToken.objects.filter( user_open_id=user_open_id).count() if prev_token_count == 1: prev_token = AuthToken.objects.get(user_open_id=user_open_id) prev_token.access_token = auth_token prev_token.scope = self.scope prev_token.save() result.set('token', auth_token) else: token_serializer = AuthTokenSerializer(data=request_data) if token_serializer.is_valid(): token_serializer.save() result.set('token', auth_token) else: result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Request data invalid') return Response(result.get_response(), result.get_code()) return Response(result.get_response(), result.get_code())
def post(self, request): request_data = request.data result = ResultResponse(code.ARIES_200_SUCCESS, 'success') open_id = request_data['open_id'] msg = build_ios_notification('Delivering complete.', 'Enjoy it!', request_data['custom']) print(msg.custom) print(len(msg.custom)) push_app = XingeApp(self.AccessId, self.SecretKey) ret = push_app.PushSingleAccount(0, open_id, msg) result.set('ret', ret) return Response(result.get_response(), result.get_code())