Example #1
0
    def update_cabaretclub_proceed(self, uid, storemaster_all_dict,
                                   section_lasttime):
        store_list = CabaClubStorePlayerData.fetchByOwner(
            uid, using=settings.DB_READONLY)
        if not store_list:
            return

        open_stores = [store for store in store_list if store.is_open]
        for store in open_stores:
            storemaster = storemaster_all_dict[store.mid]
            store_set = CabaclubStoreSet(storemaster, store)
            lasttime = min(
                section_lasttime,
                store_set.get_limit_time() - timedelta(microseconds=1))
            if (lasttime - store.utime
                ).total_seconds() < storemaster.customer_interval:
                return

            try:
                db_util.run_in_transaction(self.tr_write, uid, storemaster,
                                           lasttime)
            except CabaretError as err:
                if err.code == CabaretError.Code.ALREADY_RECEIVED:
                    pass
                else:
                    DbgLogger.write_error(err.value)
                    raise
Example #2
0
 def check(self):
     # 店舗情報の確認.
     storeplayerdata = CabaClubStorePlayerData.getByKey(
         CabaClubStorePlayerData.makeID(self.__player.id,
                                        self.__storemaster.id))
     store = CabaclubStoreSet(self.__storemaster, storeplayerdata)
     if not store.is_alive(OSAUtil.get_now()):
         raise AppTestError(u'期限が切れています')
     elif not store.playerdata.is_open:
         raise AppTestError(u'開店していません')
     elif storeplayerdata.utime.strftime(
             "%Y%m%d%H%M%S") != self.__cabaclub_dummy.now.strftime(
                 "%Y%m%d%H%M%S"):
         raise AppTestError(u'utimeが正しくありません')
     elif storeplayerdata.etime.strftime(
             "%Y%m%d%H%M%S") != self.__cabaclub_dummy.now.strftime(
                 "%Y%m%d%H%M%S"):
         raise AppTestError(u'etimeが正しくありません')
     elif storeplayerdata.event_id != self.__eventmaster.id:
         raise AppTestError(u'イベントが設定されていません')
     # 獲得ポイントの確認.
     scoredata_weekly = CabaClubScorePlayerDataWeekly.getByKey(
         self.__cabaclub_dummy.score_weekly.id)
     scoredata_weekly_prev = CabaClubScorePlayerDataWeekly.getByKey(
         self.__cabaclub_dummy.score_weekly_prev.id)
     customer_thisweek, proceeds_thisweek = self.calcCustomerAndProceeds(
         self.__cabaclub_dummy.master, self.__storemaster, 1,
         self.__storeplayerdata.scoutman_add,
         self.__cabaclub_dummy.cardlist, 100, 100)
     customer_lastweek, proceeds_lastweek = self.calcCustomerAndProceeds(
         self.__cabaclub_dummy.master, self.__storemaster,
         self.__exec_cnt - 1, self.__storeplayerdata.scoutman_add,
         self.__cabaclub_dummy.cardlist, 100 * (self.__exec_cnt - 1),
         100 * (self.__exec_cnt - 1))
     customer = customer_thisweek + customer_lastweek
     proceeds = proceeds_thisweek + proceeds_lastweek
     if (storeplayerdata.customer -
             self.__storeplayerdata.customer) != customer:  # 仮.
         raise AppTestError(u'集客数が正しくありません')
     elif (storeplayerdata.proceeds -
           self.__storeplayerdata.proceeds) != proceeds:  # 仮.
         raise AppTestError(u'売上が正しくありません')
     elif (scoredata_weekly.customer -
           self.__cabaclub_dummy.score_weekly.customer
           ) != customer_thisweek:  # 仮.
         raise AppTestError(u'週間集客数が正しくありません')
     elif (scoredata_weekly.proceeds -
           self.__cabaclub_dummy.score_weekly.proceeds
           ) != proceeds_thisweek:  # 仮.
         raise AppTestError(u'週間売上が正しくありません')
     elif (scoredata_weekly_prev.customer -
           self.__cabaclub_dummy.score_weekly_prev.customer
           ) != customer_lastweek:  # 仮.
         raise AppTestError(u'先週の週間集客数が正しくありません')
     elif (scoredata_weekly_prev.proceeds -
           self.__cabaclub_dummy.score_weekly_prev.proceeds
           ) != proceeds_lastweek:  # 仮.
         raise AppTestError(u'先週の週間売上が正しくありません')
Example #3
0
 def check(self):
     storeplayerdata = CabaClubStorePlayerData.getByKey(
         CabaClubStorePlayerData.makeID(self.__player.id,
                                        self.__storemaster.id))
     store = CabaclubStoreSet(self.__storemaster, storeplayerdata)
     if not store.is_alive(OSAUtil.get_now()):
         raise AppTestError(u'期限が切れています')
     elif not store.playerdata.is_open:
         raise AppTestError(u'開店していません')
