| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Api;
- use App\Models\SupervisorsModel;
- use App\Services\BaseService;
- use App\Services\ConfigService;
- use App\Services\RedisService;
- /**
- * 导师管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services\Api
- */
- class SupervisorsService extends BaseService
- {
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- */
- public function __construct()
- {
- $this->model = new SupervisorsModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- /**
- * @param $params
- * @param int $pageSize
- * @return array
- */
- public function getDataList($params, $pageSize = 15)
- {
- $where = ['supervisors.mark' => 1];
- $status = isset($params['status']) ? $params['status'] : 0;
- $isRecommend = isset($params['is_recommend']) ? $params['is_recommend'] : 0;
- if ($status > 0) {
- $where['supervisors.status'] = $status;
- }
- if ($isRecommend > 0) {
- $where['supervisors.is_recommend'] = $isRecommend;
- }
- $list = $this->model->with(['member'])
- ->from('supervisors')
- ->where($where)
- ->where(function ($query) use ($params) {
- $keyword = isset($params['keyword']) ? $params['keyword'] : '';
- if ($keyword) {
- $query->where('supervisors.name', 'like', "%{$keyword}%")
- ->orWhere('supervisors.mobile','like',"%{$keyword}%");
- }
- })
- ->select(['supervisors.*'])
- ->withCount(['consults'])
- ->orderBy('supervisors.sort', 'desc')
- ->orderBy('supervisors.id', 'desc')
- ->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list ? $list->toArray() : [];
- if ($list) {
- foreach ($list['data'] as &$item) {
- $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
- }
- }
- return [
- 'pageSize' => $pageSize,
- 'total' => isset($list['total']) ? $list['total'] : 0,
- 'list' => isset($list['data']) ? $list['data'] : []
- ];
- }
- /**
- * 详情
- * @param $id
- * @param $userId
- * @return array|mixed
- */
- public function getInfo($id,$userId=0)
- {
- $cacheKey = "caches:supervisors:info_{$id}_{$userId}";
- $info = RedisService::get($cacheKey);
- if($info){
- return $info;
- }
- $where = ['id'=> $id,'mark'=>1];
- $info = $this->model->with(['member'])->where($where)->withCount(['consults'])->first();
- $info = $info? $info->toArray() : [];
- if($info){
- RedisService::set($cacheKey, $info, rand(5, 10));
- }
- return $info;
- }
- /**
- * 获取推荐数据
- * @return array|mixed
- */
- public function getRecommendList($limit=0)
- {
- $limit = $limit?$limit:ConfigService::make()->getConfigByCode('supervisors_recommend_num',6);
- $cacheKey = "caches:supervisors:recommendList";
- $datas = RedisService::get($cacheKey);
- if($datas){
- return $datas;
- }
- $datas = $this->model->with(['member'])
- ->where(['is_recommend'=> 1,'status'=>1,'mark'=>1])
- ->withCount(['consults'])
- ->limit($limit)
- ->get();
- $datas = $datas? $datas->toArray() : [];
- if($datas){
- RedisService::set($cacheKey, $datas, rand(300,600));
- }
- return $datas;
- }
- }
|