Index.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 app\common\model\UserForum;
  16. use app\common\model\UserDatum;
  17. use app\common\model\UserArticle;
  18. use app\common\model\UserVideo;
  19. use library\Controller;
  20. use library\service\AdminService;
  21. use library\service\MenuService;
  22. use library\tools\Data;
  23. use think\Console;
  24. use think\Db;
  25. use think\exception\HttpResponseException;
  26. /**
  27. * 系统公共操作
  28. * Class Index
  29. * @package app\admin\controller
  30. */
  31. class Index extends Controller
  32. {
  33. /**
  34. * 显示后台首页
  35. * @throws \ReflectionException
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. * @throws \think\exception\DbException
  39. */
  40. public function index()
  41. {
  42. $this->title = '系统管理后台';
  43. $auth = AdminService::instance()->apply(true);
  44. $this->menus = MenuService::instance()->getTree();
  45. $where[] = ['f.is_deleted','=',0];
  46. $where[] = ['f.is_new','=',1];
  47. //问答
  48. $forum = UserForum::alias('f')
  49. ->field("f.*,u.name,u.phone,u.headimg,IFNULL((SELECT count(r.id) reply_num FROM dd_forum_reply as r where r.forum_id = f.id AND r.is_deleted = 0),0) reply_num")
  50. ->leftJoin('store_member u','u.id = f.user_id')
  51. ->where($where)
  52. ->order('sort desc,f.id desc')->count();
  53. if($forum > 0){
  54. $this->forum = 1; //有新增
  55. }else{
  56. $this->forum = 0; //无新增
  57. }
  58. //资料
  59. $datum = UserDatum::alias('f')->where($where)->count();
  60. if($datum > 0){
  61. $this->datum = 1; //有新增
  62. }else{
  63. $this->datum = 0; //无新增
  64. }
  65. //图文
  66. $article = UserArticle::alias('f')->where($where)->count();
  67. if($article > 0){
  68. $this->article = 1; //有新增
  69. }else{
  70. $this->article = 0; //无新增
  71. }
  72. //图文
  73. $video = UserVideo::alias('f')->where($where)->count();
  74. if($video > 0){
  75. $this->video = 1; //有新增
  76. }else{
  77. $this->video = 0; //无新增
  78. }
  79. if (empty($this->menus) && !$auth->isLogin()) {
  80. $this->redirect('@admin/login');
  81. } else {
  82. $this->fetch();
  83. }
  84. }
  85. /**
  86. * 后台环境信息
  87. */
  88. public function main()
  89. {
  90. $this->think_ver = \think\App::VERSION;
  91. $this->mysql_ver = Db::query('select version() as ver')[0]['ver'];
  92. $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
  93. $endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
  94. $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
  95. $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
  96. $user_num = \app\common\model\User::where('status',1)->where('is_deleted',0)->count();
  97. $agency_num = \app\common\model\User::where('is_agency',1)->where('is_deleted',0)->count();
  98. $partner_num = \app\common\model\User::where('is_partner',1)->where('is_deleted',0)->count();
  99. $goods_num = \app\common\model\StoreGoods::where('is_deleted',0)->count();
  100. $order_num = \app\common\model\GoodsOrder::where('status','>=',1)->count();
  101. $order_money = \app\common\model\GoodsOrder::where('status','>=',1)->sum('price_total');
  102. $gift_order_num = \app\common\model\GiftOrder::count();
  103. $gift_order_money = \app\common\model\GiftOrder::where('status',1)->sum('price_total');
  104. $news_num = \app\common\model\InformationArticle::where('is_deleted',0)->count();
  105. $video_num = \app\common\model\VideoIntro::where('is_deleted',0)->count();
  106. $new_user = \app\common\model\User::where('status',1)->whereBetweenTime('create_at',$beginToday,$endToday)->count();
  107. $data = [
  108. 'user_num' => $user_num,
  109. 'agency_num' => $agency_num,
  110. 'partner_num' => $partner_num,
  111. 'goods_num' => $goods_num,
  112. 'order_num' => $order_num,
  113. 'order_money' => $order_money,
  114. 'news_num' => $news_num,
  115. 'video_num' => $video_num,
  116. 'new_user' => $new_user,
  117. 'gift_order_num' => $gift_order_num,
  118. 'gift_order_money' => $gift_order_money,
  119. ];
  120. $this->assign('data',$data);
  121. $this->fetch();
  122. }
  123. /**
  124. * 修改密码
  125. * @login true
  126. * @param integer $id
  127. * @throws \think\Exception
  128. * @throws \think\db\exception\DataNotFoundException
  129. * @throws \think\db\exception\ModelNotFoundException
  130. * @throws \think\exception\DbException
  131. * @throws \think\exception\PDOException
  132. */
  133. public function pass($id)
  134. {
  135. $this->applyCsrfToken();
  136. if (intval($id) !== intval(session('user.id'))) {
  137. $this->error('只能修改当前用户的密码!');
  138. }
  139. if (!AdminService::instance()->isLogin()) {
  140. $this->error('需要登录才能操作哦!');
  141. }
  142. if ($this->request->isGet()) {
  143. $this->verify = true;
  144. $this->_form('SystemUser', 'admin@user/pass', 'id', [], ['id' => $id]);
  145. } else {
  146. $data = $this->_input([
  147. 'password' => $this->request->post('password'),
  148. 'repassword' => $this->request->post('repassword'),
  149. 'oldpassword' => $this->request->post('oldpassword'),
  150. ], [
  151. 'oldpassword' => 'require',
  152. 'password' => 'require|min:4',
  153. 'repassword' => 'require|confirm:password',
  154. ], [
  155. 'oldpassword.require' => '旧密码不能为空!',
  156. 'password.require' => '登录密码不能为空!',
  157. 'password.min' => '登录密码长度不能少于4位有效字符!',
  158. 'repassword.require' => '重复密码不能为空!',
  159. 'repassword.confirm' => '重复密码与登录密码不匹配,请重新输入!',
  160. ]);
  161. $user = Db::name('SystemUser')->where(['id' => $id])->find();
  162. if (md5($data['oldpassword']) !== $user['password']) {
  163. $this->error('旧密码验证失败,请重新输入!');
  164. }
  165. if (Data::save('SystemUser', ['id' => $user['id'], 'password' => md5($data['password'])])) {
  166. $this->success('密码修改成功,下次请使用新密码登录!', '');
  167. } else {
  168. $this->error('密码修改失败,请稍候再试!');
  169. }
  170. }
  171. }
  172. /**
  173. * 修改用户资料
  174. * @login true
  175. * @param integer $id 会员ID
  176. * @throws \think\Exception
  177. * @throws \think\db\exception\DataNotFoundException
  178. * @throws \think\db\exception\ModelNotFoundException
  179. * @throws \think\exception\DbException
  180. * @throws \think\exception\PDOException
  181. */
  182. public function info($id = 0)
  183. {
  184. if (!AdminService::instance()->isLogin()) {
  185. $this->error('需要登录才能操作哦!');
  186. }
  187. $this->applyCsrfToken();
  188. if (intval($id) === intval(session('user.id'))) {
  189. $this->_form('SystemUser', 'admin@user/form', 'id', [], ['id' => $id]);
  190. } else {
  191. $this->error('只能修改登录用户的资料!');
  192. }
  193. }
  194. /**
  195. * 清理运行缓存
  196. * @auth true
  197. */
  198. public function clearRuntime()
  199. {
  200. try {
  201. Console::call('clear');
  202. Console::call('xclean:session');
  203. $this->success('清理运行缓存成功!');
  204. } catch (HttpResponseException $exception) {
  205. throw $exception;
  206. } catch (\Exception $e) {
  207. $this->error("清理运行缓存失败,{$e->getMessage()}");
  208. }
  209. }
  210. /**
  211. * 压缩发布系统
  212. */
  213. public function buildOptimize()
  214. {
  215. try {
  216. Console::call('optimize:route');
  217. Console::call('optimize:schema');
  218. Console::call('optimize:autoload');
  219. Console::call('optimize:config');
  220. $this->success('压缩发布成功!');
  221. } catch (HttpResponseException $exception) {
  222. throw $exception;
  223. } catch (\Exception $e) {
  224. $this->error("压缩发布失败,{$e->getMessage()}");
  225. }
  226. }
  227. }