UserNotice.php 1.8 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::where('uid','like',"%,$uid,%")->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. //定义分页信息
  29. $count = self::where('uid','like',"%,$uid,%")->count();
  30. $data["lastpage"] = ceil($count/$limit) <= ($page+1) ? 1 : 0;
  31. $where['uid'] = array("like","%,$uid,%");
  32. // $where['uid'] = array(array("like","%,$uid,%"),array("eq",""), 'or');
  33. $where['is_send'] = 1;
  34. $list = self::where($where)->field('id,user,title,content,add_time')->order("add_time desc")->limit($page*$limit,$limit)->select()->toArray();
  35. foreach ($list as $key => $value) {
  36. $list[$key]["add_time"] = date("Y-m-d H:i:s",$value["add_time"]);
  37. $list[$key]["is_see"] = UserNoticeSee::where("uid",$uid)->where("nid",$value["id"])->count() > 0 ? 1 : 0;
  38. }
  39. $data["list"] = $list;
  40. return $data;
  41. }
  42. /**
  43. * @return array
  44. */
  45. public static function seeNotice($uid,$nid){
  46. if(UserNoticeSee::where("uid",$uid)->where("nid",$nid)->count() <= 0){
  47. $data["nid"] = $nid;
  48. $data["uid"] = $uid;
  49. $data["add_time"] = time();
  50. UserNoticeSee::create($data);
  51. }
  52. }
  53. }