Showing
7 changed files
with
225 additions
and
4 deletions
... | @@ -144,6 +144,44 @@ class ImmerseController extends Controller | ... | @@ -144,6 +144,44 @@ class ImmerseController extends Controller |
144 | else return Response::success(); | 144 | else return Response::success(); |
145 | } | 145 | } |
146 | 146 | ||
147 | + public function praiseList(Request $request) | ||
148 | + { | ||
149 | + $page = $request->get('page',1); | ||
150 | + $page_size = $request->get('page_size',20); | ||
151 | + | ||
152 | + $user = $request->user(); | ||
153 | + | ||
154 | + $collects = Praise::query()->where(['user_id' => $user->id, 'state' => 1]) | ||
155 | + ->orderByDesc('created_at') | ||
156 | + ->skip(($page - 1) * $page_size)->take($page_size + 1)->get(); | ||
157 | + | ||
158 | + $lists = []; | ||
159 | + | ||
160 | + if ($collects->count()){ | ||
161 | + foreach ($collects as $collect){ | ||
162 | + if ($collect->immerse){ // 避免删除过临境的还存在收藏列表里 | ||
163 | + $data['user_id'] = $collect->user_id; | ||
164 | + $data['immerse_id'] = $collect->immerse_id; | ||
165 | + $data['content'] = $collect->immerse->content; | ||
166 | + $data['thumbnail'] = $collect->immerse->thumbnail; | ||
167 | + $data['url'] = $collect->immerse->url; | ||
168 | + $data['type'] = $collect->immerse->type; | ||
169 | + $data['is_praise'] = $collect->immerse->isPraise($collect->immerse_id, $user->id); | ||
170 | + $data['is_collect'] = $collect->immerse->isCollect($collect->immerse_id, $user->id); | ||
171 | + | ||
172 | + $lists[] = $data; | ||
173 | + } | ||
174 | + } | ||
175 | + } | ||
176 | + | ||
177 | + return \response([ | ||
178 | + 'status' => 'success', | ||
179 | + 'code' => 200, | ||
180 | + 'message' => 'Http ok', | ||
181 | + 'data' => $lists, | ||
182 | + ], 200); | ||
183 | + } | ||
184 | + | ||
147 | public function collect($id, Request $request) | 185 | public function collect($id, Request $request) |
148 | { | 186 | { |
149 | $user = $request->user(); | 187 | $user = $request->user(); | ... | ... |
1 | +<?php | ||
2 | + | ||
3 | +namespace App\Http\Controllers\V1; | ||
4 | + | ||
5 | +use App\Http\Controllers\Controller; | ||
6 | +use App\Models\Feedback; | ||
7 | +use Carbon\Carbon; | ||
8 | +use Illuminate\Http\Request; | ||
9 | +use Illuminate\Support\Facades\Auth; | ||
10 | +use Jiannei\Response\Laravel\Support\Facades\Response; | ||
11 | + | ||
12 | +class MessageController extends Controller | ||
13 | +{ | ||
14 | + // | ||
15 | + public function insertFeedback(Request $request) | ||
16 | + { | ||
17 | + $user_id = Auth::user()->getAuthIdentifier(); | ||
18 | + $type = $request->post("type", 1); | ||
19 | + $content = $request->post("content"); | ||
20 | + | ||
21 | + if (!$content) return Response::fail('内容不可为空'); | ||
22 | + | ||
23 | + $insert = [ | ||
24 | + [ | ||
25 | + 'from_user_id' => $user_id, | ||
26 | + 'to_user_id' => 1, | ||
27 | + 'type' => $type, | ||
28 | + 'content' => $content, | ||
29 | + 'is_from_user' => 1, | ||
30 | + 'state' => 1, | ||
31 | + 'send_time' => Carbon::now() | ||
32 | + ], | ||
33 | + [ | ||
34 | + 'from_user_id' => 1, | ||
35 | + 'to_user_id' => $user_id, | ||
36 | + 'type' => $type, | ||
37 | + 'content' => $content, | ||
38 | + 'is_from_user' => 0, | ||
39 | + 'state' => 0, | ||
40 | + 'send_time' => Carbon::now() | ||
41 | + ] | ||
42 | + ]; | ||
43 | + Feedback::query()->insert($insert); | ||
44 | + | ||
45 | + return Response::success(); | ||
46 | + } | ||
47 | + | ||
48 | + public function feedbackList() | ||
49 | + { | ||
50 | + $user_id = Auth::user()->getAuthIdentifier(); | ||
51 | + $data = Feedback::query() | ||
52 | + ->where('from_user_id', $user_id) | ||
53 | + ->where('to_user_id', 1) | ||
54 | + ->orderBy('send_time') | ||
55 | + ->limit(10) | ||
56 | + ->get(); | ||
57 | + | ||
58 | + return Response::success($data); | ||
59 | + } | ||
60 | + | ||
61 | + public function unreadFeedbackCount() | ||
62 | + { | ||
63 | + $user_id = Auth::user()->getAuthIdentifier(); | ||
64 | + $count = Feedback::query() | ||
65 | + ->where('from_user_id', $user_id) | ||
66 | + ->where('is_from_user', 0) | ||
67 | + ->count(); | ||
68 | + return Response::success(['count' => $count]); | ||
69 | + } | ||
70 | + | ||
71 | + public function readFeedback() | ||
72 | + { | ||
73 | + $user_id = Auth::user()->getAuthIdentifier(); | ||
74 | + $count = Feedback::query() | ||
75 | + ->where('from_user_id', $user_id) | ||
76 | + ->where('is_from_user', 0) | ||
77 | + ->update(['state' => 1]); | ||
78 | + return Response::success(['count' => $count]); | ||
79 | + } | ||
80 | +} |
... | @@ -15,10 +15,10 @@ class Authenticate extends Middleware | ... | @@ -15,10 +15,10 @@ class Authenticate extends Middleware |
15 | */ | 15 | */ |
16 | protected function redirectTo($request) | 16 | protected function redirectTo($request) |
17 | { | 17 | { |
18 | - if (! $request->expectsJson()) { | 18 | +// if ($request->isJson()) { |
19 | - return route('login'); | 19 | + Response::errorUnauthorized(); // 授权失败 401 |
20 | - } | 20 | +// } |
21 | 21 | ||
22 | - Response::errorUnauthorized(); // 授权失败 401 | 22 | +// return route('app'); |
23 | } | 23 | } |
24 | } | 24 | } | ... | ... |
app/Models/Feedback.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use Illuminate\Database\Migrations\Migration; | ||
4 | +use Illuminate\Database\Schema\Blueprint; | ||
5 | +use Illuminate\Support\Facades\Schema; | ||
6 | + | ||
7 | +class AlterUserProfiles extends Migration | ||
8 | +{ | ||
9 | + /** | ||
10 | + * Run the migrations. | ||
11 | + * | ||
12 | + * @return void | ||
13 | + */ | ||
14 | + public function up() | ||
15 | + { | ||
16 | + // | ||
17 | + Schema::table('user_profiles', function (Blueprint $table) { | ||
18 | + $table->string('intro')->after('user_id')->default("")->comment('简介'); | ||
19 | + $table->date('birthday')->after('intro')->default("2023-01-01")->comment('生日'); | ||
20 | + | ||
21 | + $table->unsignedInteger('follow_count')->after('video_count')->default(0)->comment('关注数量'); | ||
22 | + $table->unsignedInteger('fans_count')->after('follow_count')->default(0)->comment('粉丝数量'); | ||
23 | + $table->unsignedInteger('popular_count')->after('fans_count')->default(0)->comment('人气数量'); | ||
24 | + | ||
25 | + }); | ||
26 | + } | ||
27 | + | ||
28 | + /** | ||
29 | + * Reverse the migrations. | ||
30 | + * | ||
31 | + * @return void | ||
32 | + */ | ||
33 | + public function down() | ||
34 | + { | ||
35 | + // | ||
36 | + Schema::dropColumns('user_profiles', ['intro','birthday','follow_count','fans_count','popular_count']); | ||
37 | + } | ||
38 | +} |
1 | +<?php | ||
2 | + | ||
3 | +use Illuminate\Database\Migrations\Migration; | ||
4 | +use Illuminate\Database\Schema\Blueprint; | ||
5 | +use Illuminate\Support\Facades\Schema; | ||
6 | + | ||
7 | +class CreateFeedbackTable extends Migration | ||
8 | +{ | ||
9 | + /** | ||
10 | + * Run the migrations. | ||
11 | + * | ||
12 | + * @return void | ||
13 | + */ | ||
14 | + public function up() | ||
15 | + { | ||
16 | + Schema::create('feedback', function (Blueprint $table) { | ||
17 | + $table->id(); | ||
18 | + $table->unsignedInteger("from_user_id")->comment("发起用户"); | ||
19 | + $table->unsignedInteger("to_user_id")->default(1)->comment("接收用户"); | ||
20 | + $table->unsignedTinyInteger("type")->comment("消息类型"); | ||
21 | + $table->text("content")->comment("内容"); | ||
22 | + $table->unsignedTinyInteger("is_from_user")->comment("发起者"); | ||
23 | + $table->unsignedTinyInteger("state")->comment("0=未读1=已读"); | ||
24 | + $table->timestamp('send_time', 0)->nullable()->comment("发送时间"); | ||
25 | + }); | ||
26 | + } | ||
27 | + | ||
28 | + /** | ||
29 | + * Reverse the migrations. | ||
30 | + * | ||
31 | + * @return void | ||
32 | + */ | ||
33 | + public function down() | ||
34 | + { | ||
35 | + Schema::dropIfExists('feedback'); | ||
36 | + } | ||
37 | +} |
... | @@ -97,6 +97,9 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->middleware('auth:sanc | ... | @@ -97,6 +97,9 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->middleware('auth:sanc |
97 | /** 点赞 */ | 97 | /** 点赞 */ |
98 | $api->post('/praise/{id}', 'ImmerseController@praise'); | 98 | $api->post('/praise/{id}', 'ImmerseController@praise'); |
99 | 99 | ||
100 | + /** 点赞列表 */ | ||
101 | + $api->get('/praise', 'ImmerseController@praiseList'); | ||
102 | + | ||
100 | /** 收藏 */ | 103 | /** 收藏 */ |
101 | $api->post('/collect/{id}', 'ImmerseController@collect'); | 104 | $api->post('/collect/{id}', 'ImmerseController@collect'); |
102 | 105 | ||
... | @@ -117,4 +120,16 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->middleware('auth:sanc | ... | @@ -117,4 +120,16 @@ Route::prefix('v1')->namespace('App\Http\Controllers\V1')->middleware('auth:sanc |
117 | 120 | ||
118 | /** 调起支付 */ | 121 | /** 调起支付 */ |
119 | $api->apiResource('/pay', 'PayController'); | 122 | $api->apiResource('/pay', 'PayController'); |
123 | + | ||
124 | + /** 用户反馈 */ | ||
125 | + $api->post('/feedback', 'MessageController@insertFeedback'); | ||
126 | + | ||
127 | + /** 反馈消息记录 */ | ||
128 | + $api->get('/feedback', 'MessageController@feedbackList'); | ||
129 | + | ||
130 | + /** 未读反馈消息数量 */ | ||
131 | + $api->get('/unreadfc', 'MessageController@unreadFeedbackCount'); | ||
132 | + | ||
133 | + /** 更新读取反馈状态 */ | ||
134 | + $api->put('/feedback', 'MessageController@readFeedback'); | ||
120 | }); | 135 | }); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment