def FreePackageInMonthFirst(self): '''免费套餐在月初''' now_month_used = self.Month_Sum_Flow - self.Now_Month_Flow now_month_extr = now_month_used - self.Now_Month_Flow if now_month_used >= 0: if now_month_extr >= 0: new_month_used_flow = self.Now_Month_Flow new_month_advance_flow = now_month_extr is_flow_alarm = 1 is_write_redis = 0 SendMail(self.Email, "FreeFlowOver", self.logger) elif now_month_extr < -self.Now_Month_Flow * 0.1: new_month_used_flow = now_month_used new_month_advance_flow = 0 is_flow_alarm = 0 is_write_redis = 1 else: new_month_used_flow = now_month_used new_month_advance_flow = 0 is_flow_alarm = 1 is_write_redis = 1 SendMail(self.Email, "FreeFlowAlert", self.logger) else: new_month_used_flow = 0 new_month_advance_flow = 0 is_flow_alarm = 0 is_write_redis = 1 '''更新uflow相关信息''' sql = "update uflow set month_used_flow=%s,month_advance_flow=%s,is_flow_alarm=%s where uid = %s " param = (new_month_used_flow, new_month_advance_flow, is_flow_alarm, self.uid) self.ExeMysqlCmd(sql, param) '''更新redis键uid_flow信息''' self.ExeRedisCmd("%s_flow" % self.uid, is_write_redis)
def ContinueToPay(self): '''用户套餐续费''' old_starttime_list = self.old_starttime.split("-") old_endtime_list = self.Now_EndDate.split('-') old_starttime_list[0] = str(old_endtime_list[0]) new_begindate = '-'.join(old_starttime_list) new_enddate = self.ext_enddate new_month_count = self.total_mouth - self.Now_Month_Count new_month_flow = self.o_mount_flow now_month_used = self.Month_Sum_Flow - self.Now_Month_Flow if now_month_used > 0: now_month_extr = now_month_used - new_month_flow if now_month_extr > new_month_flow * 0.1: '''now_month_used > new_month_flow*110%''' new_month_used_flow = new_month_flow new_month_advance_flow = now_month_extr is_flow_alarm = 1 is_write_redis = 0 SendMail(self.Email, "PayFlowOver", self.logger) elif 0 < now_month_extr <= new_month_flow * 0.1: '''new_month_flow < now_month_used <= new_month_flow*110%''' new_month_used_flow = new_month_flow new_month_advance_flow = now_month_extr is_flow_alarm = 1 is_write_redis = 1 SendMail(self.Email, "PayFlowAlert", self.logger) elif -new_month_flow * 0.1 < now_month_extr <= 0: '''new_month_flow*90% < now_month_used <= new_month_flow''' new_month_used_flow = now_month_used new_month_advance_flow = 0 is_flow_alarm = 1 is_write_redis = 1 SendMail(self.Email, "PayFlowAlert", self.logger) else: '''now_month_used < new_month_flow*90%''' new_month_used_flow = now_month_used new_month_advance_flow = 0 is_flow_alarm = 0 is_write_redis = 1 else: '''now_month_used <= 0''' new_month_used_flow = 0 new_month_advance_flow = 0 is_flow_alarm = 0 is_write_redis = 1 '''更新uflow相关信息''' sqlone = "update uflow set startdate=%s,enddate=%s,month_count=%s,month_flow=%s,month_used_flow=%s,month_advance_flow=%s,is_flow_alarm=%s where uid =%s" param = (new_begindate, new_enddate, new_month_count, new_month_flow, new_month_used_flow, new_month_advance_flow, is_flow_alarm, self.uid) self.ExeMysqlCmd(sqlone, param) '''更新redis键uid_flow信息''' self.ExeRedisCmd("%s_flow" % self.uid, is_write_redis) '''更新ucurrntetc表,开启续费开关''' sqltwo = 'update ucurrenttc set xufei_status=1 where uid = %s' param = (uid) self.ExeMysqlCmd(sqltwo, param)
def CheckDaemonProcess(self, cid): ptmp1 = subprocess.Popen( "/bin/ps -aux | grep %s | grep -v grep | grep ffstart | wc -l" % cid, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) DaemonNum = int(ptmp1.stdout.read()) if DaemonNum != 1: MailObj = SendMail(self.logger, "ffstart daemon process exception", "%s" % cid) MailObj.start()
def RechargePackageInMonthMiddle(self): '''充值套餐在月中''' now_month_used = self.Month_Sum_Flow - self.Now_Month_Flow if now_month_used >= 0: '''充值流量全部用完,降级''' self.FallLevel("RechargeFlowOver") else: if self.Month_Sum_Flow > self.Now_Month_Flow * 0.9: new_month_used_flow = self.Month_Sum_Flow new_month_advance_flow = 0 is_flow_alarm = 1 is_write_redis = 1 SendMail(self.Email, "RechargeFlowAlert", self.logger) else: new_month_used_flow = self.Month_Sum_Flow new_month_advance_flow = 0 is_flow_alarm = 0 is_write_redis = 1 '''更新uflow相关信息''' sql = "update uflow set month_used_flow=%s,month_advance_flow=%s,is_flow_alarm=%s where uid =%s" param = (new_month_used_flow, new_month_advance_flow, is_flow_alarm, self.uid) self.ExeMysqlCmd(sql, param) '''更新redis键uid_flow信息''' self.ExeRedisCmd("%s_flow" % self.uid, is_write_redis)
def PayPackageInMonthFirst(self): '''付费套餐到月初''' now_month_used = self.Month_Sum_Flow - self.Now_Month_Flow if now_month_used > 0: now_month_extr = now_month_used - self.Now_Month_Flow if now_month_extr > self.Now_Month_Flow * 0.1: '''now_month_used > self.Now_Month_Flow*110%''' new_month_used_flow = self.Now_Month_Flow new_month_advance_flow = now_month_extr is_flow_alarm = 1 is_write_redis = 0 SendMail(self.Email, "PayFlowOver", self.logger) elif 0 < now_month_extr <= self.Now_Month_Flow * 0.1: '''self.Now_Month_Flow < now_month_used <= self.Now_Month_Flow*110% ''' new_month_used_flow = self.Now_Month_Flow new_month_advance_flow = now_month_extr is_flow_alarm = 1 is_write_redis = 1 SendMail(self.Email, "PayFlowAlert", self.logger) elif -self.Now_Month_Flow * 0.1 < now_month_extr <= 0: '''self.Now_Month_Flow*90% < now_month_used <= self.Now_Month_Flow ''' new_month_used_flow = now_month_used new_month_advance_flow = 0 is_flow_alarm = 1 is_write_redis = 1 SendMail(self.Email, "PayFlowAlert", self.logger) else: new_month_used_flow = now_month_used new_month_advance_flow = 0 is_flow_alarm = 0 is_write_redis = 1 else: new_month_used_flow = 0 new_month_advance_flow = 0 is_flow_alarm = 0 is_write_redis = 1 '''更新uflow相关信息''' sql = "update uflow set month_used_flow=%s,month_advance_flow=%s,is_flow_alarm=%s where uid =%s" param = (new_month_used_flow, new_month_advance_flow, is_flow_alarm, self.uid) self.ExeMysqlCmd(sql, param) '''更新redis键uid_flow信息''' self.ExeRedisCmd("%s_flow" % self.uid, is_write_redis)
def FallLevel(self, emailflag): '''用户套餐降级到免费套餐''' new_begindate = datetime.datetime.now().strftime("%Y-%m-%d") new_enddate = self.Free_EndDate new_month_flow = self.Free_Month_Flow new_month_count = self.Free_Month_Count now_month_used = self.Month_Sum_Flow - self.Now_Month_Flow if now_month_used >= 0: now_month_extr = now_month_used - self.Free_Month_Flow if now_month_extr > 0: new_month_used_flow = self.Free_Month_Flow new_month_advance_flow = now_month_extr is_flow_alarm = 1 is_write_redis = 0 elif now_month_extr < -self.Free_Month_Flow * 0.1: new_month_used_flow = now_month_used new_month_advance_flow = 0 is_flow_alarm = 0 is_write_redis = 1 else: new_month_used_flow = now_month_used new_month_advance_flow = 0 is_flow_alarm = 1 is_write_redis = 1 else: new_month_used_flow = 0 new_month_advance_flow = 0 is_flow_alarm = 0 is_write_redis = 1 data = [ new_begindate, new_enddate, new_month_count, new_month_flow, new_month_used_flow, new_month_advance_flow, is_flow_alarm, is_write_redis ] '''更新uflow表相关信息''' sqlOne = "update uflow set startdate=%s,enddate=%s,month_count=%s,month_flow=%s,month_used_flow=%s,month_advance_flow=%s,is_flow_alarm=%s where uid = %s" param = (data[0], data[1], data[2], data[3], data[4], data[5], data[6], self.uid) self.ExeMysqlCmd(sqlOne, param) '''更新uinfo表相关信息''' sqlTwo = "update uinfo set tid = %s where uid = %s" param = (self.Free_TypeID, self.uid) self.ExeMysqlCmd(sqlTwo, param) '''更新redis键uid_flow信息''' self.ExeRedisCmd("%s_flow" % self.uid, data[7]) '''发邮件通知用户已降级''' SendMail(self.Email, emailflag, self.logger)
def CheckDaemonProcess(self,cid): ptmp1 = subprocess.Popen("/bin/ps -aux | grep %s | grep -v grep | grep ffstart | wc -l"%cid,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) DaemonNum= int(ptmp1.stdout.read()) if DaemonNum != 1: MailObj = SendMail(self.logger,"ffstart daemon process exception","%s"%cid) MailObj.start()