123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- <?php
-
- namespace App\Http\Controllers;
-
- use Illuminate\Http\Request;
- use App\Models\Classify;
-
- class ClassifyController extends Controller
- {
-
- public function list(Request $request)
- {
- return Classify::paginate(100);
- }
-
- /**
- * 每页20进行分页
- * @param Request $request
- * @return mixed
- */
- public function home(Request $request)
- {
- $top = Classify::where("location", "top")->limit(3);
- $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": "/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": "/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,
- "summary" => $record->summary,
- "api" => $data["api"],
- "fields" => $data["fields"]
- ]
- ]);
- }
- 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不能为空!"
- ]);
- }
- }
- }
|