CommonController.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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\GoodsCustom;
  8. use App\Models\Goods\Spec;
  9. use App\Modules\Admin\Services\SettingService;
  10. class CommonController extends BaseController
  11. {
  12. public function groupMap()
  13. {
  14. $group = AdminGroup::all();
  15. return $this->ok([
  16. "list" => $group->map(function (AdminGroup $m) {
  17. return [
  18. "id" => $m->id,
  19. "name" => $m->name,
  20. ];
  21. }),
  22. ]);
  23. }
  24. public function permissionMap()
  25. {
  26. $all = AdminPermission::all();
  27. return $this->ok([
  28. "list" => $all->map(function (AdminPermission $m) {
  29. return [
  30. "id" => $m->id,
  31. "name" => $m->name,
  32. ];
  33. }),
  34. ]);
  35. }
  36. public function settingMap()
  37. {
  38. return $this->ok(
  39. app(SettingService::class)->settingMap(),
  40. );
  41. }
  42. public function settingSave()
  43. {
  44. $data = request()->validate([
  45. "hot_keywords.id" => "required",
  46. "hot_keywords.values" => "array",
  47. ]);
  48. return $this->ok(app(SettingService::class)->settingSave($data));
  49. }
  50. public function allSpec()
  51. {
  52. return $this->ok([
  53. "list" => Spec::get()->map(function (Spec $s) {
  54. return [
  55. "id" => $s->id,
  56. "name" => $s->name,
  57. "attr_name" => $s->attrs->pluck("name"),
  58. ];
  59. }),
  60. ]);
  61. }
  62. public function allCategory()
  63. {
  64. return $this->ok([
  65. "list" => Category::get()->map(function (Category $c) {
  66. return $c->format();
  67. }),
  68. ]);
  69. }
  70. public function allCustom()
  71. {
  72. return $this->ok([
  73. "list" => GoodsCustom::get()->map(function (GoodsCustom $c) {
  74. return [
  75. "id" => $c->id,
  76. "name" => $c->title,
  77. "en_name" => $c->en_title,
  78. ];
  79. }),
  80. ]);
  81. }
  82. }