westdc-core/Westdc/User/User.php

131 lines
2.4 KiB
PHP
Raw Permalink Normal View History

2014-09-19 09:10:29 +00:00
<?php
/**
* Created by PhpStorm.
* User: Li Jianxuan
* Date: 14-9-19
* Time: 下午3:21
*/
namespace Westdc\User;
2014-12-19 02:25:49 +00:00
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Westdc\EventModel\AbstractEventManager;
2014-09-19 09:10:29 +00:00
2015-01-26 18:28:03 +00:00
class User extends AbstractEventManager implements ServiceManagerAwareInterface {
2014-09-19 09:10:29 +00:00
2015-01-26 18:28:03 +00:00
protected $serviceManager;
2014-12-19 02:25:49 +00:00
2015-01-26 18:28:03 +00:00
private $db;
2014-12-19 02:25:49 +00:00
2015-01-26 18:28:03 +00:00
public function setServiceManager (ServiceManager $serviceManager) {
$this->serviceManager = $serviceManager;
2014-12-19 02:25:49 +00:00
2015-01-26 18:28:03 +00:00
$this->init();
2014-12-19 02:25:49 +00:00
2015-01-26 18:28:03 +00:00
return $this;
}
private function init () {
$dbService = $this->serviceManager->get('Db');
$this->db = $dbService->getPdo();
}
2014-12-19 02:25:49 +00:00
2015-01-26 18:28:03 +00:00
/**
2015-02-13 15:21:33 +00:00
* 所有用户
2015-01-26 18:28:03 +00:00
* @param $usertype
* @return mixed
*/
public function fetchAll ($usertype) {
$sql = "SELECT * FROM users WHERE usertype = '$usertype'";
2014-12-19 03:58:47 +00:00
$rs = $this->db->query($sql);
2015-01-26 18:28:03 +00:00
2014-12-19 03:58:47 +00:00
return $rs->fetchAll(\PDO::FETCH_ASSOC);
2015-01-26 18:28:03 +00:00
}
/**
2015-02-13 15:21:33 +00:00
* 用户详细信息
* @param $userid
* @return mixed
*/
public function view ($userid) {
$sql = "SELECT * FROM users WHERE id = $userid";
$rs = $this->db->query($sql);
return $rs->fetchAll(\PDO::FETCH_ASSOC);
}
/**
* 禁止用户
* @param $userid
* @return mixed
*/
public function ban ($userid, $status) {
$sql = "UPDATE users SET status= $status WHERE id = $userid";
$this->db->exec($sql);
return true;
}
2015-03-03 03:59:07 +00:00
/**
* 修改用户类型
* @param $userid
* @param $usertype
* @return bool
*/
public function usertypeChange ($userid, $usertype) {
$sql = "UPDATE users SET usertype = '$usertype' WHERE id = $userid";
$this->db->exec($sql);
return true;
}
/**
* 修改用户密码
* @param $userid
* @param $userpwd
* @return bool
*/
public function userpwdChange ($userid, $userpwd) {
$sql = "UPDATE users SET password = '$userpwd' WHERE id = $userid";
$this->db->exec($sql);
return true;
}
2015-02-13 15:21:33 +00:00
/**
* 黑河用户
2015-01-26 18:28:03 +00:00
* @return bool
*/
public function fetchAllHeiHe () {
2014-12-19 03:58:47 +00:00
2015-01-26 18:28:03 +00:00
$sql = "SELECT * FROM heiheuser ORDER BY id DESC";
$rs = $this->db->query($sql);
return $rs->fetchAll(\PDO::FETCH_ASSOC);
return true;
}
2015-02-13 15:21:33 +00:00
/**
* 所有长时间未登录的用户
* @return mixed
*/
2015-01-26 18:28:03 +00:00
public function fetchAllSendmail () {
2015-03-03 03:59:07 +00:00
$time = date("Y-m-d H:i:s", time() - 3 * 365 * 24 * 3600);
2015-01-26 18:28:03 +00:00
$sql = "SELECT * FROM users
WHERE ts_last_login<'$time'
ORDER BY ts_last_login DESC";
$rs = $this->db->query($sql);
return $rs->fetchAll(\PDO::FETCH_ASSOC);
2014-12-19 03:58:47 +00:00
}
2014-09-19 09:10:29 +00:00
}