Index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\controller;
  15. use library\Controller;
  16. use library\service\AdminService;
  17. use library\service\MenuService;
  18. use library\tools\Data;
  19. use think\Console;
  20. use think\Db;
  21. use think\exception\HttpResponseException;
  22. /**
  23. * 系统公共操作
  24. * Class Index
  25. * @package app\admin\controller
  26. */
  27. class Index extends Controller
  28. {
  29. /**
  30. * 显示后台首页
  31. * @throws \ReflectionException
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. * @throws \think\exception\DbException
  35. */
  36. public function index()
  37. {
  38. $this->title = '系统管理后台';
  39. $auth = AdminService::instance()->apply(true);
  40. $this->menus = MenuService::instance()->getTree();
  41. if (empty($this->menus) && !$auth->isLogin()) {
  42. $this->redirect('@admin/login');
  43. } else {
  44. $this->fetch();
  45. }
  46. }
  47. /**
  48. * 后台环境信息
  49. */
  50. public function main()
  51. {
  52. $notice = Db::name('store_notice')->where('is_deleted','=',0)->order('create_at','DESC')->limit(3)->select();
  53. $activity = Db::name('store_activity')->where('is_deleted','=',0)->order('id','DESC')->limit(1)->find();
  54. $activity['content'] = strip_tags(htmlspecialchars_decode($activity['content']));
  55. $member_count = Db::name('store_member')->count('id');
  56. $sta_week = date("Y-m-d H:i:s", mktime(0,0,0,date("m"),date("d")-date("w")+1,date("Y"))); //2020-03-09 00:00:00
  57. $end_week = date("Y-m-d H:i:s", mktime(0,0,0,date("m"),date("d")-date("w")+7,date("Y"))); //2020-03-09 00:00:00
  58. $weeek_regiz = Db::name('store_member')->whereBetween('create_at',[$sta_week,$end_week])->count();
  59. $member_rz = Db::name('store_member')->where('vip_level','=',1)->count('id');
  60. $activity_count= Db::name('store_activity')->where('is_deleted','=',0)->count();
  61. $forum_count = Db::name('store_emotional_counseling')->where('is_deleted','=',0)->count();
  62. $examine_count = Db::name('store_examine')->where('status','=',1)->count();
  63. $examine_forum =Db::name('store_forum')->where('status','=',1)->count();
  64. $examine_report =Db::name('store_report')->where('status','=',1)->count();
  65. $no_emotion = Db::name('store_emotional_counseling')->where('is_deleted','=',0)->where('status','=',1)->count();
  66. $nan_count = Db::name('store_member')->where('sex',1)->count('id');
  67. $nv_count = Db::name('store_member')->where('sex',2)->count('id');
  68. $lanshan_count = Db::name('store_member')->where('area_id',1480)->count('id');
  69. $luozhuang_count = Db::name('store_member')->where('area_id',1481)->count('id');
  70. $hedong_count = Db::name('store_member')->where('area_id',1482)->count('id');
  71. $yinan_count = Db::name('store_member')->where('area_id',1483)->count('id');
  72. $tancheng_count = Db::name('store_member')->where('area_id',1484)->count('id');
  73. $yishui_count = Db::name('store_member')->where('area_id',1485)->count('id');
  74. $lanling_count = Db::name('store_member')->where('area_id',1486)->count('id');
  75. $fei_count = Db::name('store_member')->where('area_id',1487)->count('id');
  76. $pingyi_count = Db::name('store_member')->where('area_id',1488)->count('id');
  77. $junan_count = Db::name('store_member')->where('area_id',1489)->count('id');
  78. $mengyin_count = Db::name('store_member')->where('area_id',1490)->count('id');
  79. $linshu_count = Db::name('store_member')->where('area_id',1491)->count('id');
  80. //男女学历统计
  81. $a1 = Db::name('store_member')->where('sex',1)->where('education','=','高中')->count();
  82. $b1= Db::name('store_member')->where('sex',2)->where('education','=','高中')->count();
  83. $a2 = Db::name('store_member')->where('sex',1)->where('education','=','大专')->count();
  84. $b2= Db::name('store_member')->where('sex',2)->where('education','=','大专')->count();
  85. $a3 = Db::name('store_member')->where('sex',1)->where('education','=','本科')->count();
  86. $b3= Db::name('store_member')->where('sex',2)->where('education','=','本科')->count();
  87. $a4 = Db::name('store_member')->where('sex',1)->where('education','=','研究生')->count();
  88. $b4= Db::name('store_member')->where('sex',2)->where('education','=','研究生')->count();
  89. $a5 = Db::name('store_member')->where('sex',1)->where('education','=','博士')->count();
  90. $b5= Db::name('store_member')->where('sex',2)->where('education','=','博士')->count();
  91. $working = Db::name('store_work_nature')
  92. ->alias('w')
  93. ->join('store_member m','w.id=m.nature')
  94. ->field('w.id,w.name,count(*) count')
  95. ->where('w.is_deleted','=',0)
  96. ->group('m.nature')
  97. ->order('count desc')
  98. ->limit(10)
  99. ->select();
  100. $nature = [];
  101. $nature_count_nan = [];
  102. $nature_count_nv = [];
  103. foreach ($working as $k=>$v){
  104. $nature[$k] ="'".$working[$k]['name']."'";
  105. $nature_count_nan[$k] = Db::name('store_member')->where('sex',1)->where('nature',$working[$k]['id'])->count();
  106. $nature_count_nv[$k] = Db::name('store_member')->where('sex',2)->where('nature',$working[$k]['id'])->count();
  107. }
  108. $nature = implode(',',$nature);
  109. $nature_count_nan = implode(',',$nature_count_nan);
  110. $nature_count_nv = implode(',',$nature_count_nv);
  111. $sale =[['min'=>20,'max'=>22],['min'=>23,'max'=>25],['min'=>26,'max'=>28],['min'=>29,'max'=>31],['min'=>32,'max'=>34],['min'=>35,'max'=>37],['min'=>38,'max'=>40],['min'=>41,'max'=>43],['min'=>44,'max'=>46],['min'=>47,'max'=>49],['min'=>50,'max'=>52],['min'=>53,'max'=>55],['min'=>56,'max'=>58],['min'=>59,'max'=>61],['min'=>62,'max'=>64]];
  112. $age_count_nan = [];
  113. $age_count_nv = [];
  114. foreach ($sale as $k1=>$v1){
  115. $where = [];
  116. $where[] = ['age', 'between', [$sale[$k1]['min'], $sale[$k1]['max']]];
  117. $age_count_nan[$k1] = Db::name('store_member')->where('sex',1)->where($where)->count();
  118. $age_count_nv[$k1] = Db::name('store_member')->where('sex',2)->where($where)->count();
  119. }
  120. // die;
  121. // print_r($age_count_nv);print_r($age_count_nan);
  122. $age_count_nan = implode(',',$age_count_nan);
  123. $age_count_nv = implode(',',$age_count_nv);
  124. $this->fetch('main',
  125. [
  126. 'member_count'=>$member_count,
  127. 'member_rz'=>$member_rz,
  128. 'activity_count'=>$activity_count,
  129. 'forum_count'=>$forum_count,
  130. 'examine_count'=>$examine_count,
  131. 'examine_forum'=>$examine_forum,
  132. 'examine_report'=>$examine_report,
  133. 'no_emotion'=>$no_emotion,
  134. 'nan_count'=>$nan_count,
  135. 'nv_count'=>$nv_count,
  136. 'activity'=>$activity,
  137. 'notice'=>$notice,
  138. 'nature'=>$nature,
  139. 'nature_count_nan'=>$nature_count_nan,
  140. 'nature_count_nv'=>$nature_count_nv,
  141. 'age_count_nan'=>$age_count_nan,
  142. 'age_count_nv'=>$age_count_nv,
  143. 'gaozhong' => "['高中',$a1,$b1]",
  144. 'dazhuan' => "['大专',$a2,$b2]",
  145. 'benke' => "['本科',$a3,$b3]",
  146. 'shuoshi' => "['硕士',$a4,$b4]",
  147. 'boshi' => "['博士',$a5,$b5]",
  148. 'count'=>$weeek_regiz,
  149. 'lanshan_count'=>$lanshan_count,
  150. 'luozhuang_count'=>$luozhuang_count,
  151. 'hedong_count'=>$hedong_count,
  152. 'yinan_count'=>$yinan_count,
  153. 'tancheng_count'=>$tancheng_count,
  154. 'yishui_count'=>$yishui_count,
  155. 'lanling_count'=>$lanling_count,
  156. 'fei_count'=>$fei_count,
  157. 'pingyi_count'=>$pingyi_count,
  158. 'junan_count'=>$junan_count,
  159. 'mengyin_count'=>$mengyin_count,
  160. 'linshu_count'=>$linshu_count,
  161. ]);
  162. }
  163. public function tongji(){
  164. $this->fetch('tongji');
  165. }
  166. /**
  167. * 修改密码
  168. * @login true
  169. * @param integer $id
  170. * @throws \think\Exception
  171. * @throws \think\db\exception\DataNotFoundException
  172. * @throws \think\db\exception\ModelNotFoundException
  173. * @throws \think\exception\DbException
  174. * @throws \think\exception\PDOException
  175. */
  176. public function pass($id)
  177. {
  178. $this->applyCsrfToken();
  179. if (intval($id) !== intval(session('user.id'))) {
  180. $this->error('只能修改当前用户的密码!');
  181. }
  182. if (!AdminService::instance()->isLogin()) {
  183. $this->error('需要登录才能操作哦!');
  184. }
  185. if ($this->request->isGet()) {
  186. $this->verify = true;
  187. $this->_form('SystemUser', 'admin@user/pass', 'id', [], ['id' => $id]);
  188. } else {
  189. $data = $this->_input([
  190. 'password' => $this->request->post('password'),
  191. 'repassword' => $this->request->post('repassword'),
  192. 'oldpassword' => $this->request->post('oldpassword'),
  193. ], [
  194. 'oldpassword' => 'require',
  195. 'password' => 'require|min:4',
  196. 'repassword' => 'require|confirm:password',
  197. ], [
  198. 'oldpassword.require' => '旧密码不能为空!',
  199. 'password.require' => '登录密码不能为空!',
  200. 'password.min' => '登录密码长度不能少于4位有效字符!',
  201. 'repassword.require' => '重复密码不能为空!',
  202. 'repassword.confirm' => '重复密码与登录密码不匹配,请重新输入!',
  203. ]);
  204. $user = Db::name('SystemUser')->where(['id' => $id])->find();
  205. if (md5($data['oldpassword']) !== $user['password']) {
  206. $this->error('旧密码验证失败,请重新输入!');
  207. }
  208. if (Data::save('SystemUser', ['id' => $user['id'], 'password' => md5($data['password'])])) {
  209. $this->success('密码修改成功,下次请使用新密码登录!', '');
  210. } else {
  211. $this->error('密码修改失败,请稍候再试!');
  212. }
  213. }
  214. }
  215. /**
  216. * 修改用户资料
  217. * @login true
  218. * @param integer $id 会员ID
  219. * @throws \think\Exception
  220. * @throws \think\db\exception\DataNotFoundException
  221. * @throws \think\db\exception\ModelNotFoundException
  222. * @throws \think\exception\DbException
  223. * @throws \think\exception\PDOException
  224. */
  225. public function info($id = 0)
  226. {
  227. if (!AdminService::instance()->isLogin()) {
  228. $this->error('需要登录才能操作哦!');
  229. }
  230. $this->applyCsrfToken();
  231. if (intval($id) === intval(session('user.id'))) {
  232. $this->_form('SystemUser', 'admin@user/form', 'id', [], ['id' => $id]);
  233. } else {
  234. $this->error('只能修改登录用户的资料!');
  235. }
  236. }
  237. /**
  238. * 清理运行缓存
  239. * @auth true
  240. */
  241. public function clearRuntime()
  242. {
  243. try {
  244. Console::call('clear');
  245. Console::call('xclean:session');
  246. $this->success('清理运行缓存成功!');
  247. } catch (HttpResponseException $exception) {
  248. throw $exception;
  249. } catch (\Exception $e) {
  250. $this->error("清理运行缓存失败,{$e->getMessage()}");
  251. }
  252. }
  253. /**
  254. * 压缩发布系统
  255. * @auth true
  256. */
  257. public function buildOptimize()
  258. {
  259. try {
  260. Console::call('optimize:route');
  261. Console::call('optimize:schema');
  262. Console::call('optimize:autoload');
  263. Console::call('optimize:config');
  264. $this->success('压缩发布成功!');
  265. } catch (HttpResponseException $exception) {
  266. throw $exception;
  267. } catch (\Exception $e) {
  268. $this->error("压缩发布失败,{$e->getMessage()}");
  269. }
  270. }
  271. }