UserNotice.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/11
  6. */
  7. namespace app\models\user;
  8. use app\admin\model\user\UserNoticeSee;
  9. use crmeb\traits\ModelTrait;
  10. use crmeb\basic\BaseModel;
  11. /**
  12. * TODO 用户通知Model
  13. * Class UserNotice
  14. * @package app\models\user
  15. */
  16. class UserNotice extends BaseModel
  17. {
  18. use ModelTrait;
  19. public static function getNotice($uid){
  20. $count_notice = self::whereIn('uid', [$uid, 0])->where("is_send",1)->count();
  21. $see_notice = UserNoticeSee::where("uid", $uid)->count();
  22. return $count_notice-$see_notice;
  23. }
  24. /**
  25. * @return array
  26. */
  27. public static function getNoticeList($uid, $page, $limit = 8){
  28. $list = self::whereIn('uid', [$uid,0])
  29. ->where('is_send', 1)
  30. ->field('id,user,title,content,add_time')
  31. ->order("add_time desc")
  32. ->limit($page*$limit,$limit)->select()->toArray();
  33. foreach ($list as $key => $value) {
  34. $list[$key]["add_time"] = date("Y-m-d H:i:s",$value["add_time"]);
  35. $list[$key]["is_see"] = 0; //UserNoticeSee::where("uid",$uid)->where("nid",$value["id"])->count() > 0 ? 1 : 0;
  36. }
  37. $data["list"] = $list;
  38. return $data;
  39. }
  40. /**
  41. * @return array
  42. */
  43. public static function seeNotice($uid, $nid){
  44. if(UserNoticeSee::where("uid", $uid)->where("nid", $nid)->count() <= 0){
  45. $data["nid"] = $nid;
  46. $data["uid"] = $uid;
  47. $data["add_time"] = time();
  48. UserNoticeSee::create($data);
  49. }
  50. }
  51. }