コード例 #1
0
    def post(self):
        args = self.parser.parse_args()
        user_id = args['user_id']
        player_id = args['player_id']

        playerdata = query(BagPlayer).filter_by(user_id = user_id, player_id = player_id).first()
        trail_card = query(BagTrailCard).filter_by(user_id = user_id,player_id = player_id).first()
        if trail_card is None or trail_card.num <= 0:
            return BagMessage(None,*BagError.NOT_ENOUGH_TRAIL_CARD).response

        #若已有player,续duetime
        if playerdata is not None:
            due = playerdata.duedate
            playerdata.duedate = due + timedelta(trail_card.time)
            trail_card.num -= 1
            if trail_card.num <= 0:
                db.session.delete(trail_card)
            commit()
            return BagMessage(playerdata.player.name, *BagMessage.USING_TRAIL_CARD_ADD_DUETIME).response
        #若没有player,add a player
        else:
            today = datetime.today()
            due = today.replace(day = today.day + trail_card.time)
            player = query(PlayerBase).filter_by(id=player_id).first()
            #contract = '%d年%d月%d日,%d年%d月%d日到期' % (today.year, today.month, today.day, due.year, due.month, due.day)
            contract = 'start:%d:%d:%d,due:%d:%d:%d' % (today.year, today.month, today.day, due.year, due.month, due.day)
            add(BagPlayer(user_id = user_id, player_id = player_id, score = player.score, salary = player.price, duedate = due, contract = contract))
            trail_card.num -= 1
            if trail_card.num <= 0:
                db.session.delete(trail_card)
            commit()
            return BagMessage(player.name, *BagMessage.USING_TRAIL_CARD_ADD_PLAYER).response
コード例 #2
0
ファイル: recruit.py プロジェクト: zwkatgithub/iFantasy
def addPlayer(user_id, player):
    today = datetime.datetime.today()
    duedate = today.replace(year=today.year + 1)
    contract = '一年%d万,%d年%d月%d日签约,%d年%d月%d日到期' % (player.price, today.year,
                                                  today.month, today.day, duedate.year, duedate.month, duedate.day)
    add(BagPlayer(user_id, player.id, player.score, player.price, duedate, contract))
    return {"name": player.name, "id": player.id, "type": "player"}
コード例 #3
0
ファイル: bag.py プロジェクト: xiaolinzi-xl/bishe
    def post(self):
        args = self.parser.parse_args()
        user_id = args['user_id']
        player_id = args['player_id']
        # 判断该user是否已经有这个player
        if BagPlayer.query.filter_by(user_id=user_id,
                                     player_id=player_id).first() is not None:
            return BagMessage(None, *BagError.PLAYER_REPEAT).response

        data = BagPiece.query.filter_by(user_id=user_id,
                                        player_id=player_id).first()
        #判断user是否有piece
        if data is None:
            return BagMessage(None, *BagError.NO_PIECE).response
        piece_data = {}
        piece_data['num'] = data.num
        piece_data['total_num'] = query(Piece).filter_by(
            player_id=player_id).first().total_num
        piece_data['name'] = data.player_base.name

        #判断piece 是否足够合成
        if piece_data['num'] < piece_data['total_num']:
            return BagMessage(None, *BagError.NOT_ENOUGH_PIECE).response

        # 消耗使用的piece
        if piece_data['num'] == piece_data['total_num']:
            db.session.delete(data)
            commit()
        else:
            new_num = piece_data['num'] - piece_data['total_num']
            data.num = new_num
            commit()
        # 合成player
        today = datetime.now()
        due = today.replace(year=today.year + 1)
        player = query(PlayerBase).filter_by(id=player_id).first()
        contract = '一年%d万,%d年%d月%d日签约,%d年%d月%d日到期' % (
            player.price, today.year, today.month, today.day, due.year,
            due.month, due.day)
        add(
            BagPlayer(user_id=user_id,
                      player_id=player_id,
                      score=player.score,
                      salary=player.price,
                      duedate=due,
                      contract=contract))
        commit()
        return BagMessage(player.name,
                          *BagMessage.USING_PIECE_ADD_PLAYER).response