SiteController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. class SiteController extends AdminController
  3. {
  4. /**
  5. * 后台首页
  6. */
  7. public function actionIndex()
  8. {
  9. $admin_info = $this->getAdminInfo();
  10. $admin_user = Yii::app()->user->getId();
  11. $data = array('user_name' => '');
  12. $data['has_fake_user'] = false;
  13. if ($admin_info){
  14. $data['user_name'] = $admin_info['name'];
  15. $data['has_fake_user'] = $admin_info['fake_users'] ? true : false;
  16. }
  17. $criteria = new EMongoCriteria();
  18. $criteria->status('==', 1);
  19. $criteria->sort('sort', EMongoCriteria::SORT_ASC);
  20. $cursor = AdminMenuAR::model()->findAll($criteria);
  21. $auth = Yii::app()->authManager;
  22. $filter_ids = array();
  23. $is_super_admin = $this->isSuperAdmin();
  24. if (!$is_super_admin){
  25. $filter_parent = array();
  26. foreach ($cursor as $v){
  27. if (in_array($v->_id, $filter_ids) || ($v->auth_item != '' && $auth->checkAccess($v->auth_item, $admin_user))){
  28. if ($v->parent != '' && !in_array($v->parent, $filter_ids)){
  29. $filter_ids[] = $v->parent;
  30. $filter_parent[] = $v->parent;
  31. }
  32. if (!in_array($v->_id, $filter_ids)){
  33. $filter_ids[] = $v->_id;
  34. }
  35. }
  36. }
  37. //临时处理3级深层目录的情况,后面改为code来优化
  38. foreach ($cursor as $v){
  39. if (in_array($v->_id, $filter_parent) && $v->parent != ''){
  40. $filter_ids[] = $v->parent;
  41. }
  42. }
  43. }
  44. $rows = array();
  45. $index = array();
  46. foreach ($cursor as $v){
  47. $temp = $v->attributes;
  48. $temp['_id'] = (string)$temp['_id'];
  49. $temp['parent'] = (string)$temp['parent'];
  50. if ($temp['url'] != ''){
  51. $index[$temp['_id']] = array(
  52. 'name' => $temp['name'],
  53. 'url' => Yii::app()->request->baseUrl . $temp['url'],
  54. 'id' => $temp['_id']
  55. );
  56. }
  57. if ($is_super_admin || in_array($v->_id, $filter_ids)){
  58. $rows[] = $temp;
  59. }
  60. }
  61. $data['menu_index'] = $index;
  62. $data['menu'] = CommonFn::composeTreeData($rows);
  63. // 判断服务器(测试版or正式版)
  64. if (ENVIRONMENT == 'test') {
  65. $data['site'] = 'test';
  66. } else if (ENVIRONMENT == 'develop') {
  67. $data['site'] = 'dev';
  68. } else {
  69. $data['site'] = 'admin';
  70. }
  71. $this->render('index_new', $data);
  72. }
  73. /**
  74. * 登录页面
  75. */
  76. public function actionLogin()
  77. {
  78. $model = new LoginForm();
  79. if (isset($_POST['LoginForm'])){
  80. $model->attributes = $_POST['LoginForm'];
  81. if ($model->validate() && $model->login()){
  82. $this->redirect(Yii::app()->user->returnUrl);
  83. }
  84. }
  85. $this->renderPartial('login', array('model'=>$model));
  86. }
  87. /**
  88. * 注册页面
  89. */
  90. public function actionRegister(){
  91. $model = new RegisterForm('register');
  92. if (isset($_POST['RegisterForm'])){
  93. $model->attributes = $_POST['RegisterForm'];
  94. if ($model->validate()){
  95. $user = $model->register();
  96. $this->redirect(Yii::app()->homeUrl);
  97. }
  98. }
  99. $this->renderPartial('register', array('model'=>$model));
  100. }
  101. /**
  102. * 退出登录
  103. */
  104. public function actionLogout()
  105. {
  106. Yii::app()->user->logout();
  107. $this->redirect(Yii::app()->homeUrl);
  108. }
  109. public function actionError(){
  110. if ($error=Yii::app()->errorHandler->error){
  111. if(ENVIRONMENT != 'product'){
  112. var_dump($error);die();
  113. }
  114. if(Yii::app()->request->isAjaxRequest){
  115. echo $error['message'];
  116. } else {
  117. $this->renderPartial('error', $error);
  118. }
  119. }
  120. }
  121. public function actionTest(){
  122. $list = new ARedisList('o2o_after_pay_success567');
  123. $list->push('abc');
  124. while ($list->getCount() > 0) {
  125. try {
  126. $res = $list->pop();
  127. var_dump($res);exit;
  128. } catch (Exception $e) {
  129. continue;
  130. }
  131. }
  132. /* $redis = new Redis();
  133. $redis->connect('10.9.160.211', 6379);
  134. $key = "testkey";
  135. $tvalue = "testvalue";
  136. $redis->set($key, $tvalue);
  137. $nvalue = $redis->get($key);
  138. print_r($nvalue . "\n");*/
  139. }
  140. }