Example #4
0
 def check(self):
     arr = (
         'cabaclub_management_info',
         'cabaclubstoreevent',
         'url_store',
         'url_title',
     )
     for k in arr:
         if not self.response.has_key(k):
             raise AppTestError(u'%sが設定されていない' % k)
     # 店舗情報の確認.
     storeplayerdata = CabaClubStorePlayerData.getByKey(
         CabaClubStorePlayerData.makeID(self.__player.id,
                                        self.__storemaster.id))
     store = CabaclubStoreSet(self.__storemaster, storeplayerdata)
     if not store.is_alive(OSAUtil.get_now()):
         raise AppTestError(u'期限が切れています')
     elif not store.playerdata.is_open:
         raise AppTestError(u'開店していません')
     elif storeplayerdata.utime.strftime(
             "%Y%m%d%H%M%S") != self.__cabaclub_dummy.now.strftime(
                 "%Y%m%d%H%M%S"):
         raise AppTestError(u'utimeが正しくありません')
     elif storeplayerdata.etime.strftime(
             "%Y%m%d%H%M%S") != self.__cabaclub_dummy.now.strftime(
                 "%Y%m%d%H%M%S"):
         raise AppTestError(u'etimeが正しくありません')
     elif storeplayerdata.event_id != self.__eventmaster.id:
         raise AppTestError(u'イベントが設定されていません')
     # 獲得ポイントの確認.
     scoredata_weekly = CabaClubScorePlayerDataWeekly.getByKey(
         self.__cabaclub_dummy.score_weekly.id)
     customer, proceeds = self.calcCustomerAndProceeds(
         self.__cabaclub_dummy.master, self.__storemaster, self.__exec_cnt,
         self.__storeplayerdata.scoutman_add,
         self.__cabaclub_dummy.cardlist, 100 * self.__exec_cnt,
         100 * self.__exec_cnt)
     if (storeplayerdata.customer -
             self.__storeplayerdata.customer) != customer:  # 仮.
         raise AppTestError(u'集客数が正しくありません')
     elif (storeplayerdata.proceeds -
           self.__storeplayerdata.proceeds) != proceeds:  # 仮.
         raise AppTestError(u'売上が正しくありません')
     elif (scoredata_weekly.customer -
           self.__cabaclub_dummy.score_weekly.customer) != customer:  # 仮.
         raise AppTestError(u'週間集客数が正しくありません')
     elif (scoredata_weekly.proceeds -
           self.__cabaclub_dummy.score_weekly.proceeds) != proceeds:  # 仮.
         raise AppTestError(u'週間売上が正しくありません')
Example #5
0
 def check(self):
     # 店舗情報の確認.
     storeplayerdata = CabaClubStorePlayerData.getByKey(
         CabaClubStorePlayerData.makeID(self.__player.id,
                                        self.__storemaster.id))
     store = CabaclubStoreSet(self.__storemaster, storeplayerdata)
     if not store.is_alive(OSAUtil.get_now()):
         raise AppTestError(u'借り入れできていません')
     elif storeplayerdata.customer != 0 or storeplayerdata.proceeds != 0:
         raise AppTestError(u'スコア情報がリセットされていません')
     # 特別なマネーの確認.
     scoredata = CabaClubScorePlayerData.getByKey(self.__player.id)
     if (self.__cabaclub_dummy.score.money -
             scoredata.money) != self.__storemaster.cost_0:
         raise AppTestError(u'特別なマネーが正しく消費されていません')
