wesmiler před 6 dny
rodič
revize
45fadef5f9

+ 0 - 108
app/Http/Controllers/Api/v1/MeetingController.php

@@ -1,108 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\Api\v1;
-
-use App\Http\Controllers\Api\webApp;
-use App\Services\Api\MeetingService;
-use App\Services\MpService;
-
-/**
- * 会议管理
- * @package App\Http\Controllers\Api
- */
-class MeetingController extends webApp
-{
-
-    /**
-     * 列表
-     * @return array
-     */
-    public function index()
-    {
-        $params =request()->post();
-        $pageSize = request()->post('pageSize', 15);
-        $params['user_id'] = $this->userId;
-        $datas = MeetingService::make()->getDataList($params, $pageSize);
-        return message(1010, true, $datas);
-    }
-
-
-
-    /**
-     * 详情
-     */
-    public function info()
-    {
-        $params = request()->all();
-        $id = isset($params['id'])? intval($params['id']) : 0;
-        $type = isset($params['type']) && $params['type']? intval($params['type']) : 1;
-        if(empty($id)){
-            return message(1036, false);
-        }
-
-        if($info = MeetingService::make()->getInfo($id,$this->userId,$type)){
-            return message(1010, true, $info);
-        }else{
-            return message(1009, false);
-        }
-    }
-
-
-    /**
-     * 会议链接
-     */
-    public function getLink()
-    {
-        $params = request()->all();
-        $id = isset($params['id'])? intval($params['id']) : 0;
-        if(empty($id)){
-            return message(1036, false);
-        }
-
-        if($link = MpService::make()->getMiniShareLink('pagesSub/pages/meeting/books?id='.$id,'邀请您参加会议')){
-            return message(1010, true, $link);
-        }else{
-            return message(MpService::make()->getError(), false);
-        }
-    }
-
-
-
-    /**
-     * 签到
-     */
-    public function books()
-    {
-        $params = request()->post();
-        try {
-            if ($result = MeetingService::make()->books($this->userId, $params)) {
-                return showJson(MeetingService::make()->getError(), true, $result);
-            } else {
-                return showJson(MeetingService::make()->getError(), false);
-            }
-        }  catch (\Exception $exception) {
-            $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
-            return showJson(1046, false, $error);
-        }
-    }
-
-    /**
-     * 签到记录
-     */
-    public function records()
-    {
-        $params = request()->post();
-        $pageSize = request()->post('pageSize',20);
-        try {
-            if ($datas = MeetingService::make()->records($params,$pageSize)) {
-                return showJson(1010, true, $datas);
-            } else {
-                return showJson(1009, false);
-            }
-        }  catch (\Exception $exception) {
-            $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
-            return showJson(1046, false, $error);
-        }
-    }
-
-}

+ 47 - 0
app/Http/Controllers/Api/v1/MessageController.php

@@ -0,0 +1,47 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\webApp;
+use App\Services\Api\MessageService;
+
+/**
+ * 消息管理
+ * @package App\Http\Controllers\Api
+ */
+class MessageController extends webApp
+{
+
+    /**
+     * 列表
+     * @return array
+     */
+    public function index()
+    {
+        $datas = MessageService::make()->getIndexList($this->userId);
+        return showJson(1010, true, $datas);
+    }
+
+    /**
+     * 列表
+     * @return array
+     */
+    public function list()
+    {
+        $params = request()->all();
+        $pageSize = isset($params['pageSize'])?$params['pageSize']: 20;
+        $params['to_uid'] = $this->userId;
+        $datas = MessageService::make()->getDataList($params,$pageSize);
+        return showJson(1010, true, $datas);
+    }
+
+    /**
+     * 一键已读
+     * @return array
+     */
+    public function readAll()
+    {
+        $datas = MessageService::make()->readAll($this->userId);
+        return showJson(1010, true, $datas);
+    }
+}

+ 0 - 84
app/Http/Controllers/Api/v1/SupervisorsController.php

@@ -1,84 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\Api\v1;
-
-use App\Http\Controllers\Api\webApp;
-use App\Http\Validator\ConsultValidator;
-use App\Services\Api\SupervisorsService;
-
-/**
- * 导师信息
- * @package App\Http\Controllers\Api
- */
-class SupervisorsController extends webApp
-{
-
-    /**
-     * 列表
-     * @return array
-     */
-    public function index()
-    {
-        $params =request()->post();
-        $pageSize = request()->post('pageSize', 15);
-        $datas = SupervisorsService::make()->getDataList($params, $pageSize);
-        return showJson(1010, true, $datas);
-    }
-
-    /**
-     * 分类
-     * @return array
-     */
-    public function categorys()
-    {
-        $datas = [
-            ['id'=>1,'name'=>'专项导师'],
-            ['id'=>2,'name'=>'研究导师'],
-            ['id'=>3,'name'=>'发展导师'],
-        ];
-        return message(1010, true, $datas);
-    }
-
-    /**
-     * 详情
-     * @return array
-     */
-    public function info()
-    {
-        $params = request()->all();
-        $id = isset($params['id'])? $params['id'] : 0;
-        try {
-            if(!$result = SupervisorsService::make()->getInfo($id, $this->userId)){
-                return showJson(1009, false);
-            }else{
-                return showJson(1010, true, $result);
-            }
-        } catch (\Exception $exception) {
-            $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
-            return showJson(1046, false, $error);
-        }
-    }
-
-    /**
-     * 咨询提交
-     */
-    public function consult(ConsultValidator $validator)
-    {
-        $params = request()->post();
-        $params = $validator->check($params, 'submit');
-        if (!is_array($params)) {
-            return showJson($params, false);
-        }
-
-        try {
-            if (SupervisorsService::make()->consultSubmit($this->userId, $params)) {
-                return showJson(SupervisorsService::make()->getError(), true);
-            } else {
-                return showJson(SupervisorsService::make()->getError(), false);
-            }
-        }  catch (\Exception $exception) {
-            $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
-            return showJson(1046, false, $error);
-        }
-    }
-}

