| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- <?php
- /**
- * userService类
- * @author meitu
- */
- class userService extends Service
- {
- /**
- *
- * @var userDao
- */
- private $userDao;
- public function __construct()
- {
- parent::__construct();
- $this->userDao = InitPHP::getDao("user");
- }
- /**
- * 添加一个用户
- */
- public function createUser($data)
- {
- $port = $this->userDao->getLastPort();
- $data['port'] = $port + rand(1, 2);
- return $this->userDao->createUser($data);
- }
- /**
- * 更新用户的信息
- *
- * @param integer $id
- * @param array $data
- * @return boolean
- */
- public function updateUser($id, $data)
- {
- return $this->userDao->updateUser($id, $data);
- }
- public function resetTran()
- {
- set_time_limit(0);
- $users = $this->getUsers();
- sort($users);
- foreach ($users as $k => $v) {
- if ((time() - $v['last_login_time'] > 86400 * 30) && (time() - $v['last_check_in_time'] > 86400 * 30) && $v['switch'] == 1 && $v['plan'] == 'A') {
- if ($v['u'] + $v['d'] < 1024 * 1024) {
- self::delUser($v['uid']);
- $subject = $v['user_name'] . ':您在shadowsocks5上的账号由于长期未使用已经被冻结';
- $message = "<html>
- <head>
- <title>欢迎使用ShadowSocks服务</title>
- </head>
- <body>
- <p>尊敬的ss5用户:" . $v['user_name'] . "</p>
- <table>
- <tr>
- 您在 <a href='".SITE_URL."'>SS5</a> 上的账号由于长期未使用已经被冻结,具体可能的情况如下:
- <br>1、您已没有近一个月没有登录过我们的网站了;
- <br>2、您在本月的使用流量小于1M;
- <br>您可以登录网站后按照网站提示进行解除冻结操作,在冻结解除之前您将无法继续使用ss5提供的shadowsocks服务,感谢您的支持与理解!
- <br>本邮件由系统自动发送,请不要直接回复本邮件,如有问题请发送邮件到support@tailsocks.com
- </tr>
- </table>
- </body>
- </html>";
- sendmail($v['email'],$subject,$message,'webmaster@tailsocks.com');
- sleep(1);
- }
- }
- }
- return $this->userDao->resetTran();
- }
- /**
- * 获取所有用户的总流量
- */
- public function getAllTran()
- {
- return $this->userDao->getAllTran();
- }
- /**
- * 更新用户信息
- *
- * @param integer $id
- * @param array $data
- * @return bool
- */
- public function updateUserinfo($id, $data)
- {
- $userinfo = $this->userDao->getUserById($id);
- $nowpass = md5($data['nowpassword']);
- if ($userinfo['pass'] != $nowpass) {
- return false;
- }
- if ($data['password'] != "") {
- $userdata['pass'] = md5($data['password']);
- }
- if ($data['email'] != "") {
- $userdata['email'] = $data['email'];
- }
- if (empty($userdata)) {
- return true;
- }
- return $this->userDao->updateUser($id, $userdata);
- }
- public function updatePortPass($id, $data)
- {
- return $this->userDao->updateUser($id, $data);
- }
- /**
- * 根据用户id获取用户信息
- *
- * @param int $uid
- * 用户id
- * @return Ambigous
- */
- public function getUserById($uid)
- {
- return $this->userDao->getUserById($uid);
- }
- /**
- * 登陆
- *
- * @param array $data
- * @return boolean|Ambigous <Ambigous, boolean, multitype:>
- */
- public function login($data)
- {
- $userinfo = $this->userDao->getUserByName($data['username']);
- if ($userinfo['pass'] != md5($data['password'])) {
- $userinfo = $this->userDao->getUserByEmail($data['username']);
- if ($userinfo['pass'] != md5($data['password'])) {
- return false;
- }
- }
- $u_data['last_login_time'] = time();
- $this->userDao->updateUser($userinfo['uid'], $u_data);
- return $userinfo;
- }
- public function getUserByNameOrEmail($name)
- {
- $userinfo = $this->userDao->getUserByName($name);
- if (!$userinfo) {
- $userinfo = $this->userDao->getUserByEmail($name);
- if (!$userinfo) {
- return false;
- }
- }
- return $userinfo;
- }
- /**
- * 对用户解除冻结
- *
- * @param int $uid
- * 用户的uid
- * @param string $code
- * 校验码
- * @param bool $pass
- * @return bool
- */
- public function doReset($uid, $code, $pass = FALSE)
- {
- if ($pass === true) {
- $user_info = $this->userDao->getUserById($uid);
- if ($user_info['code'] == $code && time() < $user_info['vaild_time']) {
- return true;
- } else {
- return false;
- }
- } elseif (strlen($pass) > 6) {
- $user_info = $this->userDao->getUserById($uid);
- if ($user_info['code'] == $code && time() < $user_info['vaild_time']) {
- $data['code'] = "";
- $data['vaild_time'] = 0;
- $data['pass'] = md5($pass);
- return $this->userDao->updateUser($uid, $data);
- } else {
- return false;
- }
- } else {
- $data['code'] = $code;
- $data['vaild_time'] = time() + 3600;
- return $this->userDao->updateUser($uid, $data);
- }
- }
- /**
- * 获取所有用户
- */
- public function getUsers($num = NULL, $offset = 0)
- {
- return $this->userDao->getUsers($num, $offset);
- }
- /**
- * 获取所有用户
- */
- public function getUserByPort($port)
- {
- return $this->userDao->getUserByField(array(
- 'port' => $port
- ));
- }
- /**
- * 删除一个用户
- *
- * @param integer $uid
- * @return boolean
- */
- public function delUser($uid)
- {
- return $this->userDao->delUser($uid);
- }
- /**
- * 获取所有用户数
- *
- * @return number
- */
- public function getCount()
- {
- return $this->userDao->getCount();
- }
- /**
- * 检测用户是否可以注册
- *
- * @param array $userinfo
- * @return boolean
- */
- public function checkUser($userinfo)
- {
- return $this->userDao->checkUser($userinfo);
- }
- /**
- * 检测邀请码
- *
- * @param string $code
- * @return boolean
- */
- public function checkInvite($code)
- {
- $invite = InitPHP::getDao("invite");
- $data = $invite->getOneByInvite($code);
- if ($data['status'] == 1) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * 删除邀请码
- *
- * @param string $code
- */
- public function deleteInvite($code)
- {
- $invite = InitPHP::getDao("invite");
- return $invite->delete($code);
- }
- /**
- * 增加邀请码
- *
- * @param string $pre
- * 邀请码前缀设置
- * @param int $num
- * 产生个数
- * @param string $platform
- * 产生平台来源
- * @return boolean
- */
- public function add($pre, $num, $platform)
- {
- $invite = InitPHP::getDao("invite");
- $str = "";
- for ($i = 0; $i < $num; $i++) {
- $data = array();
- $data['code'] = $pre . $i . substr(md5($i . time() . uniqid()), 0, 8);
- $data['platform'] = $platform;
- $invite->add($data);
- $str .= $data['code'] . "<br>";
- }
- return $str;
- }
- /**
- * 获取一个随机邀请码
- */
- public function getInvite()
- {
- $invite = InitPHP::getDao("invite");
- $codes = $invite->getAll();
- return $codes[rand(0, count($codes) - 1)];
- }
- /**
- * 对用户解除冻结
- *
- * @param int $uid
- * 用户的uid
- * @param string $code
- * 校验码
- * @param bool|string $free
- * 是否执行解冻
- * @return bool
- */
- public function doFreeze($uid, $code, $free = FALSE)
- {
- if ($free) {
- $user_info = $this->userDao->getUserById($uid);
- if ($user_info['code'] == $code && time() < $user_info['vaild_time']) {
- $data['switch'] = 1;
- // $data['enable'] = 1;
- $data['code'] = "";
- $data['vaild_time'] = 0;
- return $this->userDao->updateUser($uid, $data);
- } else {
- return false;
- }
- } else {
- $data['code'] = $code;
- $data['vaild_time'] = time() + 86400 * 2;
- return $this->userDao->updateUser($uid, $data);
- }
- }
- }
|