浏览代码

动态置顶

lizhen_gitee 1 年之前
父节点
当前提交
23dfac00cb

+ 17 - 1
application/admin/controller/Topicdongtai.php

@@ -57,7 +57,8 @@ class Topicdongtai extends Backend
             $list = $this->model
                     ->with(['user','topichub'])
                     ->where($where)
-                    ->order($sort, $order)
+//                    ->order($sort, $order)
+                    ->order('toptime desc,id desc')
                     ->paginate($limit);
 
             foreach ($list as $row) {
@@ -74,6 +75,21 @@ class Topicdongtai extends Backend
     }
 
     /**
+     * 置顶
+     */
+    public function toptime(){
+
+        if ($this->request->isAjax()) {
+            $id = input('id',0);
+
+            $rs = Db::name('topic_dongtai')->where('id',$id)->update(['toptime'=>time()]);
+
+            $this->success('完成');
+        }
+
+    }
+
+    /**
      * 删除
      */
     public function del($ids = "")

+ 2 - 1
application/admin/lang/zh-cn/topicdongtai.php

@@ -23,5 +23,6 @@ return [
     'Is_public 1'   => '公开',
     'Is_public 2'   => '私密',
     'User.username' => '用户名',
-    'Topichub.name' => '话题名称'
+    'Topichub.name' => '话题名称',
+    'toptime'       => '置顶时间',
 ];

+ 1 - 0
application/admin/view/topicdongtai/index.html

@@ -25,6 +25,7 @@
                     <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
                            data-operate-edit="{:$auth->check('topicdongtai/edit')}" 
                            data-operate-del="{:$auth->check('topicdongtai/del')}" 
+                           data-operate-toptime="{:$auth->check('topicdongtai/toptime')}"
                            width="100%">
                     </table>
                 </div>

+ 2 - 2
application/api/controller/Topicdongtai.php

@@ -191,7 +191,7 @@ class Topicdongtai extends Api
         }
         //最新
         $order = input('orderby','new');
-        $orderby  = 'dt.id desc';
+        $orderby  = 'dt.toptime desc,dt.id desc';
         //关注
         if($order == 'follow'){
             $follow_user_ids = Db::name('user_follow')->where(['uid'=>$this->auth->id])->column('follow_uid');
@@ -200,7 +200,7 @@ class Topicdongtai extends Api
         //附近,根据距离排序
         if($order == 'near'){
 //            $where['dt.cityname'] = $this->auth->cityname;
-            $orderby  = 'distance asc';
+            $orderby  = 'distance asc,dt.toptime desc,';
         }
 
         //性别

+ 18 - 1
public/assets/js/backend/topicdongtai.js

@@ -46,7 +46,21 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
 //                        {field: 'latitude', title: __('Latitude'), operate: 'LIKE'},
 //                        {field: 'aite', title: __('Aite'), operate: 'LIKE'},
                         {field: 'is_public', title: __('Is_public'), searchList: {"1":__('Is_public 1'),"2":__('Is_public 2')}, formatter: Table.api.formatter.normal},
-                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                        {field: 'toptime', title: __('toptime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+                        {field: 'operate', title: __('Operate'), table: table,
+                            buttons:[
+                                {
+                                    name:'toptime',
+                                    text:'置顶',
+                                    title:'置顶',
+                                    icon:'fa fa-exclamation-circle',
+                                    classname:'btn btn-xs btn-info btn-ajax',
+                                    url:'topicdongtai/toptime/id/{ids}?dialog=1',
+                                    target:'_self',
+                                    refresh:true,
+                                }
+                            ],
+                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                     ]
                 ]
             });
@@ -54,6 +68,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             // 为表格绑定事件
             Table.api.bindevent(table);
         },
+        toptime: function () {
+            Controller.api.bindevent();
+        },
         add: function () {
             Controller.api.bindevent();
         },