| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace app\controller\merchant;
- use app\extra\basic\Base;
- use app\extra\tools\CodeExtend;
- use app\middleware\AuthMiddleware;
- use app\model\system\SystemUser;
- use app\service\system\UserService;
- use DI\Attribute\Inject;
- use LinFly\Annotation\Attributes\Route\Controller;
- use LinFly\Annotation\Attributes\Route\GetMapping;
- use LinFly\Annotation\Attributes\Route\Middleware;
- use LinFly\Annotation\Attributes\Route\PostMapping;
- use support\Request;
- use support\Response;
- #[Controller("/api/merchant/user"),Middleware(AuthMiddleware::class)]
- class User extends Base
- {
- #[Inject]
- protected UserService $service;
- #[Inject]
- protected SystemUser $model;
- #[GetMapping('list')]
- public function getDataList(Request $request): Response
- {
- try {
- $param = $request->all();
- $param['type'] = 3;
- $param['store_id'] = $request->user['store_id'];
- $data = $this->service->setModel()->getList($param,"account");
- return successTrans(100010,pageFormat($data),200);
- } catch (\Throwable $th) {
- return error($th->getMessage());
- }
- }
- /**
- * 账户列表
- * @param Request $request
- * @return Response
- */
- #[PostMapping("save")]
- public function setUserData(Request $request): Response
- {
- try {
- $param = $request->post();
- if(!isset($param['id'])) // 新增
- {
- $param['salt'] = CodeExtend::random(6,3);
- $param['password'] = md5($param['password'].$param['salt']);
- $param['create_ip'] = $request->getRealIp();
- $param['store_id'] = $request->user['store_id'];
- $user = $this->model->where("username",$param['username'])->findOrEmpty();
- if (!$user->isEmpty()) return errorTrans(20011);
- }
- if (isset($param['app_id'])) {
- $param['app_id'] = json_encode($param['app_id']);
- }
- if(isset($param['role_path']) && is_array($param['role_path'])){
- $parent = $param['role_path'];
- $param['role_path'] = implode(",",$parent);
- $param['role_id'] = $parent[count($parent) - 1];
- }
- $state = $this->model->setAutoData($param);
- if (!$state) return errorTrans(100011);
- return successTrans(100010);
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- }
|