コード例 #1
0
    def requestPromotionAchieveFlags(handler,
                                     appname,
                                     dmmid,
                                     ridlist=None,
                                     do_execute=True):
        """プロモーション達成状態を問い合わせる.
        """
        sandbox = handler.appparam.sandbox

        if ridlist:
            conditionId = ','.join([str(rid) for rid in ridlist])
        else:
            conditionId = 'all'

        endpoint_urlparams = dict(userId=dmmid, conditionId=conditionId)
        requet = PromotionUtil.__makePromotionApiRequest(
            handler, appname, 'check', endpoint_urlparams, sandbox, None)
        reqkey = 'requestPromotionAchieveFlags:%s' % OSAUtil.makeSessionID()

        response = {}

        def cb(ret_data, reqkey, response):
            json_obj = ret_data[reqkey].get()
            for k, v in json_obj.items():
                if isinstance(v, (str, unicode)):
                    v = v.lower() in ('1', 'true')
                response[k] = v

        handler.addAppApiRequest(reqkey, requet, cb, reqkey, response)

        if do_execute:
            handler.execute_api()

        return response
コード例 #2
0
    def process(self):
        args = self.getUrlArgs('/compositiondo/')
        try:
            if settings_sub.IS_BENCH:
                requestkey = OSAUtil.makeSessionID()
            else:
                self.__baseid = int(args.get(0))
                self.__materialidlist = self.getMaterialIdList()
                requestkey = urllib.unquote(args.get(1))
        except:
            raise CabaretError(u'引数が想定外です', CabaretError.Code.ILLEGAL_ARGS)

        v_player = self.getViewerPlayer()

        try:
            model_mgr = db_util.run_in_transaction(Handler.tr_write,
                                                   v_player.id, self.__baseid,
                                                   self.__materialidlist,
                                                   requestkey)
            model_mgr.write_end()
        except CabaretError, e:
            if e.code == CabaretError.Code.ALREADY_RECEIVED:
                pass
            else:
                if settings_sub.IS_LOCAL:
                    raise CabaretError(u'合成できませんでした.%s' %
                                       CabaretError.getCodeString(e.code))
                url = UrlMaker.composition()
                self.appRedirect(self.makeAppLinkUrlRedirect(url))
                return
コード例 #3
0
ファイル: lose.py プロジェクト: hitandaway100/caba
 def setUp(self):
     # Player.
     self.__player0 = self.create_dummy(DummyType.PLAYER)
     
     # デッキ.
     deck = Deck(id=self.__player0.id)
     cardmaster = self.create_dummy(DummyType.CARD_MASTER)
     
     arr = []
     for _ in xrange(Defines.DECK_CARD_NUM_MAX - 3):
         cardmaster = self.create_dummy(DummyType.CARD_MASTER)
         arr.append(self.create_dummy(DummyType.CARD, self.__player0, cardmaster).id)
     deck.set_from_array(arr)
     deck.save()
     
     # ボス.
     boss = self.create_dummy(DummyType.BOSS_MASTER)
     boss.hp = 100000
     boss.defense = 10000
     boss.save()
     
     # エリア.
     area = self.create_dummy(DummyType.AREA_MASTER, bossid=boss.id)
     
     # スカウト.
     for _ in xrange(5):
         scout = self.create_dummy(DummyType.SCOUT_MASTER, area=area)
         self.create_dummy(DummyType.SCOUT_PLAY_DATA, self.__player0.id, scout.id, scout.execution)
     
     self.__area = area
     self.__battlekey = OSAUtil.makeSessionID()
コード例 #4
0
    def requestPromotionConditionGet(handler,
                                     appname,
                                     ridlist=None,
                                     do_execute=True):
        """プロモーション達成条件を問い合わせる.
        """
        now = OSAUtil.get_now()
        namespace = 'PromotionCondition:%s' % appname

        sandbox = handler.appparam.sandbox

        not_found_ids = None

        cached_data = {}
        client = localcache.Client()
        if ridlist:
            cache_keys = [str(rid) for rid in ridlist]

            tmp = client.get_many(cache_keys, namespace=namespace)
            for k, v in tmp.items():
                if v['date'] < now:
                    continue
                cached_data[k] = v['data']

            not_found_ids = list(set(cache_keys) - set(cached_data.keys()))
            if not not_found_ids:
                return cached_data

        if not_found_ids:
            conditionId = ','.join(not_found_ids)
        else:
            conditionId = 'all'

        endpoint_urlparams = dict(conditionId=conditionId)
        requet = PromotionUtil.__makePromotionApiRequest(
            handler, appname, 'conditionget', endpoint_urlparams, sandbox,
            None)

        reqkey = 'requestPromotionConditionGet:%s' % OSAUtil.makeSessionID()

        response = cached_data

        def cb(ret_data, reqkey, response, client, cache_limitdate):
            json_obj = ret_data[reqkey].get()
            for k, v in json_obj.items():
                client.set(k,
                           dict(data=v, date=cache_limitdate),
                           namespace=namespace)
            response.update(json_obj)

        handler.addAppApiRequest(reqkey, requet, cb, reqkey, response, client,
                                 now + datetime.timedelta(seconds=3600 * 6))

        if do_execute:
            handler.execute_api()
        return response
