Ver Fonte

Merge branch 'master' of http://git.dongerkj.com:9095/waibao/NN2022060401

49107199@qq.com há 3 anos atrás
pai
commit
8fd1b715ba

+ 2 - 2
app/api/common.php

@@ -39,9 +39,9 @@ if (!function_exists('getPreview')) {
             $host = request()->header('host');
             $fileConfig = config('filesystem.disks');
             $uploadPath = (isset($fileConfig['public']) && $fileConfig['public']['url'])? $fileConfig['public']['url']:'/uploads';
-            $url = preg_match("/^(https|http):\/\//", trim($url,'//')) ? $url : '//'.$host . $uploadPath .'/' . ltrim($url, '/');
+            $url = preg_match("/^(https|http):\/\//", trim($url,'//')) ? $url : 'https://'.$host . $uploadPath .'/' . ltrim($url, '/');
         }
-        $url = $url? preg_replace("/^(https|http):\/\//", '//', $url) : '';
+//        $url = $url? preg_replace("/^(http):\/\//", '//', $url) : '';
         if(preg_match("/127.0|localhost/", $host) && $url){
             $url = preg_replace("/^\/\//", 'http://', $url);
         }

+ 37 - 0
app/api/controller/Banner.php

@@ -0,0 +1,37 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types = 1);
+
+namespace app\api\controller;
+
+use app\api\model\Banner as BannerModel;
+
+/**
+ * 幻灯片控制器
+ * Class Banner
+ * @package app\api\controller
+ */
+class Banner extends Controller
+{
+    /**
+     * 文章列表
+     * @param int $position
+     * @return array
+     * @throws \think\db\exception\DbException
+     */
+    public function list(int $position = 0)
+    {
+        $model = new BannerModel;
+        $list = $model->getList(['position'=> $position], 6);
+        return $this->renderSuccess(compact('list'));
+    }
+
+}

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

@@ -3,6 +3,11 @@
 namespace app\api\controller;
 
 use app\api\model\School as SchoolModel;
+use app\api\model\SchoolSpeciality;
+use app\api\model\SchoolNew;
+use app\api\model\UserDynamic;
+use app\api\service\User as UserService;
+use app\common\model\SchoolAlbum;
 
 /**
  * 学校控制器
@@ -36,4 +41,74 @@ class School extends Controller
         $list = $model->getOptionList($this->request->param());
         return $this->renderSuccess(compact('list'));
     }
+
+    /**
+     * 获取学校主页数据
+     * @return \think\response\Json
+     * @throws \cores\exception\BaseException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function homeData()
+    {
+        $schoolId = $this->request->param('school_id', 0);
+        if($schoolId<=0){
+            $userInfo = UserService::getCurrentLoginUser(true);
+            $schoolId = isset($userInfo['info']['school_id'])? intval($userInfo['info']['school_id']) : 0;
+            $userType = isset($userInfo['user_type'])? $userInfo['user_type'] : 0;
+            $schoolId = $userType != 3? 0 : $schoolId;
+        }
+
+        if($schoolId <= 0){
+            return $this->renderSuccess('您无权访问或未绑定学校信息,请先绑定');
+        }
+
+        $data = [
+            'info'=> SchoolModel::detail($schoolId),
+            'albums'=> SchoolAlbum::getShowList($schoolId, 6),
+            'news'=> SchoolNew::getShowList($schoolId, 1, 3),
+            'scenery'=> SchoolNew::getShowList($schoolId, 2, 6)
+        ];
+
+        return $this->renderSuccess($data);
+    }
+
+    /**
+     * 校园时态
+     * @return \think\response\Json
+     * @throws \think\db\exception\DbException
+     */
+    public function dynamic(){
+        $model = new UserDynamic();
+        $schoolId = $this->request->param('school_id', 0);
+        $userInfo = UserService::getCurrentLoginUser(true);
+        $userId = isset($userInfo['user_id'])? intval($userInfo['user_id']) : 0;
+        if($schoolId <= 0){
+            return $this->renderSuccess('您无权访问或未绑定学校信息,请先绑定');
+        }
+
+        $list = $model->getListBySchool($schoolId, $userId, $this->request->param());
+        return $this->renderSuccess(compact('list'));
+    }
+
+    /**
+     * 校园专业时态
+     * @return \think\response\Json
+     * @throws \think\db\exception\DbException
+     */
+    public function specialityDynamic(){
+        $model = new SchoolSpeciality;
+        $userInfo = UserService::getCurrentLoginUser(true);
+        $userId = isset($userInfo['user_id'])? intval($userInfo['user_id']) : 0;
+        $schoolId = isset($userInfo['info']['school_id'])? intval($userInfo['info']['school_id']) : 0;
+        $userType = isset($userInfo['user_type'])? $userInfo['user_type'] : 0;
+        $schoolId = $userType != 3? 0 : $schoolId;
+        if($schoolId <= 0){
+            return $this->renderSuccess('您无权访问或未绑定学校信息,请先绑定');
+        }
+
+        $list = $model->getList(['school_id'=> $schoolId]);
+        return $this->renderSuccess(compact('list'));
+    }
 }

+ 31 - 2
app/api/controller/SchoolSpeciality.php

@@ -2,6 +2,7 @@
 
 namespace app\api\controller;
 
+use app\api\model\School;
 use app\api\model\SchoolSpeciality as SchoolSpecialityModel;
 use think\response\Json;
 
@@ -12,10 +13,38 @@ use think\response\Json;
  */
 class SchoolSpeciality extends Controller
 {
-
-    public function options(): Json
+    /**
+     * 学校列表
+     * @return \think\response\Json
+     * @throws \think\db\exception\DbException
+     */
+    public function list()
     {
+        // 获取列表数据
         $model = new SchoolSpecialityModel;
+        $pageSize = $this->request->param('pageSize', 12);
+        $list = $model->getList($this->request->param(), $pageSize);
+        return $this->renderSuccess(compact('list'));
+    }
+
+    /**
+     * 文章详情
+     * @param int $articleId
+     * @return array|\think\response\Json
+     * @throws \app\common\exception\BaseException
+     */
+    public function detail(int $id)
+    {
+        $detail = SchoolSpecialityModel::getDetail($id);
+        return $this->renderSuccess(compact('detail'));
+    }
 
+    public function sameList()
+    {
+        // 获取列表数据
+        $model = new School;
+        $pageSize = $this->request->param('pageSize', 12);
+        $list = $model->getList($this->request->param(), $pageSize);
+        return $this->renderSuccess(compact('list'));
     }
 }