Example #6
0
 def check(self):
     # 店舗情報の確認.
     storeplayerdata = CabaClubStorePlayerData.getByKey(
         CabaClubStorePlayerData.makeID(self.__player.id,
                                        self.__storemaster.id))
     store = CabaclubStoreSet(self.__storemaster, storeplayerdata)
     if not store.is_alive(OSAUtil.get_now()):
         raise AppTestError(u'期限が切れています')
     elif not store.playerdata.is_open:
         raise AppTestError(u'開店していません')
     elif storeplayerdata.utime.strftime(
             "%Y%m%d%H%M%S") != self.__cabaclub_dummy.now.strftime(
                 "%Y%m%d%H%M%S"):
         raise AppTestError(u'utimeが正しくありません')
     elif storeplayerdata.etime.strftime("%Y%m%d%H%M%S") != (
             self.__cabaclub_dummy.now - datetime.timedelta(
                 seconds=(self.__storemaster.customer_interval *
                          (self.__exec_cnt - 1)) %
                 Defines.CABARETCLUB_STORE_EVENT_INTERVAL)
     ).strftime("%Y%m%d%H%M%S"):
         raise AppTestError(u'etimeが正しくありません')
     elif storeplayerdata.event_id != self.__eventmaster.id:
         raise AppTestError(u'イベントが設定されていません')
     # 獲得ポイントの確認.
     scoredata_weekly = CabaClubScorePlayerDataWeekly.getByKey(
         self.__cabaclub_dummy.score_weekly.id)
     customer, proceeds = self.calcCustomerAndProceeds(
         self.__cabaclub_dummy.master, self.__storemaster, self.__exec_cnt,
         self.__storeplayerdata.scoutman_add,
         self.__cabaclub_dummy.cardlist,
         self.__eventmaster.customer_up * self.__exec_cnt,
         self.__eventmaster.proceeds_up * self.__exec_cnt)
     if (storeplayerdata.customer -
             self.__storeplayerdata.customer) != customer:  # 仮.
         raise AppTestError(u'集客数が正しくありません')
     elif (storeplayerdata.proceeds -
           self.__storeplayerdata.proceeds) != proceeds:  # 仮.
         raise AppTestError(u'売上が正しくありません')
     elif (scoredata_weekly.customer -
           self.__cabaclub_dummy.score_weekly.customer) != customer:  # 仮.
         raise AppTestError(u'週間集客数が正しくありません')
     elif (scoredata_weekly.proceeds -
           self.__cabaclub_dummy.score_weekly.proceeds) != proceeds:  # 仮.
         raise AppTestError(u'週間売上が正しくありません')
Example #7
0
    def process(self):
        args = self.getUrlArgs('/item_useyesno/')
        try:
            mid = int(args.get(0))
            use_num = int(self.request.get(Defines.URLQUERY_NUMBER, 1))
            if use_num < 1:
                raise CabaretError()
        except:
            raise CabaretError(u'リクエストが正しくありません',
                               CabaretError.Code.ILLEGAL_ARGS)

        model_mgr = self.getModelMgr()
        v_player = self.getViewerPlayer()
        # 使用するアイテム情報.
        num = BackendApi.get_item_nums(model_mgr,
                                       v_player.id, [mid],
                                       using=settings.DB_READONLY).get(mid, 0)
        if num < 1:
            # 手に入れたことすらない.
            if settings_sub.IS_LOCAL:
                raise CabaretError(u'リクエストが正しくありません',
                                   CabaretError.Code.ILLEGAL_ARGS)
            url = UrlMaker.itemlist()
            self.appRedirect(self.makeAppLinkUrlRedirect(url))
            return

        master = BackendApi.get_itemmaster(model_mgr,
                                           mid,
                                           using=settings.DB_READONLY)
        self.html_param['item'] = Objects.item(self, master, num)
        self.html_param['use_num'] = use_num

        if num < use_num:
            self.html_param['is_not_enough'] = True
        elif mid in Defines.ItemEffect.ACTION_RECOVERY_ITEMS:
            if v_player.get_ap() == v_player.get_ap_max():
                self.html_param['is_overlimit'] = True
        # テンション全回復.
        elif mid in Defines.ItemEffect.TENSION_RECOVERY_ITEMS:
            if v_player.get_bp() == v_player.get_bp_max():
                self.html_param['is_overlimit'] = True

        elif mid == Defines.ItemEffect.CARD_BOX_EXPANSION:
            if Defines.CARDLIMITITEM_MAX < (v_player.cardlimititem +
                                            master.evalue):
                self.html_param['is_overlimit'] = True
        elif mid in Defines.ItemEffect.SCOUT_GUM_ITEMS:
            eventmaster = BackendApi.get_current_scouteventmaster(
                model_mgr, using=settings.DB_READONLY)
            if eventmaster is None:
                self.html_param['is_noevent'] = True
            else:
                playdata = BackendApi.get_event_playdata(
                    model_mgr,
                    eventmaster.id,
                    v_player.id,
                    using=settings.DB_READONLY)
                now = OSAUtil.get_now()
                if now <= playdata.feveretime:
                    self.html_param['is_fever'] = True
        elif mid == Defines.ItemEffect.CABACLUB_SCOUTMAN:
            # 店舗.
            cabaclubstoremaster = None
            if Defines.FromPages.CABACLUB_STORE == self.getFromPageName():
                args = self.getFromPageArgs()
                if args:
                    cabaclubstoremaster = BackendApi.get_cabaretclub_store_master(
                        model_mgr, int(args[0]), using=settings.DB_READONLY)
            if cabaclubstoremaster is None:
                raise CabaretError(u'店舗が存在しません',
                                   CabaretError.Code.ILLEGAL_ARGS)
            playerdata = BackendApi.get_cabaretclub_storeplayerdata(
                model_mgr,
                v_player.id,
                cabaclubstoremaster.id,
                using=settings.DB_READONLY)
            storeset = CabaclubStoreSet(cabaclubstoremaster, playerdata)
            if not storeset.is_alive(OSAUtil.get_now()):
                self.appRedirect(
                    self.makeAppLinkUrlRedirect(
                        UrlMaker.cabaclubstore(cabaclubstoremaster.id)))
                return
            # 使用可能にする.
            self.html_param['item']['master']['useable'] = True
            # 残りを確認.
            rest = cabaclubstoremaster.scoutman_add_max - storeset.playerdata.scoutman_add
            if rest < (master.evalue * use_num):
                self.html_param['is_overlimit'] = True
        elif mid == Defines.ItemEffect.CABACLUB_PREFERENTIAL:
            itemdata = BackendApi.get_cabaretclub_item_playerdata(
                model_mgr, v_player.id, using=settings.DB_READONLY)
            storeset = CabaclubStoreSet(None, None, itemdata=itemdata)
            if storeset.get_current_preferential_item_id(
                    OSAUtil.get_now()) == mid:
                self.html_param['is_overlimit'] = True
        elif mid == Defines.ItemEffect.CABACLUB_BARRIER:
            itemdata = BackendApi.get_cabaretclub_item_playerdata(
                model_mgr, v_player.id, using=settings.DB_READONLY)
            storeset = CabaclubStoreSet(None, None, itemdata=itemdata)
            if storeset.get_current_barrier_item_id(OSAUtil.get_now()) == mid:
                self.html_param['is_overlimit'] = True

        # アイテム結果URLを取得.


