Exemple #1
0
    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):
        try:
            auth_info = header_parser.parse_authentication(request)
            open_id = auth_info[0]

            EventHistory.objects.filter(open_id=open_id).delete()
        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())
    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 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())
Exemple #5
0
    def post(self, request):

        authentication = header_parser.parse_authentication(request)

        open_id = authentication[0]
        access_token = authentication[1]
        order_id = request.data.get('order_id', None)

        try:
            user_manager = UserManager()
            result = user_manager.send_order_cancel_msg(open_id, access_token, order_id)
            return Response(result.get_response(), result.get_code())

        except Exception as e:
            print(e)
            result = ResultResponse(code.ARIES_400_BAD_REQUEST, str(e))
            return Response(result.get_response(), result.get_code())
    def get(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())

        page = int(request.GET.get('page', 1))
        limit = int(request.GET.get('limit', 20))

        stock_manager = StockManager(self.logger_info, self.logger_error)
        hub_stock_result = stock_manager.get_stock_list(hub_id, page, limit)

        result = ResultResponse(code.ARIES_200_SUCCESS, self.SUCCESS_STR)
        result.set('total_count', hub_stock_result[0])
        result.set('hub_stock', hub_stock_result[1])

        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:
            event = event_manager.get_event_status(auth_info, None,
                                                   language_info[0])
        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', event['event'])
            result.set('event_reward', event['event_reward'])
            result.set('event_info', event['event_info'])

        return Response(result.get_response(), result.get_code())
    def get(self, request):
        try:
            auth_info = header_parser.parse_authentication(request)

            event_manager = EventManager(self.logger_info, self.logger_error)
            event_result = event_manager.check_event_history_count(
                auth_info[0], auth_info[1])

            if event_result:
                event_result = True
            else:
                event_result = False
        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_result', event_result)

        return Response(result.get_response(), result.get_code())
    def post(self, request, folder_name):
        result = ResultResponse(code.ARIES_200_SUCCESS, 'Upload success')
        authentication = header_parser.parse_authentication(request)

        if authentication[1] is None:
            result = ResultResponse(code.ARIES_401_UNAUTHORIZED,
                                    get_msg(code.ARIES_401_UNAUTHORIZED))
            return Response(result.get_response(), result.get_code())

        if not api_request_util.get_user_information(authentication[0],
                                                     authentication[1]):
            result = ResultResponse(code.ARIES_401_UNAUTHORIZED,
                                    get_msg(code.ARIES_401_UNAUTHORIZED))
            return Response(result.get_response(), result.get_code())

        cdn_manager = CdnManager(request, folder_name=folder_name)

        if not cdn_manager.check_file_exists():
            result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR,
                                    "File doesn't exists")
            return Response(result.get_response(), result.get_code())

        if not cdn_manager.check_file_size():
            result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR,
                                    get_msg(code.ERROR_1102_FILE_OVERSIZE))
            result.set_error(code.ERROR_1102_FILE_OVERSIZE)
            return Response(result.get_response(), result.get_code())

        if not cdn_manager.get_content_md5():
            result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR,
                                    "Get content md5 error")
            return Response(result.get_response(), result.get_code())

        if not cdn_manager.upload_file():
            result = ResultResponse(code.ARIES_500_INTERNAL_SERVER_ERROR,
                                    "File upload failed")
            return Response(result.get_response(), result.get_code())

        return Response(result.get_response(), result.get_code())
Exemple #10
0
    def get(self, request):
        auth_info = header_parser.parse_authentication(request)
        language_info = header_parser.parse_language(request.META)

        try:
            coupon_util.auth_info_validator(auth_info, language_info[0])
            coupon_util.os_info_validator(request)

            coupon_manager = CouponManagerV3(logger_info, logger_error)
            coupon_manager.create_coupon_pack(auth_info, self.coupon_pack_info,
                                              language_info[0])
        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')

        return Response(result.get_response(), result.get_code())
    def post(self, request):
        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())

        try:
            request_data = request.data
            menu_en = request_data['menu_en']
            menu_cn = request_data['menu_cn']
        except Exception as e:
            self.logger_error.error(str(e))
            result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Request data invalid')
            return Response(result.get_response(), result.get_code())

        try:
            menu_manager = MenuManager(self.logger_info, self.logger_error)
            result = menu_manager.create_menu(menu_en, menu_cn)
        except Exception as e:
            self.logger_info.info(str(e))
            result = ResultResponse(code.ARIES_400_BAD_REQUEST, 'Request data error')

        return Response(result.get_response(), result.get_code())