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): 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 delete(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()) # Delete account try: account = Operator.objects.get(id=operator_id) account.delete() except ObjectDoesNotExist: result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Account not found') 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())
def delete(self, request): result = ResultResponse(code.ARIES_200_SUCCESS, 'success') request_data = request.data logger_info.info(request_data) # Parsing request parameter try: menu_id = request_data['menu_id'] prev_rate = request_data['prev_rate'] except Exception as e: logger_info.info(str(e)) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Request data invalid') return Response(result.get_response(), result.get_code()) # Get a object try: menu_statics = MenuReviewStatics.objects.get(menu=menu_id) # Calculate rate original_rate = menu_statics.review_count * menu_statics.average_point original_rate -= prev_rate new_rate = round(original_rate/(menu_statics.review_count-1), 1) # Save data menu_statics.review_count -= 1 menu_statics.average_point = new_rate menu_statics.save() return Response(result.get_response(), result.get_code()) except Exception as e: logger_info.info(str(e)) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Object data not found') return Response(result.get_response(), result.get_code())
def get(self, request): 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_info.info(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_list = order_manager.get_search_orders(request, False) result.set('result', { 'orders': order_list, 'total_count': len(order_list) }) result.set('orders', order_list) result.set('total_count', len(order_list)) except Exception as e: logger_info.info(str(e)) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Bad request') return Response(result.get_response(), result.get_code())
def post(self, request): request_data = request.data logger_info.info(request_data) lang_info = parse_language_v2(request.META) try: login_type = request_data['login_type'] sign_in_manager = SignInManager(logger_info, logger_error) sign_in_manager.set_login_info(login_type, request_data, lang_info.accept_lang) except Exception as e: logger_info.info(str(e)) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Request data is invalid') return Response(result.get_response(), result.get_code()) if sign_in_manager.login_validation(): result = sign_in_manager.do_sign_in() sign_in_manager.update_user_information(request_data) else: logger_info.info('ID or password is incorrect') result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'ID or password is incorrect.') 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 delete(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'] user_account = request_data['user_account'] auth_token = AuthToken.objects.get(user_open_id=user_open_id, user_account=user_account) user = User.objects.get(open_id=user_open_id, access_token=auth_token.access_token) user.access_token = '' user.save() auth_token.delete() except Exception as e: logger_info.info(str(e)) 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 get(self, request): result = ResultResponse(code.ARIES_200_SUCCESS, 'success') try: user_open_id = request.META['HTTP_OPEN_ID'] access_token = str( request.META['HTTP_AUTHORIZATION']).split(' ')[1] except KeyError as e: logger_info.info(str(e)) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Request data invalid') return Response(result.get_response(), result.get_code()) # Get access token with open id try: auth_token = AuthToken.objects.get(access_token=access_token, user_open_id=user_open_id) if auth_token.access_token_state != 0: logger_error.error('token_expired') result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Token is expired') return Response(result.get_response(), result.get_code()) except Exception as e: logger_error.error(str(e)) result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Token is not found') return Response(result.get_response(), result.get_code()) 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, login_key): verification_code = str(cache.get(login_key)) logger_info.info(login_key + ':' + str(cache.get(login_key))) if len(verification_code) < 6: logger_error.error('Unauthorized') result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'It needs verification') return Response(result.get_response(), result.get_code()) try: cache_data = cache.get(login_key) if cache_data == 'complete': result = ResultResponse(code.ARIES_200_SUCCESS, 'success') else: logger_info.info('verification failed') result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Verification failed') return Response(result.get_response(), result.get_code()) except Exception as e: logger_info.info(str(e)) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Verification failed') return Response(result.get_response(), result.get_code()) return Response(result.get_response(), result.get_code())
def put(self, request, open_id): request_data = request.data result = ResultResponse(code.ARIES_200_SUCCESS, 'success') logger_info.info(request_data) # 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 or user not found') return Response(result.get_response(), result.get_code()) # Update data try: user_serializer = UserSerializer(user_instance, data=request_data, partial=True) if user_serializer.is_valid(): user_serializer.save() else: logger_info.info(user_serializer.errors) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Request data invalid') return Response(result.get_response(), result.get_code()) except Exception as e: logger_info.info(str(e)) result = ResultResponse(code.ARIES_400_BAD_REQUEST, e) return Response(result.get_response(), result.get_code()) return Response(result.get_response(), 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, 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 put(self, request): request_data = request.data 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] user = User.objects.get(access_token=access_token, open_id=open_id) user_notify_info = UserNotifyInfo.objects.get(user=user) 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()) # Change data serializer = UserNotifyInfoSerializer(user_notify_info, data=request_data, partial=True) if serializer.is_valid(): serializer.save() return Response(result.get_response(), result.get_code()) else: print(serializer.errors) result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Token or user not found') 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, open_id): result = ResultResponse(code.ARIES_200_SUCCESS, 'success') # This open id is not open id mdn = open_id cn_header = False # Popup header check try: accept_lang = request.META['HTTP_ACCEPT_LANGUAGE'] if 'zh' in accept_lang: cn_header = True except Exception as e: print(e) response = requests.get( urlmapper.get_url('USER_SMS_VERIFICATION') + open_id) if response.status_code != code.ARIES_200_SUCCESS: logger_info.info(response.text) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Verification info is not found') return Response(result.get_response(), result.get_code()) try: user_login_info_count = UserLoginInfo.objects.filter( login_type=0, login_key=mdn).count() if user_login_info_count == 1: user_login_info = UserLoginInfo.objects.get(login_type=0, login_key=mdn) password = user_login_info.login_value masked_password = password[:3] + (len(password) - 3) * '*' result.set('password', masked_password) result.set('guide_message', 'Your password is ' + masked_password) else: user_count = User.objects.filter(mdn=mdn).count() if user_count >= 1: result.set( 'password', get_msg(code.ERROR_1301_MDN_ALREADY_EXIST, cn_header)) result.set( 'guide_message', get_msg(code.ERROR_1301_MDN_ALREADY_EXIST, cn_header)) else: result.set( 'password', get_msg(code.ERROR_1302_MDN_INFO_NOT_FOUND, cn_header)) result.set( 'guide_message', get_msg(code.ERROR_1302_MDN_INFO_NOT_FOUND, cn_header)) return Response(result.get_response(), result.get_code()) except Exception as e: logger_info.info(str(e)) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Member info is not found') return Response(result.get_response(), result.get_code())
def get(self, request, user_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 User object try: # User data user = User.objects.get(id=user_id) serializer = UserSerializer(user) user_data = serializer.data user_data['connection_account'] = json.loads( user_data['connection_account']) user_open_id = user.open_id addresses = UserAddressInfo.objects.filter(user=user) serializer = UserAddressInformationSerializer(addresses, many=True) address_data = serializer.data address_list = list() for address in address_data: address_list.append(address) headers = {'open-id': user_open_id} response = requests.get(urlmapper.get_url('COUPON_LIST'), headers=headers) if response.status_code == code.ARIES_200_SUCCESS: response_json = response.json() coupons = response_json['coupons'] else: coupons = [] result.set('user', user_data) result.set('addresses', address_list) result.set('coupons', coupons) except ObjectDoesNotExist: logger_info.info('User not found') result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'User not found') 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())
def post(self, request): request_data = request.data logger_info.info(request_data) result = ResultResponse(code.ARIES_200_SUCCESS, 'success') # Operation check try: access_token = str( request.META['HTTP_AUTHORIZATION']).split(' ')[1] url = urlmapper.get_url('ADMIN_VALIDATE') payload = {'access_token': access_token} response = requests.post(url, json=payload) if response.status_code != code.ARIES_200_SUCCESS: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Token or user not found') return Response(result.get_response(), result.get_code()) except Exception as e: print(e) result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Error : ' + str(e)) return Response(result.get_response(), result.get_code()) try: open_id = request_data['open_id'] news_type = request_data['type'] title = request_data['title'] title_cn = request_data['title_cn'] content = request_data['content'] content_cn = request_data['content_cn'] detail = request_data['detail'] detail_cn = request_data['detail_cn'] user = User.objects.get(open_id=open_id) UserNews.objects.create(user=user, type=news_type, title=title, title_cn=title_cn, content=content, content_cn=content_cn, has_read=False, detail=detail, detail_cn=detail_cn) user_notify_info = UserNotifyInfo.objects.get(user=user) user_notify_info.has_news = True user_notify_info.news_count = F('news_count') + 1 user_notify_info.save() except Exception as e: logger_error.error(str(e)) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Error : ' + str(e)) return Response(result.get_response(), result.get_code()) 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 get(self, request, product_id): result = ResultResponse(code.ARIES_200_SUCCESS, 'success') 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_queryset = Product.objects.filter(id=product_id, type__lte=10) product_count = product_queryset.count() if product_count < 1: result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Product not found') return Response(result.get_response(), status=result.get_code()) # Create manager product_manager = ProductManagerV3(logger_info, logger_error) menu_manager = MenuManagerV2(logger_info, logger_error) review_manager = ReviewManager(logger_info, logger_error) # Get product information product = product_manager.get_product_data(product_id) hub_id = product['hub'] # Parsing menu and restaurant data menu_manager.get_menu_data(product, target_db, cn_header) result.set('product', product) # Recommend product information product_list = product_manager.get_recommend_product(hub_id) for product_obj in product_list: menu_manager.get_menu_data(product_obj, target_db, cn_header) result.set('products', product_list) # Time bomb information 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_map = product_manager.get_all_discount_info(time_bomb_id, cn_header) if product['id'] in discount_map: discount_info = discount_map[product['id']] add_discount_information(product, discount_info) # Expert review expert_review = review_manager.get_expert_review(target_db, product['menu']['id']) result.set('expert_review', expert_review) # Review articles # reviews = review_manager.get_product_review(language_info[2], product_id) result.set('total_count', 0) result.set('page_size', 0) result.set('customer_reviews', []) return Response(result.get_response(), status=result.get_code())
def post(self, request): request_data = request.data logger_info.info(request_data) result = ResultResponse(code.ARIES_200_SUCCESS, 'success') # Operation check try: access_token = request_data['access_token'] url = urlmapper.get_url('ADMIN_VALIDATE') payload = {'access_token': access_token} response = requests.post(url, json=payload) if response.status_code != code.ARIES_200_SUCCESS: result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Token or user not found') return Response(result.get_response(), result.get_code()) except Exception as e: logger_error.error(str(e)) result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Error : ' + str(e)) return Response(result.get_response(), result.get_code()) try: open_id = request_data['open_id'] address_id = request_data['address_id'] user = User.objects.get(open_id=open_id) serializer = UserSerializer(user) user_data = serializer.data user_info = UserInfo.objects.get(user=user) serializer = UserInfoSerializer(user_info) user_info_data = serializer.data address_manager = AddressManagerV2(logger_info, logger_error) user_address = address_manager.get_address(open_id, address_id) if user_address is None: user_address = '' result.set('user', user_data) result.set('user_info', user_info_data) result.set('user_address', user_address) return Response(result.get_response(), result.get_code()) except Exception as e: logger_error.error(str(e)) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Error : ' + str(e)) return Response(result.get_response(), result.get_code())
def put(self, request): request_data = request.data result = ResultResponse(code.ARIES_200_SUCCESS, 'success') logger_info.info(request_data) # AUthorization check try: open_id = request.META['HTTP_OPEN_ID'] access_token = str(request.META['HTTP_AUTHORIZATION']).split(' ')[1] url = urlmapper.get_url('TOKEN_VALIDATE') headers = {'open-id': open_id, 'authorization': 'bearer ' + access_token} response = requests.get(url, headers=headers) if response.status_code != 200: raise Exception except Exception as e: print(e) result = ResultResponse(code.ARIES_401_UNAUTHORIZED, get_msg(code.ARIES_401_UNAUTHORIZED)) return Response(result.get_response(), result.get_code()) # Request data parsing try: # Check selective review object product_id = request_data['product_id'] comment = request_data['comment'] if len(comment) <= 0: request_data['visible'] = False else: request_data['visible'] = True except Exception as e: logger_info.info(str(e)) result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Request data invalid') return Response(result.get_response(), result.get_code()) review = CustomerReview.objects.get(open_id=open_id, product_id=product_id) serializer = CustomerReviewSerializer(review, data=request_data, partial=True) if serializer.is_valid(): serializer.save() # Statics information apply payload = {'menu_id': review.menu, 'prev_rate': review.menu_rate, 'menu_rate': request_data['menu_rate']} statics_result = requests.put(urlmapper.get_url('MENU_STATICS'), json=payload) logger_info.info(statics_result.text) else: logger_info.info(serializer.errors) 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): 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): result = ResultResponse(code.ARIES_200_SUCCESS, 'success') try: open_id = request.META.get('HTTP_OPEN_ID') user = User.objects.get(open_id=open_id) user.delete() except Exception as e: logger_error.error(str(e)) result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Error : ' + str(e)) return Response(result.get_response(), result.get_code()) 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 put(self, request, hub_id): authentication = header_parser.parse_authentication(request) if not api_request_util.get_admin_token_validate(authentication[1]): result = ResultResponse(code.ARIES_401_UNAUTHORIZED, 'Token or user not found') return Response(result.get_response(), result.get_code()) hub_stock_list = request.data.get('hub_stock_list', []) stock_manager = StockManager(self.logger_info, self.logger_error) if not stock_manager.update_stock_list(hub_id, hub_stock_list): result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR, 'Internal error') return Response(result.get_response(), result.get_code()) result = ResultResponse(code.ARIES_200_SUCCESS, self.SUCCESS_STR) 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 post(self, request): request_data = request.data self.logger_info.info('[ReferralFirstPurchase][post][' + str(request_data) + ']') referral_manager = ReferralManager(self.logger_info, self.logger_error) try: open_id_param_validation(request_data) open_id = request_data['open_id'] referral_manager.do_first_purchase_up(open_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') return Response(result.get_response(), result.get_code())