コード例 #5
0
 def procPost(self):
     """ 決済確認.
     """
     # 決済情報の確認.
     if settings_sub.IS_LOCAL:
         sku_id = self.request.get('_sku_id')
         buynum = self.request.get('_count')
         v_player = self.getViewerPlayer()
         payment_id = "%s%s" % (v_player.dmmid, OSAUtil.makeSessionID())
     else:
         # JSONフォーマットで返ってくるので生のPOSTデータにアクセス
         #body = Json.decode(self.request.django_request.raw_post_data)
         body = Json.decode(self.request.django_request.body)
         self.json_param['ITEMS'] = body.get('ITEMS')
         self.json_param['PAYMENT_TYPE'] = body.get('PAYMENT_TYPE')
         self.json_param['PAYMENT_ID'] = body.get('PAYMENT_ID')
         self.json_param['ORDERER_TIME'] = body.get('ORDERER_TIME')
         
         sku_id = self.json_param['ITEMS'][0].get('SKU_ID')
         buynum = self.json_param['ITEMS'][0].get('COUNT')
         payment_id = self.json_param['PAYMENT_ID']
     
     # 'SH' or 'GA'
     data_type = sku_id[:2]
     mid = sku_id[2:]
     
     if data_type == Handler.PAYMENT_TYPE_SHOP:
         # ショップ
         self.procShopDo(mid, buynum, payment_id)
     elif data_type == Handler.PAYMENT_TYPE_GACHA:
         # ガチャ
         self.procGachaDo(mid, buynum, payment_id)
     else:
         raise CabaretError(u'存在しない商品です', CabaretError.Code.INVALID_MASTERDATA)
     
     if not self.response.isEnd:
         self.response.set_status(200)
         self.response.send('{"response_code":"OK"}')
コード例 #6
0
ファイル: do.py プロジェクト: hitandaway100/caba
    def proc_payment(self, master, buynum):
        """課金して購入.
        """
        # TODO:PC版は後で実装。今はここにきたらエラーを飛ばしとく.
        if self.is_pc:
            raise CabaretError(u'未実装')

        mid = master.id
        v_player = self.getViewerPlayer()
        # ここまで来たら購入出来るのが確定..
        if settings_sub.IS_LOCAL:
            # ローカル動作確認用に課金トランザクション情報を作成.
            paymentdata = PaymentData()
            paymentdata.paymentId = "%s%s" % (v_player.dmmid,
                                              OSAUtil.makeSessionID())
            paymentdata.status = PaymentData.Status.START

            item = PaymentItem()
            item.itemId = master.id
            item.quantity = buynum
            paymentdata.paymentItems = [item]

            url = UrlMaker.shoppay()
            url = OSAUtil.addQuery(url, 'paymentId', paymentdata.paymentId)
            url = OSAUtil.addQuery(url, Defines.URLQUERY_STATE,
                                   PaymentData.Status.COMPLETED)
            transactionUrl = self.makeAppLinkUrlRedirect(url)
        else:
            if self.osa_util.is_admin_access:
                # このアクセスは対処しなくてもいいでしょ..
                url = UrlMaker.shopresult(mid)
                self.appRedirect(self.makeAppLinkUrlRedirect(url))
                return

            data = PaymentPostRequestData()
            data.callbackUrl = self.makeAppLinkUrl(UrlMaker.shoppay())
            data.finishPageUrl = self.makeAppLinkUrl(UrlMaker.shopresult(mid))
            data.message = master.text
            data.addItem(master.id, master.name, master.price, buynum,
                         self.makeAppLinkUrlImg(master.thumb), master.text)

            request = self.osa_util.makeApiRequest(ApiNames.PaymentPost, data)
            self.addAppApiRequest('payment_start', request)

            ret_data = self.execute_api()

            paymentresult = ret_data['payment_start'].get()
            transactionUrl = paymentresult.transactionUrl

            # PostのレスポンスデータはUrlとステータスしか入ってない...
            item = PaymentItem()
            item.itemId = master.id
            item.quantity = buynum

            paymentdata = PaymentData()
            paymentdata.paymentId = paymentresult.paymentId
            paymentdata.status = paymentresult.status
            paymentdata.paymentItems = data._paymentItems

        mgr = db_util.run_in_transaction(Handler.tr_create_entry, v_player,
                                         paymentdata, self.__now)
        mgr.write_end()

        self.appRedirect(transactionUrl)
