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

ClassifyController.php 12KB

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