+ 94 - 0
app/api/model/Banner.php

@@ -0,0 +1,94 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\api\model;
+
+use app\common\exception\BaseException;
+use app\common\library\helper;
+use app\common\model\Banner as BannerModel;
+use app\common\model\Region;
+
+/**
+ * 轮播幻灯片模型
+ * Class Banner
+ * @package app\api\model
+ */
+class Banner extends BannerModel
+{
+    /**
+     * 隐藏字段
+     * @var array
+     */
+    protected $hidden = [
+        'create_time',
+        'update_time'
+    ];
+
+    /**
+     * 获取列表
+     * @param array $param 查询条件
+     * @param int $listRows 分页数量
+     * @return mixed|\think\model\Collection|\think\Paginator
+     * @throws \think\db\exception\DbException
+     */
+    public function getList(array $param = [], int $listRows = 15)
+    {
+        // 整理查询参数
+        $params = array_merge($param, ['status' => 1]);
+        // 获取商品列表
+        $list = parent::getList($params, $listRows);
+        if ($list->isEmpty()) {
+            return $list;
+        }
+        // 隐藏冗余的字段
+        $list->hidden(array_merge($this->hidden, ['albums']));
+        // 整理列表数据并返回
+        return $this->setListDataFromApi($list);
+    }
+
+    /**
+     * 设置展示的数据 api模块
+     * @param $info
+     * @return mixed
+     */
+    private function setListDataFromApi($info)
+    {
+        return $this->setListData($info, function ($data){
+            // 整理数据 api模块
+            $this->setDataFromApi($data);
+        });
+    }
+
+    /**
+     * 整理数据 api模块
+     * @param $info
+     * @return mixed
+     */
+    private function setDataFromApi($info)
+    {
+        return $this->setData($info, function ($data) {
+            $this->hidden(['update_time','status']);
+        });
+    }
+
+    /**
+     * 获取图片预览
+     * @param $value
+     * @return string
+     */
+    public function getImageAttr($value)
+    {
+        return $value? getPreview($value) : '';
+    }
+
+
+}

+ 47 - 2
app/api/model/School.php

@@ -56,6 +56,27 @@ class School extends SchoolModel
     }
 
     /**
+     * 获取专业同类学校列表
+     * @param array $param 查询条件
+     * @param int $listRows 分页数量
+     * @return mixed|\think\model\Collection|\think\Paginator
+     * @throws \think\db\exception\DbException
+     */
+    public function getSpecialityList(int $specialityId, array $param = [], int $listRows = 15)
+    {
+        // 整理查询参数
+        $params = array_merge($param, ['audit_status' => 1]);
+        // 获取商品列表
+        $list = parent::getList($params, $listRows);
+        if ($list->isEmpty()) {
+            return $list;
+        }
+
+        // 整理列表数据并返回
+        return $this->setListDataFromApi($list);
+    }
+
+    /**
      * 设置展示的数据 api模块
      * @param $info
      * @return mixed
@@ -68,6 +89,9 @@ class School extends SchoolModel
 
             // 整理数据 api模块
             $this->setDataFromApi($data);
+
+            // 隐藏冗余的字段
+            $this->hidden(array_merge($this->hidden, ['recruit_phone','post_code','index_url','albums','introduce','recruitment','characteristic','book_fields']));
         });
     }
 
@@ -141,9 +165,30 @@ class School extends SchoolModel
         if (is_array($where)) {
             $filter = array_merge($filter, $where);
         } else {
-            $filter['user_id'] = (int)$where;
+            $filter['id'] = (int)$where;
+        }
+        $data = static::get($filter, $with);
+        $data->hidden(['book_fields']);
+        if($data['logo']){
+            $data['logo'] = getPreview($data['logo']);
+        }
+
+        if(is_int($where)){
+            self::setIncViews((int)$where);
         }
-        return static::get($filter, $with);
+
+        return $data;
+    }
+
+    /**
+     * 获取用户所属招生学校
+     * @param $userId
+     * @param string $field
+     * @return mixed
+     */
+    public static function getUserSchool($userId, $field=''){
+        $model = new SchoolModel;
+        return $model->userSchool($userId, $field??'id, school_name');
     }
 
 

+ 14 - 0
app/api/model/SchoolAlbum.php

@@ -30,4 +30,18 @@ class SchoolAlbum extends SchoolAlbumModel
     protected $hidden = [
         'update_time'
     ];
