diff --git a/app/Admin/Controllers/ActivityController.php b/app/Admin/Controllers/ActivityController.php index 962f254..b16ea83 100644 --- a/app/Admin/Controllers/ActivityController.php +++ b/app/Admin/Controllers/ActivityController.php @@ -162,7 +162,7 @@ class ActivityController extends AdminController amis()->TableColumn('home_logo', __('admin.activity_games.home_logo'))->type('image')->height('30px')->width('30px'), amis()->TableColumn('away', __('admin.activity_games.away')), amis()->TableColumn('away_logo', __('admin.activity_games.away_logo'))->type('image')->height('30px')->width('30px'), - amis()->TableColumn('game_at', __('admin.activity_games.game_at')), + amis()->TableColumn('game_at', __('admin.activity_games.game_at'))->type('datetime'), amis()->TableColumn('mark', __('admin.activity_games.mark')), amis()->TableColumn('score', __('admin.activity_games.score')), amisMake()->Operation()->label(__('admin.actions'))->buttons([ diff --git a/app/Http/Controllers/Api/ActivityGameController.php b/app/Http/Controllers/Api/ActivityGameController.php index 90a20f0..dd86ff9 100644 --- a/app/Http/Controllers/Api/ActivityGameController.php +++ b/app/Http/Controllers/Api/ActivityGameController.php @@ -35,6 +35,6 @@ class ActivityGameController extends ApiController return ActivityGameResource::make($game); } - return $this->success(null); + return $this->success(); } } \ No newline at end of file diff --git a/app/Http/Controllers/Api/AdController.php b/app/Http/Controllers/Api/AdController.php new file mode 100644 index 0000000..4828a42 --- /dev/null +++ b/app/Http/Controllers/Api/AdController.php @@ -0,0 +1,23 @@ +input('address', ''); + + $ads = Ad::where('address', $address)->show()->sort()->get(); + + return $this->success(['ads'=>AdResource::collection($ads)->resolve()]); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Api/ArticleController.php b/app/Http/Controllers/Api/ArticleController.php new file mode 100644 index 0000000..0139d23 --- /dev/null +++ b/app/Http/Controllers/Api/ArticleController.php @@ -0,0 +1,52 @@ +where('is_recommend', 1)->sort() + ->simplePaginate($request->query('per_page', 20)); + + return $this->success(['articles'=>ArticleResource::collection($articles)->resolve()]); + } + + public function category(Request $request) + { + $categories = Keyword::allChildrenOfKey('article_category')->orderBy('sort', 'asc')->get(); + + return $this->success(['categories'=>ArticleCategoryResource::collection($categories)->resolve()]); + } + + public function index(Request $request) + { + $categoryId = $request->input('category_key', 0); + $query = Article::query(); + if($categoryId > 0){ + $query->where('category', $categoryId); + } + + $articles = $query->show()->sort() + ->simplePaginate($request->query('per_page', 20)); + + return $this->success(['articles'=>ArticleResource::collection($articles)->resolve()]); + } + + public function show(Article $article) + { + return ArticleResource::make($article); + } + + + +} \ No newline at end of file diff --git a/app/Http/Resources/Api/AdResource.php b/app/Http/Resources/Api/AdResource.php new file mode 100644 index 0000000..daff2ed --- /dev/null +++ b/app/Http/Resources/Api/AdResource.php @@ -0,0 +1,29 @@ + $this->resource->resource, + 'jump_type' => $this->jump_type, + 'jump_config' => $this->jump_config ?? [] + ]; + } + + public function with($request) + { + return ['code' => Response::HTTP_OK, 'message' => '']; + } +} \ No newline at end of file diff --git a/app/Http/Resources/Api/ArticleCategoryResource.php b/app/Http/Resources/Api/ArticleCategoryResource.php new file mode 100644 index 0000000..88d97c3 --- /dev/null +++ b/app/Http/Resources/Api/ArticleCategoryResource.php @@ -0,0 +1,29 @@ + $this->id, + 'name' => $this->name, + 'key' => $this->key, + ]; + } + + public function with($request) + { + return ['code' => Response::HTTP_OK, 'message' => '']; + } +} \ No newline at end of file diff --git a/app/Http/Resources/Api/ArticleResource.php b/app/Http/Resources/Api/ArticleResource.php new file mode 100644 index 0000000..d770498 --- /dev/null +++ b/app/Http/Resources/Api/ArticleResource.php @@ -0,0 +1,32 @@ + $this->id, + 'title' => $this->title, + 'cover' => $this->cover ?? '', + 'published_at' => $this->published_at->format('Y-m-d H:i'), + 'source' => $this->source ?? '', + 'content' => $this->content ?? '', + ]; + } + + public function with($request) + { + return ['code' => Response::HTTP_OK, 'message' => '']; + } +} \ No newline at end of file diff --git a/app/Models/Ad.php b/app/Models/Ad.php index 6311db2..b3e082b 100644 --- a/app/Models/Ad.php +++ b/app/Models/Ad.php @@ -72,8 +72,8 @@ class Ad extends Model ]; } - public function scopeShow(){ - $q->where('is_enable', true)->where('published_at', '>=', now()); + public function scopeShow($q){ + $q->where('is_enable', true)->where('published_at', '<=', now()); } public function scopeSort($q) diff --git a/app/Models/Article.php b/app/Models/Article.php index 25e909a..2b60947 100644 --- a/app/Models/Article.php +++ b/app/Models/Article.php @@ -21,9 +21,7 @@ class Article extends Model protected $appends = ['tags']; protected $casts = [ - 'created_at' => 'datetime:Y-m-d H:i:s', - 'updated_at' => 'datetime:Y-m-d H:i:s', - 'published_at' => 'datetime:Y-m-d H:i:s', + 'published_at' => 'datetime', 'is_enable' => 'boolean', 'is_recommend' => 'boolean', 'appendixes' => 'array', @@ -43,8 +41,8 @@ class Article extends Model 'source' ]; - public function scopeShow(){ - $q->where('is_enable', true)->where('published_at', '>=', now()); + public function scopeShow($q){ + $q->where('is_enable', true)->where('published_at', '<=', now()); } public function scopeSort($q) diff --git a/app/Services/Admin/AdService.php b/app/Services/Admin/AdService.php index 84fa949..5f3fdd1 100644 --- a/app/Services/Admin/AdService.php +++ b/app/Services/Admin/AdService.php @@ -26,7 +26,7 @@ class AdService extends BaseService $columns = $this->getTableColumns(); $model = $this->getModel(); - $isEnable = Arr::get($data, 'is_enabled'); + $isEnable = Arr::get($data, 'is_enable'); $publishedAt = Arr::get($data, 'published_at'); if ($isEnable && empty($publishedAt)) { $data['published_at'] = now(); diff --git a/app/Services/Admin/ArticleService.php b/app/Services/Admin/ArticleService.php index 3fcc219..acc8db6 100644 --- a/app/Services/Admin/ArticleService.php +++ b/app/Services/Admin/ArticleService.php @@ -26,7 +26,7 @@ class ArticleService extends BaseService $columns = $this->getTableColumns(); $model = $this->getModel(); - $isEnable = Arr::get($data, 'is_enabled'); + $isEnable = Arr::get($data, 'is_enable'); $publishedAt = Arr::get($data, 'published_at'); if ($isEnable && empty($publishedAt)) { $data['published_at'] = now(); diff --git a/lang/zh_CN/admin.php b/lang/zh_CN/admin.php index 5caa4ac..ef95a0a 100644 --- a/lang/zh_CN/admin.php +++ b/lang/zh_CN/admin.php @@ -265,6 +265,19 @@ return [ 'selected_rows_no_data' => '请选择要导出的数据', 'please_install_laravel_excel' => '请先安装 laravel-excel 扩展', ], + 'components' => [ + 'parent_select' => '父级', + 'order' => '排序', + 'decimal' => '金额', + 'content' => '内容', + 'status' => '状态', + 'status_map' => [ + 'enabled' => '开启', + 'disabled' => '关闭' + ], + 'files' => '文件', + 'tag' => "标签" + ], 'keywords' => [ 'search_name' => '名称/KEY', 'parent_keyword' => '父级关键字', diff --git a/routes/api.php b/routes/api.php index 4e33cfc..2a6b548 100644 --- a/routes/api.php +++ b/routes/api.php @@ -23,6 +23,13 @@ Route::group(['prefix' => 'miniprogram', 'namespace' => 'Api\Miniprogram'], func Route::post('refresh-token', [App\Http\Controllers\Api\AuthController::class, 'refreshToken']); // 首页接口 Route::get('latest-game', [App\Http\Controllers\Api\ActivityGameController::class, 'latestGame']); + Route::get('recommend-articles', [App\Http\Controllers\Api\ArticleController::class, 'recommend']); + Route::get('ads', [App\Http\Controllers\Api\AdController::class, 'index']); + // 资讯接口 + Route::get('categories', [App\Http\Controllers\Api\ArticleController::class, 'category']); + Route::get('articles', [App\Http\Controllers\Api\ArticleController::class, 'index']); + Route::get('articles/{article}', [App\Http\Controllers\Api\ArticleController::class, 'show']); + // 已授权绑定手机号 Route::middleware([HasBindPhone::class])->group(function(){