瀏覽代碼

update: 大概 user_notice 表相关代码,适合新表格式

joe 4 年之前
父節點
當前提交
a5f2129f35
共有 3 個文件被更改,包括 25 次插入26 次删除
  1. 0 1
      app/admin/controller/user/UserNotice.php
  2. 12 12
      app/admin/model/user/UserNotice.php
  3. 13 13
      app/models/user/UserNotice.php

+ 0 - 1
app/admin/controller/user/UserNotice.php

@@ -4,7 +4,6 @@ namespace app\admin\controller\user;
 
 use app\admin\controller\AuthController;
 use crmeb\services\{FormBuilder as Form, UtilService as Util, JsonService as Json};
-use crmeb\services\JsonService;
 use think\facade\Route as Url;
 use app\admin\model\user\UserNotice as UserNoticeModel;
 use app\admin\model\user\UserNoticeSee as UserNoticeSeeModel;

+ 12 - 12
app/admin/model/user/UserNotice.php

@@ -41,16 +41,16 @@ class UserNotice extends BaseModel
         $model->order('id desc');
         if (!empty($where)) {
             $data = ($data = $model->page((int)$where['page'], (int)$where['limit'])->select()) && count($data) ? $data->toArray() : [];
-            foreach ($data as &$item) {
-                if ($item["uid"] != '') {
-                    $uids = explode(",", $item["uid"]);
-                    array_splice($uids, 0, 1);
-                    array_splice($uids, count($uids) - 1, 1);
-                    $item["uid"] = $uids;
-                }
-                $item['send_time'] = date('Y-m-d H:i:s', $item['send_time']);
-            }
-            $count = self::count();
+//            foreach ($data as &$item) {
+//                if ($item["uid"] != '') {
+//                    $uids = explode(",", $item["uid"]);
+//                    array_splice($uids, 0, 1);
+//                    array_splice($uids, count($uids) - 1, 1);
+//                    $item["uid"] = $uids;
+//                }
+//                $item['send_time'] = date('Y-m-d H:i:s', $item['send_time']);
+//            }
+            $count = count($data); // self::count();
             return compact('data', 'count');
         }
         return self::page($model, function ($item, $key) {
@@ -71,9 +71,9 @@ class UserNotice extends BaseModel
     public static function getUserList($where = array())
     {
         $model = new self;
-        if (isset($where['title']) && $where['title'] != '') $model = $model->where('title', 'LIKE', "%" . $where['title'] . "%");
+        if (isset($where['title']) && $where['title'] != '')
+            $model = $model->where('title', 'LIKE', "%" . $where['title'] . "%");
         $model = $model->where('type', 2);
-//        $model = $model->where('is_send',0);
         $model = $model->order('id desc');
         return self::page($model, $where);
     }

+ 13 - 13
app/models/user/UserNotice.php

@@ -20,34 +20,34 @@ class UserNotice extends BaseModel
 {
     use ModelTrait;
     public static function getNotice($uid){
-        $count_notice = self::where('uid','like',"%,$uid,%")->where("is_send",1)->count();
-        $see_notice = UserNoticeSee::where("uid",$uid)->count();
+        $count_notice = self::whereIn('uid', [$uid, 0])->where("is_send",1)->count();
+        $see_notice = UserNoticeSee::where("uid", $uid)->count();
         return $count_notice-$see_notice;
     }
+
     /**
      * @return array
      */
-    public static function getNoticeList($uid,$page,$limit = 8){
-        //定义分页信息
-        $count = self::where('uid','like',"%,$uid,%")->count();
-        $data["lastpage"] = ceil($count/$limit) <= ($page+1) ? 1 : 0;
+    public static function getNoticeList($uid, $page, $limit = 8){
+        $list = self::whereIn('uid', [$uid,0])
+            ->where('is_send', 1)
+            ->field('id,user,title,content,add_time')
+            ->order("add_time desc")
+            ->limit($page*$limit,$limit)->select()->toArray();
 
-        $where['uid'] = array("like","%,$uid,%");
-//        $where['uid'] = array(array("like","%,$uid,%"),array("eq",""), 'or');
-        $where['is_send'] = 1;
-        $list = self::where($where)->field('id,user,title,content,add_time')->order("add_time desc")->limit($page*$limit,$limit)->select()->toArray();
         foreach ($list as $key => $value) {
             $list[$key]["add_time"] = date("Y-m-d H:i:s",$value["add_time"]);
-            $list[$key]["is_see"] = UserNoticeSee::where("uid",$uid)->where("nid",$value["id"])->count() > 0 ? 1 : 0;
+            $list[$key]["is_see"] = 0; //UserNoticeSee::where("uid",$uid)->where("nid",$value["id"])->count() > 0 ? 1 : 0;
         }
         $data["list"] = $list;
         return $data;
     }
+
     /**
      * @return array
      */
-    public static function seeNotice($uid,$nid){
-        if(UserNoticeSee::where("uid",$uid)->where("nid",$nid)->count() <= 0){
+    public static function seeNotice($uid, $nid){
+        if(UserNoticeSee::where("uid", $uid)->where("nid", $nid)->count() <= 0){
             $data["nid"] = $nid;
             $data["uid"] = $uid;
             $data["add_time"] = time();