ActionBarController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\Validator;
  6. class ActionBarController extends Controller
  7. {
  8. public function AddActionBar(Request $request)
  9. {
  10. $validator = Validator::make($request->all(), [
  11. "parent" => "required|integer|min:0",
  12. "name" => "required|between:1,64",
  13. "description" => "max:255",
  14. "icon" => "max:255",
  15. "link_type" => "between:1,32",
  16. "link" => "max:255",
  17. ]);
  18. if ($validator->fails()) {
  19. return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors());
  20. }
  21. $params = [];
  22. $params["parent"] = (int)$request->input("parent");
  23. $params["name"] = $request->input("name");
  24. $params["description"] = $request->input("description");
  25. $params["icon"] = $request->input("icon");
  26. $params["link_type"] = $request->input("link_type");
  27. $params["link"] = $request->input("link");
  28. $bar = new Models\ActionBar();
  29. $result = $bar->AddActionBar($params);
  30. if ($result["code"] == 0) {
  31. return $this->success($result["data"]);
  32. }
  33. return $this->fail($result["code"], $this->error[$result["code"]]);
  34. }
  35. public function ModifyActionBar(Request $request)
  36. {
  37. $validator = Validator::make($request->all(), [
  38. "id" => "required|integer|min:1",
  39. "parent" => "integer|min:0",
  40. "name" => "between:1,64",
  41. "description" => "max:255",
  42. "icon" => "max:255",
  43. "link_type" => "max:32",
  44. "link" => "max:255",
  45. ]);
  46. if ($validator->fails()) {
  47. return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors());
  48. }
  49. $params = [];
  50. $params["id"] = $request->input("id");
  51. $params["parent"] = $request->input("parent");
  52. $params["name"] = $request->input("name");
  53. $params["description"] = $request->input("description");
  54. $params["icon"] = $request->input("icon");
  55. $params["link_type"] = $request->input("link_type");
  56. $params["link"] = $request->input("link");
  57. $params["name"] = $request->input("name");
  58. $bar = new Models\ActionBar();
  59. $code = $bar->ModifyActionBar($params);
  60. return $this->response($code, $this->error[$code]);
  61. }
  62. public function DeleteActionBar(Request $request)
  63. {
  64. $validator = Validator::make($request->all(), [
  65. "id" => "required|integer|min:1",
  66. ]);
  67. if ($validator->fails()) {
  68. return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors());
  69. }
  70. $params = [];
  71. $bid = (int)$request->input("id");
  72. $params["id"] = $bid;
  73. $bar = new Models\ActionBar();
  74. $code = $bar->DeleteActionBar($params);
  75. return $this->response($code, $this->error[$code]);
  76. }
  77. /**
  78. * 管理员加载所有的菜单数据,根据层次返回数据给前端
  79. *
  80. * @param Request $request
  81. * @return \Illuminate\Http\JsonResponse
  82. */
  83. public function LoadActionBar(Request $request)
  84. {
  85. // $validator = Validator::make($request->all(), [
  86. // "uid" => "required|integer|min:1",
  87. // ]);
  88. // if ($validator->fails()) {
  89. // return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors());
  90. // }
  91. // $params = [];
  92. // $uid = $request->input("uid");
  93. // $params["uid"] = $uid;
  94. $bar = new Models\ActionBar();
  95. $result = $bar->LoadActionBarByIds_Format([], true);
  96. return $this->success($result);
  97. }
  98. }