def __init__(self, char_id): self.char_id = char_id try: self.mongo_union_member = MongoUnionMember.objects.get(id=char_id) except DoesNotExist: self.mongo_union_member = MongoUnionMember(id=char_id) self.mongo_union_member.buy_buff_times = {} self.mongo_union_member.save()
def __new__(cls, char_id, union_id=None): mongo_member = MongoUnionMember._get_collection().find_one( {'_id': char_id}, {'joined': 1}) if not mongo_member: return UnionDummy(char_id) char_union_id = mongo_member['joined'] if not char_union_id and not union_id: return UnionDummy(char_id) if not union_id: union_id = char_union_id # FIXME 本来是有这个判断的,但是目前为了省事,对于这个最后返回的是 UnionMember # 其实应该为这个添加一个新类: UnionObserver # 表示自己加入了一个工会,但是要查看其他工会的信息 # if char_union_id != union_id: # return UnionDummy(char_id) mongo_union = MongoUnion._get_collection().find_one({'_id': union_id}, {'owner': 1}) if char_id == mongo_union['owner']: return UnionOwner(char_id, union_id) return UnionMember(char_id, union_id)
def __new__(cls, char_id, union_id=None): mongo_member = MongoUnionMember._get_collection().find_one( {'_id': char_id}, {'joined': 1} ) if not mongo_member: return UnionDummy(char_id) char_union_id = mongo_member['joined'] if not char_union_id and not union_id: return UnionDummy(char_id) if not union_id: union_id = char_union_id # FIXME 本来是有这个判断的,但是目前为了省事,对于这个最后返回的是 UnionMember # 其实应该为这个添加一个新类: UnionObserver # 表示自己加入了一个工会,但是要查看其他工会的信息 # if char_union_id != union_id: # return UnionDummy(char_id) mongo_union = MongoUnion._get_collection().find_one( {'_id': union_id}, {'owner': 1} ) if char_id == mongo_union['owner']: return UnionOwner(char_id, union_id) return UnionMember(char_id, union_id)
def cron_job(): condition = {"$or": [ {"checkin_times": {"$gt": 0}}, {"boss_times": {"$gt": 0}} ]} updater = { 'checkin_times': 0, 'boss_times': 0 } members = MongoUnionMember._get_collection().find(condition, {'_id': 1}) MongoUnionMember._get_collection().update({}, {'$set': updater}, multi=True) for m in members: Member(m['_id']).send_personal_notify()
def cron_job(): condition = { "$or": [{ "checkin_times": { "$gt": 0 } }, { "boss_times": { "$gt": 0 } }] } updater = {'checkin_times': 0, 'boss_times': 0} members = MongoUnionMember._get_collection().find( condition, {'_id': 1}) MongoUnionMember._get_collection().update({}, {'$set': updater}, multi=True) for m in members: Member(m['_id']).send_personal_notify()
def get_battle_members(self): # 获取可参加工会战的会员 now = arrow.utcnow().timestamp hours24 = 24 * 3600 checkin_limit = now - hours24 condition = { '$and': [ {'joined': self.union_id}, {'last_checkin_timestamp': {'$gte': checkin_limit}} ] } docs = MongoUnionMember._get_collection().find(condition, {'_id': 1}) return [doc['_id'] for doc in docs]
def get_battle_members(self): # 获取可参加工会战的会员 now = arrow.utcnow().timestamp hours24 = 24 * 3600 checkin_limit = now - hours24 condition = { '$and': [{ 'joined': self.union_id }, { 'last_checkin_timestamp': { '$gte': checkin_limit } }] } docs = MongoUnionMember._get_collection().find(condition, {'_id': 1}) return [doc['_id'] for doc in docs]
def applied_list(self): # 申请者ID列表 members = MongoUnionMember._get_collection().find({'applied': self.union_id}, {'_id': 1}) return [i['_id'] for i in members]
class Member(object): """ 一个工会成员对象 成员相关操作 """ def __init__(self, char_id): self.char_id = char_id try: self.mongo_union_member = MongoUnionMember.objects.get(id=char_id) except DoesNotExist: self.mongo_union_member = MongoUnionMember(id=char_id) self.mongo_union_member.buy_buff_times = {} self.mongo_union_member.save() @property def checkin_total_amount(self): return VIP(self.char_id).get_max_times('union_checkin') @property def checkin_current_amount(self): return self.mongo_union_member.checkin_times def checkin(self): # 签到 from core.union.union import Union from core.union.battle import UnionBattle if not self.mongo_union_member.joined: raise SanguoException(errormsg.INVALID_OPERATE, self.char_id, "Union Checkin", "not join union") if self.mongo_union_member.checkin_times + 1 > self.checkin_total_amount: raise SanguoException(errormsg.UNION_CHECKIN_REACH_MAX_TIMES, self.char_id, "Union Checkin", "reached max times") try: c = UNION_CHECKIN[self.mongo_union_member.checkin_times + 1] except KeyError: raise SanguoException( errormsg.UNION_CHECKIN_REACH_MAX_TIMES, self.char_id, "Union Checkin", "reached max times. UNION_CHECKIN KeyError: {0}".format( self.mongo_union_member.checkin_times + 1)) if c.cost_type == 1: needs = {'gold': -c.cost_value} else: needs = {'sycee': -c.cost_value} resources = Resource(self.char_id, "Union Checkin") with resources.check(**needs): self.mongo_union_member.checkin_times += 1 self.mongo_union_member.last_checkin_timestamp = arrow.utcnow( ).timestamp self.add_coin(c.got_coin, send_notify=False) self.add_contribute_points(c.got_contributes, send_notify=False) self.mongo_union_member.save() self.send_personal_notify() Union(self.char_id).add_contribute_points(c.got_contributes) UnionBattle(self.char_id).send_notify() doc = MongoUnion._get_collection().find_one( {'_id': self.mongo_union_member.joined}, {'owner': 1}) owner = doc['owner'] UnionBattle(owner).send_notify() drop = make_standard_drop_from_template() drop['union_coin'] = c.got_coin drop['union_contribute_points'] = c.got_contributes return standard_drop_to_attachment_protomsg(drop) def make_member_message(self): msg = protomsg.UnionNotify.UnionMember() msg.char.MergeFrom(create_character_infomation_message(self.char_id)) msg.position = self.mongo_union_member.position msg.contribute_points = self.mongo_union_member.contribute_points return msg def send_personal_notify(self): if not self.mongo_union_member.joined: return msg = protomsg.UnionPersonalInformationNotify() msg.union_coin = self.mongo_union_member.coin msg.checkin_total_amount = self.checkin_total_amount msg.checkin_current_amount = self.checkin_current_amount publish_to_char(self.char_id, pack_msg(msg)) def apply_union(self, union_id): # 申请加入工会 from core.union.union import Union, UnionList doc = MongoUnion._get_collection().find_one({'_id': union_id}, {'owner': 1}) if not doc: raise SanguoException(errormsg.UNION_NOT_EXIST, self.char_id, "Member Apply Union", "union {0} not exist".format(union_id)) if self.mongo_union_member.joined: raise SanguoException( errormsg.UNION_CANNOT_APPLY_ALREADY_IN, self.char_id, "Member Apply Union", "already in {0}".format(self.mongo_union_member.joined)) if len(self.mongo_union_member.applied) >= 10: raise SanguoException(errormsg.UNION_CANNOT_APPLY_FULL, self.char_id, "Member Apply Union", "apply list too long") if union_id not in self.mongo_union_member.applied: self.mongo_union_member.applied.append(union_id) self.mongo_union_member.save() Union(doc['owner']).send_apply_list_notify() UnionList.send_list_notify(self.char_id) def join_union(self, union_id): # 加入工会 - 由Union调用 doc = MongoUnion._get_collection().find_one({'_id': union_id}, {'_id': 1}) if not doc: raise SanguoException(errormsg.UNION_NOT_EXIST, self.char_id, "UnionMember Join Union", "union {0} not eixst".format(union_id)) if self.mongo_union_member.joined == union_id: return self.mongo_union_member.applied = [] self.mongo_union_member.joined = union_id self.mongo_union_member.contribute_points = 0 self.mongo_union_member.position = 1 self.mongo_union_member.last_checkin_timestamp = 0 self.mongo_union_member.save() self.send_personal_notify() def quit_union(self): # 退出工会 - 由Union调用 self.mongo_union_member.joined = 0 self.mongo_union_member.contribute_points = 0 self.mongo_union_member.position = 1 self.mongo_union_member.last_checkin_timestamp = 0 self.mongo_union_member.save() self.send_personal_notify() def check_coin(self, coin_needs, raise_exception=False, func_name=""): if not raise_exception: if self.mongo_union_member.coin < coin_needs: return False return True if self.mongo_union_member.coin < coin_needs: raise SanguoException( errormsg.UNION_COIN_NOT_ENOUGH, self.char_id, func_name, "union coin not enough, {0} < {1}".format( self.mongo_union_member.coin, coin_needs)) def cost_coin(self, coin_needs): self.mongo_union_member.coin -= coin_needs self.mongo_union_member.save() self.send_personal_notify() def add_coin(self, coin, send_notify=True): self.mongo_union_member.coin += coin self.mongo_union_member.save() if send_notify: self.send_personal_notify() def add_contribute_points(self, point, send_notify=True): self.mongo_union_member.contribute_points += point to_next_position_contributes_needs = UNION_POSITION[ self.mongo_union_member.position].contributes_needs if self.mongo_union_member.position >= MAX_UNION_POSITION: self.mongo_union_member.position = MAX_UNION_POSITION if self.mongo_union_member.contribute_points >= to_next_position_contributes_needs: self.mongo_union_member.contribute_points = to_next_position_contributes_needs else: if self.mongo_union_member.contribute_points >= to_next_position_contributes_needs: self.mongo_union_member.contribute_points -= to_next_position_contributes_needs self.mongo_union_member.position += 1 self.mongo_union_member.save() if send_notify: self.send_personal_notify() @staticmethod def cron_job(): condition = { "$or": [{ "checkin_times": { "$gt": 0 } }, { "boss_times": { "$gt": 0 } }] } updater = {'checkin_times': 0, 'boss_times': 0} members = MongoUnionMember._get_collection().find( condition, {'_id': 1}) MongoUnionMember._get_collection().update({}, {'$set': updater}, multi=True) for m in members: Member(m['_id']).send_personal_notify()
class UnionMember(object): """ 一个工会成员对象 成员相关操作 """ def __init__(self, char_id): self.char_id = char_id try: self.mongo_union_member = MongoUnionMember.objects.get(id=char_id) except DoesNotExist: self.mongo_union_member = MongoUnionMember(id=char_id) self.mongo_union_member.buy_buff_times = {} self.mongo_union_member.save() @property def checkin_total_amount(self): return VIP(self.char_id).get_max_times('union_checkin') @property def checkin_current_amount(self): return self.mongo_union_member.checkin_times def checkin(self): if not self.mongo_union_member.joined: raise SanguoException( errormsg.INVALID_OPERATE, self.char_id, "Union Checkin", "not join union" ) if self.mongo_union_member.checkin_times + 1 > self.checkin_total_amount: raise SanguoException( errormsg.UNION_CHECKIN_REACH_MAX_TIMES, self.char_id, "Union Checkin", "reached max times" ) try: c = UNION_CHECKIN[self.mongo_union_member.checkin_times+1] except KeyError: raise SanguoException( errormsg.UNION_CHECKIN_REACH_MAX_TIMES, self.char_id, "Union Checkin", "reached max times. UNION_CHECKIN KeyError: {0}".format(self.mongo_union_member.checkin_times+1) ) if c.cost_type == 1: needs = {'gold': -c.cost_value} else: needs = {'sycee': -c.cost_value} resources = Resource(self.char_id, "Union Checkin") with resources.check(**needs): self.mongo_union_member.checkin_times += 1 self.mongo_union_member.last_checkin_timestamp = arrow.utcnow().timestamp self.add_coin(c.got_coin, send_notify=False) self.add_contribute_points(c.got_contributes, send_notify=False) self.mongo_union_member.save() self.send_personal_notify() Union(self.char_id, self.mongo_union_member.joined).add_contribute_points(c.got_contributes) def make_member_message(self): msg = protomsg.UnionNotify.UnionMember() msg.char.MergeFrom(create_character_infomation_message(self.char_id)) msg.position = self.mongo_union_member.position msg.contribute_points = self.mongo_union_member.contribute_points return msg def send_personal_notify(self): if not self.mongo_union_member.joined: return msg = protomsg.UnionPersonalInformationNotify() msg.union_coin = self.mongo_union_member.coin msg.checkin_total_amount = self.checkin_total_amount msg.checkin_current_amount = self.checkin_current_amount publish_to_char(self.char_id, pack_msg(msg)) def is_applied(self, union_id): # 是否申请过union_id的工会 return union_id in self.mongo_union_member.applied def apply_join(self, union_id): # 申请加入 if union_id not in self.mongo_union_member.applied: self.mongo_union_member.applied.append(union_id) self.mongo_union_member.save() Union(self.char_id, union_id).send_notify(to_owner=True) UnionManager(self.char_id).send_list_notify() def join_union(self, union_id): # 加入工会的后续设置 try: MongoUnion.objects.get(id=union_id) except DoesNotExist: raise SanguoException( errormsg.UNION_NOT_EXIST, self.char_id, "UnionMember Join Union", "union {0} not eixst".format(union_id) ) if self.mongo_union_member.joined == union_id: return self.mongo_union_member.applied = [] self.mongo_union_member.joined = union_id self.mongo_union_member.contribute_points = 0 self.mongo_union_member.position = 1 self.mongo_union_member.save() self.send_personal_notify() def quit_union(self): # 退出工会 self.mongo_union_member.joined = 0 self.mongo_union_member.contribute_points = 0 self.mongo_union_member.position = 1 self.mongo_union_member.save() self.send_personal_notify() def check_coin(self, coin_needs, raise_exception=False, func_name=""): if not raise_exception: if self.mongo_union_member.coin < coin_needs: return False return True if self.mongo_union_member.coin < coin_needs: raise SanguoException( errormsg.UNION_COIN_NOT_ENOUGH, self.char_id, func_name, "union coin not enough, {0} < {1}".format(self.mongo_union_member.coin, coin_needs) ) def cost_coin(self, coin_needs): self.mongo_union_member.coin -= coin_needs self.mongo_union_member.save() self.send_personal_notify() def add_coin(self, coin, send_notify=True): self.mongo_union_member.coin += coin self.mongo_union_member.save() if send_notify: self.send_personal_notify() def add_contribute_points(self, point, send_notify=True): self.mongo_union_member.contribute_points += point to_next_position_contributes_needs = UNION_POSITION[self.mongo_union_member.position].contributes_needs if self.mongo_union_member.position >= MAX_UNION_POSITION: self.mongo_union_member.position = MAX_UNION_POSITION if self.mongo_union_member.contribute_points >= to_next_position_contributes_needs: self.mongo_union_member.contribute_points = to_next_position_contributes_needs else: if self.mongo_union_member.contribute_points >= to_next_position_contributes_needs: self.mongo_union_member.contribute_points -= to_next_position_contributes_needs self.mongo_union_member.position += 1 self.mongo_union_member.save() if send_notify: self.send_personal_notify() def cron_job(self): self.mongo_union_member.checkin_times = 0 self.mongo_union_member.boss_times = 0 self.mongo_union_member.save() self.send_personal_notify()
class Member(object): """ 一个工会成员对象 成员相关操作 """ def __init__(self, char_id): self.char_id = char_id try: self.mongo_union_member = MongoUnionMember.objects.get(id=char_id) except DoesNotExist: self.mongo_union_member = MongoUnionMember(id=char_id) self.mongo_union_member.buy_buff_times = {} self.mongo_union_member.save() @property def checkin_total_amount(self): return VIP(self.char_id).get_max_times('union_checkin') @property def checkin_current_amount(self): return self.mongo_union_member.checkin_times def checkin(self): # 签到 from core.union.union import Union from core.union.battle import UnionBattle if not self.mongo_union_member.joined: raise SanguoException( errormsg.INVALID_OPERATE, self.char_id, "Union Checkin", "not join union" ) if self.mongo_union_member.checkin_times + 1 > self.checkin_total_amount: raise SanguoException( errormsg.UNION_CHECKIN_REACH_MAX_TIMES, self.char_id, "Union Checkin", "reached max times" ) try: c = UNION_CHECKIN[self.mongo_union_member.checkin_times+1] except KeyError: raise SanguoException( errormsg.UNION_CHECKIN_REACH_MAX_TIMES, self.char_id, "Union Checkin", "reached max times. UNION_CHECKIN KeyError: {0}".format(self.mongo_union_member.checkin_times+1) ) if c.cost_type == 1: needs = {'gold': -c.cost_value} else: needs = {'sycee': -c.cost_value} resources = Resource(self.char_id, "Union Checkin") with resources.check(**needs): self.mongo_union_member.checkin_times += 1 self.mongo_union_member.last_checkin_timestamp = arrow.utcnow().timestamp self.add_coin(c.got_coin, send_notify=False) self.add_contribute_points(c.got_contributes, send_notify=False) self.mongo_union_member.save() self.send_personal_notify() Union(self.char_id).add_contribute_points(c.got_contributes) UnionBattle(self.char_id).send_notify() owner = MongoUnion.objects.get(id=self.mongo_union_member.joined).owner UnionBattle(owner).send_notify() drop = make_standard_drop_from_template() drop['union_coin'] = c.got_coin drop['union_contribute_points'] = c.got_contributes return standard_drop_to_attachment_protomsg(drop) def make_member_message(self): msg = protomsg.UnionNotify.UnionMember() msg.char.MergeFrom(create_character_infomation_message(self.char_id)) msg.position = self.mongo_union_member.position msg.contribute_points = self.mongo_union_member.contribute_points return msg def send_personal_notify(self): if not self.mongo_union_member.joined: return msg = protomsg.UnionPersonalInformationNotify() msg.union_coin = self.mongo_union_member.coin msg.checkin_total_amount = self.checkin_total_amount msg.checkin_current_amount = self.checkin_current_amount publish_to_char(self.char_id, pack_msg(msg)) def apply_union(self, union_id): # 申请加入工会 from core.union.union import Union, UnionList try: mongo_union = MongoUnion.objects.get(id=union_id) except DoesNotExist: raise SanguoException( errormsg.UNION_NOT_EXIST, self.char_id, "Member Apply Union", "union {0} not exist".format(union_id) ) if self.mongo_union_member.joined: raise SanguoException( errormsg.UNION_CANNOT_APPLY_ALREADY_IN, self.char_id, "Member Apply Union", "already in {0}".format(self.mongo_union_member.joined) ) if len(self.mongo_union_member.applied) >= 10: raise SanguoException( errormsg.UNION_CANNOT_APPLY_FULL, self.char_id, "Member Apply Union", "apply list too long" ) if union_id not in self.mongo_union_member.applied: self.mongo_union_member.applied.append(union_id) self.mongo_union_member.save() Union(mongo_union.owner).send_apply_list_notify() UnionList.send_list_notify(self.char_id) def join_union(self, union_id): # 加入工会 - 由Union调用 try: MongoUnion.objects.get(id=union_id) except DoesNotExist: raise SanguoException( errormsg.UNION_NOT_EXIST, self.char_id, "UnionMember Join Union", "union {0} not eixst".format(union_id) ) if self.mongo_union_member.joined == union_id: return self.mongo_union_member.applied = [] self.mongo_union_member.joined = union_id self.mongo_union_member.contribute_points = 0 self.mongo_union_member.position = 1 self.mongo_union_member.last_checkin_timestamp = 0 self.mongo_union_member.save() self.send_personal_notify() def quit_union(self): # 退出工会 - 由Union调用 self.mongo_union_member.joined = 0 self.mongo_union_member.contribute_points = 0 self.mongo_union_member.position = 1 self.mongo_union_member.last_checkin_timestamp = 0 self.mongo_union_member.save() self.send_personal_notify() def check_coin(self, coin_needs, raise_exception=False, func_name=""): if not raise_exception: if self.mongo_union_member.coin < coin_needs: return False return True if self.mongo_union_member.coin < coin_needs: raise SanguoException( errormsg.UNION_COIN_NOT_ENOUGH, self.char_id, func_name, "union coin not enough, {0} < {1}".format(self.mongo_union_member.coin, coin_needs) ) def cost_coin(self, coin_needs): self.mongo_union_member.coin -= coin_needs self.mongo_union_member.save() self.send_personal_notify() def add_coin(self, coin, send_notify=True): self.mongo_union_member.coin += coin self.mongo_union_member.save() if send_notify: self.send_personal_notify() def add_contribute_points(self, point, send_notify=True): self.mongo_union_member.contribute_points += point to_next_position_contributes_needs = UNION_POSITION[self.mongo_union_member.position].contributes_needs if self.mongo_union_member.position >= MAX_UNION_POSITION: self.mongo_union_member.position = MAX_UNION_POSITION if self.mongo_union_member.contribute_points >= to_next_position_contributes_needs: self.mongo_union_member.contribute_points = to_next_position_contributes_needs else: if self.mongo_union_member.contribute_points >= to_next_position_contributes_needs: self.mongo_union_member.contribute_points -= to_next_position_contributes_needs self.mongo_union_member.position += 1 self.mongo_union_member.save() if send_notify: self.send_personal_notify() @staticmethod def cron_job(): condition = {"$or": [ {"checkin_times": {"$gt": 0}}, {"boss_times": {"$gt": 0}} ]} updater = { 'checkin_times': 0, 'boss_times': 0 } members = MongoUnionMember._get_collection().find(condition, {'_id': 1}) MongoUnionMember._get_collection().update({}, {'$set': updater}, multi=True) for m in members: Member(m['_id']).send_personal_notify()
def cronjob_auto_transfer_union(cls): transfer_dict = {} now = arrow.utcnow() local_date = now.to(settings.TIME_ZONE).date() timestamp = now.timestamp - 3600 * 24 * 3 unions = MongoUnion._get_collection().find({}, {'owner': 1}) owner_union_id_dict = {doc['owner']: doc['_id'] for doc in unions} conditions = { '$and': [{ '_id': { '$in': owner_union_id_dict.keys() } }, { 'last_checkin_timestamp': { '$lte': timestamp } }] } member_docs = MongoUnionMember._get_collection().find( conditions, {'last_checkin_timestamp': 1}) for doc in member_docs: char_id = doc['_id'] union_id = owner_union_id_dict[char_id] last_checkin_date = arrow.get(doc['last_checkin_timestamp']).to( settings.TIME_ZONE).date() days = (local_date - last_checkin_date).days # 昨天签到了,今天检测的时候, days 就是1 # 但是从逻辑上看,应该是连续签到的, # 前天签到,昨天没有,今天检测的时候,days是2 # 逻辑看来是已经 一天 没有签到了 # 所以 days 在这里 -1 days -= 1 if days < 3: continue u = Union(char_id, union_id) if days >= 7: # transfer next_owner = u.find_next_owner() transfer_dict[union_id] = (char_id, next_owner) if next_owner: u.transfer(next_owner) m = Mail(char_id) m.add( MAIL_UNION_OWNER_TRANSFER_DONE_TITLE, MAIL_UNION_OWNER_TRANSFER_DONE_CONTENT.format( get_char_property(char_id, 'name'))) else: members = u.member_list for mid in members: m = Mail(mid) m.add( MAIL_UNION_OWNER_TRANSFER_NOTIFY_TITLE, MAIL_UNION_OWNER_TRANSFER_NOTIFY_CONTENT.format(days)) return transfer_dict
def member_list(self): # 成员ID列表 members = MongoUnionMember._get_collection().find({'joined': self.union_id}, {'_id': 1}) return [i['_id'] for i in members]
def member_list(self): # 成员ID列表 members = MongoUnionMember._get_collection().find( {'joined': self.union_id}, {'_id': 1}) return [i['_id'] for i in members]
def applied_list(self): # 申请者ID列表 members = MongoUnionMember._get_collection().find( {'applied': self.union_id}, {'_id': 1}) return [i['_id'] for i in members]
def cronjob_auto_transfer_union(cls): transfer_dict = {} now = arrow.utcnow() local_date = now.to(settings.TIME_ZONE).date() timestamp = now.timestamp - 3600 * 24 * 3 unions = MongoUnion._get_collection().find({}, {'owner': 1}) owner_union_id_dict = {doc['owner']: doc['_id'] for doc in unions} conditions = { '$and': [ {'_id': {'$in': owner_union_id_dict.keys()}}, {'last_checkin_timestamp': {'$lte': timestamp}} ] } member_docs = MongoUnionMember._get_collection().find( conditions, {'last_checkin_timestamp':1} ) for doc in member_docs: char_id = doc['_id'] union_id = owner_union_id_dict[char_id] last_checkin_date = arrow.get(doc['last_checkin_timestamp']).to(settings.TIME_ZONE).date() days = (local_date - last_checkin_date).days # 昨天签到了,今天检测的时候, days 就是1 # 但是从逻辑上看,应该是连续签到的, # 前天签到,昨天没有,今天检测的时候,days是2 # 逻辑看来是已经 一天 没有签到了 # 所以 days 在这里 -1 days -= 1 if days < 3: continue u = Union(char_id, union_id) if days >= 7: # transfer next_owner = u.find_next_owner() transfer_dict[union_id] = (char_id, next_owner) if next_owner: u.transfer(next_owner) m = Mail(char_id) m.add( MAIL_UNION_OWNER_TRANSFER_DONE_TITLE, MAIL_UNION_OWNER_TRANSFER_DONE_CONTENT.format(get_char_property(char_id, 'name')) ) else: members = u.member_list for mid in members: m = Mail(mid) m.add( MAIL_UNION_OWNER_TRANSFER_NOTIFY_TITLE, MAIL_UNION_OWNER_TRANSFER_NOTIFY_CONTENT.format(days) ) return transfer_dict