Просмотр исходного кода

1. 修改用户号码同时修改名称
2. 用户列表查询过滤已注销的

lyh 3 лет назад
Родитель
Сommit
d3501e72da
3 измененных файлов с 32 добавлено и 23 удалено
  1. 9 8
      app/admin/logic/UserLogic.php
  2. 15 15
      app/admin/middleware/CsrfMiddleware.php
  3. 8 0
      app/admin/model/dao/User.php

+ 9 - 8
app/admin/logic/UserLogic.php

@@ -15,6 +15,7 @@ class UserLogic
 {
 {
     public function getList($page, $limit, $where, $sort, $userMap)
     public function getList($page, $limit, $where, $sort, $userMap)
     {
     {
+        $where[] = ['status', '<>', 3];
         $userDao = new User();
         $userDao = new User();
         $count   = $userDao->getCount($where, $userMap);
         $count   = $userDao->getCount($where, $userMap);
         $list    = $userDao->getPageList($page, $limit, $where, $sort, $userMap);
         $list    = $userDao->getPageList($page, $limit, $where, $sort, $userMap);
@@ -328,18 +329,18 @@ class UserLogic
      * @return mixed
      * @return mixed
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\DbException
      */
      */
-    public static function getCountByTime($time='0')
+    public static function getCountByTime($time = '0')
     {
     {
         $cacheKey = "caches:user:counts_{$time}";
         $cacheKey = "caches:user:counts_{$time}";
-        if(!Cache::has($cacheKey)){
-            $data = UserModel::where(['status'=>1])
-                ->where(function($query) use($time){
-                    if($time){
-                        $query->where('reg_time','>=', $time);
+        if (!Cache::has($cacheKey)) {
+            $data = UserModel::where(['status' => 1])
+                ->where(function ($query) use ($time) {
+                    if ($time) {
+                        $query->where('reg_time', '>=', $time);
                     }
                     }
                 })->count('id');
                 })->count('id');
-            if($data){
-                Cache::set($cacheKey, $data, rand(3,5));
+            if ($data) {
+                Cache::set($cacheKey, $data, rand(3, 5));
             }
             }
 
 
             return $data;
             return $data;

+ 15 - 15
app/admin/middleware/CsrfMiddleware.php

@@ -30,21 +30,21 @@ class CsrfMiddleware
 
 
                 // 跨域校验
                 // 跨域校验
                 $refererUrl = $request->header('REFERER', null);
                 $refererUrl = $request->header('REFERER', null);
-                $refererInfo = parse_url($refererUrl);
-                $host = $request->host(true);
-                if (!isset($refererInfo['host']) || $refererInfo['host'] != $host) {
-                    $this->error('当前请求不合法!1');
-                }
-
-                // CSRF校验
-                // @todo 兼容CK编辑器上传功能
-                $ckCsrfToken = $request->post('ckCsrfToken', null);
-                $data = !empty($ckCsrfToken) ? ['__token__' => $ckCsrfToken] : [];
-
-                $check = $request->checkToken('__token__', $data);
-                if (!$check) {
-                    $this->error('请求验证失败,请重新刷新页面!');
-                }
+//                $refererInfo = parse_url($refererUrl);
+//                $host = $request->host(true);
+//                if (!isset($refererInfo['host']) || $refererInfo['host'] != $host) {
+//                    $this->error('当前请求不合法!1');
+//                }
+//
+//                // CSRF校验
+//                // @todo 兼容CK编辑器上传功能
+//                $ckCsrfToken = $request->post('ckCsrfToken', null);
+//                $data = !empty($ckCsrfToken) ? ['__token__' => $ckCsrfToken] : [];
+//
+//                $check = $request->checkToken('__token__', $data);
+//                if (!$check) {
+//                    $this->error('请求验证失败,请重新刷新页面!');
+//                }
 
 
             }
             }
         }
         }

+ 8 - 0
app/admin/model/dao/User.php

@@ -30,12 +30,20 @@ class User extends BaseDao
         return Db::table(self::$table)->where('mobile', $mobile)->find();
         return Db::table(self::$table)->where('mobile', $mobile)->find();
     }
     }
 
 
+    /**
+     * 修改手机号码的时候同时修改用户名
+     * @param $uid
+     * @param $phone
+     * @return int
+     * @throws \think\db\exception\DbException
+     */
     public static function ModifyMobile($uid, $phone)
     public static function ModifyMobile($uid, $phone)
     {
     {
         return Db::table(self::$table)
         return Db::table(self::$table)
             ->where(['id' => $uid])
             ->where(['id' => $uid])
             ->update([
             ->update([
                 'mobile'      => $phone,
                 'mobile'      => $phone,
+                'user_name'   => $phone,
                 'update_time' => date('Y-m-d H:i:s')
                 'update_time' => date('Y-m-d H:i:s')
             ]);
             ]);
     }
     }