#        url = OSAUtil.addQuery(UrlMaker.item_use(mid, num), Defines.URLQUERY_NUMBER, use_num)
        url = OSAUtil.addQuery(
            UrlMaker.item_use2(mid, v_player.req_confirmkey),
            Defines.URLQUERY_NUMBER, use_num)
        self.html_param['url_use'] = self.makeAppLinkUrl(url)

        self.putFromBackPageLinkUrl()

        if mid in Defines.ItemEffect.SCOUT_GUM_ITEMS:
            eventmaster = BackendApi.get_current_scouteventmaster(
                model_mgr, using=settings.DB_READONLY)
            if eventmaster is not None:
                self.html_param[
                    'url_scoutevent_scouttop'] = self.makeAppLinkUrl(
                        UrlMaker.scoutevent())

        self.writeAppHtml('item/useyesno')
Example #8
0
 def __procView(self, uid):
     """詳細表示.
     """
     model_mgr = self.getModelMgr()
     now = OSAUtil.get_now()
     
     playerlist = BackendApi.get_players(self, [uid], using=backup_db)
     if not playerlist:
         self.putAlertToHtmlParam(u'見つかりませんでした', AlertCode.ERROR)
         self.__procSearch()
         return
     player = playerlist[0]
     person = BackendApi.get_dmmplayers(self, [player], using=backup_db, do_execute=True).get(player.dmmid)
     obj_player = Objects.player(self, player, person)
     obj_player['userType'] = person.userType or u'一般'
     self.html_param['player'] = obj_player
     
     # 招待してくれた人.
     invitedata = BackendApi.get_model(model_mgr, InviteData, player.dmmid, using=backup_db)
     if invitedata and invitedata.fid:
         playerlist = BackendApi.get_players(self, [invitedata.fid], [], using=backup_db, model_mgr=model_mgr)
         invite_from_player = playerlist[0] if playerlist else None
         if invite_from_player:
             invite_from_person = BackendApi.get_dmmplayers(self, [invite_from_player], using=backup_db, do_execute=True).get(invite_from_player.dmmid)
             self.html_param['invitedata'] = {
                 'url' : self.makeAppLinkUrlAdmin(UrlMaker.view_player(invite_from_player.id)),
                 'player' : Objects.player(self, invite_from_player, invite_from_person),
                 'ctime' : invitedata.ctime,
                 'state' : Defines.InviteState.NAMES[invitedata.state],
             }
     
     # 招待した人数.
     inviterecordlist = Invite.fetchValues(filters={'uid':player.id}, order_by='mid', using=backup_db)
     if inviterecordlist:
         midlist = [inviterecord.mid for inviterecord in inviterecordlist]
         invitemasterdict = BackendApi.get_model_dict(model_mgr, InviteMaster, midlist, get_instance=True, using=backup_db)
         
         obj_inviterecordlist = []
         for inviterecord in inviterecordlist:
             invitemaster = invitemasterdict.get(inviterecord.mid)
             obj_inviterecordlist.append({
                 'id' : invitemaster.id,
                 'name' : invitemaster.name,
                 'cnt' : inviterecord.cnt,
             })
         self.html_param['inviterecordlist'] = obj_inviterecordlist
     
     regist = False
     if player.getModel(PlayerRegist) is not None:
         regist = True
         
         # アイテム.
         itemidlist = Defines.ItemEffect.NAMES.keys()
         itemmasterdict = BackendApi.get_model_dict(model_mgr, ItemMaster, itemidlist, using=backup_db)
         itemnums = BackendApi.get_model_list(model_mgr, Item, [Item.makeID(uid, iid) for iid in Defines.ItemEffect.NAMES.keys()], using=backup_db)
         iteminfolist = []
         for item in itemnums:
             master = itemmasterdict.get(item.mid)
             if master:
                 iteminfolist.append({
                     'master' : master,
                     'nums' : item,
                 })
         self.html_param['itemlist'] = iteminfolist
         
         # 所持カード.
         deck = BackendApi.get_deck(uid, arg_model_mgr=model_mgr, using=backup_db)
         raiddeck = BackendApi.get_raid_deck(uid, arg_model_mgr=model_mgr, using=backup_db)
         
         cardlist = BackendApi.get_card_list(uid, arg_model_mgr=model_mgr, using=backup_db)
         obj_cardlist = []
         obj_deckcards = {}
         obj_raiddeckcards = {}
         cardcounts = {}
         for cardset in cardlist:
             obj_card = Objects.card(self, cardset, deck)
             obj_card['way'] = Defines.CardGetWayType.NAMES.get(cardset.card.way, u'不明')
             obj_card['raiddeckmember'] = raiddeck.is_member(cardset.id)
             if obj_card['deckmember']:
                 obj_deckcards[cardset.id] = obj_card
             elif obj_card['raiddeckmember']:
                 obj_card['raiddeckmember'] = True
                 obj_raiddeckcards[cardset.id] = obj_card
             else:
                 obj_cardlist.append(obj_card)
             mid = cardset.master.id
             data = cardcounts[mid] = cardcounts.get(mid) or {'name':cardset.master.name, 'cnt':0}
             data['cnt'] += 1
         self.html_param['deckcardlist'] = [obj_deckcards[cardid] for cardid in deck.to_array()]
         self.html_param['raiddeckcardlist'] = [obj_raiddeckcards[cardid] for cardid in raiddeck.to_array() if obj_raiddeckcards.get(cardid)]
         self.html_param['cardlist'] = obj_cardlist
         self.html_param['cardcounts'] = cardcounts
         
         # フレンド.
         table = {
             'friendlist' : BackendApi.get_friend_idlist,
             'friendrequestlist' : BackendApi.get_friendrequest_send_idlist,
             'friendreceivelist' : BackendApi.get_friendrequest_receive_idlist,
         }
         for k,func in table.items():
             uidlist = func(uid, arg_model_mgr=model_mgr, using=backup_db)
             friendlist = BackendApi.get_players(self, uidlist, [], using=backup_db)
             friendmodels = BackendApi.get_model_dict(model_mgr, Friend, [Friend.makeID(uid, fid) for fid in uidlist], using=backup_db)
             obj_friendlist = []
             for friend in friendlist:
                 obj_friend = self.makeListPlayer(friend)
                 friendmodel = friendmodels.get(Friend.makeID(uid, friend.id))
                 if friendmodel:
                     obj_friend['f_time'] = friendmodel.ctime.strftime("%Y/%m/%d %H:%M:%S")
                 obj_friendlist.append(obj_friend)
             self.html_param[k] = obj_friendlist
         
         # バトル情報.
         self.html_param['battleKOs'] = BackendApi.get_battleKOs(uid, arg_model_mgr=model_mgr, using=backup_db)
         battleplayer = BackendApi.get_battleplayer(model_mgr, uid, using=backup_db)
         if battleplayer:
             # 最大ランク.
             self.html_param['max_rank'] = BackendApi.get_battlerank_max(model_mgr, using=backup_db)
             
             rankmaster = BackendApi.get_battlerank(model_mgr, battleplayer.rank, using=backup_db)
             self.html_param['battleplayer'] = Objects.battleplayer(self, battleplayer, rankmaster)
         
         # ハプニング.
         if player.getModel(PlayerHappening):
             happeningraidset = BackendApi.get_happeningraidset(model_mgr, player.happening, using=backup_db)
             if happeningraidset:
                 model_happening = happeningraidset.happening.happening
                 prize = BackendApi.aggregate_happeningprize(model_happening, model_happening.is_canceled())
                 self.html_param['happening'] = Objects.happening(self, happeningraidset, prize)
         
         self.html_param['is_ban'] = not BackendApi.check_player_ban(model_mgr, uid, using=backup_db)
         
         # スカウトイベント.
         scevent = []
         config = BackendApi.get_current_scouteventconfig(model_mgr, using=backup_db)
         if config:
             eventmaster = BackendApi.get_scouteventmaster(model_mgr, config.mid, using=backup_db)
             if eventmaster:
                 playdata = BackendApi.get_event_playdata(model_mgr, eventmaster.id, uid, using=backup_db)
                 arr = BackendApi.get_event_stages(model_mgr, [playdata.stage], using=backup_db)
                 stage = arr[0] if arr else None
                 arr = BackendApi.get_event_stages(model_mgr, [playdata.cleared], using=backup_db)
                 cleared = arr[0] if arr else None
                 scorerecord = BackendApi.get_scoutevent_scorerecord(model_mgr, eventmaster.id, uid, using=backup_db)
                 produce_list = BackendApi.get_scoutevent_presentprizemaster_by_eventid(model_mgr, eventmaster.id, using=backup_db)
                 produce_data = BackendApi.get_scoutevent_presentnums_record(model_mgr, eventmaster.id, uid, using=backup_db)
                 if produce_data:
                     nums = produce_data.nums
                 else:
                     nums = {}
                 obj_produce_list = [(produce.name, nums.get(produce.number, 0)) for produce in produce_list]
                 
                 tanzaku_list = BackendApi.get_scoutevent_tanzakumaster_by_eventid(model_mgr, eventmaster.id, using=backup_db)
                 obj_tanzaku_list = None
                 current_cast_number = -1
                 if tanzaku_list:
                     tanzakudata = ScoutEventTanzakuCastData.getByKey(ScoutEventTanzakuCastData.makeID(uid, eventmaster.id), using=backup_db)
                     current_cast_number = tanzakudata.current_cast if tanzakudata else -1
                     obj_tanzaku_list = [dict(Objects.scoutevent_tanzaku(self, tanzakumaster, tanzakudata), current=current_cast_number==tanzakumaster.number) for tanzakumaster in tanzaku_list]
                 
                 event = {'name': eventmaster.name,
                          'stage': stage,
                          'cleared': cleared,
                          'scorerecord': scorerecord,
                          'produce_list' : obj_produce_list,
                          'tanzaku_list' : obj_tanzaku_list,
                         }
                 scevent.insert(0, event)
         self.html_param['scevent'] = scevent
         
         # バトルイベント.
         battleevent_config = BackendApi.get_current_battleeventconfig(model_mgr, using=backup_db)
         if battleevent_config.mid:
             eventmaster = BackendApi.get_battleevent_master(model_mgr, battleevent_config.mid, using=backup_db)
             if eventmaster:
                 eventid = eventmaster.id
                 obj_battleevent = {
                     'id' : eventmaster.id,
                     'name' : eventmaster.name,
                     'point' : 0,
                     'point_total' : 0,
                     'rank' : 0,
                     'rankname' : u'未参加',
                     'fame' : 0,
                     'fame_next' : 0,
                 }
                 scorerecord = BackendApi.get_battleevent_scorerecord(model_mgr, eventid, uid, using=backup_db)
                 if scorerecord:
                     obj_battleevent.update({
                         'point' : scorerecord.getPointToday(),
                         'point_total' : scorerecord.point_total,
                     })
                 rankrecord = BackendApi.get_battleevent_rankrecord(model_mgr, eventid, uid, using=backup_db)
                 if rankrecord:
                     rank = rankrecord.getRank(battleevent_config)
                     rankmaster = BackendApi.get_battleevent_rankmaster(model_mgr, eventid, rank, using=backup_db)
                     
                     obj_battleevent.update({
                         'rank' : rank,
                         'rankname' : rankmaster.name if rankmaster else u'不明',
                         'fame' : rankrecord.fame,
                         'fame_next' : rankrecord.fame_next,
                     })
                 # ランク別バトルポイント.
                 rankmasterlist = BackendApi.get_battleevent_rankmaster_by_eventid(model_mgr, eventid, using=backup_db, do_check_open=False)
                 idlist = [BattleEventScorePerRank.makeID(uid, BattleEventScorePerRank.makeMid(eventid, rankmaster.rank)) for rankmaster in rankmasterlist]
                 scoredata_dict = BackendApi.get_model_dict(model_mgr, BattleEventScorePerRank, idlist, using=backup_db, key=lambda x:x.rank)
                 obj_rankscorelist = []
                 rankmasterlist.sort(key=lambda x:x.rank, reverse=True)
                 for rankmaster in rankmasterlist:
                     obj_rankscorelist.append({
                         'rank' : rankmaster.rank,
                         'rankname' : rankmaster.name if rankmaster else u'不明',
                         'score' : scoredata_dict[rankmaster.rank].point if scoredata_dict.get(rankmaster.rank) else 0,
                     })
                 obj_battleevent['rankscorelist'] = obj_rankscorelist
                 
                 # 現在の贈り物.
                 presentdata = BackendApi.get_model(model_mgr, BattleEventPresentData, BattleEventPresentData.makeID(uid, eventid), using=backup_db)
                 obj_presentdata = None
                 if presentdata and presentdata.getData():
                     data = presentdata.getData()
                     presentmaster = BackendApi.get_battleeventpresent_master(model_mgr, eventid, data['number'], using=backup_db)
                     contentmaster = BackendApi.get_battleeventpresent_content_master(model_mgr, data['content'], using=backup_db)
                     obj_presentdata = {
                         'present' : presentmaster,
                         'content' : contentmaster,
                         'point' : presentdata.point,
                     }
                 obj_battleevent['presentdata'] = obj_presentdata
                 
                 self.html_param['battleevent'] = obj_battleevent
     
     obj_player['regist'] = regist
     
     # ガチャチケット.
     tickettypes = Defines.GachaConsumeType.GachaTicketType.NAMES.keys()
     ticket_num_models = BackendApi.get_additional_gachaticket_nums(model_mgr, uid, tickettypes, using=backup_db)
     ticket_list = []
     for tickettype in tickettypes:
         num_model = ticket_num_models.get(tickettype)
         ticket_list.append({
             'name' : Defines.GachaConsumeType.GachaTicketType.NAMES[tickettype],
             'num' : num_model.num if num_model else 0,
         })
     self.html_param['ticket_list'] = ticket_list
     
     # ランキングガチャ.
     rankinggachascore_list = RankingGachaScore.fetchByOwner(uid, using=backup_db)
     rankinggacha_master_dict = BackendApi.get_rankinggacha_master_dict(model_mgr, [rankinggachascore.mid for rankinggachascore in rankinggachascore_list], using=backup_db)
     obj_rankinggacha_list = []
     for rankinggachascore in rankinggachascore_list:
         rankinggacha_master = rankinggacha_master_dict.get(rankinggachascore.mid)
         obj_rankinggacha_list.append({
             'id' : rankinggachascore.mid,
             'name' : rankinggacha_master.name if rankinggacha_master else u'不明',
             'single' : rankinggachascore.single,
             'total' : rankinggachascore.total,
             'firstpoint' : rankinggachascore.firstpoint,
             'firsttime' : (rankinggachascore.firsttime or OSAUtil.get_datetime_min()).strftime("%Y-%m-%d %H:%M:%S"),
         })
     self.html_param['rankinggacha_list'] = obj_rankinggacha_list
     
     # 店舗.
     cabaclubstoremaster_all = BackendApi.get_cabaretclub_store_master_all(model_mgr, using=backup_db)
     midlist = [cabaclubstoremaster.id for cabaclubstoremaster in cabaclubstoremaster_all]
     store_set_dict = BackendApi.get_cabaretclub_storeset_dict(model_mgr, uid, midlist, using=backup_db)
     obj_store_list = []
     for cabaclubstoremaster in cabaclubstoremaster_all:
         store_set = store_set_dict.get(cabaclubstoremaster.id) or CabaclubStoreSet(cabaclubstoremaster, None)
         obj = Objects.cabaclubstore(self, store_set, now)
         obj['utime'] = store_set.playerdata.utime
         obj['rtime'] = store_set.playerdata.rtime
         obj['etime'] = store_set.playerdata.etime
         obj_store_list.append(obj)
     self.html_param['cabaclubstore_list'] = obj_store_list
     
     # 称号.
     title_set = BackendApi.get_current_title_set(model_mgr, uid, now, using=backup_db)
     if title_set:
         self.html_param['title'] = Objects.title(self, title_set.master, title_set.playerdata, now)
     
     self.writeAppHtml('infomations/view_player/detail')