+
+
+    /**
+     * @param $schoolId
+     * @param int $limitRow
+     * @return array|mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function getShowList($schoolId, $limitRow = 0)
+    {
+        return parent::getShowList($schoolId, $limitRow); // TODO: Change the autogenerated stub
+    }
 }

+ 47 - 0
app/api/model/SchoolNew.php

@@ -0,0 +1,47 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\api\model;
+use app\common\model\SchoolNew as SchoolNewModel;
+
+/**
+ * 学校新闻资讯模型类
+ * Class SchoolNew
+ * @package app\api\model
+ */
+class SchoolNew extends SchoolNewModel
+{
+
+    protected $globalScope = [''];
+
+    /**
+     * 隐藏字段
+     * @var array
+     */
+    protected $hidden = [
+        'update_time'
+    ];
+
+    /**
+     * @param $schoolId
+     * @param int $type
+     * @param int $limitRow
+     * @return array|mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function getShowList($schoolId, $type = 1, $limitRow = 0)
+    {
+        return parent::getShowList($schoolId, $type, $limitRow); // TODO: Change the autogenerated stub
+    }
+}

+ 102 - 3
app/api/model/SchoolSpeciality.php

@@ -11,6 +11,9 @@
 declare (strict_types=1);
 
 namespace app\api\model;
+use app\common\exception\BaseException;
+use app\common\library\helper;
+use app\common\model\Region;
 use app\common\model\SchoolSpeciality as SchoolSpecialityModel;
 
 /**
@@ -21,8 +24,6 @@ use app\common\model\SchoolSpeciality as SchoolSpecialityModel;
 class SchoolSpeciality extends SchoolSpecialityModel
 {
 
-    protected $globalScope = [''];
-
     /**
      * 隐藏字段
      * @var array
@@ -32,6 +33,75 @@ class SchoolSpeciality extends SchoolSpecialityModel
     ];
 
     /**
+     * 获取列表
+     * @param array $param 查询条件
+     * @param int $listRows 分页数量
+     * @return mixed|\think\model\Collection|\think\Paginator
+     * @throws \think\db\exception\DbException
+     */
+    public function getList(array $param = [], int $listRows = 12)
+    {
+        // 整理查询参数
+        $params = array_merge($param, ['status' => 1]);
+        // 获取商品列表
+        $list = parent::getList($params, $listRows);
+        if ($list->isEmpty()) {
+            return $list;
+        }
+
+        // 整理列表数据并返回
+        return $this->setListDataFromApi($list);
+    }
+
+    /**
+     * 设置展示的数据 api模块
+     * @param $info
+     * @return mixed
+     */
+    private function setListDataFromApi($info)
+    {
+        return $this->setListData($info, function ($data){
+
+            // 整理数据 api模块
+            $this->setDataFromApi($data);
+
+            // 隐藏冗余的字段
+            $this->hidden(array_merge($this->hidden, ['introduce','curriculum','job_direction','get_certificate','status']));
+
+        });
+    }
+
+    /**
+     * 整理数据 api模块
+     * @param $info
+     * @return mixed
+     */
+    private function setDataFromApi($info)
+    {
+        return $this->setData($info, function ($data) {
+            // logo封面
+            $data['speciality_logo'] = $data['speciality_logo']? getPreview($data['speciality_logo']) : '';
+
+            // 已报名人数
+            if(!is_null($data['recruit_num'])){
+                $bookNum = SpecialityBook::getBooks($data['speciality_id']);
+                $data['book_num'] = intval($bookNum);
+                $data['remainder_num'] = max(0,$data['recruit_num'] - $bookNum);
+            }
+
+            // 浏览数
+            if(!is_null($data['views'])){
+                $data['views'] = $data['views']? ($data['views']<10000? "{$data['views']}" : round($data['views']/10000,1).'w') :'';
+            }
+
+            if(isset($data['school']['logo'])){
+                $data['school']['logo'] = $data['school']['logo']? getPreview($data['school']['logo']) : '';
+            }
+        });
+    }
+
+
+    /**
      * 获取学校的专业
      * @param int $school_id  学校ID
      * @param string $field 返回字段
@@ -43,10 +113,39 @@ class SchoolSpeciality extends SchoolSpecialityModel
      */
     public function getHots(int $school_id, $field='', $limit=3)
     {
-        return $this->where(['school_id'=>$school_id])
+        return $this->where(['school_id'=>$school_id,'status'=>1])
             ->field($field?:'speciality_id,speciality_name,school_id,recruit_num')
             ->order('views desc,speciality_id desc')
             ->limit($limit?? 3)
             ->select()??[];
     }
+
+
+    /**
+     * 获取详情并累计访问次数
+     * @param int $articleId 文章ID
+     * @return static|null
+     * @throws BaseException
+     */
+    public static function getDetail(int $id)
+    {
+        // 获取文章详情
+        $detail = parent::detail($id, ['school']);
+        if (empty($detail) || $detail['status'] != 1) {
+            throwError('很抱歉,当前数据不存在');
+        }
+
+        // 累积阅读数
+        static::setIncViews($id);
+        return (new SchoolSpeciality)->setDataFromApi($detail);
+    }
+
+
+    /**
+     * 访问量
+     * @param $id
+     */
+    public static function setIncViews($id){
+        (new SchoolSpecialityModel)->setInc(['speciality_id'=> $id], 'views', 1);
+    }
 }

+ 104 - 0
app/api/model/SpecialityBook.php