コード例 #7
0
 def procPc(self):
     def redirect_to_app(url):
         self.html_param['url_redirect'] = url
         self.writeAppHtml('gacha/do_redirect')
     
     model_mgr = self.getModelMgr()
     v_player = self.getViewerPlayer()
     master = self.getGachaMaster()
     playcount = self.getGachaPlayCount()
     
     seatplaydata = self.getSeatPlayData()
     is_first = 0 < BackendApi.get_gacha_firstplay_restnum(master, playcount, self.__now, seatplaydata=seatplaydata)
     continuity = BackendApi.get_gacha_continuity_num(model_mgr, master, v_player, is_first)
     
     stock = BackendApi.get_gacha_stock(model_mgr, master, playcount, using=settings.DB_READONLY)
     if stock is not None and stock < 1:
         # これ以上引き抜けない.
         url = OSAUtil.addQuery(UrlMaker.gacha(), Defines.URLQUERY_GTYPE, Defines.GachaConsumeType.GTYPE_NAMES[master.consumetype])
         redirect_to_app(self.makeAppLinkUrlRedirect(url))
         return
     elif master.consumetype == Defines.GachaConsumeType.MINI_SEAT:
         # ミニシートは1周だけ.
         seatplaycount = self.getSeatPlayCount()
         if seatplaycount and 0 < seatplaycount.lap:
             url = OSAUtil.addQuery(UrlMaker.gacha(), Defines.URLQUERY_GTYPE, Defines.GachaConsumeType.GTYPE_NAMES[master.consumetype])
             redirect_to_app(self.makeAppLinkUrlRedirect(url))
             return
     elif not self.checkStep(master, playcount):
         url = OSAUtil.addQuery(UrlMaker.gacha(), Defines.URLQUERY_GTYPE, Defines.GachaConsumeType.GTYPE_NAMES[master.consumetype])
         redirect_to_app(self.makeAppLinkUrlRedirect(url))
         return
     
     if settings_sub.IS_LOCAL:
         # ローカル動作確認用に課金トランザクション情報を作成.
         paymentdata = PaymentData()
         paymentdata.paymentId = "%s%s" % (v_player.dmmid, OSAUtil.makeSessionID())
         paymentdata.status = PaymentData.Status.START
         
         item = PaymentItem()
         item.itemId = master.id
         item.quantity = 1
         paymentdata.paymentItems = [item]
         
         url = UrlMaker.gachapay()
         url = OSAUtil.addQuery(url, 'paymentId', paymentdata.paymentId)
         url = OSAUtil.addQuery(url, Defines.URLQUERY_STATE, PaymentData.Status.COMPLETED)
         transactionUrl = self.makeAppLinkUrlRedirect(url)
         
         mgr = db_util.run_in_transaction(Handler.tr_create_entry, v_player, paymentdata, continuity, self.__now)
         mgr.write_end()
         
         redirect_to_app(transactionUrl)
     else:
         price = BackendApi.get_consumevalue(master, continuity, is_first, playcount, seatplaydata=seatplaydata)
         self.html_param['sku_id'] = master.id
         self.html_param['price'] = price
         self.html_param['count'] = 1
         self.html_param['name'] = master.name
         self.html_param['description'] = master.text
         if self.is_pc:
             self.html_param['image_url'] = self.makeAppLinkUrlStatic('img/pc/'+master.pay_thumb_pc)
         else:
             self.html_param['image_url'] = self.makeAppLinkUrlImgMedium(master.pay_thumb)
         self.html_param['finish_page_url'] = self.makeAppLinkUrl(UrlMaker.gachaanim(master.id, v_player.req_confirmkey))
         
         self.writeAppHtml('gacha/do')
