def getSigninLog(self): '''获取签到记录''' table = 'tb_activity_signin' fields = ['Refill', 'SignInDate', 'SignInCount', 'SignInTime'] where = 'UserId=%s' % self.uid re = self.db.out_fields(table, fields, where) now = common.nowtime() if not re: SignInDate = '0000000000000000000000000000000' openDay = self.OpenInThisMonth() if openDay: SignInDate = list(SignInDate) SignInDate[openDay - 1] = '2' #开服当天标记 SignInDate = ''.join(SignInDate) re = { 'UserId': self.uid, 'Refill': 0, 'SignInDate': SignInDate, 'SignInCount': 0, 'SignInTime': now } self.db.insert(table, re) return re
def signin(self, optId, classMethod, date=None): '''签到''' now = datetime.datetime.now() signinLog = self.getSigninLog() signedtime = signinLog['SignInTime'] signedtime = time.localtime(signedtime) #隔月清空签到数据和补签次数 if now.year != signedtime[0] or now.month != signedtime[1]: signinLog['SignInDate'] = '0000000000000000000000000000000' signinLog['SignInTime'] = common.nowtime() signinLog['Refill'] = 0 self.updateSigninLog(signinLog) signInDate = list(signinLog['SignInDate']) openDay = self.OpenInThisMonth() #获取开服日 cost = 0 if date is None: date = now.day if signInDate[date - 1] == '1' or (openDay == date and signInDate[date - 1] == '3'): return -1 #该日期已签 if date != now.day: if date > now.day or date < openDay: return -2 #日期错误 if signinLog['Refill'] >= 5: return -3 #没有重签次数 modCoin = Gcore.getMod('Coin', self.uid) #signinFee = Gcore.getCfg('tb_cfg_act_signin_fee', signinLog['Refill'] + 1) signinFee = Gcore.loadCfg(2303).get(str(signinLog['Refill'] + 1)) #by Lizr cost = signinFee re = modCoin.PayCoin(optId, 1, cost, classMethod) if re < 0: return -4 #货币不足 cost = re signinLog['Refill'] += 1 #开服当天记录签到记录3,其他签到记录1 if openDay == date: signInDate[date - 1] = '3' else: signInDate[date - 1] = '1' signinLog['SignInDate'] = ''.join(signInDate) signinLog['SignInCount'] += 1 self.updateSigninLog(signinLog) count = signinLog['SignInCount'] % 30 if count != 0: awards = Gcore.getCfg('tb_cfg_act_signin_award') awardId = filter(lambda dic: dic['Day'] == count, awards.values())[0]['AwardId'] if count == 0: finalAwards = Gcore.loadCfg(CFG_ACT_SIGNIN)['FinalAwardId'] #awards = finalAwards.split(',') awards = finalAwards n = ((signinLog['SignInCount']) / 30) % len(awards) if signinLog['SignInCount'] % 30 == 0: n -= 1 awardId = int(awards[n]) self.insertGifts(2, awardId) #发放全勤奖 daysOfMonth = calendar.monthrange(now.year, now.month)[1] if daysOfMonth == now.day: fullMonthOnline = True if openDay and signInDate[openDay - 1] != '3': fullMonthOnline = False startDay = openDay if fullMonthOnline: for i in xrange(startDay, daysOfMonth): if '1' != signInDate[i]: fullMonthOnline = False break if fullMonthOnline: if (daysOfMonth - openDay + 1) < 20: awardId = 2001 #开服至今小于20天的礼包ID else: awardId = 3000 + now.month self.insertGifts(2, awardId) return cost