123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
-
- namespace App\Http\Controllers;
-
- use App\Models\HomePage;
- use Illuminate\Http\Request;
- use App\Models\Classify;
-
- class ClassifyController extends Controller
- {
-
- public function list(Request $request)
- {
- return Classify::paginate(100);
- }
-
- public function setHome(Request $request) {
- $introduce = $request->input("introduce");
-
- if($introduce) {
- $homePage = HomePage::find(1);
- $homePage->introduce = $introduce;
- $homePage->save();
-
- return response()->json([
- "status" => 0,
- "message" => '修改成功'
- ]);
- } else {
- return Response()->json([
- "status" => -1,
- "message" => "信息不能为空!"
- ]);
- }
- }
-
- /**
- * 每页20进行分页
- * @param Request $request
- * @return mixed
- */
- public function home(Request $request)
- {
- $top = Classify::where("location", "top")->orderBy("updated_at", "desc")->limit(5)->get()->toArray();
- //$bottom = Classify::where("location", "bottom")->orderBy("updated_at", "desc")->first();
- $homePage = HomePage::find(1);
- $tops = array_map(function ($t) {
- return [
- "id" => $t["id"],
- "server" => $t["server"],
- "content" => $t["content"],
- "photo" => $t["photo"],
- "location" => $t["location"]
- ];
- }, $top);
-
- return Response()->json([
- "top" => $tops,
- "introduce" => $homePage->bottom_introduce,
- "bottom" => [
- "id" => $homePage->id,
- "server" => "",
- "content" => $homePage->content,
- "photo" => $homePage->photo,
- "location" => "bottom"
- ]
- ]);
- }
-
-
- /**
- * 获取某个记录
- * @param Request $request
- * @param $id
- * @return \Illuminate\Http\JsonResponse
- */
- public function get(Request $request, $id)
- {
- $id = $request->route("id");
-
- $data = [];
- if ($id) {
- $record = Classify::find($id);
- if ($record) {
- $data["api"] = $record->api;
- $data["fields"] = json_decode($record->fields_json, true);
- return Response()->json([
- "status" => 0,
- "data" => [
- "id" => $record->id,
- "pid" => $record->pid,
- "name" => $record->name,
- "info" => $record->info,
- "content" => $record->summary,
- "photo" => $record->photo,
- "api" => $data["api"],
- "fields" => $data["fields"],
- "type" => $record->name,
- ]
- ]);
- }
- return Response()->json([
- "status" => -2,
- "message" => "不存在的记录!"
- ]);
- } else {
- return Response()->json([
- "status" => -1,
- "message" => "id不能为空!"
- ]);
- }
- }
-
- /**
- * @param Request $request
- * @param $id
- * @return \Illuminate\Http\JsonResponse
- */
- public function server_content(Request $request, $id) {
-
- $id = $request->route("id");
- if ($id) {
- $record = Classify::find($id);
- if ($record) {
- return Response()->json([
- "status" => 0,
- "data" => [
- "id" => $record->id,
- "server" => $record->server,
- "content" => $record->content,
- "photo" => $record->photo,
- "location" => $record->location,
- ]
- ]);
- }
- return Response()->json([
- "status" => -2,
- "message" => "不存在的记录!"
- ]);
- } else {
- return Response()->json([
- "status" => -1,
- "message" => "id不能为空!"
- ]);
- }
- }
-
-
- /**
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function store(Request $request)
- {
- $id = $request->input('id');
- $pid = $request->input('pid');
- $name = $request->input('name');
- $info = $request->input('info');
- $summary = $request->input('summary');
- $server = $request->input('server');
- $content = $request->input('content');
- $photo = $request->input('photo');
- $location = $request->input('location');
- $fields_json = $request->input('fields_json');
- $api = $request->input('api');
- if ($id) {
- $classify = Classify::find($id);
- } else {
- $classify = new Classify;
- if(!$api) {
- $classify->api = "option_order/store";
- }
- }
- if ($pid && $name && $info && $summary && $server && $content && $photo && $location) {
- $classify->pid = $pid;
- $classify->name = $name;
- $classify->info = $info;
- $classify->summary = $summary;
- $classify->server = $server;
- $classify->content = $content;
- $classify->photo = $photo;
- $classify->location = $location;
- $classify->fields_json = $fields_json;
- $classify->save();
- return Response()->json([
- "status" => 0,
- "message" => "保存成功!"
- ]);
- } else {
- return Response()->json([
- "status" => -1,
- "message" => "信息不能为空!"
- ]);
- }
- }
-
- public function parent(Request $request) {
- $classifies = Classify::where("pid", 0)->get();
- return Response()->json([
- "status" => 0,
- "data" => $classifies
- ]);
- }
-
- public function list2(Request $request) {
- return Classify::where("pid", ">", 0)->paginate(100);;
- }
- }
|