家政小程序
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 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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(5)->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->bottom_introduce,
  51. "bottom" => [
  52. "id" => $homePage->id,
  53. "server" => "",
  54. "content" => $homePage->content,
  55. "photo" => $homePage->photo,
  56. "location" => "bottom"
  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. $data = [];
  70. if ($id) {
  71. $record = Classify::find($id);
  72. if ($record) {
  73. $data["api"] = $record->api;
  74. $data["fields"] = json_decode($record->fields_json, true);
  75. return Response()->json([
  76. "status" => 0,
  77. "data" => [
  78. "id" => $record->id,
  79. "pid" => $record->pid,
  80. "name" => $record->name,
  81. "info" => $record->info,
  82. "content" => $record->summary,
  83. "photo" => $record->photo,
  84. "api" => $data["api"],
  85. "fields" => $data["fields"],
  86. "type" => $record->name,
  87. ]
  88. ]);
  89. }
  90. return Response()->json([
  91. "status" => -2,
  92. "message" => "不存在的记录!"
  93. ]);
  94. } else {
  95. return Response()->json([
  96. "status" => -1,
  97. "message" => "id不能为空!"
  98. ]);
  99. }
  100. }
  101. /**
  102. * @param Request $request
  103. * @param $id
  104. * @return \Illuminate\Http\JsonResponse
  105. */
  106. public function server_content(Request $request, $id) {
  107. $id = $request->route("id");
  108. if ($id) {
  109. $record = Classify::find($id);
  110. if ($record) {
  111. return Response()->json([
  112. "status" => 0,
  113. "data" => [
  114. "id" => $record->id,
  115. "server" => $record->server,
  116. "content" => $record->content,
  117. "photo" => $record->photo,
  118. "location" => $record->location,
  119. ]
  120. ]);
  121. }
  122. return Response()->json([
  123. "status" => -2,
  124. "message" => "不存在的记录!"
  125. ]);
  126. } else {
  127. return Response()->json([
  128. "status" => -1,
  129. "message" => "id不能为空!"
  130. ]);
  131. }
  132. }
  133. /**
  134. * @param Request $request
  135. * @return \Illuminate\Http\JsonResponse
  136. */
  137. public function store(Request $request)
  138. {
  139. $id = $request->input('id');
  140. $pid = $request->input('pid');
  141. $name = $request->input('name');
  142. $info = $request->input('info');
  143. $summary = $request->input('summary');
  144. $server = $request->input('server');
  145. $content = $request->input('content');
  146. $photo = $request->input('photo');
  147. $location = $request->input('location');
  148. $fields_json = $request->input('fields_json');
  149. $api = $request->input('api');
  150. if ($id) {
  151. $classify = Classify::find($id);
  152. } else {
  153. $classify = new Classify;
  154. if(!$api) {
  155. $classify->api = "option_order/store";
  156. }
  157. }
  158. if ($pid && $name && $info && $summary && $server && $content && $photo && $location) {
  159. $classify->pid = $pid;
  160. $classify->name = $name;
  161. $classify->info = $info;
  162. $classify->summary = $summary;
  163. $classify->server = $server;
  164. $classify->content = $content;
  165. $classify->photo = $photo;
  166. $classify->location = $location;
  167. $classify->fields_json = $fields_json;
  168. $classify->save();
  169. return Response()->json([
  170. "status" => 0,
  171. "message" => "保存成功!"
  172. ]);
  173. } else {
  174. return Response()->json([
  175. "status" => -1,
  176. "message" => "信息不能为空!"
  177. ]);
  178. }
  179. }
  180. public function parent(Request $request) {
  181. $classifies = Classify::where("pid", 0)->get();
  182. return Response()->json([
  183. "status" => 0,
  184. "data" => $classifies
  185. ]);
  186. }
  187. public function list2(Request $request) {
  188. return Classify::where("pid", ">", 0)->paginate(100);;
  189. }
  190. }