@@ -0,0 +1,104 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\api\model;
+use app\common\model\SpecialityBook as SpecialityBookModel;
+
+/**
+ * 学校专业模型类
+ * Class SpecialityBook
+ * @package app\api\model
+ */
+class SpecialityBook extends SpecialityBookModel
+{
+
+    protected $globalScope = [''];
+
+    /**
+     * 隐藏字段
+     * @var array
+     */
+    protected $hidden = [
+        'update_time'
+    ];
+
+    /**
+     * 获取列表
+     * @param array $param 查询条件
+     * @param int $listRows 分页数量
+     * @return mixed|\think\model\Collection|\think\Paginator
+     * @throws \think\db\exception\DbException
+     */
+    public function getList(array $param = [], int $listRows = 12)
+    {
+        // 整理查询参数
+        $params = array_merge($param);
+
+        // 获取商品列表
+        $list = parent::getList($params, $listRows);
+        if ($list->isEmpty()) {
+            return $list;
+        }
+
+        // 整理列表数据并返回
+        return $this->setListDataFromApi($list);
+    }
+
+    /**
+     * 设置展示的数据 api模块
+     * @param $info
+     * @return mixed
+     */
+    private function setListDataFromApi($info)
+    {
+        return $this->setListData($info, function ($data){
+
+            // 整理数据 api模块
+            $this->setDataFromApi($data);
+
+            // 隐藏冗余的字段
+            $this->hidden(array_merge($this->hidden, ['transaction_id']));
+
+        });
+    }
+
+    /**
+     * 整理数据 api模块
+     * @param $info
+     * @return mixed
+     */
+    private function setDataFromApi($info)
+    {
+        return $this->setData($info, function ($data) {
+
+        });
+    }
+
+
+    /**
+     * 获取学校的专业
+     * @param int $school_id  学校ID
+     * @param string $field 返回字段
+     * @param int $limit 返回数量
+     * @return SpecialityBook[]|array|\think\Collection
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function getBooks(int $speciality_id)
+    {
+        return self::where(['speciality_id'=>$speciality_id])->where('status','>', 2)->count('id');
+    }
+
+
+
+}

+ 16 - 20
app/api/model/User.php

@@ -49,6 +49,8 @@ class User extends UserModel
         return strlen($value) === 11 ? hide_mobile($value) : $value;
     }
 
+
+
     /**
      * 获取用户信息
      * @param string $token
@@ -67,7 +69,9 @@ class User extends UserModel
         // 用户基本信息
         $userInfo = self::detail($userId);
         $userInfo['info']=$userInfo['info']? $userInfo['info'] : [];
-        $userInfo['info']['school']=$userInfo['info']['school']? $userInfo['info']['school'] : [];
+        if($userInfo['info']){
+            $userInfo['info']['school']= isset($userInfo['info']['school']) && $userInfo['info']['school']? $userInfo['info']['school'] : [];
+        }
         if (empty($userInfo) || $userInfo['is_delete']) {
             throwError('很抱歉,用户信息不存在或已删除', config('status.not_logged'));
         }
@@ -130,11 +134,11 @@ class User extends UserModel
         $this->checkInfo($data, $userInfo);
 
         $info = UserInfo::detail($userInfo['user_id']);
-        if(!is_null($info) && $info['school_id'] != $data['school_id']){
+        if(!is_null($info) && $info['school_id'] && $info['school_id'] != $data['school_id']){
             throwError('已认证注册,无法修改学校,请联系客服');
         }
 
-        if ($userInfo['user_type'] && $data['user_type'] != $userInfo['user_type']){
+        if ((!is_null($info) && $info['school_id']) && $userInfo['user_type'] && $data['user_type'] != $userInfo['user_type']){
             throwError('账号类型不可修改');
         }
 
@@ -143,16 +147,15 @@ class User extends UserModel
             try {
                 $userData = [
                     'user_id'=> $userInfo['user_id'],
-                    'nick_name'=> $data['nick_name'],
                     'real_name'=> $data['real_name'],
                     'gender'=> (int)$data['gender'],
                     'age'=> isset($data['age'])? intval($data['age']) : 0,
                     'student_no'=>isset($data['student_no'])? $data['student_no'] :'',
-                    'user_login'=> $data['user_login'],
+                    'user_login'=> isset($data['user_login'])? $data['user_login'] :'',
                     'mobile'=> $data['mobile'],
                 ];
 
-                if($userInfo['user_type']<=0){
+                if($userInfo['user_type']<=0 || (is_null($info) || $info['school_id']<=0)){
                     $userData['user_type'] = (int)$data['user_type'];
                 }
 
@@ -198,7 +201,7 @@ class User extends UserModel
      * @param $info
      * @return bool
      */
-    public function checkModifyInfo(array $data, UserInfo $info): bool
+    public function checkModifyInfo(array $data,  $info): bool
     {
         if($data['user_type'] != 3){
             return false;
@@ -241,29 +244,22 @@ class User extends UserModel
         }
 
         if($data['user_type'] == 1){
-            if(empty($data['student_no'])){
-                throwError('学号不为空');
-            }
 
-            if(empty($data['admission_year'])){
+            /*if(empty($data['admission_year'])){
                 throwError('请选择入学年份');
             }
 
-            if(empty($data['speciality'])){
-                throwError('请选择就读专业');
-            }
-
             if(empty($data['education_certify'])){
                 throwError('请上传教育证明');
-            }
+            }*/
         }else if($data['user_type'] == 3){
             if(empty($data['position'])){
                 throwError('请选择职务');
             }
 
-            if(empty($data['work_certify'])){
+            /*if(empty($data['work_certify'])){
                 throwError('请上传职务证明');
-            }
+            }*/
         }
 
         if($userInfo['mobile'] != $data['mobile']) {
@@ -282,9 +278,9 @@ class User extends UserModel
             throwError('身份证号码已被使用');
         }
 
-        if(empty($data['idcard_front_img'])){
+        /*if(empty($data['idcard_front_img'])){
             throwError('请上传身份证明');
-        }
+        }*/
 
         $chekId = self::checkExistByMobile($data['mobile']);
         if($data['mobile'] && $chekId && $userInfo['user_id'] != $chekId){

+ 144 - 0
app/api/model/UserDynamic.php

@@ -0,0 +1,144 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\api\model;
+use app\common\model\UserDynamic as UserDynamicModel;
+
+/**
+ * 用户动态模型类
+ * Class UserDynamic
+ * @package app\api\model
+ */
+class UserDynamic extends UserDynamicModel
+{
+
+    protected $globalScope = [''];
+
+    /**
+     * 隐藏字段
+     * @var array
+     */
+    protected $hidden = [
+        'update_time'
+    ];
+
+    /**
+     * 获取列表
+     * @param array $param
+     * @param int $listRows
+     * @return mixed
+     * @throws \think\db\exception\DbException
+     */
+    public function getList(array $param = [], int $listRows = 15)
+    {
+        // 整理查询参数
+        $params = array_merge($param, ['status' => 1]);
+        // 获取商品列表
+        $list = parent::getList($params, $listRows);
+        if ($list->isEmpty()) {
+            return $list;
+        }
+
+        // 隐藏冗余的字段
+        $list->hidden(array_merge($this->hidden, ['status']));
+        // 整理列表数据并返回
+        return $this->setListDataFromApi($list);
+    }
+
+    /**
+     * 设置展示的数据 api模块
+     * @param $info
+     * @return mixed
+     */
+    private function setListDataFromApi($info)
+    {
+        return $this->setListData($info, function ($data) {
+
+            // 整理数据 api模块
+            $this->setDataFromApi($data);
+        });
+    }
+
+    /**
+     * 整理数据 api模块
+     * @param $info
+     * @return mixed
+     */
+    private function setDataFromApi($info)
+    {
+        return $this->setData($info, function ($data) {
+
+            // logo封面
+            $data['logo'] = $data['logo']? getPreview($data['logo']) : '';
+            $data['file_url'] = $data['file_url']? getPreview($data['file_url']) : '';
+
+            // 点赞喜欢数
+            if(!is_null($data['like_num'])){
+                $data['like_num'] = $data['like_num']? ($data['like_num']<10000? "{$data['like_num']}" : round($data['like_num']/10000,1).'w') :'';
+            }
+
+            // 收藏数
+            if(!is_null($data['collect_num'])){
+                $data['collect_num'] = $data['collect_num']? ($data['collect_num']<10000? "{$data['collect_num']}" : round($data['collect_num']/10000,1).'w') :'';
+            }
+
+            // 浏览数
+            if(!is_null($data['views'])){
+                $data['views'] = $data['views']? ($data['views']<10000? "{$data['views']}" : round($data['views']/10000,1).'w') :'';
+            }
+
+        });
+    }
+
+
+    /**
+     * 获取详情信息
+     * @param $where
+     * @param array $with
+     * @return static|array|false|null
+     */
+    public static function detail($where, array $with = [])
+    {
+        $filter = [];
+        if (is_array($where)) {
+            $filter = array_merge($filter, $where);
+        } else {
+            $filter['id'] = (int)$where;
+        }
+        return static::get($filter, $with);
+    }
+
+    /**
+     * 获取学校动态列表
+     * @param int $schoolId
+     * @param array $param
+     * @param int $listRows
+     * @return mixed
+     */
+    public function getListBySchool(int $schoolId,int $userId = 0, array $param = [], int $listRows = 15)
+    {
+        // 整理查询参数
+        $params = array_merge($param, [$this->name.'.status' => 1, 'ui.school_id'=> $schoolId]);
+
+        // 获取商品列表
+        $list = parent::getListBySchool($schoolId, $userId, $params, $listRows);
+        if ($list->isEmpty()) {
+            return $list;
+        }
+
+        // 隐藏冗余的字段
+        $list->hidden(array_merge($this->hidden, ['status']));
+        // 整理列表数据并返回
+        return $this->setListDataFromApi($list);
+    }
+
+}

+ 43 - 0
app/api/model/UserFans.php

@@ -0,0 +1,43 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\api\model;
+use app\common\model\UserFans as UserFansModel;
+
+/**
+ * 用户粉丝模型类
+ * Class UserFans
+ * @package app\api\model
+ */
+class UserFans extends UserFansModel
+{
+
+    protected $globalScope = [''];
+
+    /**
+     * 隐藏字段
+     * @var array
+     */
+    protected $hidden = [
+        'update_time'
+    ];
+
+    /**
+     * 获取粉丝用户ID
+     * @param int $userId
+     * @return array
+     */
+    public static function getFansUid(int $userId)
+    {
+        return self::where(['user_id'=> $userId, 'status'=>1])->column('fans_id');
+    }
+}

+ 4 - 1
app/api/service/passport/Party.php

@@ -104,7 +104,10 @@ class Party extends BaseService
         $partyUserInfo = $partyData['userInfo'];
         $data = [
             'nick_name' => $partyUserInfo['nickName'],
-            'gender' => $partyUserInfo['gender']
+            'gender' => $partyUserInfo['gender'],
+            'country' => $partyUserInfo['country'],
+            'province' => $partyUserInfo['province'],
+            'city' => $partyUserInfo['city'],
         ];
         // 下载用户头像
         if ($isGetAvatarUrl) {

+ 0 - 2
app/api/validate/user/Info.php

@@ -31,8 +31,6 @@ class Info extends Validate
         // 用户手机号
         'idcard' => ['require','idCard','max:20'],
         'real_name'=> ['require','max:20'],
-        'nick_name'=> ['require','max:100'],
-        'user_login'=> ['require','max:30'],
         'mobile'=> ['require','mobile'],
         'gender'=> ['require'],
         'user_type'=> ['require'],

+ 140 - 0
app/common/model/Banner.php

@@ -0,0 +1,140 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\common\model;
+
+use cores\BaseModel;
+use think\model\Collection;
+use think\model\relation\HasOne;
+use think\Paginator;
+
+/**
+ * 轮播幻灯片模型类
+ * Class Banner
+ * @package app\common\model
+ */
+class Banner extends BaseModel
+{
+    protected $globalScope = [''];
+
+    // 定义表名
+    protected $name = 'banners';
+
+    // 定义主键
+    protected $pk = 'id';
+
+    /**
+     * 获取列表
+     * @param array $param 查询条件
+     * @param int $listRows 分页数量
+     * @return mixed
+     * @throws \think\db\exception\DbException
+     */
+    public function getList(array $param = [], int $listRows = 15)
+    {
+        // 筛选条件
+        $query = $this->getQueryFilter($param);
+        // 排序条件
+        $sort = $this->setQuerySort($param);
+
+        // 执行查询
+        $list = $query->alias($this->name)
+            ->order($sort)
+            ->paginate($listRows);
+
+        // 整理列表数据并返回
+        return $list;
+    }
+
+    /**
+     * 设置商品展示的数据
+     * @param Collection|Paginator $list 商品列表
+     * @param callable|null $callback 回调函数
+     * @return mixed
+     */
+    protected function setListData($list, callable $callback = null)
+    {
+        if ($list->isEmpty()) return $list;
+        // 遍历商品列表整理数据
+        foreach ($list as &$item) {
+            $data = $this->setData($item, $callback);
+        }
+        return $list;
+    }
+
+    /**
+     * 整理数据
+     * @param Collection|static $info
+     * @param callable|null $callback
+     * @return mixed
+     */
+    protected function setData($info, callable $callback = null)
+    {
+        // 回调函数
+        is_callable($callback) && call_user_func($callback, $info);
+        return $info->hidden(array_merge($this->hidden, ['update_time']));
+    }
+
+    /**
+     * 检索查询条件
+     * @param array $params
+     * @return \think\db\BaseQuery
+     */
+    private function getQueryFilter(array $params)
+    {
+        $filter = [];
+
+        // 实例化新查询对象
+        $query = $this->getNewQuery();
+
+        // 位置
+        !empty($params['position']) && $filter[] = ['position', '=', "{$params['position']}"];
+
+        // 类型
+        !empty($params['type']) && $filter[] = ['type', '=', "{$params['type']}"];
+
+        // 状态
+        !empty($params['status']) && $filter[] = ['status', '=', "{$params['status']}"];
+
+        // 实例化新查询对象
+        return $query->where($filter)->where(function($query) use ($params){
+            // 关键词
+            if(!empty($params['keyword'])){
+                $query->where('name','like', "%{$params['keyword']}%");
+          }
+        });
+    }
+
+
+    /**
+     * 检索排序条件
+     * @param array $param
+     * @return array|string[]
+     */
+    private function setQuerySort(array $param = [])
+    {
+        $params = $this->setQueryDefaultValue($param, [
+            'sortType' => 'all',    // 排序类型
+            'sort_order' => false,   // 排序 (true高到低 false低到高)
+        ]);
+        // 排序规则
+        $sort = [];
+        if ($params['sortType'] === 'all') {
+            $sort = ['sort_order' => 'desc','id'=>'desc'];
+        } elseif ($params['sortType'] === 'pay') {
+            $sort = ['id' => 'desc'];
+        }
+
+        return array_merge($sort, [$this->getPk() => 'desc']);
+    }
+
+}

+ 42 - 0
app/common/model/School.php

@@ -13,6 +13,7 @@ declare (strict_types=1);
 namespace app\common\model;
 
 use cores\BaseModel;
+use think\facade\Cache;
 use think\model\Collection;
 use think\model\relation\HasMany;
 use think\model\relation\HasOne;
@@ -137,6 +138,18 @@ class School extends BaseModel
                 $query->where('school_name','like', "%{$params['keyword']}%");
 //                $query->where('school_name','like', "%{$params['keyword']}%")->whereOr('address','like',"%{$params['keyword']}%");
             }
+
+            // 匹配同专业学校
+            $specialityName = isset($params['speciality_name'])? $params['speciality_name'] : '';
+            if($specialityName){
+                $query->whereIn('id', SchoolSpeciality::getSchools($specialityName));
+            }
+
+            // 过滤学校
+            $schoolId = isset($params['school_id'])? $params['school_id'] : 0;
+            if($schoolId){
+                $query->whereNotIn('id', [$schoolId]);
+            }
         });
     }
 
@@ -190,4 +203,33 @@ class School extends BaseModel
     {
         return $this->HasOne('region','id','region_id')->bind(['name as region_name']);
     }
+
+    /**
+     * @param $userId
+     * @return mixed
+     */
+    public function userSchool($userId, $field=''){
+        $data = \think\facade\Cache::get("caches:user:schoolData:{$userId}");
+        if($data){
+            return $data;
+        }
+
+        $data = self::alias($this->name)
+            ->leftJoin('user_info ui','ui.school_id='.$this->name.'.id')
+            ->where(['ui.user_id'=> $userId])
+            ->find();
+        if($data){
+            Cache::set("caches:user:schoolData:{$userId}", $data, rand(5, 10));
+        }
+
+        return $data;
+    }
+
+    /**
+     * 访问量
+     * @param $id
+     */
+    public static function setIncViews($id){
+        self::setInc(['speciality_id'=> $id], 'views', 1);
+    }
 }

+ 34 - 1
app/common/model/SchoolAlbum.php

@@ -13,7 +13,6 @@ declare (strict_types=1);
 namespace app\common\model;
 
 use cores\BaseModel;
-use think\model\relation\HasOne;
 
 /**
  * 学校图库模型类
@@ -22,6 +21,8 @@ use think\model\relation\HasOne;
  */
 class SchoolAlbum extends BaseModel
 {
+    protected $globalScope = [''];
+
     // 定义表名
     protected $name = 'school_album';
 
@@ -29,4 +30,36 @@ class SchoolAlbum extends BaseModel
     protected $pk = 'album_id';
 
 
+    /**
+     * 获取学校的图库列表
+     * @param $schoolId
+     * @param int $limitRow
+     * @return array|mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function getShowList($schoolId, $limitRow=0){
+        if($list = \think\facade\Cache::get('caches:schools:albums:'.$schoolId)){
+            return $list;
+        }
+
+        $query = self::where(['school_id'=>$schoolId]);
+        if($limitRow){
+            $query->limit($limitRow);
+        }
+
+        $list = $query->field('album_id,title,album_url')
+            ->order('album_id desc')
+            ->select();
+        $list = $list? $list->toArray() :[];
+        if($list){
+            foreach ($list as &$item){
+                $item['album_url_preview'] = $item['album_url']? getPreview($item['album_url']) : '';
+            }
+            \think\facade\Cache::set('caches:schools:albums:'.$schoolId, $list, rand(5, 10));
+        }
+
+        return $list;
+    }
 }

+ 70 - 0
app/common/model/SchoolNew.php

@@ -0,0 +1,70 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\common\model;
+
+use cores\BaseModel;
+
+/**
+ * 学校图库模型类
+ * Class SchoolNew
+ * @package app\common\model
+ */
+class SchoolNew extends BaseModel
+{
+    protected $globalScope = [''];
+
+    // 定义表名
+    protected $name = 'school_news';
+
+    // 定义主键
+    protected $pk = 'news_id';
+
+    /**
+     * 获取学校新闻资讯列表
+     * @param $schoolId
+     * @param int $limitRow
+     * @return array|mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function getShowList($schoolId, $type = 1, $limitRow=0){
+        $cacheKey = "caches:schools:news:{$schoolId}_{$type}_{$limitRow}";
+        if($list = \think\facade\Cache::get($cacheKey)){
+            return $list;
+        }
+
+        $query = self::where(['school_id'=>$schoolId, 'type'=> $type, 'status'=>1]);
+        if($limitRow){
+            $query->limit($limitRow);
+        }
+
+        $list = $query->order('addtime desc,news_id desc')->select();
+        $list->hidden(['content','update_time','status']);
+        $list = $list? $list->toArray() :[];
+        if($list){
+            foreach ($list as &$item){
+                $item['logo_preview'] = $item['logo']? getPreview($item['logo']) : '';
+                $item['publish_time'] = $item['addtime']? date('Y/m/d', strtotime($item['addtime'])) : '';
+            }
+
+            \think\facade\Cache::set($cacheKey, $list, rand(10, 30));
+        }
+
+        return $list;
+    }
+
+    public function getList($where, $limitRow= 15){
+
+    }
+}

+ 139 - 0
app/common/model/SchoolSpeciality.php

@@ -13,7 +13,9 @@ declare (strict_types=1);
 namespace app\common\model;
 
 use cores\BaseModel;
+use think\model\Collection;
 use think\model\relation\HasOne;
+use think\Paginator;
 
 /**
  * 学校专业模型类
@@ -22,12 +24,149 @@ use think\model\relation\HasOne;
  */
 class SchoolSpeciality extends BaseModel
 {
+    protected $globalScope = [''];
+
     // 定义表名
     protected $name = 'school_speciality';
 
     // 定义主键
     protected $pk = 'speciality_id';
 
+    /**
+     * 获取列表
+     * @param array $param 查询条件
+     * @param int $listRows 分页数量
+     * @return mixed
+     * @throws \think\db\exception\DbException
+     */
+    public function getList(array $param = [], int $listRows = 15)
+    {
+        // 筛选条件
+        $query = $this->getQueryFilter($param);
+        // 排序条件
+        $sort = $this->setQuerySort($param);
+
+        // 执行查询
+        $list = $query->alias($this->name)
+            ->leftJoin('schools s','s.id='.$this->name.'.school_id')
+            ->field($this->name.'.*,s.school_name')
+            ->order($sort)
+            ->paginate($listRows);
+
+        // 整理列表数据并返回
+        return $list;
+    }
+
+    /**
+     * 设置商品展示的数据
+     * @param Collection|Paginator $list 商品列表
+     * @param callable|null $callback 回调函数
+     * @return mixed
+     */
+    protected function setListData($list, callable $callback = null)
+    {
+        if ($list->isEmpty()) return $list;
+        // 遍历商品列表整理数据
+        foreach ($list as &$item) {
+            $data = $this->setData($item, $callback);
+        }
+        return $list;
+    }
+
+    /**
+     * 整理数据
+     * @param Collection|static $info
+     * @param callable|null $callback
+     * @return mixed
+     */
+    protected function setData($info, callable $callback = null)
+    {
+        // 回调函数
+        is_callable($callback) && call_user_func($callback, $info);
+        return $info->hidden(array_merge($this->hidden, ['']));
+    }
+
+    /**
+     * 检索查询条件
+     * @param array $params
+     * @return \think\db\BaseQuery
+     */
+    private function getQueryFilter(array $params)
+    {
+        $filter = [];
+
+        // 实例化新查询对象
+        $query = $this->getNewQuery();
+
+        // 学校层次,类型
+        !empty($params['school_id']) && $filter[] = ['school_id', '=', "{$params['school_id']}"];
+
+        // 状态
+        !empty($params['status']) && $filter[] = [$this->name.'.status', '=', "{$params['status']}"];
+
+        // 实例化新查询对象
+        return $query->where($filter)->where(function($query) use ($params){
+            // 关键词
+            if(!empty($params['keyword'])){
+                $query->where('speciality_name','like', "%{$params['keyword']}%")
+                    ->whereOr('s.school_name','like', "%{$params['keyword']}%");
+            }
+
+        });
+    }
+
+
+    /**
+     * 检索排序条件
+     * @param array $param
+     * @return array|string[]
+     */
+    private function setQuerySort(array $param = [])
+    {
+        $params = $this->setQueryDefaultValue($param, [
+            'sortType' => 'all',    // 排序类型
+            $this->name.'.views' => false,   // 热门排序 (true高到低 false低到高)
+        ]);
+        // 排序规则
+        $sort = [];
+        if ($params['sortType'] === 'all') {
+            $sort = [$this->name.'.views' => 'desc'];
+        } elseif ($params['sortType'] === 'view') {
+            $sort = ['speciality_id' => 'desc'];
+        }
+
+        return array_merge($sort, [$this->getPk() => 'desc']);
+    }
+
+    /**
+     * 关联学校
+     * @return HasOne
+     */
+    public function school(): HasOne
+    {
+        return $this->HasOne('School','id','school_id')->bind(['school_name']);
+    }
+
+    /**
+     * 详情
+     * @param int $id
+     * @param array $with
+     * @return array|null|static
+     */
+    public static function detail(int $id, array $with = [])
+    {
+        return self::get($id, $with);
+    }
 
+    /**
+     * 获取该专业所有学校ID
+     * @param $specialityName
+     * @return array
+     */
+    public static function getSchools($specialityName){
+        return self::where(['status'=>1])->where(function($query) use ($specialityName){
+            $query->where('speciality_name','=', $specialityName)->whereOr('speciality_name','like',"{$specialityName}%");
+        })->column('school_id');
+    }
 
 }

+ 168 - 0
app/common/model/SpecialityBook.php

@@ -0,0 +1,168 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\common\model;
+
+use cores\BaseModel;
+use think\model\Collection;
+use think\model\relation\HasOne;
+use think\Paginator;
+
+/**
+ * 学校专业模型类
+ * Class SpecialityBook
+ * @package app\common\model
+ */
+class SpecialityBook extends BaseModel
+{
+    // 定义表名
+    protected $name = 'speciality_book';
+
+    // 定义主键
+    protected $pk = 'id';
+
+    /**
+     * 获取列表
+     * @param array $param 查询条件
+     * @param int $listRows 分页数量
+     * @return mixed
+     * @throws \think\db\exception\DbException
+     */
+    public function getList(array $param = [], int $listRows = 15)
+    {
+        // 筛选条件
+        $query = $this->getQueryFilter($param);
+        // 排序条件
+        $sort = $this->setQuerySort($param);
+
+        // 执行查询
+        $list = $query->alias($this->name)
+            ->order($sort)
+            ->paginate($listRows);
+
+        // 整理列表数据并返回
+        return $list;
+    }
+
+    /**
+     * 设置商品展示的数据
+     * @param Collection|Paginator $list 商品列表
+     * @param callable|null $callback 回调函数
+     * @return mixed
+     */
+    protected function setListData($list, callable $callback = null)
+    {
+        if ($list->isEmpty()) return $list;
+        // 遍历商品列表整理数据
+        foreach ($list as &$item) {
+            $data = $this->setData($item, $callback);
+        }
+        return $list;
+    }
+
+    /**
+     * 整理数据
+     * @param Collection|static $info
+     * @param callable|null $callback
+     * @return mixed
+     */
+    protected function setData($info, callable $callback = null)
+    {
+        // 回调函数
+        is_callable($callback) && call_user_func($callback, $info);
+        return $info->hidden(array_merge($this->hidden, ['transaction_id']));
+    }
+
+    /**
+     * 检索查询条件
+     * @param array $params
+     * @return \think\db\BaseQuery
+     */
+    private function getQueryFilter(array $params)
+    {
+        $filter = [];
+
+        // 实例化新查询对象
+        $query = $this->getNewQuery();
+
+        // 报名用户
+        !empty($params['user_id']) && $filter[] = ['user_id', '=', "{$params['user_id']}"];
+
+        // 专业学校
+        !empty($params['school_id']) && $filter[] = ['school_id', '=', "{$params['school_id']}"];
+
+        // 专业
+        !empty($params['speciality_id']) && $filter[] = ['speciality_id', '=', "{$params['speciality_id']}"];
+
+        // 状态
+        !empty($params['status']) && $filter[] = ['status', '=', "{$params['status']}"];
+
+        // 实例化新查询对象
+        return $query->where($filter)->where(function($query) use ($params){
+            // 关键词
+            if(!empty($params['keyword'])){
+                $query->where('order_no','like', "%{$params['keyword']}%");
+          }
+        });
+    }
+
+
+    /**
+     * 检索排序条件
+     * @param array $param
+     * @return array|string[]
+     */
+    private function setQuerySort(array $param = [])
+    {
+        $params = $this->setQueryDefaultValue($param, [
+            'sortType' => 'all',    // 排序类型
+            'create_time' => false,   // 排序 (true高到低 false低到高)
+        ]);
+        // 排序规则
+        $sort = [];
+        if ($params['sortType'] === 'all') {
+            $sort = ['create_time' => 'desc','pay_time'=>'desc'];
+        } elseif ($params['sortType'] === 'pay') {
+            $sort = ['pay_time' => 'desc'];
+        }
+
+        return array_merge($sort, [$this->getPk() => 'desc']);
+    }
+
+    /**
+     * @return HasOne
+     */
+    public function speciality(): HasOne
+    {
+        return $this->HasOne('SchoolSpeciality','speciality_id','speciality_id')->bind(['speciality_name','speciality_logo']);
+    }
+
+
+    /**
+     * @return HasOne
+     */
+    public function school(): HasOne
+    {
+        return $this->HasOne('School','id','school_id')->bind(['school_name','logo as school_logo']);
+    }
+
+    /**
+     * @return HasOne
+     */
+    public function user(): HasOne
+    {
+        return $this->HasOne('User','user_id','user_id')
+            ->with('avatar')
+            ->field('user_id,gender,nick_name,preview_url as avatar_url')
+            ->bind(['nick_name','avatar_url']);
+    }
+}

+ 207 - 0
app/common/model/UserDynamic.php

@@ -0,0 +1,207 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\common\model;
+
+use cores\BaseModel;
+use think\model\Collection;
+use think\Paginator;
+
+/**
+ * 用户动态模型类
+ * Class UserDynamic
+ * @package app\common\model
+ */
+class UserDynamic extends BaseModel
+{
+    // 定义表名
+    protected $name = 'user_dynamic';
+
+    // 定义主键
+    protected $pk = 'id';
+
+    /**
+     * 获取列表
+     * @param array $param 查询条件
+     * @param int $listRows 分页数量
+     * @return mixed
+     * @throws \think\db\exception\DbException
+     */
+    public function getList(array $param = [], int $listRows = 15)
+    {
+        // 筛选条件
+        $query = $this->getQueryFilter($param);
+        // 排序条件
+        $sort = $this->setQuerySort($param);
+
+        // 执行查询
+        $list = $query->alias($this->name)
+            ->order($sort)
+            ->paginate($listRows);
+
+        // 整理列表数据并返回
+        return $list;
+    }
+
+    /**
+     * 获取学校下的列表
+     * @param int $schoolId
+     * @param int 当前用户ID,用户过滤好友可看动态,需param传lookUids字段过滤
+     * @param array $param
+     * @param int $listRows
+     * @return mixed
+     */
+    public function getListBySchool(int $schoolId,int $userId = 0, array $param = [], int $listRows = 15)
+    {
+        // 筛选条件
+        $query = $this->getQueryFilter($param);
+        // 排序条件
+        $sort = $this->setQuerySort($param);
+
+        // 执行查询
+        $list = $query->alias($this->name)
+            ->leftJoin('user_info ui','ui.user_id='.$this->name.'.user_id')
+            ->where(function($query) use($userId, $param){
+                if($userId>0){
+                    // 获取粉丝用户ID,并验证
+                    $query->where(function($query) use($userId){
+                        // 粉丝只能看公开或好友可看
+                        $query->whereIn($this->name.'.user_id', \app\api\model\UserFans::getFansUid($userId))
+                            ->whereIn($this->name.'.look_type',[1,2]);
+                    })->whereOr(function($query) use ($userId){
+                        // 用户自己所有
+                        $query->where([$this->name.'.user_id'=> $userId]);
+                    })->whereOr(function($query){
+                        // 公开对所有
+                        $query->where([$this->name.'.look_type'=> 1]);
+                    });
+                }
+            })
+            ->field($this->name.'.*, ui.school_id')
+            ->order($sort)
+            ->paginate($listRows);
+
+       // echo $query->getLastSql();
+
+        // 整理列表数据并返回
+        return $list;
+    }
+
+    /**
+     * 设置商品展示的数据
+     * @param Collection|Paginator $list 商品列表
+     * @param callable|null $callback 回调函数
+     * @return mixed
+     */
+    protected function setListData($list, callable $callback = null)
+    {
+        if ($list->isEmpty()) return $list;
+        // 遍历商品列表整理数据
+        foreach ($list as &$item) {
+            $data = $this->setData($item, $callback);
+        }
+        return $list;
+    }
+
+    /**
+     * 整理数据
+     * @param Collection|static $info
+     * @param callable|null $callback
+     * @return mixed
+     */
+    protected function setData($info, callable $callback = null)
+    {
+        // 回调函数
+        is_callable($callback) && call_user_func($callback, $info);
+        return $info->hidden(array_merge($this->hidden, ['status']));
+    }
+
+    /**
+     * 检索查询条件
+     * @param array $params
+     * @return \think\db\BaseQuery
+     */
+    private function getQueryFilter(array $params)
+    {
+        $filter = [];
+
+        // 实例化新查询对象
+        $query = $this->getNewQuery();
+
+        // 浏览类型
+        !empty($params['ui.school_id']) && $filter[] = ['ui.school_id', '=', "{$params['ui.school_id']}"];
+
+        // 状态
+        !empty($params[$this->name.'.status']) && $filter[] = [$this->name.'.status', '=', "{$params[$this->name.'.status']}"];
+
+        // 浏览类型
+        !empty($params['look_type']) && $filter[] = ['look_type', '=', "{$params['look_type']}"];
+
+        // 类型
+        !empty($params['type']) && $filter[] = [$this->name.'.type', '=', "{$params['type']}"];
+
+        // 实例化新查询对象
+        return $query->where($filter)->where(function($query) use ($params){
+            // 关键词
+            if(!empty($params['keyword'])){
+                $query->where('content','like', "%{$params['keyword']}%");
+            }
+
+            if(!empty($params['tag'])){
+                $query->where('content','like', "%#{$params['tag']}%");
+            }
+        });
+    }
+
+
+    /**
+     * 检索排序条件
+     * @param array $param
+     * @return array|string[]
+     */
+    private function setQuerySort(array $param = [])
+    {
+        $params = $this->setQueryDefaultValue($param, [
+            'sortType' => 'all',    // 排序类型
+            $this->name.'.create_time' => false,   // 热门排序 (true高到低 false低到高)
+        ]);
+        // 排序规则
+        $sort = [];
+        if ($params['sortType'] === 'all') {
+            $sort = [$this->name.'.create_time' => 'desc'];
+        } elseif ($params['sortType'] === 'view') {
+            $sort = [$this->name.'.views' => 'desc'];
+        }
+
+        return array_merge($sort, [$this->getPk() => 'desc']);
+    }
+
+    /**
+     * 封面览图
+     * @param $value
+     * @return string|string[]|null
+     */
+    public function getImageAttr($value): string
+    {
+        return $value? getPreview($value) : '';
+    }
+
+    /**
+     * 资源文件
+     * @param $value
+     * @return string|string[]|null
+     */
+    public function getFileUrlAttr($value): string
+    {
+        return $value? getPreview($value) : '';
+    }
+}

+ 31 - 0
app/common/model/UserFans.php

@@ -0,0 +1,31 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\common\model;
+
+use cores\BaseModel;
+use think\model\relation\HasOne;
+
+/**
+ * 用户粉丝模型类
+ * Class UserFans
+ * @package app\common\model
+ */
+class UserFans extends BaseModel
+{
+    // 定义表名
+    protected $name = 'user_fans';
+
+    // 定义主键
+    protected $pk = 'id';
+
+}