Index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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)->where('vip_level',0)->count('id');
  67. $nv_count = Db::name('store_member')->where('sex',2)->where('vip_level',0)->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. // print_r($nan_count);
  125. // exit;
  126. $this->fetch('main',
  127. [
  128. 'member_count'=>$member_count,
  129. 'member_rz'=>$member_rz,
  130. 'activity_count'=>$activity_count,
  131. 'forum_count'=>$forum_count,
  132. 'examine_count'=>$examine_count,
  133. 'examine_forum'=>$examine_forum,
  134. 'examine_report'=>$examine_report,
  135. 'no_emotion'=>$no_emotion,
  136. 'nan_count'=>$nan_count,
  137. 'nv_count'=>$nv_count,
  138. 'activity'=>$activity,
  139. 'notice'=>$notice,
  140. 'nature'=>$nature,
  141. 'nature_count_nan'=>$nature_count_nan,
  142. 'nature_count_nv'=>$nature_count_nv,
  143. 'age_count_nan'=>$age_count_nan,
  144. 'age_count_nv'=>$age_count_nv,
  145. 'gaozhong' => "['高中',$a1,$b1]",
  146. 'dazhuan' => "['大专',$a2,$b2]",
  147. 'benke' => "['本科',$a3,$b3]",
  148. 'shuoshi' => "['硕士',$a4,$b4]",
  149. 'boshi' => "['博士',$a5,$b5]",
  150. 'count'=>$weeek_regiz,
  151. 'lanshan_count'=>$lanshan_count,
  152. 'luozhuang_count'=>$luozhuang_count,
  153. 'hedong_count'=>$hedong_count,
  154. 'yinan_count'=>$yinan_count,
  155. 'tancheng_count'=>$tancheng_count,
  156. 'yishui_count'=>$yishui_count,
  157. 'lanling_count'=>$lanling_count,
  158. 'fei_count'=>$fei_count,
  159. 'pingyi_count'=>$pingyi_count,
  160. 'junan_count'=>$junan_count,
  161. 'mengyin_count'=>$mengyin_count,
  162. 'linshu_count'=>$linshu_count,
  163. ]);
  164. }
  165. public function tongji(){
  166. $this->fetch('tongji');
  167. }
  168. /**
  169. * 修改密码
  170. * @login true
  171. * @param integer $id
  172. * @throws \think\Exception
  173. * @throws \think\db\exception\DataNotFoundException
  174. * @throws \think\db\exception\ModelNotFoundException
  175. * @throws \think\exception\DbException
  176. * @throws \think\exception\PDOException
  177. */
  178. public function pass($id)
  179. {
  180. $this->applyCsrfToken();
  181. if (intval($id) !== intval(session('user.id'))) {
  182. $this->error('只能修改当前用户的密码!');
  183. }
  184. if (!AdminService::instance()->isLogin()) {
  185. $this->error('需要登录才能操作哦!');
  186. }
  187. if ($this->request->isGet()) {
  188. $this->verify = true;
  189. $this->_form('SystemUser', 'admin@user/pass', 'id', [], ['id' => $id]);
  190. } else {
  191. $data = $this->_input([
  192. 'password' => $this->request->post('password'),
  193. 'repassword' => $this->request->post('repassword'),
  194. 'oldpassword' => $this->request->post('oldpassword'),
  195. ], [
  196. 'oldpassword' => 'require',
  197. 'password' => 'require|min:4',
  198. 'repassword' => 'require|confirm:password',
  199. ], [
  200. 'oldpassword.require' => '旧密码不能为空!',
  201. 'password.require' => '登录密码不能为空!',
  202. 'password.min' => '登录密码长度不能少于4位有效字符!',
  203. 'repassword.require' => '重复密码不能为空!',
  204. 'repassword.confirm' => '重复密码与登录密码不匹配,请重新输入!',
  205. ]);
  206. $user = Db::name('SystemUser')->where(['id' => $id])->find();
  207. if (md5($data['oldpassword']) !== $user['password']) {
  208. $this->error('旧密码验证失败,请重新输入!');
  209. }
  210. if (Data::save('SystemUser', ['id' => $user['id'], 'password' => md5($data['password'])])) {
  211. $this->success('密码修改成功,下次请使用新密码登录!', '');
  212. } else {
  213. $this->error('密码修改失败,请稍候再试!');
  214. }
  215. }
  216. }
  217. /**
  218. * 修改用户资料
  219. * @login true
  220. * @param integer $id 会员ID
  221. * @throws \think\Exception
  222. * @throws \think\db\exception\DataNotFoundException
  223. * @throws \think\db\exception\ModelNotFoundException
  224. * @throws \think\exception\DbException
  225. * @throws \think\exception\PDOException
  226. */
  227. public function info($id = 0)
  228. {
  229. if (!AdminService::instance()->isLogin()) {
  230. $this->error('需要登录才能操作哦!');
  231. }
  232. $this->applyCsrfToken();
  233. if (intval($id) === intval(session('user.id'))) {
  234. $this->_form('SystemUser', 'admin@user/form', 'id', [], ['id' => $id]);
  235. } else {
  236. $this->error('只能修改登录用户的资料!');
  237. }
  238. }
  239. /**
  240. * 清理运行缓存
  241. * @auth true
  242. */
  243. public function clearRuntime()
  244. {
  245. try {
  246. Console::call('clear');
  247. Console::call('xclean:session');
  248. $this->success('清理运行缓存成功!');
  249. } catch (HttpResponseException $exception) {
  250. throw $exception;
  251. } catch (\Exception $e) {
  252. $this->error("清理运行缓存失败,{$e->getMessage()}");
  253. }
  254. }
  255. /**
  256. * 压缩发布系统
  257. * @auth true
  258. */
  259. public function buildOptimize()
  260. {
  261. try {
  262. Console::call('optimize:route');
  263. Console::call('optimize:schema');
  264. Console::call('optimize:autoload');
  265. Console::call('optimize:config');
  266. $this->success('压缩发布成功!');
  267. } catch (HttpResponseException $exception) {
  268. throw $exception;
  269. } catch (\Exception $e) {
  270. $this->error("压缩发布失败,{$e->getMessage()}");
  271. }
  272. }
  273. }