Răsfoiți Sursa

增加用户设置密码的接口

lip 20 ore în urmă
părinte
comite
964f41b71a
2 a modificat fișierele cu 30 adăugiri și 0 ștergeri
  1. 29 0
      app/Http/Controllers/admin/User.php
  2. 1 0
      routes/admin.php

+ 29 - 0
app/Http/Controllers/admin/User.php

@@ -20,6 +20,35 @@ use App\Models\UserLogin;
 
 class User extends Controller
 {
+
+    //修改用户密码/资金密码
+    function setPassword()
+    {
+        try {
+            $params = request()->validate([
+                'member_id' => ['required', 'string', 'min:1'],
+                'password' => ['nullable'],
+                'payment_password' => ['nullable'],
+            ]);
+            $user = UserModel::where('member_id', $params['member_id'])->first();
+            if (!$user) throw new Exception("用户不存在", HttpStatus::CUSTOM_ERROR);
+
+            if (!empty($params['password'])) {
+                $user->password = password_hash($params['password'], PASSWORD_DEFAULT);
+                $user->save();
+            }
+            if (!empty($params['payment_password'])) {
+                $user->payment_password = password_hash($params['payment_password'], PASSWORD_DEFAULT);
+                $user->save();
+            }
+        } catch (ValidationException $e) {
+            return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
+        } catch (Exception $e) {
+            return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
+        }
+        return $this->success();
+    }
+
     function banned()
     {
         try {

+ 1 - 0
routes/admin.php

@@ -223,6 +223,7 @@ Route::middleware(['admin.jwt'])->group(function () {
             Route::post('/banned', [User::class, 'banned']);
             Route::get('/loginLog', [User::class, 'loginLog']);
             Route::post('/setRechargeChannelGroup', [User::class, 'setRechargeChannelGroup']);
+            Route::post('/setPassword', [User::class, 'setPassword']);
 
 
         });