|
|
@@ -12,6 +12,7 @@ use crmeb\basic\BaseModel;
|
|
|
use think\facade\Db;
|
|
|
use think\facade\Log;
|
|
|
use think\facade\Config;
|
|
|
+use think\facade\Env;
|
|
|
/**
|
|
|
* Class UserNotice
|
|
|
* @package app\models\user
|
|
|
@@ -59,13 +60,15 @@ class UserNotice extends BaseModel
|
|
|
}
|
|
|
// 获取未读数
|
|
|
public static function getNotice($uid){
|
|
|
- $row = Db::query("
|
|
|
- select count(*) as unread from tw_user_notice where id not in (
|
|
|
- select nid from tw_user_notice_see where uid=?
|
|
|
- ) and uid in (?, 0) and del_time=0
|
|
|
- ", [$uid, $uid]
|
|
|
- );
|
|
|
-
|
|
|
+ $prefix = Env::get('database.prefix', 'eb_');
|
|
|
+ $tnotice = $prefix . 'user_notice';
|
|
|
+ $tnotice_see = $prefix . 'user_notice_see';
|
|
|
+ $sql = sprintf("
|
|
|
+ select count(*) as unread from %s where id not in (
|
|
|
+ select nid from %s where uid=%d
|
|
|
+ ) and uid in (%d, 0) and del_time=0
|
|
|
+ ", $tnotice, $tnotice_see, $uid, $uid);
|
|
|
+ $row = Db::query($sql);
|
|
|
return intval($row[0]['unread']);
|
|
|
}
|
|
|
|
|
|
@@ -74,13 +77,17 @@ class UserNotice extends BaseModel
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function getNoticeList($uid, $page, $limit = 20){
|
|
|
- $data = Db::query("
|
|
|
+ $prefix = Env::get('database.prefix', 'eb_');
|
|
|
+ $tnotice = $prefix . 'user_notice';
|
|
|
+ $tnotice_see = $prefix . 'user_notice_see';
|
|
|
+ $sql = sprintf("
|
|
|
select n.id, n.icon, n.`user` as `from`, n.title as subject, n.content as `body`, n.add_time as ts, n.`type`, count(s.id) as `read`
|
|
|
- from tw_user_notice n right join tw_user_notice_see s on n.uid = s.uid
|
|
|
- where n.uid in (?, 0) and n.del_time=0
|
|
|
+ from %s n right join %s s on n.uid = s.uid
|
|
|
+ where n.uid in (%d, 0) and n.del_time=0
|
|
|
group by s.id
|
|
|
- order by n.add_time desc limit ?,?
|
|
|
- ", [$uid, ($page-1)*$limit, $limit]);
|
|
|
+ order by n.add_time desc limit %d,%d
|
|
|
+ ", $tnotice, $tnotice_see, $uid, ($page-1)*$limit, $limit);
|
|
|
+ $data = Db::query($sql);
|
|
|
|
|
|
return $data;
|
|
|
}
|