家政小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClassifyController.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\HomePage;
  4. use Illuminate\Http\Request;
  5. use App\Models\Classify;
  6. class ClassifyController extends Controller
  7. {
  8. public function list(Request $request)
  9. {
  10. return Classify::paginate(100);
  11. }
  12. public function setHome(Request $request) {
  13. $top1 = $request->input("top1");
  14. $top2 = $request->input("top2");
  15. $top3 = $request->input("top3");
  16. $bottom = $request->input("bottom");
  17. $introduce = $request->input("introduce");
  18. if($top1 && $top2 && $top3 && $bottom && $introduce) {
  19. $homePage = HomePage::find(1);
  20. $homePage->top1 = $top1;
  21. $homePage->top2 = $top2;
  22. $homePage->top3 = $top3;
  23. $homePage->bottom = $bottom;
  24. $homePage->introduce = $introduce;
  25. $homePage->save();
  26. return response()->json([
  27. "status" => 0,
  28. "message" => '修改成功'
  29. ]);
  30. } else {
  31. return Response()->json([
  32. "status" => -1,
  33. "message" => "信息不能为空!"
  34. ]);
  35. }
  36. }
  37. /**
  38. * 每页20进行分页
  39. * @param Request $request
  40. * @return mixed
  41. */
  42. public function home(Request $request)
  43. {
  44. $top = Classify::where("location", "top")->limit(3)->get()->toArray();
  45. $bottom = Classify::where("location", "bottom")->first();
  46. $tops = array_map(function ($t) {
  47. return [
  48. "id" => $t["id"],
  49. "server" => $t["server"],
  50. "content" => $t["content"],
  51. "photo" => $t["photo"],
  52. "location" => $t["location"]
  53. ];
  54. }, $top);
  55. return Response()->json([
  56. "top" => $tops,
  57. "introduce" => "服务介绍",
  58. "bottom" => [
  59. "id" => $bottom["id"],
  60. "server" => $bottom["server"],
  61. "content" => $bottom["content"],
  62. "photo" => $bottom["photo"],
  63. "location" => $bottom["location"]
  64. ]
  65. ]);
  66. }
  67. /**
  68. * 获取某个记录
  69. * @param Request $request
  70. * @param $id
  71. * @return \Illuminate\Http\JsonResponse
  72. */
  73. public function get(Request $request, $id)
  74. {
  75. $id = $request->route("id");
  76. $fields_josn = "";
  77. if($id == 6) {
  78. $fields_josn ='{
  79. "id": 6,
  80. "api": "maternity_matron_order/store",
  81. "fields": [
  82. {
  83. "name": "level",
  84. "name_cn": "一价全包",
  85. "input_group": [
  86. {
  87. "type": "radio",
  88. "value": "8800(初级月嫂)"
  89. },
  90. {
  91. "type": "radio",
  92. "value": "9800(普通月嫂)"
  93. },
  94. {
  95. "type": "radio",
  96. "value": "12800(高级月嫂)"
  97. },
  98. {
  99. "type": "radio",
  100. "value": "15800(金牌月嫂)"
  101. },
  102. {
  103. "type": "radio",
  104. "value": "18800(特级月嫂)"
  105. }
  106. ]
  107. }
  108. ]
  109. }';
  110. } else {
  111. $fields_josn = '{
  112. "id": 7,
  113. "api": "housekeeper_order/store",
  114. "fields": [
  115. {
  116. "name": "contents",
  117. "name_cn": "服务内容",
  118. "input_group": [
  119. {
  120. "type": "radio",
  121. "value": "保洁"
  122. },
  123. {
  124. "type": "radio",
  125. "value": "婴儿看护"
  126. },
  127. {
  128. "type": "radio",
  129. "value": "老人看护"
  130. },
  131. {
  132. "type": "radio",
  133. "value": "全护理老人"
  134. },
  135. {
  136. "type": "radio",
  137. "value": "空调清洗"
  138. },
  139. {
  140. "type": "radio",
  141. "value": "冰箱清洗"
  142. },
  143. {
  144. "type": "radio",
  145. "value": "抽油烟机清洗"
  146. },
  147. {
  148. "type": "radio",
  149. "value": "家庭除螨"
  150. },
  151. {
  152. "type": "radio",
  153. "value": "开荒清洁"
  154. },
  155. {
  156. "type": "radio",
  157. "value": "催乳"
  158. },
  159. {
  160. "type": "radio",
  161. "value": "产后康复"
  162. }
  163. ]
  164. },
  165. {
  166. "name": "people_num",
  167. "name_cn": "人口数量",
  168. "input_group": [
  169. {
  170. "type": "radio",
  171. "value": "1-2人"
  172. },
  173. {
  174. "type": "radio",
  175. "value": "3-4人"
  176. },
  177. {
  178. "type": "radio",
  179. "value": "5-6人"
  180. },
  181. {
  182. "type": "radio",
  183. "value": "6人以上"
  184. }
  185. ]
  186. },
  187. {
  188. "name": "area",
  189. "name_cn": "房屋面积",
  190. "input_group": [
  191. {
  192. "type": "radio",
  193. "value": "60平以下"
  194. },
  195. {
  196. "type": "radio",
  197. "value": "60-120平"
  198. },
  199. {
  200. "type": "radio",
  201. "value": "120-160平"
  202. },
  203. {
  204. "type": "radio",
  205. "value": "160-200平"
  206. },
  207. {
  208. "type": "radio",
  209. "value": "200平以上"
  210. }
  211. ]
  212. },
  213. {
  214. "name": "server_time",
  215. "name_cn": "服务时间",
  216. "input_group": [
  217. {
  218. "type": "radio",
  219. "value": "全白天"
  220. },
  221. {
  222. "type": "radio",
  223. "value": "住家"
  224. }
  225. ]
  226. },
  227. {
  228. "name": "rest",
  229. "name_cn": "休息安排",
  230. "input_group": [
  231. {
  232. "type": "radio",
  233. "value": "每周单休"
  234. },
  235. {
  236. "type": "radio",
  237. "value": "每周双休"
  238. }
  239. ]
  240. }
  241. ]
  242. }';
  243. }
  244. $data = json_decode($fields_josn, true);
  245. $data["id"] = $id;
  246. if ($id) {
  247. $record = Classify::find($id);
  248. if ($record) {
  249. return Response()->json([
  250. "status" => 0,
  251. "data" => [
  252. "id" => $record->id,
  253. "pid" => $record->pid,
  254. "name" => $record->name,
  255. "info" => $record->info,
  256. "content" => $record->summary,
  257. "photo" => $record->photo,
  258. "api" => $data["api"],
  259. "fields" => $data["fields"],
  260. "type" => $record->name,
  261. ]
  262. ]);
  263. }
  264. return Response()->json([
  265. "status" => -2,
  266. "message" => "不存在的记录!"
  267. ]);
  268. } else {
  269. return Response()->json([
  270. "status" => -1,
  271. "message" => "id不能为空!"
  272. ]);
  273. }
  274. }
  275. /**
  276. * @param Request $request
  277. * @param $id
  278. * @return \Illuminate\Http\JsonResponse
  279. */
  280. public function server_content(Request $request, $id) {
  281. $id = $request->route("id");
  282. if ($id) {
  283. $record = Classify::find($id);
  284. if ($record) {
  285. return Response()->json([
  286. "status" => 0,
  287. "data" => [
  288. "id" => $record->id,
  289. "server" => $record->server,
  290. "content" => $record->content,
  291. "photo" => $record->photo,
  292. "location" => $record->location,
  293. ]
  294. ]);
  295. }
  296. return Response()->json([
  297. "status" => -2,
  298. "message" => "不存在的记录!"
  299. ]);
  300. } else {
  301. return Response()->json([
  302. "status" => -1,
  303. "message" => "id不能为空!"
  304. ]);
  305. }
  306. }
  307. /**
  308. * @param Request $request
  309. * @return \Illuminate\Http\JsonResponse
  310. */
  311. public function store(Request $request)
  312. {
  313. $id = $request->input('id');
  314. $pid = $request->input('pid');
  315. $name = $request->input('name');
  316. $info = $request->input('info');
  317. $summary = $request->input('summary');
  318. $server = $request->input('server');
  319. $content = $request->input('content');
  320. $photo = $request->input('photo');
  321. $location = $request->input('location');
  322. if ($id) {
  323. $classify = Classify::find($id);
  324. } else {
  325. $classify = new Classify;
  326. }
  327. if ($pid && $name && $info && $summary && $server && $content && $photo && $location) {
  328. $classify->pid = $pid;
  329. $classify->name = $name;
  330. $classify->info = $info;
  331. $classify->summary = $summary;
  332. $classify->server = $server;
  333. $classify->content = $content;
  334. $classify->photo = $photo;
  335. $classify->location = $location;
  336. $classify->save();
  337. return Response()->json([
  338. "status" => 0,
  339. "message" => "保存成功!"
  340. ]);
  341. } else {
  342. return Response()->json([
  343. "status" => -1,
  344. "message" => "信息不能为空!"
  345. ]);
  346. }
  347. }
  348. }