123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <?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) {
- $top1 = $request->input("top1");
- $top2 = $request->input("top2");
- $top3 = $request->input("top3");
- $bottom = $request->input("bottom");
- $introduce = $request->input("introduce");
-
- if($top1 && $top2 && $top3 && $bottom && $introduce) {
- $homePage = HomePage::find(1);
- $homePage->top1 = $top1;
- $homePage->top2 = $top2;
- $homePage->top3 = $top3;
- $homePage->bottom = $bottom;
- $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")->limit(3)->get()->toArray();
- $bottom = Classify::where("location", "bottom")->first();
-
- $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" => "服务介绍",
- "bottom" => [
- "id" => $bottom["id"],
- "server" => $bottom["server"],
- "content" => $bottom["content"],
- "photo" => $bottom["photo"],
- "location" => $bottom["location"]
- ]
- ]);
- }
-
-
- /**
- * 获取某个记录
- * @param Request $request
- * @param $id
- * @return \Illuminate\Http\JsonResponse
- */
- public function get(Request $request, $id)
- {
- $id = $request->route("id");
- $fields_josn = "";
- if($id == 6) {
- $fields_josn ='{
- "id": 6,
- "api": "maternity_matron_order/store",
- "fields": [
- {
- "name": "level",
- "name_cn": "一价全包",
- "input_group": [
- {
- "type": "radio",
- "value": "8800(初级月嫂)"
- },
- {
- "type": "radio",
- "value": "9800(普通月嫂)"
- },
- {
- "type": "radio",
- "value": "12800(高级月嫂)"
- },
- {
- "type": "radio",
- "value": "15800(金牌月嫂)"
- },
- {
- "type": "radio",
- "value": "18800(特级月嫂)"
- }
- ]
- }
- ]
- }';
- } else {
- $fields_josn = '{
- "id": 7,
- "api": "housekeeper_order/store",
- "fields": [
- {
- "name": "contents",
- "name_cn": "服务内容",
- "input_group": [
- {
- "type": "radio",
- "value": "保洁"
- },
- {
- "type": "radio",
- "value": "婴儿看护"
- },
- {
- "type": "radio",
- "value": "老人看护"
- },
- {
- "type": "radio",
- "value": "全护理老人"
- },
- {
- "type": "radio",
- "value": "空调清洗"
- },
- {
- "type": "radio",
- "value": "冰箱清洗"
- },
- {
- "type": "radio",
- "value": "抽油烟机清洗"
- },
- {
- "type": "radio",
- "value": "家庭除螨"
- },
- {
- "type": "radio",
- "value": "开荒清洁"
- },
- {
- "type": "radio",
- "value": "催乳"
- },
- {
- "type": "radio",
- "value": "产后康复"
- }
- ]
- },
- {
- "name": "people_num",
- "name_cn": "人口数量",
- "input_group": [
- {
- "type": "radio",
- "value": "1-2人"
- },
- {
- "type": "radio",
- "value": "3-4人"
- },
- {
- "type": "radio",
- "value": "5-6人"
- },
- {
- "type": "radio",
- "value": "6人以上"
- }
- ]
- },
- {
- "name": "area",
- "name_cn": "房屋面积",
- "input_group": [
- {
- "type": "radio",
- "value": "60平以下"
- },
- {
- "type": "radio",
- "value": "60-120平"
- },
- {
- "type": "radio",
- "value": "120-160平"
- },
- {
- "type": "radio",
- "value": "160-200平"
- },
- {
- "type": "radio",
- "value": "200平以上"
- }
- ]
- },
- {
- "name": "server_time",
- "name_cn": "服务时间",
- "input_group": [
- {
- "type": "radio",
- "value": "全白天"
- },
- {
- "type": "radio",
- "value": "住家"
- }
- ]
- },
- {
- "name": "rest",
- "name_cn": "休息安排",
- "input_group": [
- {
- "type": "radio",
- "value": "每周单休"
- },
- {
- "type": "radio",
- "value": "每周双休"
- }
- ]
- }
- ]
- }';
- }
-
- $data = json_decode($fields_josn, true);
- $data["id"] = $id;
- if ($id) {
- $record = Classify::find($id);
- if ($record) {
-
- 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');
- if ($id) {
- $classify = Classify::find($id);
- } else {
- $classify = new Classify;
- }
- 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->save();
- return Response()->json([
- "status" => 0,
- "message" => "保存成功!"
- ]);
- } else {
- return Response()->json([
- "status" => -1,
- "message" => "信息不能为空!"
- ]);
- }
- }
- }
|