+ 54 - 0
app/Services/Api/MessageService.php

@@ -154,6 +154,60 @@ class MessageService extends BaseService
     }
     }
 
 
     /**
     /**
+     * 消息分类数据
+     * @param $userId
+     * @return array|array[]|mixed
+     */
+    public function getIndexList($userId)
+    {
+        $cacheKey = "caches:message:index_{$userId}";
+        $datas = RedisService::get($cacheKey);
+        if($datas){
+            return $datas;
+        }
+
+        $datas  = [
+            6=>['id'=>6,'title'=>'交易通知','count'=>0],
+            5=>['id'=>5,'title'=>'活动通知','count'=>0],
+            4=>['id'=>4,'title'=>'互动通知','count'=>0],
+            2=>['id'=>2,'title'=>'系统消息','count'=>0],
+            1=>['id'=>1,'title'=>'客服消息','count'=>0],
+            3=>['id'=>3,'title'=>'服务通知','count'=>0],
+        ];
+
+        $counts = $this->model->where(['to_uid'=>$userId,'status'=>1,'mark'=>1])
+            ->selectRaw('count(id) as count,type')
+            ->groupBy('type')
+            ->first();
+        $counts = $counts?$counts->toArray() :[];
+        if($counts){
+            foreach ($counts as $item){
+                $type = isset($item['type'])?$item['type']:0;
+                if(isset($datas[$type])){
+                    $datas[$type]['count'] = isset($item['count'])?$item['count']:0;
+                }
+            }
+        }
+
+        $datas = array_values($datas);
+        RedisService::set($cacheKey, $datas, rand(5,10));
+        return $datas;
+    }
+
+    /**
+     * 设置全部已读
+     * @param $id
+     * @param $userId
+     * @return bool
+     */
+    public function readAll($userId)
+    {
+        $this->model->where(['to_id'=>$userId])->update(['is_read'=>1,'update_time'=>time()]);
+        $this->error = '设置成功';
+        return true;
+    }
+
+    /**
      * 消息推送处理
      * 消息推送处理
      * @param $userId 用户
      * @param $userId 用户
      * @param $msgData 消息数据
      * @param $msgData 消息数据

+ 6 - 14
routes/api.php

@@ -41,10 +41,6 @@ Route::prefix('v1')->group(function() {
     Route::post('/goods/category/list', [\App\Http\Controllers\Api\v1\GoodsController::class, 'categorys']);
     Route::post('/goods/category/list', [\App\Http\Controllers\Api\v1\GoodsController::class, 'categorys']);
 
 
     Route::get('/order/info', [\App\Http\Controllers\Api\v1\OrderController::class, 'info']);
     Route::get('/order/info', [\App\Http\Controllers\Api\v1\OrderController::class, 'info']);
-    Route::post('/supervisor/index', [\App\Http\Controllers\Api\v1\SupervisorsController::class, 'index']);
-    Route::post('/supervisor/category/list', [\App\Http\Controllers\Api\v1\SupervisorsController::class, 'categorys']);
-    Route::get('/supervisor/info', [\App\Http\Controllers\Api\v1\SupervisorsController::class, 'info']);
-
 });
 });
 
 
 
 
@@ -111,19 +107,15 @@ Route::prefix('v1')->middleware('web.login')->group(function() {
     Route::post('/address/save', [\App\Http\Controllers\Api\v1\AddressController::class, 'save']);
     Route::post('/address/save', [\App\Http\Controllers\Api\v1\AddressController::class, 'save']);
     Route::post('/address/delete', [\App\Http\Controllers\Api\v1\AddressController::class, 'delete']);
     Route::post('/address/delete', [\App\Http\Controllers\Api\v1\AddressController::class, 'delete']);
 
 
-    // 导师
-    Route::post('/supervisor/consult', [\App\Http\Controllers\Api\v1\SupervisorsController::class, 'consult']);
+    // 举报
+    Route::post('/complaint/submit', [\App\Http\Controllers\Api\v1\ComplaintController::class, 'submit']);
 
 
-    // 会议
-    Route::post('/meeting/index', [\App\Http\Controllers\Api\v1\MeetingController::class, 'index']);
-    Route::post('/meeting/info', [\App\Http\Controllers\Api\v1\MeetingController::class, 'info']);
-    Route::post('/meeting/getLink', [\App\Http\Controllers\Api\v1\MeetingController::class, 'getLink']);
-    Route::post('/meeting/books', [\App\Http\Controllers\Api\v1\MeetingController::class, 'books']);
-    Route::post('/meeting/record/list', [\App\Http\Controllers\Api\v1\MeetingController::class, 'records']);
 
 
+    // 消息
+    Route::post('/message/index', [\App\Http\Controllers\Api\v1\MessageController::class, 'index']);
+    Route::post('/message/list', [\App\Http\Controllers\Api\v1\MessageController::class, 'list']);
+    Route::post('/message/readAll', [\App\Http\Controllers\Api\v1\MessageController::class, 'readAll']);
 
 
-    // 举报
-    Route::post('/complaint/submit', [\App\Http\Controllers\Api\v1\ComplaintController::class, 'submit']);
 
 
 
 
 });
 });