User.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\controller\merchant;
  3. use app\extra\basic\Base;
  4. use app\extra\tools\CodeExtend;
  5. use app\middleware\AuthMiddleware;
  6. use app\model\system\SystemUser;
  7. use app\service\system\UserService;
  8. use DI\Attribute\Inject;
  9. use LinFly\Annotation\Attributes\Route\Controller;
  10. use LinFly\Annotation\Attributes\Route\GetMapping;
  11. use LinFly\Annotation\Attributes\Route\Middleware;
  12. use LinFly\Annotation\Attributes\Route\PostMapping;
  13. use support\Request;
  14. use support\Response;
  15. #[Controller("/api/merchant/user"),Middleware(AuthMiddleware::class)]
  16. class User extends Base
  17. {
  18. #[Inject]
  19. protected UserService $service;
  20. #[Inject]
  21. protected SystemUser $model;
  22. #[GetMapping('list')]
  23. public function getDataList(Request $request): Response
  24. {
  25. try {
  26. $param = $request->all();
  27. $param['type'] = 3;
  28. $param['store_id'] = $request->user['store_id'];
  29. $data = $this->service->setModel()->getList($param,"account");
  30. return successTrans(100010,pageFormat($data),200);
  31. } catch (\Throwable $th) {
  32. return error($th->getMessage());
  33. }
  34. }
  35. /**
  36. * 账户列表
  37. * @param Request $request
  38. * @return Response
  39. */
  40. #[PostMapping("save")]
  41. public function setUserData(Request $request): Response
  42. {
  43. try {
  44. $param = $request->post();
  45. if(!isset($param['id'])) // 新增
  46. {
  47. $param['salt'] = CodeExtend::random(6,3);
  48. $param['password'] = md5($param['password'].$param['salt']);
  49. $param['create_ip'] = $request->getRealIp();
  50. $param['store_id'] = $request->user['store_id'];
  51. $user = $this->model->where("username",$param['username'])->findOrEmpty();
  52. if (!$user->isEmpty()) return errorTrans(20011);
  53. }
  54. if (isset($param['app_id'])) {
  55. $param['app_id'] = json_encode($param['app_id']);
  56. }
  57. if(isset($param['role_path']) && is_array($param['role_path'])){
  58. $parent = $param['role_path'];
  59. $param['role_path'] = implode(",",$parent);
  60. $param['role_id'] = $parent[count($parent) - 1];
  61. }
  62. $state = $this->model->setAutoData($param);
  63. if (!$state) return errorTrans(100011);
  64. return successTrans(100010);
  65. } catch (\Throwable $throwable) {
  66. return error($throwable->getMessage());
  67. }
  68. }
  69. }