Recorddata.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\h5\controller;
  3. use app\hander\HelpHander;
  4. use think\Controller;
  5. use think\Db;
  6. class Recorddata extends Controller {
  7. private $userid;
  8. private $token;
  9. public function __construct() {
  10. parent::__construct();
  11. $this->token = input('token');
  12. if (empty($this->token)) {
  13. $this->lo(url('/h5/index/errorPage'));
  14. }
  15. $this->userid = $this->checktoken();
  16. }
  17. public function record() {
  18. $this->assign('token', $this->token);
  19. return $this->fetch('StaffLearning/record');
  20. }
  21. public function recordChart() {
  22. $days_arr = get_one_month();
  23. $days = array();
  24. $days2 = array();
  25. $times = array();
  26. foreach ($days_arr as $k => $v) {
  27. $days[] = date('m-d', strtotime($v));
  28. $days2[date('m-d', strtotime($v))] = $v;
  29. $times_list = Db::name('record')
  30. ->field('SUM(time) as times')
  31. ->where('user_id', $this->userid)
  32. ->where('create_yyyymmdd', $v)
  33. ->find();
  34. $times[] = empty($times_list['times']) ? 0 : $times_list['times'];
  35. }
  36. $data = array(
  37. 'days' => $days,
  38. 'days2' => $days2,
  39. 'times' => $times,
  40. );
  41. HelpHander::success($data);
  42. }
  43. public function recordList() {
  44. $day = input('day');
  45. $where = array();
  46. if ($day == '') {
  47. $where[] = ['record.create_yyyymmdd', '=', date('Ymd')];
  48. }
  49. else {
  50. $where[] = ['record.create_yyyymmdd', '=', $day];
  51. }
  52. $data = Db::name('record')
  53. ->field('article.title,record.time,record.create_time,record.create_yyyymmdd')
  54. ->where($where)
  55. ->where('record.user_id', $this->userid)
  56. ->join('article', 'article.id = record.article_id')
  57. ->select();
  58. HelpHander::success($data);
  59. }
  60. public function lo($url) {
  61. header("Location: $url");
  62. exit();
  63. }
  64. public function checkToken() {
  65. $token = input('token');
  66. if (!$token) {
  67. $this->lo(url('/h5/index/errorPage'));
  68. }
  69. $tokenInfo = Db::name('token')
  70. ->where('token', $token)
  71. ->find();
  72. if (empty($tokenInfo)) {
  73. $this->lo(url('/h5/index/errorPage'));
  74. }
  75. return $tokenInfo['user_id'];
  76. }
  77. }