Staff.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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\BrandModel;
  9. use app\api\model\GroupModel;
  10. use app\api\model\StaffModel;
  11. use app\common\until\Until;
  12. class Staff extends BaseController {
  13. /**
  14. * @OA\Post(path="/api/Staff/index",
  15. * tags={"职员管理"},
  16. * summary="职员列表",
  17. * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
  18. * @OA\Parameter(name="page", in="query", description="页码", @OA\Schema(type="ineger",default="1")),
  19. * @OA\Parameter(name="pageSize", in="query", description="页尺寸", @OA\Schema(type="integer",default="10")),
  20. * @OA\Parameter(name="status", in="query", description="状态 1正常 2删除", @OA\Schema(type="integer",default="1")),
  21. * @OA\Parameter(name="name", in="query", description="职员名", @OA\Schema(type="string")),
  22. * @OA\Parameter(name="mobile", in="query", description="手机号", @OA\Schema(type="string")),
  23. * @OA\RequestBody(
  24. * ),
  25. * @OA\Response(response="200", description="请求成功")
  26. * )
  27. */
  28. public function index() {
  29. $input = request()->get();
  30. $model = new StaffModel();
  31. $model->setPage($input['page'] ?? 1);
  32. $model->setPageSize($input['pageSize'] ?? 10);
  33. if ($this->isAdmin()) {
  34. $where = [];
  35. } else {
  36. $where[] = ['s.status', '=', $model::NORMAL];
  37. }
  38. if (!empty($input['name'])) {
  39. $where[] = ['s.staff_name', 'like', "%{$input['name']}%"];
  40. }
  41. if (!empty($input['mobile'])) {
  42. $where[] = ['s.mobile', 'like', "%{$input['mobile']}%"];
  43. }
  44. $model->setWhere($where);
  45. $data = $model->getStaffList();
  46. Until::output($data);
  47. }
  48. /**
  49. * @OA\Post(path="/api/Staff/save",
  50. * tags={"职员管理"},
  51. * summary="保存职员信息",
  52. * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
  53. * @OA\RequestBody(
  54. * @OA\MediaType(
  55. * mediaType="multipart/form-data",
  56. * @OA\Schema(
  57. * @OA\Property(description="职员名称", property="name", type="string", default="tony"),
  58. * @OA\Property(description="职员工号", property="code", type="string", default="A9527"),
  59. * @OA\Property(description="职员手机号", property="mobile", type="string", default="12367897654"),
  60. * @OA\Property(description="入职日期", property="joinTime", type="string", default="2020-01-04"),
  61. * @OA\Property(description="职称id", property="staffTitleId", type="integer", default="1"),
  62. * @OA\Property(description="storeId", property="storeId", type="integer", default="1"),
  63. * required={"name","code","mobile","joinTime","staffTitleId","storeId"})
  64. * )
  65. * ),
  66. * @OA\Response(response="200", description="请求成功")
  67. * )
  68. */
  69. public function save() {
  70. $input = Until::getInput();
  71. $rule = [
  72. 'name|职员名称' => 'require',
  73. 'code|职员工号' => 'require',
  74. 'mobile|职员手机号' => 'require',
  75. 'joinTime|入职日期' => 'require',
  76. 'staffTitleId|职称id' => 'require',
  77. 'storeId|storeId' => 'require',
  78. ];
  79. Until::check($rule, $input);
  80. $model = new StaffModel();
  81. if (!empty($input['id'])) {
  82. $id = (int)$input['id'];
  83. $model::where(['id' => $id])->update([
  84. 'staff_name' => $input['name'],
  85. 'staff_code' => $input['code'],
  86. 'mobile' => $input['mobile'],
  87. 'join_time' => $input['joinTime'],
  88. 'staff_title_id' => $input['staffTitleId'],
  89. 'store_id' => $input['storeId'],
  90. 'status' => $input['status'] ?? $model::NORMAL
  91. ]);
  92. } else {
  93. $id = $model->insertGetId([
  94. 'staff_name' => $input['name'],
  95. 'staff_code' => $input['code'],
  96. 'mobile' => $input['mobile'],
  97. 'join_time' => $input['joinTime'],
  98. 'staff_title_id' => $input['staffTitleId'],
  99. 'store_id' => $input['storeId']
  100. ]);
  101. }
  102. $where[] = ['s.id', '=', (int)$id];
  103. $model->setWhere($where);
  104. $info = $model->getStaffInfo();
  105. Until::output(['info' => $info]);
  106. }
  107. /**
  108. * @OA\GET(path="/api/Staff/read",
  109. * tags={"职员管理"},
  110. * summary="查看职员信息",
  111. * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
  112. * @OA\Parameter(name="id", in="query", description="职员id", @OA\Schema(type="ineger",default="1")),
  113. * @OA\RequestBody(
  114. * ),
  115. * @OA\Response(response="200", description="请求成功")
  116. * )
  117. */
  118. public function read($id) {
  119. $model = new StaffModel();
  120. $where[] = ['s.id', '=', (int)$id];
  121. $model->setWhere($where);
  122. $info = $model->getStaffInfo();
  123. Until::output(['info' => $info]);
  124. }
  125. /**
  126. * @OA\GET(path="/api/Staff/delete",
  127. * tags={"职员管理"},
  128. * summary="删除职员信息",
  129. * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
  130. * @OA\Parameter(name="id", in="query", description="职员id", @OA\Schema(type="ineger",default="1")),
  131. * @OA\Parameter(name="status", in="query", description="1正常 2删除", @OA\Schema(type="ineger",default="1")),
  132. * @OA\RequestBody(
  133. * ),
  134. * @OA\Response(response="200", description="请求成功")
  135. * )
  136. */
  137. public function delete($id,$status) {
  138. $model = new StaffModel();
  139. $where[] = ['id', '=', (int)$id];
  140. $data = ['status' => (int)$status];
  141. $isSuccess = $model::where($where)->update($data);
  142. Until::output(['isSuccess' => $isSuccess]);
  143. }
  144. }