wesmiler 2 meses atrás
pai
commit
d88abddace

+ 23 - 0
app/Http/Controllers/Api/v1/ArticleController.php

@@ -4,6 +4,8 @@ namespace App\Http\Controllers\Api\v1;
 
 use App\Http\Controllers\Api\webApp;
 use App\Services\Api\ArticleService;
+use App\Services\Api\SupervisorsService;
+use App\Services\Common\AdService;
 
 /**
  * 文章管理
@@ -26,6 +28,27 @@ class ArticleController extends webApp
     }
 
     /**
+     * 行业数据
+     * @return array
+     */
+    public function industry()
+    {
+        try {
+            $data = [
+                // 轮播
+                'banners' => AdService::make()->getListByPosition(2), // 轮播
+                'supervisors' => SupervisorsService::make()->getRecommendList(), // 推荐导师
+                'articles' => ArticleService::make()->getListByType(2), // 行业政策资讯
+            ];
+
+            return showJson(1010, true, $data);
+        } catch (\Exception $exception) {
+            $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
+            return showJson(1046, false, $error);
+        }
+    }
+
+    /**
      * 详情
      */
     public function info()

+ 0 - 21
app/Http/Controllers/Api/v1/IndexController.php

@@ -73,27 +73,6 @@ class IndexController extends webApp
     }
 
     /**
-     * 行业数据
-     * @return array
-     */
-    public function industry()
-    {
-        try {
-            $data = [
-                // 轮播
-                'banners' => AdService::make()->getListByPosition(2),
-                'supervisors' => S::make()->getListByPosition(2),
-                'articles' => ArticleService::make()->getListByType(2),
-            ];
-
-            return showJson(1010, true, $data);
-        } catch (\Exception $exception) {
-            $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
-            return showJson(1046, false, $error);
-        }
-    }
-
-    /**
      * 验证更新
      * @return array
      */

+ 3 - 35
app/Http/Controllers/Api/v1/SupervisorsController.php

@@ -3,7 +3,7 @@
 namespace App\Http\Controllers\Api\v1;
 
 use App\Http\Controllers\Api\webApp;
-use App\Services\Api\JobsService;
+use App\Services\Api\SupervisorsService;
 
 /**
  * 导师信息
@@ -20,18 +20,7 @@ class SupervisorsController extends webApp
     {
         $params =request()->post();
         $pageSize = request()->post('pageSize', 15);
-        $datas = JobsService::make()->getDataList($params, $pageSize);
-        return showJson(1010, true, $datas);
-    }
-
-
-    /**
-     * 分类
-     * @return array
-     */
-    public function categorys()
-    {
-        $datas = JobsService::make()->getCategoryList();
+        $datas = SupervisorsService::make()->getDataList($params, $pageSize);
         return showJson(1010, true, $datas);
     }
 
@@ -44,7 +33,7 @@ class SupervisorsController extends webApp
         $params = request()->all();
         $id = isset($params['id'])? $params['id'] : 0;
         try {
-            if(!$result = JobsService::make()->getInfo($id, $this->userId)){
+            if(!$result = SupervisorsService::make()->getInfo($id, $this->userId)){
                 return showJson(1009, false);
             }else{
                 return showJson(1010, true, $result);
@@ -54,25 +43,4 @@ class SupervisorsController extends webApp
             return showJson(1046, false, $error);
         }
     }
-
-    /**
-     * 申请
-     * @return array
-     */
-    public function apply()
-    {
-        $params = request()->all();
-
-       try {
-           if(!$result = JobsService::make()->apply($this->userId, $params)){
-               return showJson(JobsService::make()->getError(), false);
-           }else{
-               return showJson(JobsService::make()->getError(), true, $result);
-           }
-       } catch (\Exception $exception) {
-           $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
-           return showJson(1046, false, $error);
-       }
-    }
-
 }

+ 0 - 1
app/Services/Api/ArticleService.php

@@ -196,7 +196,6 @@ class ArticleService extends BaseService
         return $datas;
     }
 
-
     /**
      * 获取文章推荐分类
      * @param int $type

+ 27 - 2
app/Services/Api/SupervisorsService.php

@@ -13,6 +13,7 @@ namespace App\Services\Api;
 
 use App\Models\SupervisorsModel;
 use App\Services\BaseService;
+use App\Services\ConfigService;
 use App\Services\RedisService;
 
 /**
@@ -105,15 +106,39 @@ class SupervisorsService extends BaseService
             return $info;
         }
         $where = ['id'=> $id,'mark'=>1];
-        $info = $this->model->with(['store','category'])->where($where)->first();
+        $info = $this->model->with(['member'])->where($where)->withCount(['consults'])->first();
         $info = $info? $info->toArray() : [];
         if($info){
-            $info['category_name'] = isset($info['category']) && $info['category']?$info['category']['name'] : '';
             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;
+    }
 
 }

+ 1 - 0
routes/api.php

@@ -52,6 +52,7 @@ Route::prefix('v1')->middleware('web.login')->group(function() {
     // 配置和首页数据
     Route::get('/config', [\App\Http\Controllers\Api\v1\IndexController::class, 'config']);
     Route::get('/index/data', [\App\Http\Controllers\Api\v1\IndexController::class, 'data']);
+    Route::get('/industry/data', [\App\Http\Controllers\Api\v1\Ind::class, 'data']);
 
     // 用户信息
     Route::get('/user/info', [\App\Http\Controllers\Api\v1\MemberController::class, 'info']);