Dashboard.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\Admin;
  4. use app\admin\model\box\Box;
  5. use app\admin\model\goods\Goods;
  6. use app\admin\model\trade\Order;
  7. use app\admin\model\trade\Rechargeorder;
  8. use app\admin\model\User;
  9. use app\common\controller\Backend;
  10. use app\common\model\Attachment;
  11. use fast\Date;
  12. use think\Db;
  13. /**
  14. * 控制台
  15. *
  16. * @icon fa fa-dashboard
  17. * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
  18. */
  19. class Dashboard extends Backend
  20. {
  21. /**
  22. * 查看
  23. */
  24. public function index()
  25. {
  26. try {
  27. \think\Db::execute("SET @@sql_mode='';");
  28. } catch (\Exception $e) {
  29. }
  30. $column = [];
  31. $starttime = Date::unixtime('day', -6);
  32. $endtime = Date::unixtime('day', 0, 'end');
  33. $joinlist = Db("user")->where('jointime', 'between time', [$starttime, $endtime])
  34. ->field('jointime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(jointime), "%Y-%m-%d") AS join_date')
  35. ->group('join_date')
  36. ->select();
  37. for ($time = $starttime; $time <= $endtime;) {
  38. $column[] = date("Y-m-d", $time);
  39. $time += 86400;
  40. }
  41. $userlist = array_fill_keys($column, 0);
  42. foreach ($joinlist as $k => $v) {
  43. $userlist[$v['join_date']] = $v['nums'];
  44. }
  45. $this->view->assign([
  46. 'totaluser' => User::count(),
  47. 'usedBoxOrderCount' => Order::where('status','used')->count(),
  48. 'totalgoods' => Goods::count(),
  49. 'totalbox' => Box::count(),
  50. 'todayusersignup' => User::whereTime('jointime', 'today')->count(),
  51. 'todayuserlogin' => User::whereTime('logintime', 'today')->count(),
  52. 'sevendau' => User::whereTime('jointime|logintime|prevtime', '-7 days')->count(),
  53. 'thirtydau' => User::whereTime('jointime|logintime|prevtime', '-30 days')->count(),
  54. 'threednu' => User::whereTime('jointime', '-3 days')->count(),
  55. 'sevendnu' => User::whereTime('jointime', '-7 days')->count(),
  56. 'money_box_unpay' => Order::where('status','unpay')->sum('rmb_amount'),
  57. 'money_box_paid' => Order::where('status','unused')->whereOr('status','used')->sum('rmb_amount'),
  58. 'money_recharge_unpay' => Rechargeorder::where('status','unpay')->sum('rmb_amount'),
  59. 'money_recharge_paid' => Rechargeorder::where('status','paid')->sum('rmb_amount'),
  60. 'attachmentnums' => Attachment::count(),
  61. 'attachmentsize' => Attachment::sum('filesize'),
  62. 'picturenums' => Attachment::where('mimetype', 'like', 'image/%')->count(),
  63. 'picturesize' => Attachment::where('mimetype', 'like', 'image/%')->sum('filesize'),
  64. 'today_uv' => db("uv")->whereTime("createtime", "today")->count(),
  65. 'total_uv' => db("uv")->count(),
  66. ]);
  67. $this->assignconfig('column', array_keys($userlist));
  68. $this->assignconfig('userdata', array_values($userlist));
  69. return $this->view->fetch();
  70. }
  71. }