<?php

	Class AnYue_DayJob{

		function delete_peie (){

			require_once '../Admin/config.php';
			require_once '../Source/function/global.php';
			date_default_timezone_set("Asia/Shanghai");

			$result = mysql_query ('SELECT * FROM `peie`');
			$date = date ('Ymd');

			while ($row = mysql_fetch_array($result)){

				if ($date > $row['endday']){

					$info = mysql_fetch_array (mysql_query ("SELECT * FROM `user` WHERE `user`='{$row['user']}'"));
					$new_peie = $info['peie'] - $row['number'];
					mysql_query ("DELETE FROM `peie` WHERE `user`='{$row['user']}' and `key`='{$row['key']}'");
					mysql_query ("UPDATE `user` SET `peie`='{$new_peie}' WHERE `user`='{$row['user']}'");

					if ($info['qqnum'] > ($new_peie+10)){ //系统默认赠送10配额

						$dele = $info['qqnum'] - ($new_peie+10);

						$dele_list = mysql_query ("SELECT * FROM `qqlist` WHERE `myqq`='{$row['user']}'");

						$text = '';
						for ($i=0;$i<$dele;$i++){

							$fetch = mysql_fetch_array ($dele_list);

							mysql_query ("DELETE FROM `{$fetch['fwq']}` WHERE `qid`='{$fetch['qid']}' and `qq`='{$fetch['qq']}'");
							mysql_query ("DELETE FROM `qqlist` WHERE `qid`='{$fetch['qid']}' and `qq`='{$fetch['qq']}'");

							$text .= '<h5 style="color: red;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QQ: '.$fetch['qq'].' ---- 已删除<h5>';

						}

						mysql_query ("UPDATE `user` SET `qqnum`='".($info['qqnum']-$dele)."' WHERE `user`='{$row['user']}'");

					}


					Send_out_Mail ($info['email'],'['.$configure['webname'].'] 挂Q配额过期提示','<p>亲爱的 '.$row['user'].'，您在 '.$configure['webname'].' 的挂Q配额已经到期，详细信息如下：</p><p><h4>&nbsp;&nbsp;&nbsp;配额数: '.$row['number'].' 个</h4></p><p><h4>&nbsp;&nbsp;&nbsp;起始时间: '.$row['doday'].'</h4></p><p><h4>&nbsp;&nbsp;&nbsp;终止时间: '.$row['endday'].'</p></h4><p><h4>&nbsp;&nbsp;&nbsp;配额标识码: '.$row['key'].'</p></h4><hr><p>强制删除QQ：</p>'.$text.'<font color="blue" size="20px">为了您的正常使用，请及时续费购买新的挂Q配额。</font><br /><br /><p>如有疑问请联系站长：'.$configure['mymail'].'，</p>'.date ('Y年m月d日 H时i分s秒').' 发布！');
					echo '<h3>'.$row['user'].'----过期挂Q配额数量: '.$dele.'</h3>',$text,'<hr />';


				}

			}

		}


	}

