Просмотр исходного кода

Wesmiler 校企小程序 更新解决冲突合并

wesmiler 3 лет назад
Родитель
Сommit
d04e7453e7
3 измененных файлов с 64 добавлено и 1 удалено
  1. 22 0
      app/api/controller/School.php
  2. 1 1
      app/api/imsocket/imsocket.php
  3. 41 0
      app/api/model/School.php

+ 22 - 0
app/api/controller/School.php

@@ -111,4 +111,26 @@ class School extends Controller
         $list = $model->getList(['school_id'=> $schoolId]);
         return $this->renderSuccess(compact('list'));
     }
+
+    /**
+     * @return \think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function comparison()
+    {
+        $ids = $this->request->param('ids','');
+        $ids = $ids? explode(',', $ids) : [];
+        if(empty($ids)){
+            return $this->renderSuccess('请先选择对比学校');
+        }
+        if(count($ids) > 3){
+            return $this->renderSuccess('一次最多选择3个');
+        }
+ 
+        $model = new SchoolModel;
+        $list = $model->getComparisonList($ids, 3);
+        return $this->renderSuccess(compact('list'));
+    }
 }

+ 1 - 1
app/api/imsocket/imsocket.php

@@ -5,7 +5,7 @@ use think\worker\Server;
 use GatewayWorker\Lib\Gateway;
 class imsocket extends Server
 {
-    protected $socket = 'websocket://0.0.0.0:6550';
+    protected $socket = 'websocket://0.0.0.0:2345';
     protected $uidConnnections = array();
     public function __construct()
     {

+ 41 - 0
app/api/model/School.php

@@ -14,6 +14,7 @@ namespace app\api\model;
 use app\common\library\helper;
 use app\common\model\Region;
 use app\common\model\School as SchoolModel;
+use think\facade\Db;
 
 /**
  * 学校模型类
@@ -191,5 +192,45 @@ class School extends SchoolModel
         return $model->userSchool($userId, $field??'id, school_name');
     }
 
+    /**
+     * 获取对比学校数据
+     * @param $ids
+     * @param int $listRows
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getComparisonList($ids, $listRows = 3)
+    {
+        $list = self::whereIn('id',$ids)
+            ->where(['audit_status'=> 1])
+            ->field('school_name,logo,stablish_time,property,education_levels,type,level,area,students,city_id,region_id,views,labels')
+            ->limit($listRows)
+            ->order(Db::raw("field(id,".implode(',', $ids).")"))
+            ->select();
 
+        $datas = [];
+        $list = $list? $list->toArray() : [];
+        if($list){
+            foreach ($list as $v){
+                $datas['school_name'][] = $v['school_name'];
+                $datas['logo'][] = $v['logo']? getPreview($v['logo']) : '';
+                $datas['stablish_time'][] = $v['stablish_time'];
+                $datas['property'][] = $v['property'];
+                $datas['type'][] = $v['type'];
+                $datas['education_levels'][] = $v['education_levels']? ($v['education_levels']==1? '中职':'高职'):'';
+                $datas['level'][] = $v['level'];
+                $datas['area'][] = $v['area'];
+                $datas['students'][] = $v['students'];
+                $cityName = $v['city_id']? Region::getNameById($v['city_id']) : '';
+                $regionName = $v['region_id']? Region::getNameById($v['region_id']) : '';
+                $datas['address'][] = "{$cityName}{$regionName}";
+                $datas['views'][] = $v['views']? ($v['views']<10000? "{$v['views']}" : round($v['views']/10000,1).'w') :'';
+                $datas['labels'][] = $v['labels']? str_replace(',','、', $v['labels']) : '';
+            }
+        }
+
+        return $datas;
+    }
 }