SettingPermissionController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Services\SettingPermissionService;
  4. use Slowlyo\OwlAdmin\Controllers\AdminController;
  5. /**
  6. * @group 后台
  7. *
  8. * 设置权限管理
  9. *
  10. * @property SettingPermissionService $service
  11. */
  12. class SettingPermissionController extends AdminController
  13. {
  14. protected string $serviceName = SettingPermissionService::class;
  15. public function list()
  16. {
  17. $crud = $this->baseCRUD()
  18. ->filterTogglable(false)
  19. ->headerToolbar([
  20. $this->createButton('dialog'),
  21. ...$this->baseHeaderToolBar()
  22. ])
  23. ->columns([
  24. amis()->TableColumn('id', 'ID')->sortable(),
  25. amis()->TableColumn('item_id', '设置项ID'),
  26. amis()->TableColumn('object_type', '业务对象类型:PLATFORM,AGENT,SHOP,COACH'),
  27. amis()->TableColumn('can_edit', '是否可编辑'),
  28. amis()->TableColumn('min_value', '最小值限制'),
  29. amis()->TableColumn('max_value', '最大值限制'),
  30. amis()->TableColumn('options', '可选值限制'),
  31. amis()->TableColumn('created_at', admin_trans('admin.created_at'))->type('datetime')->sortable(),
  32. amis()->TableColumn('updated_at', admin_trans('admin.updated_at'))->type('datetime')->sortable(),
  33. $this->rowActions('dialog')
  34. ]);
  35. return $this->baseList($crud);
  36. }
  37. public function form($isEdit = false)
  38. {
  39. return $this->baseForm()->body([
  40. amis()->TextControl('item_id', '设置项ID'),
  41. amis()->TextControl('object_type', '业务对象类型:PLATFORM,AGENT,SHOP,COACH'),
  42. amis()->TextControl('can_edit', '是否可编辑'),
  43. amis()->TextControl('min_value', '最小值限制'),
  44. amis()->TextControl('max_value', '最大值限制'),
  45. amis()->TextControl('options', '可选值限制'),
  46. ]);
  47. }
  48. public function detail()
  49. {
  50. return $this->baseDetail()->body([
  51. amis()->TextControl('id', 'ID')->static(),
  52. amis()->TextControl('item_id', '设置项ID')->static(),
  53. amis()->TextControl('object_type', '业务对象类型:PLATFORM,AGENT,SHOP,COACH')->static(),
  54. amis()->TextControl('can_edit', '是否可编辑')->static(),
  55. amis()->TextControl('min_value', '最小值限制')->static(),
  56. amis()->TextControl('max_value', '最大值限制')->static(),
  57. amis()->TextControl('options', '可选值限制')->static(),
  58. amis()->TextControl('created_at', admin_trans('admin.created_at'))->static(),
  59. amis()->TextControl('updated_at', admin_trans('admin.updated_at'))->static(),
  60. ]);
  61. }
  62. /**
  63. * [权限]获取设置权限列表
  64. *
  65. * @description 获取所有设置权限列表
  66. *
  67. * @param int item_id 设置项ID
  68. * @param string object_type 业务对象类型
  69. * @param int perPage 每页数量
  70. *
  71. * @response {
  72. * "data": [
  73. * {
  74. * "id": 1,
  75. * "item_id": 1,
  76. * "object_type": "PLATFORM",
  77. * "can_edit": 1,
  78. * "min_value": 0,
  79. * "max_value": 100,
  80. * "options": null,
  81. * "created_at": "2023-01-01 00:00:00",
  82. * "updated_at": "2023-01-01 00:00:00"
  83. * }
  84. * ]
  85. * }
  86. */
  87. public function getPermissionList()
  88. {
  89. return $this->response()->success(
  90. $this->service->list(request()->all())
  91. );
  92. }
  93. /**
  94. * [权限]创建设置权限
  95. *
  96. * @description 创建新的设置权限
  97. *
  98. * @param int item_id 设置项ID
  99. * @param string object_type 业务对象类型:PLATFORM,AGENT,SHOP,COACH
  100. * @param int can_edit 是否可编辑
  101. * @param float min_value 最小值限制
  102. * @param float max_value 最大值限制
  103. * @param json options 可选值限制
  104. *
  105. * @response {
  106. * "item_id": 1,
  107. * "object_type": "PLATFORM",
  108. * "can_edit": 1,
  109. * "min_value": 0,
  110. * "max_value": 100,
  111. * "options": null
  112. * }
  113. */
  114. public function createPermission()
  115. {
  116. return $this->response()->success(
  117. $this->service->store(request()->all())
  118. );
  119. }
  120. /**
  121. * [权限]更新设置权限
  122. *
  123. * @description 更新指定ID的设置权限
  124. *
  125. * @param int id 权限ID
  126. * @param int item_id 设置项ID
  127. * @param string object_type 业务对象类型:PLATFORM,AGENT,SHOP,COACH
  128. * @param int can_edit 是否可编辑
  129. * @param float min_value 最小值限制
  130. * @param float max_value 最大值限制
  131. * @param json options 可选值限制
  132. *
  133. * @response true
  134. */
  135. public function updatePermission($id)
  136. {
  137. return $this->response()->success(
  138. $this->service->update($id, request()->all())
  139. );
  140. }
  141. /**
  142. * [权限]删除设置权限
  143. *
  144. * @description 删除指定ID的设置权限
  145. *
  146. * @param int id 权限ID
  147. *
  148. * @response true
  149. */
  150. public function deletePermission($id)
  151. {
  152. return $this->response()->success(
  153. $this->service->destroy($id)
  154. );
  155. }
  156. /**
  157. * [权限]获取设置权限详情
  158. *
  159. * @description 获取指定ID的设置权限详情
  160. *
  161. * @param int id 权限ID
  162. *
  163. * @response {
  164. * "id": 1,
  165. * "item_id": 1,
  166. * "object_type": "PLATFORM",
  167. * "can_edit": 1,
  168. * "min_value": 0,
  169. * "max_value": 100,
  170. * "options": null,
  171. * "created_at": "2023-01-01 00:00:00",
  172. * "updated_at": "2023-01-01 00:00:00"
  173. * }
  174. */
  175. public function getPermissionDetail($id)
  176. {
  177. return $this->response()->success(
  178. $this->service->detail($id)
  179. );
  180. }
  181. }