| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Models\DynamicModel;
- use App\Models\UserLikeModel;
- use App\Models\UserSystemMessageModel;
- use App\Services\NoticeService;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- class NoticeController extends Controller
- {
- protected $noticeService;
- public function __construct()
- {
- $this->noticeService = new NoticeService();
- }
- /**
- * 获取消息列表
- * @param Request $request
- */
- public function get_notice_list(Request $request){
- try {
- $user = auth('api')->user();
- $res['notice_list'] = [];
- //未读喜欢数量
- $res['like_num'] = UserLikeModel::query()->where(["like_id"=>$user->id,'status'=>0])->count();
- //未读点赞数量
- $res['zan_num'] = DynamicModel::query()->with(["users"])->where('status','=',0)
- ->whereHas("users",function($query)use($user){
- $query->where('id',$user->id)->select();
- })->count();
- //未读系统消息
- $res['system_num'] = UserSystemMessageModel::query()->where(['user_id'=>$user->id,'status'=>0])->count();
- }catch (\Exception $exception){
- return $this->response->errorForbidden($exception->getMessage());
- }
- return response()->json($res);
- }
- /**
- * 获取喜欢列表
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse|void
- */
- public function get_like_list(Request $request){
- try {
- $user = auth('api')->user();
- $param['user_id'] = $user->id;
- $param['type'] = $request->type;
- $res = $this->noticeService->get_like_list($param);
- } catch (\Exception $exception){
- return $this->response->errorForbidden($exception->getMessage());
- }
- return response()->json($res);
- }
- /**
- * 获取点赞列表
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse|void
- */
- public function get_zan_list(Request $request){
- try {
- $user = auth('api')->user();
- $param['user_id'] = $user->id;
- $param['type'] = $request->type;
- $res = $this->noticeService->get_zan_list($param);
- } catch (\Exception $exception){
- return $this->response->errorForbidden($exception->getMessage());
- }
- return response()->json($res);
- }
- }
|