Group.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Author: luzheng.liu
  4. * Time: 2020/12/16 23:06
  5. */
  6. namespace app\api\controller;
  7. use app\api\BaseController;
  8. use app\api\model\GroupModel;
  9. use app\common\until\Until;
  10. class Group extends BaseController {
  11. /**
  12. * @OA\Get(path="/api/Group/index",
  13. * tags={"集团管理"},
  14. * summary="集团列表",
  15. * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
  16. * @OA\Parameter(name="page", in="query", description="页码", @OA\Schema(type="ineger",default="1")),
  17. * @OA\Parameter(name="pageSize", in="query", description="页尺寸", @OA\Schema(type="integer",default="10")),
  18. * @OA\RequestBody(
  19. * ),
  20. * @OA\Response(response="200", description="请求成功")
  21. * )
  22. */
  23. public function index() {
  24. $input = request()->get();
  25. $model = new GroupModel();
  26. $model->setPage($input['page'] ?? 1);
  27. $model->setPageSize($input['pageSize'] ?? 10);
  28. $where = [];
  29. $where[] = ['gr.admin_id','=',$this->adminId];
  30. $model->setWhere($where);
  31. $data = $model->getGroupList();
  32. Until::output($data);
  33. }
  34. /**
  35. * @OA\Post(path="/api/Group/save",
  36. * tags={"集团管理"},
  37. * summary="保存集团信息",
  38. * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
  39. * @OA\RequestBody(
  40. * @OA\MediaType(
  41. * mediaType="multipart/form-data",
  42. * @OA\Schema(
  43. * @OA\Property(description="集团名称", property="name", type="string", default="四海集团"),
  44. * required={"name"})
  45. * )
  46. * ),
  47. * @OA\Response(response="200", description="请求成功")
  48. * )
  49. */
  50. public function save() {
  51. $input = Until::getInput();
  52. $rule = [
  53. 'name|集团名称' => 'require',
  54. ];
  55. Until::check($rule, $input);
  56. $model = new GroupModel();
  57. if (!empty($input['id']) ) {
  58. $id = (int)$input['id'];
  59. $model::where(['id' => $id])->update([
  60. 'group_name' => $input['name']
  61. ]);
  62. } else {
  63. $id = $model->insertGetId([
  64. 'group_name' => $input['name']
  65. ]);
  66. }
  67. $info = $model::get($id);
  68. Until::output(['info' => Until::modelToArray($info)]);
  69. }
  70. public function delete($id,$status) {
  71. $model = new GroupModel();
  72. $where[] = ['id', '=', (int)$id];
  73. $data = ['status' => (int)$status];
  74. $isSuccess = $model::where($where)->update($data);
  75. Until::output(['isSuccess' => $isSuccess]);
  76. }
  77. }