Forráskód Böngészése

Wesmiler 校企小程序 更新 6.22

wesmiler 3 éve
szülő
commit
de67e68cad
1 módosított fájl, 45 hozzáadás és 2 törlés
  1. 45 2
      app/store/service/Home.php

+ 45 - 2
app/store/service/Home.php

@@ -14,6 +14,7 @@ namespace app\store\service;
 
 use app\api\model\School;
 use app\api\model\SchoolSpeciality;
+use app\api\model\SpecialityBook;
 use app\common\library\helper;
 use app\common\service\BaseService;
 use app\store\model\User as UserModel;
@@ -68,7 +69,7 @@ class Home extends BaseService
         }else if($type == 2){
             $ranks = $this->getSpecialityViewsRank(10);
         } else if($type == 3){
-            $ranks = $this->getSchoolViewsRank(10);
+            $ranks = $this->getTeacherConsultRank(10);
         }
 
         $data = [
@@ -179,7 +180,7 @@ class Home extends BaseService
     {
         $datas = [
             'names'=> $this->getRankData(1,$limit),
-            'datas'=> $this->getRankData(2,$limit)
+            'series'=> $this->getRankData(2,$limit)
         ];
         $list = SchoolSpeciality::where(['status'=> 1])->field('speciality_name, views')->order('views desc, speciality_id desc')->limit(10)->select();
         $list = $list? $list->toArray() : [];
@@ -198,6 +199,48 @@ class Home extends BaseService
     }
 
     /**
+     * 获取老师咨询排名
+     * @param int $limit
+     * @return array
+     */
+    private function getTeacherConsultRank($limit=10)
+    {
+        $datas = [
+            'names'=> $this->getRankData(1,$limit),
+            'series'=> $this->getRankData(2,$limit),
+            'success'=> $this->getRankData(2,$limit),
+        ];
+        $list = SpecialityBook::alias('a')
+            ->leftJoin('user u','u.user_id=a.user_id')
+            ->where('a.status','>=', 1)
+            ->field('a.user_id,u.nick_name, count(a.user_id) as count')
+            ->group('a.user_id')
+            ->order('count(a.`user_id`) desc, a.user_id desc')
+            ->limit(10)
+            ->select();
+        $list = $list? $list->toArray() : [];
+        if($list){
+            foreach ($list as $k => $item) {
+                $datas['names'][$k] = $item['nick_name'];
+                $datas['series'][$k] = [
+                    'title'=> $item['nick_name']." ({$item['count']})咨询",
+                    'value'=> intval($item['count']),
+                    'name'=> $item['nick_name'],
+                ];
+
+                $count = SpecialityBook::getBooksByTeacher($item['user_id'], 2);
+                $datas['success'][$k] = [
+                    'title'=> $item['nick_name']." ({$count})成交",
+                    'value'=> intval($count),
+                    'name'=> $item['nick_name'],
+                ];
+            }
+        }
+
+        return $datas;
+    }
+
+    /**
      * 默认排名数据
      * @param int $num
      * @return array