コード例 #8
0
    def procPayment(self):
        model_mgr = self.getModelMgr()
        v_player = self.getViewerPlayer()
        master = self.getGachaMaster()
        playcount = self.getGachaPlayCount()
        
        seatplaydata = self.getSeatPlayData()
        is_first = 0 < BackendApi.get_gacha_firstplay_restnum(master, playcount, self.__now, seatplaydata=seatplaydata)
        continuity = BackendApi.get_gacha_continuity_num(self.getModelMgr(), master, v_player, is_first)
        
        stock = BackendApi.get_gacha_stock(model_mgr, master, playcount, using=settings.DB_READONLY)
        if stock is not None and stock < 1:
            # これ以上引き抜けない.
            url = OSAUtil.addQuery(UrlMaker.gacha(), Defines.URLQUERY_GTYPE, Defines.GachaConsumeType.GTYPE_NAMES[master.consumetype])
            self.appRedirect(self.makeAppLinkUrlRedirect(url))
            return
        elif master.consumetype == Defines.GachaConsumeType.MINI_SEAT:
            # ミニシートは1周だけ.
            seatplaycount = self.getSeatPlayCount()
            if seatplaycount and 0 < seatplaycount.lap:
                url = OSAUtil.addQuery(UrlMaker.gacha(), Defines.URLQUERY_GTYPE, Defines.GachaConsumeType.GTYPE_NAMES[master.consumetype])
                self.appRedirect(self.makeAppLinkUrlRedirect(url))
                return
        elif not self.checkStep(master, playcount):
            url = OSAUtil.addQuery(UrlMaker.gacha(), Defines.URLQUERY_GTYPE, Defines.GachaConsumeType.GTYPE_NAMES[master.consumetype])
            self.appRedirect(self.makeAppLinkUrlRedirect(url))
            return
        
        # ここまで来たら購入出来るのが確定..
        if settings_sub.IS_LOCAL:
            # ローカル動作確認用に課金トランザクション情報を作成.
            paymentdata = PaymentData()
            paymentdata.paymentId = "%s%s" % (v_player.dmmid, OSAUtil.makeSessionID())
            paymentdata.status = PaymentData.Status.START
            
            item = PaymentItem()
            item.itemId = master.id
            item.quantity = 1
            paymentdata.paymentItems = [item]
            
            url = UrlMaker.gachapay()
            url = OSAUtil.addQuery(url, 'paymentId', paymentdata.paymentId)
            url = OSAUtil.addQuery(url, Defines.URLQUERY_STATE, PaymentData.Status.COMPLETED)
            transactionUrl = self.makeAppLinkUrlRedirect(url)
        else:
            kind = BackendApi.check_payment_lostrecords(v_player.id)
            if kind == 'gacha':
                modellist = BackendApi.get_gachapaymententry_list(v_player.id, False, 1, 0, using=settings.DB_READONLY)
                def updateGacha(paymentId, status):
                    if status == PaymentData.Status.COMPLETED:
                        # 購入書き込み.
                        self.writePlayPaymentGacha(paymentId)
                    elif status == PaymentData.Status.CANCEL:
                        # キャンセル書き込み.
                        self.writeGachaCancel(paymentId)
                    elif status == PaymentData.Status.TIMEOUT:
                        # タイムアウト書き込み.
                        self.writeGachaTimeout(paymentId)
                
                if modellist:
                    for model in modellist:
                        paymentId = model.id
                        status = BackendApi.get_restful_paymentrecord_status(self, paymentId)
                        updateGacha(paymentId, status)
                else:
                    BackendApi.delete_payment_lostrecords_flag(v_player.id)
            
            data = PaymentPostRequestData()
            data.callbackUrl = self.makeAppLinkUrl(UrlMaker.gachapay())
            data.finishPageUrl = self.makeAppLinkUrl(UrlMaker.gachaanim(master.id, v_player.req_confirmkey))
            data.message = master.text
            
            price = BackendApi.get_consumevalue(master, continuity, is_first, playcount, seatplaydata=seatplaydata)
            if self.is_pc:
                image_url = self.makeAppLinkUrlStatic('img/pc/'+master.pay_thumb_pc)
            else:
                image_url = self.makeAppLinkUrlImgMedium(master.pay_thumb)
            data.addItem(master.id, master.name, price, 1, image_url, master.text)
            
            request = self.osa_util.makeApiRequest(ApiNames.PaymentPost, data)
            self.addAppApiRequest('payment_start', request)
            
            ret_data = self.execute_api()
            
            paymentresult = ret_data['payment_start'].get()
            transactionUrl = paymentresult.transactionUrl
            
            # PostのレスポンスデータはUrlとステータスしか入ってない...
            item = PaymentItem()
            item.itemId = master.id
            item.quantity = 1
            
            paymentdata = PaymentData()
            paymentdata.paymentId = paymentresult.paymentId
            paymentdata.status = paymentresult.status
            paymentdata.paymentItems = data._paymentItems

        mgr = db_util.run_in_transaction(Handler.tr_create_entry, v_player, paymentdata, continuity, self.__now)
        mgr.write_end()
        
        self.appRedirect(transactionUrl)