Example #9
0
    def handle(self, *args, **options):

        print '================================'
        print 'aggregate_cabaretclub_weekly'
        print '================================'

        last_week_starttime = BackendApi.to_cabaretclub_section_starttime(
            OSAUtil.get_now() - datetime.timedelta(days=7))

        str_year_and_week = args[0] if 0 < len(args) else None
        if str_year_and_week:
            week = int(str_year_and_week[4:])
            first_of_year = DateTimeUtil.strToDateTime(
                "%s%02d" % (str_year_and_week[:4],
                            Defines.CABARETCLUB_EVENT_DATE_CHANGE_TIME),
                "%Y%H")
            # 0週目.
            zero = BackendApi.to_cabaretclub_section_starttime(first_of_year)
            starttime = zero + datetime.timedelta(days=week * 7)
            if last_week_starttime < starttime:
                print u'未完了の週なので集計は行えません'
                return
        else:
            # 指定がない場合は前回の週.
            starttime = last_week_starttime
        print "target:%s" % starttime.strftime("%Y%W")
        endtime = BackendApi.to_cabaretclub_section_endtime(starttime)
        section_lasttime = endtime - datetime.timedelta(microseconds=1)

        model_mgr = ModelRequestMgr()
        self.update_eventconfig_previous_mid(model_mgr, starttime)

        # 店舗のマスターデータ.
        cabaclubstoremaster_dict = dict([
            (cabaclubstoremaster.id, cabaclubstoremaster)
            for cabaclubstoremaster in model_mgr.get_mastermodel_all(
                CabaClubStoreMaster, fetch_deleted=True, using=backup_db)
        ])
        # ユーザIDの最大値.
        uid_max = PlayerTreasure.max_value('id', using=backup_db)
        for uid in xrange(1, uid_max + 1):
            # 所持している店舗.ここはreadonlyで大丈夫.
            store_list = CabaClubStorePlayerData.fetchByOwner(
                uid, using=settings.DB_READONLY)
            if store_list:
                # この週に更新された店舗数.
                update_store_cnt = 0
                # Activeな店舗を週の終了時間まですすめる.
                for store in store_list:
                    cabaclubstoremaster = cabaclubstoremaster_dict[store.mid]
                    if not store.is_open:
                        # 閉じるときに集計しているので必要なし.
                        if starttime <= store.utime:
                            update_store_cnt += 1
                        continue
                    store_set = CabaclubStoreSet(cabaclubstoremaster, store)
                    lasttime = min(
                        section_lasttime,
                        store_set.get_limit_time() -
                        datetime.timedelta(microseconds=1))
                    if (lasttime - store.utime).total_seconds(
                    ) < cabaclubstoremaster.customer_interval:
                        # 獲得時間が経過していないので更新する必要が無い.
                        if starttime <= store.utime:
                            update_store_cnt += 1
                        continue

                    def tr_advance_the_time(uid, cabaclubstoremaster, now):
                        """店舗の時間をすすめる.
                        """
                        model_mgr = ModelRequestMgr()
                        BackendApi.tr_cabaclubstore_advance_the_time_with_checkalive(
                            model_mgr, uid, cabaclubstoremaster, now)
                        model_mgr.write_all()
                        model_mgr.write_end()

                    try:
                        db_util.run_in_transaction(tr_advance_the_time, uid,
                                                   cabaclubstoremaster,
                                                   lasttime)
                    except CabaretError, err:
                        if err.code == CabaretError.Code.ALREADY_RECEIVED:
                            # ユーザー自信が更新した可能性.
                            pass
                        else:
                            DbgLogger.write_error(err.value)
                            raise
                    update_store_cnt += 1
                if 0 < update_store_cnt:
                    # 売り上げに応じた名誉ポイントを配布.
                    def tr_send_point(uid, starttime):
                        """名誉ポイントの配布.
                        """
                        model_mgr = ModelRequestMgr()
                        scoredata_weekly = CabaClubScorePlayerDataWeekly.getByKeyForUpdate(
                            CabaClubScorePlayerDataWeekly.makeID(
                                uid, starttime))
                        if scoredata_weekly is None or scoredata_weekly.flag_aggregate:
                            return 0
                        # 配布する数を計算.
                        cabaclub_honor = int(
                            math.ceil(scoredata_weekly.proceeds / 1000.0))
                        if 0 < cabaclub_honor:
                            # 報酬付与.
                            prizedata = PrizeData.create(
                                cabaclub_honor=cabaclub_honor)
                            BackendApi.tr_add_prize(
                                model_mgr, uid, [prizedata],
                                Defines.TextMasterID.CABARETCLUB_WEEKLY_PRIZE)
                        # 重複防止.
                        scoredata_weekly.flag_aggregate = True
                        model_mgr.set_save(scoredata_weekly)
                        model_mgr.write_all()
                        model_mgr.write_end()
                        return cabaclub_honor

                    cabaclub_honor = db_util.run_in_transaction(
                        tr_send_point, uid, starttime)
                    print '%s...honor=%d' % (uid, cabaclub_honor)
                else:
                    print '%s...not updated' % uid