| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 | 
							- <?php
 
- namespace Cas\Controller\Admin;
 
- use KIF\Core\Request;
 
- use KIF\Verify;
 
- use KIF\Math\Math;
 
- use Cas\Dao\BackUser as DBackUser;
 
- use Cas\Module\BackPassport;
 
- use Cas\Dao\LotteryEvents;
 
- use KIF\Core\Config;
 
- use Cas\Module\Permission;
 
- use Cas\Dao\Platform;
 
- /**
 
-  * 
 
-  * 后台用户管理
 
-  * @author lishumingoo@gmail.com
 
-  */
 
- class BackUser extends \KIF\Core\BKController {
 
- 	
 
- 	public function __construct() {
 
- 		# 是否管理员
 
- 		$IS_ADMIN = false;
 
- 		if (\KIF\Core\PermissionController::isSuperadmin()) {
 
- 			$IS_ADMIN = true;
 
- 		}
 
- 		$this->setOutput('IS_ADMIN', $IS_ADMIN);
 
- 		$this->setOutput('backuser', $this->getUser());
 
- 	}
 
- 	
 
- 	public function doLogin() {
 
- 		if (Request::isPost()) {
 
- 			$username = Request::p('username');
 
- 			if (!$username) {
 
- 				self::ajax_fail_exit('请填写用户姓名');
 
- 			}
 
- 				
 
- 			$password = Request::p('password');
 
- 			if (!$password) {
 
- 				self::ajax_fail_exit('请填写登陆密码');
 
- 			}
 
- 			
 
- 			$app_id = Config::getInstance()->get('App_Id');
 
- 			$project = Math::md5_16($app_id);
 
- 			
 
- 			$objBackPassport = new BackPassport();
 
- 			$tmpResult = $objBackPassport->login($username, $password, $project);
 
- 			if (!$tmpResult->isSuccess()) {
 
- 				self::ajax_fail_exit($tmpResult->getData());
 
- 			}
 
- 				
 
- 			self::ajax_success_exit();
 
- 		}
 
- 		$this->tpl = 'admin/backUser/login';
 
- 		$title = '登录 - 后台管理工作平台';
 
- 		$this->setOutput('title', $title);
 
- 		$this->setOutput('op', Request::g('op'));
 
- 	}
 
- 	
 
- 	public function doLogout() {
 
- 		$objBackPassport = new BackPassport();
 
- 		$objBackPassport->logout();
 
- 		self::redirect(Request::schemeDomain() . '/?c=admin_backUser&a=login&op=logout');
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 创建新帐号
 
- 	 */
 
- 	public function doCreateUser() {
 
- 		
 
- 		\KIF\Core\PermissionController::requireCompetence();
 
- 		
 
- 		$objDBackUser = new DBackUser();
 
- 		if (Request::isPost()) {
 
- 			
 
- 			$errMsg = array('ok' => true);
 
- 			do {
 
- 				$name = Request::p('name');
 
- 				if (!$name) {
 
- 					$errMsg['msg'] = '请填写姓名';
 
- 					break;
 
- 				}
 
- 			
 
- 				if ($objDBackUser->getIdByName($name)) {
 
- 					$errMsg['msg'] = "用户名\"{$name}\"已经存在";
 
- 					break;
 
- 				}
 
- 				
 
- 				$platfrom = $_POST['platfrom'];
 
- 				if (!$platfrom) {
 
- 					$errMsg['msg'] = "请选择平台列表";
 
- 					break;
 
- 				}
 
- 			
 
- 				$auto_generate = Request::p('auto_generate');
 
- 				$password = Request::p('password');
 
- 				if (!$auto_generate && !$password) {
 
- 					$auto_generate = true;
 
- 				}
 
- 			
 
- 				if ($auto_generate) {
 
- 					$password = crypt(Math::md5_16(time()), 'k');
 
- 					$_POST['password'] = $password;
 
- 				}
 
- 			
 
- 				$email = Request::p('email');
 
- 				$division = Request::p('division');
 
- 			
 
- 				$app_id = Config::getInstance()->get('App_Id');
 
- 				$project = Math::md5_16($app_id);
 
- 				
 
- 				$info = array(
 
- 					'name'		=> $name,
 
- 					'password'	=> $password,
 
- 					'email'		=> $email,
 
- 					'division'	=> $division,
 
- 					'project'	=> $project,
 
- 					'app_id'	=> $app_id,
 
- 					'permission'=> 'ordinary',
 
- 					'platfrom'	=> $platfrom,
 
- 				);
 
- 				
 
- 				$tmpResult = $objDBackUser->add($info);
 
- 				if (!$tmpResult->isSuccess()) {
 
- 					$errMsg['msg'] = $tmpResult->getData();
 
- 				} else {
 
- 					$user = $tmpResult->getData();
 
- 					$user['password'] = $password;
 
- 					$uid = $user['uid'];
 
- 					# 建立权限组
 
- // 					$objDKifUsergroup = new \Cas\Dao\KifUsergroup();
 
- // 					$groupid = $objDKifUsergroup->add(array('description' => $name));
 
- // 					$objDKifUsergroupRelation = new \Cas\Dao\KifUsergroupRelation();
 
- // 					$objDKifUsergroupRelation->add(array('uid' => $uid, 'groupid' => $groupid));
 
- // 					$objDBackUser->modify(array('groupid' => $groupid), array('uid' => $uid));
 
- 				}
 
- 			} while (false);
 
- 				
 
- 			if ($errMsg['msg']) {
 
- 				$errMsg['ok'] = false;
 
- 			}
 
- 			
 
- 			$this->setOutput('submitData', $_POST);
 
- 			$this->setOutput('errMsg', $errMsg);
 
- 			$this->setOutput('new_user', $user);
 
- 		}
 
- 		
 
- 		$app_id = Config::getInstance()->get('App_Id');
 
- 		$project = Math::md5_16($app_id);
 
- 		$uids = $objDBackUser->findIdsBy(array('project' => $project));
 
- 		$users = $objDBackUser->gets($uids);
 
- 		
 
- 		krsort($users);
 
- 		
 
- 		$objDPlatfrom = new Platform ();
 
- 		$platfrom = $objDPlatfrom->getsAll('id desc');
 
- 		
 
- 		$this->tpl = 'admin/backUser/user_list';
 
- 		$title = '帐号管理';
 
- 		$this->setOutput('title', $title);
 
- 		$this->setOutput('menu_active', array('name' => 'userslist', 'item' => '')); //激活菜单
 
- 		$this->addNavMenu('平台设置');
 
- 		$this->addNavMenu($title);
 
- 		$this->setOutput('users', $users);
 
- 		$this->setOutput('platfrom', $platfrom);
 
- 	}
 
- 	
 
- 	public function doDeleteUser() {
 
- 		\KIF\Core\PermissionController::requireCompetence();
 
- 		
 
- 		$uid = Request::p('uid');
 
- 		if (!Verify::unsignedInt($uid)) {
 
- 			$this->ajax_fail_exit('无效用户id');
 
- 		}
 
- 		
 
- 		$objDBackUser = new DBackUser();
 
- 		$tmpResult = $objDBackUser->delete(array('uid'=>$uid));
 
- 		$this->ajax_success_exit();
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 后台用户列表
 
- 	 */
 
- 	public function doUserList() {
 
- 		\KIF\Core\PermissionController::requireCompetence();
 
- 		
 
- 		$objDBackUser = new DBackUser();
 
- 		$app_id = Config::getInstance()->get('App_Id');
 
- 		$project = Math::md5_16($app_id);
 
- 		$condition = "project = '{$project}' || permission = 'admin'";
 
- 		$uids = $objDBackUser->findIdsBy($condition);
 
- 		
 
- 		$users = $objDBackUser->gets($uids);
 
- 		
 
- 		krsort($users);
 
- 		
 
- 		$objDPlatfrom = new Platform ();
 
- 		$platfrom = $objDPlatfrom->getsAll('id desc');
 
- 		
 
- 		$this->tpl = 'admin/backUser/user_list';
 
- 		$title = '帐号管理';
 
- 		$this->setOutput('title', $title);
 
- 		$this->setOutput('menu_active', array('name' => 'userslist', 'item' => '')); //激活菜单
 
- 		$this->addNavMenu('平台设置');
 
- 		$this->addNavMenu($title);
 
- 		$this->setOutput('users', $users);
 
- 		$this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据
 
- 		$this->setOutput('platfrom', $platfrom);
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 修改密码 - 自助
 
- 	 */
 
- 	public function doModifyPassword() {
 
- 		\KIF\Core\PermissionController::requireCompetence();
 
- 		
 
- 		$uid = Request::g('uid');
 
- 		if (!Verify::unsignedInt($uid)) {
 
- 			self::fail_exit_bs('无效uid');
 
- 		}
 
- 	
 
- 		$objDBackUser = new DBackUser();
 
- 		$user = $objDBackUser->get($uid);
 
- 		if (!$user) {
 
- 			self::fail_exit_bs('用户不存在');
 
- 		}
 
- 	
 
- 		if (Request::isPost()) {
 
- 			do {
 
- 				$oldPassword = Request::p('oldPassword');
 
- 				if (!$oldPassword) {
 
- 					$errMsg = '原始密码为空';
 
- 					break;
 
- 				}
 
- 				
 
- 				$newPassword = Request::p('newPassword');
 
- 				if (!$newPassword) {
 
- 					$errMsg = '新密码为空';
 
- 					break;
 
- 				}
 
- 				
 
- 				$tmpResult = $objDBackUser->modifyPassword($uid, $oldPassword, $newPassword);
 
- 				if (!$tmpResult->isSuccess()) {
 
- 					$errMsg = $tmpResult->getData();
 
- 					break;
 
- 				}
 
- 				
 
- 				$successMsg = '密码修改成功';
 
- 			} while (false);
 
- 		}
 
- 	
 
- 		$this->tpl = 'admin/backUser/modify_password';
 
- 		$title = '密码修改';
 
- 		$this->setOutput('title', $title);
 
- 		$this->setOutput('menu_active', array('name' => 'modifypassword', 'item' => '')); //激活菜单
 
- 		$this->addNavMenu('帐号管理');
 
- 		$this->addNavMenu($title);
 
- 		$this->setOutput('errMsg', $errMsg);
 
- 		$this->setOutput('successMsg', $successMsg);
 
- 		$this->setOutput('user', $user);
 
- 		$this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 密码修改 - 超级管理员使用
 
- 	 */
 
- 	public function doMP() {
 
- 		\KIF\Core\PermissionController::requireCompetence();
 
- 		
 
- 		$uid = Request::g('uid');
 
- 		if (!Verify::unsignedInt($uid)) {
 
- 			self::fail_exit_bs('无效uid');
 
- 		}
 
- 		
 
- 		$objDBackUser = new DBackUser();
 
- 		$user = $objDBackUser->get($uid);
 
- 		if (!$user) {
 
- 			self::fail_exit_bs('用户不存在');
 
- 		}
 
- 		
 
- 		if (Request::isPost()) {
 
- 			do {
 
- 				$password = Request::p('password');
 
- 				$auto_generate = Request::p('auto_generate');
 
- 				
 
- 				if (!$password && $auto_generate) {
 
- 					$password = crypt(Math::md5_16(time()), '@w');
 
- 				} else {
 
- 					if (strlen($password) < 6) {
 
- 						$errMsg['ok'] = 1;
 
- 						$errMsg['msg'] = '密码不能小于8位';
 
- 						break;
 
- 					}
 
- 				}
 
- 				
 
- 				$tableInfo = array(
 
- 					'password'	=> Math::md5_16($password),
 
- 				);
 
- 				$condition = array(
 
- 					'uid'	=> $uid,
 
- 				);
 
- 				
 
- 				$tmpResult = $objDBackUser->update($tableInfo, $condition);
 
- 				if (!$tmpResult) {
 
- 					$errMsg['ok'] = 1;
 
- 					$errMsg['msg'] = '密码修改失败';
 
- 				}
 
- 				
 
- 				$errMsg['ok'] = 2;
 
- 				$errMsg['msg'] = "密码修改成功。新密码: {$password}";
 
- 			} while (false);
 
- 		}
 
- 		
 
- 		$this->tpl = 'admin/backUser/mp';
 
- 		$title = '密码修改';
 
- 		$this->setOutput('title', $title);
 
- 		$this->setOutput('menu_active', array('name' => 'userslist', 'item' => '')); //激活菜单
 
- 		$this->addNavMenu('用户管理');
 
- 		$this->addNavMenu($title);
 
- 		$this->setOutput('user', $user);
 
- 		$this->setOutput('password', $password);
 
- 		$this->setOutput('errMsg', $errMsg);
 
- 		$this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 权限设置
 
- 	 * 选择角色:管理员、普通账号
 
- 	 */
 
- 	public function doSetPermission() {
 
- 		\KIF\Core\PermissionController::requireCompetence();
 
- 		
 
- 		$uid = Request::g('uid');
 
- 		if (!Verify::unsignedInt($uid)) {
 
- 			self::fail_exit_bs('无效uid');
 
- 		}
 
- 		
 
- 		$objDBackUser = new DBackUser();
 
- 		$user = $objDBackUser->get($uid);
 
- 		if (!$user) {
 
- 			self::fail_exit_bs('用户不存在');
 
- 		}
 
- 		
 
- 		if (Request::isPost()) {
 
- 			$permission = Request::p('permission');
 
- 			if (!in_array($permission, array('admin', 'ordinary'))) {
 
- 				$this->ajax_fail_exit('不存在的角色');
 
- 			}
 
- 			
 
- 			$info = array('permission' => $permission);
 
- 			$condition = array('uid' => $uid);
 
- 			$objDBackUser->modify($info, $condition);
 
- 			$user['permission'] = $permission;
 
- 			$errMsg['ok'] = true;
 
- 		}
 
- 		
 
- 		$this->tpl = 'admin/backUser/permission';
 
- 		$title = '权限设置';
 
- 		$this->setOutput('title', $title);
 
- 		$this->setOutput('menu_active', array('name' => 'userslist', 'item' => '')); //激活菜单
 
- 		$this->addNavMenu('用户管理');
 
- 		$this->addNavMenu($title);
 
- 		$this->setOutput('user', $user);
 
- 		$this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据
 
- 		$this->setOutput('errMsg', $errMsg);
 
- 	}
 
- 	
 
- 	public function doSetPlatfrom() {
 
- 		\KIF\Core\PermissionController::requireCompetence();
 
- 		
 
- 		$uid = Request::g('uid');
 
- 		if (!Verify::unsignedInt($uid)) {
 
- 			self::fail_exit_bs('无效uid');
 
- 		}
 
- 		
 
- 		$objDBackUser = new DBackUser();
 
- 		$user = $objDBackUser->get($uid);
 
- 		if (!$user) {
 
- 			self::fail_exit_bs('用户不存在');
 
- 		}
 
- 		
 
- 		if (Request::isPost()) {
 
- 			$platfrom = $_POST['platfrom'];
 
- 			if (!$platfrom) {
 
- 				$this->ajax_fail_exit('不存在的角色');
 
- 			}
 
- 				
 
- 			$info = array('platfrom' => $platfrom);
 
- 			$condition = array('uid' => $uid);
 
- 			$objDBackUser->modify($info, $condition);
 
- 			$user['platfrom'] = $platfrom;
 
- 			$errMsg['ok'] = true;
 
- 		}
 
- 		
 
- 		$objDPlatfrom = new Platform ();
 
- 		$platfrom = $objDPlatfrom->getsAll('id desc');
 
- 		
 
- 		$this->tpl = 'admin/backUser/platfrom';
 
- 		$title = '权限设置';
 
- 		$this->setOutput('title', $title);
 
- 		$this->setOutput('menu_active', array('name' => 'userslist', 'item' => '')); //激活菜单
 
- 		$this->addNavMenu('用户管理');
 
- 		$this->addNavMenu($title);
 
- 		$this->setOutput('user', $user);
 
- 		$this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据
 
- 		$this->setOutput('errMsg', $errMsg);
 
- 		$this->setOutput('platfrom', $platfrom);
 
- 	}
 
- 	
 
- 	public function getPagePublicData() {
 
- 		$adminPublicArray = array ();
 
- 		$adminPublicArray ['rapidEntranceUrl'] = $this->getRapidEntrance (); // 头部导航"新建"数据
 
- 		return $adminPublicArray;
 
- 	}
 
- 	
 
- 	/**
 
- 	 * 头部导航"新建"数据
 
- 	 */
 
- 	public function getRapidEntrance() {
 
- 		$url = Request::schemeDomain () . '/?c=Admin_Activity_SetBasics&a=PageCreate&type=';
 
- 		$fastCreateActivityUrlData = array (
 
- 				'大转盘' => $url . LotteryEvents::TYPE_EVENTS_TURNTABLE . '&bigType=Event',
 
- 				'刮刮卡' => $url . LotteryEvents::TYPE_EVENTS_SCRATCH . '&bigType=Event',
 
- 				'邀请函' => $url . LotteryEvents::TYPE_EVENTS_INVITATION . '&bigType=Event',
 
- 				'优惠券' => $url . LotteryEvents::TYPE_EVENTS_CODE . '&bigType=Event',
 
- 				'试用' => $url . LotteryEvents::TYPE_EVENTS_TRY . '&bigType=Event',
 
- 				'问卷调查' => $url . LotteryEvents::TYPE_EVENTS_SURVEY . '&bigType=Event',
 
- 				'投票' => $url . LotteryEvents::TYPE_EVENTS_VOTE . '&bigType=Event',
 
- 				'切屏专题' => $url . LotteryEvents::TYPE_EVENTS_CUT_SCREEN . '&bigType=H5',
 
- 				'文章' => $url . LotteryEvents::TYPE_EVENTS_ARTICLE . '&bigType=Article',
 
- 				'其他' => $url . LotteryEvents::TYPE_EVENTS_OTHER . '&bigType=Event',
 
- 		);
 
- 		return $fastCreateActivityUrlData;
 
- 	}
 
- 	
 
- 	public function display() {
 
- 		return $this->render();
 
- 	}
 
- }
 
 
  |