MainController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use common\helpers\FileHelper;
  5. use common\helpers\ResultHelper;
  6. use backend\forms\ClearCache;
  7. /**
  8. * 主控制器
  9. *
  10. * Class MainController
  11. * @package backend\controllers
  12. */
  13. class MainController extends BaseController
  14. {
  15. /**
  16. * 系统首页
  17. *
  18. * @return string
  19. */
  20. public function actionIndex()
  21. {
  22. // 触发主题切换
  23. !Yii::$app->params['isMobile'] && Yii::$app->services->theme->autoSwitcher();
  24. // 设置为 AJAX 关闭掉 DEBUG 显示
  25. YII_DEBUG && Yii::$app->request->headers->set('X-Requested-With', 'XMLHttpRequest');
  26. return $this->renderPartial('/theme/' . Yii::$app->params['theme']['layout'] . '/index', [
  27. ]);
  28. }
  29. /**
  30. * 子框架默认主页
  31. *
  32. * @return string
  33. */
  34. public function actionHome()
  35. {
  36. return $this->render($this->action->id, [
  37. 'memberCount' => Yii::$app->services->member->getCountByType(),
  38. 'memberAccount' => Yii::$app->services->memberAccount->getSumByType(),
  39. 'actionLogCount' => Yii::$app->services->actionLog->getCount(),
  40. ]);
  41. }
  42. /**
  43. * 用户指定时间内数量
  44. *
  45. * @param $type
  46. * @return array
  47. */
  48. public function actionMemberBetweenCount($type)
  49. {
  50. $data = Yii::$app->services->member->getBetweenCountStat($type);
  51. return ResultHelper::json(200, '获取成功', $data);
  52. }
  53. /**
  54. * 会员来源
  55. *
  56. * @return array|mixed
  57. */
  58. public function actionMemberSource()
  59. {
  60. $data = Yii::$app->services->member->getSourceStat();
  61. return ResultHelper::json(200, '获取成功', $data);
  62. }
  63. /**
  64. * 会员等级
  65. *
  66. * @return array|mixed
  67. */
  68. public function actionMemberLevel()
  69. {
  70. $data = Yii::$app->services->member->getLevelStat();
  71. return ResultHelper::json(200, '获取成功', $data);
  72. }
  73. /**
  74. * 充值统计
  75. *
  76. * @param $type
  77. * @return array
  78. */
  79. public function actionMemberRechargeStat($type)
  80. {
  81. $data = Yii::$app->services->memberCreditsLog->getRechargeStat($type);
  82. return ResultHelper::json(200, '获取成功', $data);
  83. }
  84. /**
  85. * 用户指定时间内消费日志
  86. *
  87. * @param $type
  88. * @return array
  89. */
  90. public function actionMemberCreditsLogBetweenCount($type)
  91. {
  92. $data = Yii::$app->services->memberCreditsLog->getBetweenCountStat($type);
  93. return ResultHelper::json(200, '获取成功', $data);
  94. }
  95. /**
  96. * 系统信息
  97. *
  98. * @return string
  99. */
  100. public function actionSystem()
  101. {
  102. // 禁用函数
  103. $disableFunctions = ini_get('disable_functions');
  104. $disableFunctions = !empty($disableFunctions) ? explode(',', $disableFunctions) : '未禁用';
  105. // 附件大小
  106. $attachmentSize = FileHelper::getDirSize(Yii::getAlias('@attachment'));
  107. $sysVersionStatus = false;
  108. try {
  109. $data = Yii::$app->services->rageFrame->queryNewest();
  110. $sysVersion = 'newest ' . $data['version'];
  111. $sysVersionStatus = true;
  112. } catch (\Exception $e) {
  113. // $sysVersion = $e->getMessage();
  114. $sysVersion = '';
  115. }
  116. return $this->render($this->action->id, [
  117. 'mysqlSize' => Yii::$app->services->base->getDefaultDbSize(),
  118. 'attachmentSize' => $attachmentSize ?? 0,
  119. 'disableFunctions' => $disableFunctions,
  120. 'sysVersion' => $sysVersion,
  121. 'sysVersionStatus' => $sysVersionStatus,
  122. ]);
  123. }
  124. /**
  125. * 清理缓存
  126. *
  127. * @return string
  128. */
  129. public function actionClearCache()
  130. {
  131. $model = new ClearCache();
  132. if ($model->load(Yii::$app->request->post())) {
  133. return $model->save()
  134. ? $this->message('清理成功', $this->refresh())
  135. : $this->message($this->getError($model), $this->refresh(), 'error');
  136. }
  137. return $this->render($this->action->id, [
  138. 'model' => $model
  139. ]);
  140. }
  141. }
粤ICP备19079148号