人人商城

notice.ctrl.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. if(empty($_W['uid'])) {
  8. exit('uid not exist');
  9. }
  10. $new_id = pdo_fetchcolumn('SELECT notice_id FROM' . tablename('article_unread_notice') . ' WHERE uid = :uid ORDER BY notice_id DESC LIMIT 1', array(':uid' => $_W['uid']));
  11. $new_id = intval($new_id);
  12. $notices = pdo_fetchall('SELECT id FROM ' . tablename('article_notice') . ' WHERE is_display = 1 AND id > :id', array(':id' => $new_id));
  13. if(!empty($notices)) {
  14. foreach($notices as &$notice) {
  15. $insert = array(
  16. 'uid' => $_W['uid'],
  17. 'notice_id' => $notice['id'],
  18. 'is_new' => 1,
  19. );
  20. pdo_insert('article_unread_notice', $insert);
  21. }
  22. }
  23. $total = 0;
  24. $notreads = array();
  25. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM' . tablename('article_unread_notice') . ' WHERE uid = :uid AND is_new = 1', array(':uid' => $_W['uid']));
  26. $categorys = pdo_fetchall('SELECT id,title FROM ' . tablename('article_category') . ' WHERE type = :type', array(':type' => 'notice'), 'id');
  27. if($total > 0) {
  28. $notreads = pdo_fetchall('SELECT id,title,createtime,cateid FROM ' . tablename('article_notice') . ' WHERE is_display = 1 AND id IN (SELECT notice_id FROM '. tablename('article_unread_notice') . ' WHERE uid = :uid AND is_new = 1) ORDER BY displayorder DESC, id DESC LIMIT 5', array(':uid' => $_W['uid']), 'id');
  29. foreach($notreads as &$notread) {
  30. $notread['catename'] = $categorys[$notread['cateid']]['title'];
  31. $notread['is_new'] = 1;
  32. }
  33. }
  34. if($total < 5) {
  35. $limit = 5 - $total;
  36. $notices = pdo_fetchall('SELECT id,title,createtime,cateid FROM ' . tablename('article_notice') . ' WHERE is_display = 1 ORDER BY displayorder DESC, id DESC LIMIT ' . $limit, array(), 'id');
  37. foreach($notices as &$notice) {
  38. $notice['catename'] = $categorys[$notice['cateid']]['title'];
  39. $notice['is_new'] = 0;
  40. }
  41. }
  42. $notices = array_merge($notreads, $notices);
  43. $html = '';
  44. if(!empty($notices)) {
  45. foreach($notices as $row) {
  46. $class = 'new';
  47. if(!$row['is_new']) {
  48. $class = 'old';
  49. }
  50. $html .= '<li>' .
  51. '<a href="'.url('article/notice-show/detail', array('id' => $row['id'])).'" target="_blank" class="clearfix">' .
  52. '<div><i class="fa fa-circle ' . $class . '"></i></div>' .
  53. '<div>' .
  54. '<h3>' . $row['title'] . '</h3>' .
  55. '<div class="date">' . date('Y-m-d', $row['createtime']) . '</div>' .
  56. '</div>' .
  57. '<div><span class="label label-info">'. $row['catename'] .'</span></div>' .
  58. '</a>' .
  59. '</li>';
  60. }
  61. }
  62. $data = array(
  63. 'total' => $total,
  64. 'notices' => $html
  65. );
  66. exit(json_encode($data));