家政小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ClassifyController.php 11KB

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