Browse Source

后台机构排名

lizhen_gitee 4 months ago
parent
commit
84aeab6872
2 changed files with 81 additions and 4 deletions
  1. 78 4
      application/admin/controller/Votejigou.php
  2. 3 0
      public/assets/js/backend/votejigou.js

+ 78 - 4
application/admin/controller/Votejigou.php

@@ -3,7 +3,7 @@
 namespace app\admin\controller;
 
 use app\common\controller\Backend;
-
+use think\Db;
 /**
  * 答题机构管理
  *
@@ -28,10 +28,84 @@ class Votejigou extends Backend
 
 
     /**
-     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
-     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
-     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
+     * 查看
      */
+    public function index()
+    {
+        //当前是否为关联查询
+        $this->relationSearch = false;
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            //如果发送的来源是Selectpage,则转发到Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
+            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
+
+            $list = $this->model
+                ->where($where)
+//                ->order($sort, $order)
+                ->order('score desc,id desc')
+                ->paginate(10000);
+
+            $lists = collection($list->items())->toArray();
+
+            //各机构的绑定人数
+            $user_jigou = Db::name('user')->where('status',1)->where('bind_jigou_id','NEQ',0)->column('bind_jigou_id');
+            $user_jigou = array_count_values($user_jigou);
+
+            //根据公式,重新计算排名分数
+            foreach($lists as $key => $jigou){
+                $jigou['newscore'] = 0;
+                if(isset($user_jigou[$jigou['id']])){
+                    $usernumber = $user_jigou[$jigou['id']];  //机构人数
+                    $jigou['newscore'] = ($usernumber * 0.7) + ($jigou['score'] / $usernumber * 0.3); //公式
+                    $jigou['newscore'] = intval(round($jigou['newscore'],0)); //四舍五入
+                    $jigou['usernumber'] = $usernumber;
+                }
+
+                $lists[$key] = $jigou;
+            }
+
+            $lists = $this->mingci_score($lists);
+
+
+            $result = array("total" => $list->total(), "rows" => $lists);
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+
+
+    //获得我的名次,分数导向
+    private function mingci_score($list){
+
+        if(empty($list)){
+            return $list;
+        }
+        //准备数据
+
+        foreach($list as $key => $row){
+            $field[$key] = $row['newscore'];
+        }
+//dump($field);
+        array_multisort($field,SORT_DESC,$list);
+//dump($list);
+
+        foreach($list as $key => $val)
+        {
+            //赋值名次
+            $val['mingci'] = $key + 1;
+//            $val['score']  = $val['newscore'];
+//            unset($val['newscore']);
+
+            $list[$key] = $val;
+        }
+
+        return $list;
+    }
 
 
 }

+ 3 - 0
public/assets/js/backend/votejigou.js

@@ -31,6 +31,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                         {field: 'score', title: __('Score')},
                         {field: 'weigh', title: __('Weigh'), operate: false},
+                        {field: 'newscore', title: '公式分数'},
+                        {field: 'usernumber', title: '绑定人数'},
+                        {field: 'mingci', title: '名次'},
                         {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                     ]
                 ]