UserNotice.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\user;
  12. use app\admin\model\user\UserNoticeSee;
  13. use traits\ModelTrait;
  14. use basic\ModelBasic;
  15. /**
  16. * 用户通知 model
  17. * Class UserNotice
  18. */
  19. class UserNotice extends ModelBasic
  20. {
  21. use ModelTrait;
  22. public static function getNotice($uid)
  23. {
  24. $count_notice = self::where('uid', 'like', "%,$uid,%")->where("is_send", 1)->count();
  25. $see_notice = UserNoticeSee::where("uid", $uid)->count();
  26. return $count_notice - $see_notice;
  27. }
  28. /**
  29. * @return array
  30. */
  31. public static function getNoticeList($uid, $page, $limit = 8)
  32. {
  33. //定义分页信息
  34. $count = self::where('uid', 'like', "%,$uid,%")->count();
  35. $data["lastpage"] = ceil($count / $limit) <= ($page + 1) ? 1 : 0;
  36. $where['uid'] = array("like", "%,$uid,%");
  37. $where['is_send'] = 1;
  38. $list = self::where($where)->field('id,user,title,content,add_time')->order("add_time desc")->limit($page * $limit, $limit)->select()->toArray();
  39. foreach ($list as $key => $value) {
  40. $list[$key]["add_time"] = date("Y-m-d H:i:s", $value["add_time"]);
  41. $list[$key]["is_see"] = UserNoticeSee::where("uid", $uid)->where("nid", $value["id"])->count() > 0 ? 1 : 0;
  42. }
  43. $data["list"] = $list;
  44. return $data;
  45. }
  46. /**
  47. * @return array
  48. */
  49. public static function seeNotice($uid, $nid)
  50. {
  51. if (UserNoticeSee::where("uid", $uid)->where("nid", $nid)->count() <= 0) {
  52. $data["nid"] = $nid;
  53. $data["uid"] = $uid;
  54. $data["add_time"] = time();
  55. UserNoticeSee::set($data);
  56. }
  57. }
  58. }