CommonController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Modules\Admin\Controllers\Admin;
  3. use App\Base\BaseController;
  4. use App\Models\Auth\AdminGroup;
  5. use App\Models\Auth\AdminPermission;
  6. use App\Models\Goods\Category;
  7. use App\Models\Goods\Spec;
  8. use App\Modules\Admin\Services\SettingService;
  9. class CommonController extends BaseController
  10. {
  11. public function groupMap()
  12. {
  13. $group = AdminGroup::all();
  14. return $this->ok([
  15. "list" => $group->map(function (AdminGroup $m) {
  16. return [
  17. "id" => $m->id,
  18. "name" => $m->name,
  19. ];
  20. }),
  21. ]);
  22. }
  23. public function permissionMap()
  24. {
  25. $all = AdminPermission::all();
  26. return $this->ok([
  27. "list" => $all->map(function (AdminPermission $m) {
  28. return [
  29. "id" => $m->id,
  30. "name" => $m->name,
  31. ];
  32. }),
  33. ]);
  34. }
  35. public function settingMap()
  36. {
  37. return $this->ok(
  38. app(SettingService::class)->settingMap(),
  39. );
  40. }
  41. public function settingSave()
  42. {
  43. $data = request()->validate([
  44. "hot_keywords.id" => "required",
  45. "hot_keywords.values" => "array",
  46. ]);
  47. return $this->ok(app(SettingService::class)->settingSave($data));
  48. }
  49. public function allSpec()
  50. {
  51. return $this->ok([
  52. "list" => Spec::get()->map(function (Spec $s) {
  53. return [
  54. "id" => $s->id,
  55. "name" => $s->name,
  56. "attr_name" => $s->attrs->pluck("name"),
  57. ];
  58. }),
  59. ]);
  60. }
  61. public function allCategory()
  62. {
  63. return $this->ok([
  64. "list" => Category::get()->map(function (Category $c) {
  65. return $c->format();
  66. }),
  67. ]);
  68. }
  69. }