Bladeren bron

账户修改密码接口,读取详情接口优化

wufeng 2 jaren geleden
bovenliggende
commit
e764b395a0
3 gewijzigde bestanden met toevoegingen van 48 en 2 verwijderingen
  1. 11 0
      app/admin/controller/Account.php
  2. 36 2
      app/admin/logic/AccountLogic.php
  3. 1 0
      app/admin/route/app.php

+ 11 - 0
app/admin/controller/Account.php

@@ -88,4 +88,15 @@ class Account extends BaseController
         return AccountLogic::batchLog($param);
     }
 
+    //修改密码
+    public function changePasswod(){
+        $param = $this->request->only(['id', 'new_password'], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.adminChangePasswod'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return AccountLogic::changePasswod($param);
+    }
+
 }

+ 36 - 2
app/admin/logic/AccountLogic.php

@@ -5,7 +5,9 @@ namespace app\admin\logic;
 use app\model\AccountBatchLogModel;
 use app\model\AccountModel;
 use app\model\CommonModel;
+use app\model\VideoModel;
 use think\Exception;
+use think\exception\ValidateException;
 use think\facade\Config;
 use think\facade\Db;
 use think\response\Json;
@@ -81,8 +83,13 @@ class AccountLogic extends BaseLogic
     {
         $res = AccountModel::field(true)
             ->where(['id' => $id, 'is_del' => CommonModel::$del_normal])
-            ->withAttr('video_ids', function ($val) {
-                return explode(',', $val);
+            ->append(['video_list'])
+            ->withAttr('video_list', function ($val, $data) {
+                return VideoModel::field('id,video_name')
+                    ->whereIn('id', $data['video_ids'])
+                    ->where('is_del', CommonModel::$del_normal)
+                    ->select()
+                    ->toArray();
             })
             ->findOrEmpty()
             ->toArray();
@@ -158,4 +165,31 @@ class AccountLogic extends BaseLogic
         return json_show(CommonModel::$success, '获取批量添加账户列表成功', ['count' => $count, 'list' => $list]);
     }
 
+    //修改密码
+    public static function changePasswod(array $data = []): Json
+    {
+        $rs = AccountModel::where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
+            ->field('id')
+            ->findOrEmpty()
+            ->isEmpty();
+
+        if ($rs) throw new ValidateException('该账户不存在');
+
+        $salt = randomkeys(6);
+        $password = getPassword($data['new_password'], $salt);
+
+        $da = [
+            'pwd' => $data['new_password'],
+            'salt' => $salt,
+            'password' => $password,
+            'updaterid' => self::$uid,
+            'updater' => self::$uname,
+            'updatetime' => date('Y-m-d H:i:s'),
+        ];
+
+        $rs = AccountModel::where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
+            ->save($da);
+
+        return $rs ? json_show(CommonModel::$success, '更改密码成功') : json_show(CommonModel::$error_param, '更改密码失败');
+    }
 }

+ 1 - 0
app/admin/route/app.php

@@ -132,6 +132,7 @@ Route::rule('accoountList', 'admin/Account/list');//列表
 Route::rule('accoountRead', 'admin/Account/read');//读取
 Route::rule('accoountEdit', 'admin/Account/edit');//修改
 Route::rule('accoountDelete', 'admin/Account/delete');//删除
+Route::rule('accoountChangePasswod', 'admin/Account/changePasswod');//更改密码