Exemple #1
0
    def process(self):
        args = self.getUrlArgs('/promotioncheck/')
        try:
            appname = args.get(0, '')
            dmmid = args.get(1, '')
            requirement_idlist = [
                int(s) for s in args.get(2, '').split(',') if s.isdigit()
            ]
        except:
            self.__sendErrorResponse(404)
            return

        model_mgr = self.getModelMgr()

        config = BackendApi.get_promotionconfig(model_mgr,
                                                appname,
                                                using=settings.DB_READONLY)
        if config is None:
            # アプリが存在しない.
            self.__sendErrorResponse(404)
            return

        # ユーザーの存在確認.
        uid = None
        if dmmid:
            uid = BackendApi.dmmid_to_appuid(self, [dmmid],
                                             using=settings.DB_READONLY).get(
                                                 dmmid, None)
        if uid is None:
            self.__sendErrorResponse(404)
            return

        if requirement_idlist:
            requirementlist = BackendApi.get_promotionrequirementmaster_list(
                model_mgr,
                appname,
                requirement_idlist,
                using=settings.DB_READONLY)
        else:
            # 全て検索.
            requirementlist = BackendApi.get_promotionrequirementmaster_all(
                model_mgr, appname, using=settings.DB_READONLY)

        if not requirementlist:
            self.__sendErrorResponse(404)
            return

        json_obj = {}

        for requirement in requirementlist:
            flag = BackendApi.check_promotionrequirement(
                self, uid, requirement)
            json_obj[str(
                requirement.id
            )] = 'true' if flag else 'false'  # PHPの方々は文字列にして欲しいらしいのでもう文字列で統一.

        self.response.set_status(200)
        self.osa_util.write_json_obj(json_obj)
Exemple #2
0
    def process(self):

        args = self.getUrlArgs('/promotiondebug/')
        appname = args.get(0, '')

        model_mgr = self.getModelMgr()
        v_player = self.getViewerPlayer()

        config = BackendApi.get_promotionconfig(model_mgr,
                                                appname,
                                                using=settings.DB_READONLY,
                                                do_get_closed=True)
        if config is None:
            raise CabaretError(u'未登録のアプリです:%s' % appname,
                               CabaretError.Code.ILLEGAL_ARGS)

        function_name = self.request.get('_proc')
        if function_name:
            func = getattr(self, 'proc_%s' % function_name)
            if func:
                func(appname)
                if self.response.isEnd:
                    return

        requirementlist = BackendApi.get_promotionrequirementmaster_all(
            model_mgr, appname, using=settings.DB_READONLY)
        requirementlist.sort(key=lambda x: x.id)
        self.html_param['requirementlist'] = [{
            'text':
            requirement.text,
            'flag':
            BackendApi.check_promotionrequirement(self, v_player.id,
                                                  requirement)
        } for requirement in requirementlist]

        prizelist = BackendApi.get_promotionprizemaster_all(
            model_mgr, appname, using=settings.DB_READONLY)
        prizelist.sort(key=lambda x: ((x.rid << 32) + x.id))
        userdata_dict = BackendApi.get_promotion_userdata(
            model_mgr,
            appname,
            v_player.id, [prize.id for prize in prizelist],
            using=settings.DB_READONLY)
        obj_prizelist = []
        for prize in prizelist:
            userdata = userdata_dict.get(prize.id)
            obj_prizelist.append({
                'id':
                prize.id,
                'name':
                prize.name,
                'status':
                userdata.status if userdata else Defines.PromotionStatus.NONE,
            })
        self.html_param['prizelist'] = obj_prizelist

        self.html_param['level'] = v_player.level

        self.html_param['url_self'] = self.makeAppLinkUrl(
            '/promotiondebug/%s/' % appname)

        self.html_param['url_promotion_top'] = self.makeAppLinkUrl(
            UrlMaker.promotion_top(appname))

        self.writeAppHtml('promotion/%s/debug' % config.htmlname)