فهرست منبع

优化联系人A_Z排序

kuaifan 5 سال پیش
والد
کامیت
28e41a21c8

+ 5 - 6
app/Http/Controllers/Api/UsersController.php

@@ -257,6 +257,7 @@ class UsersController extends Controller
         //
         if ($array) {
             DB::table('users')->where('id', $user['id'])->update($array);
+            Users::AZUpdate($user['id']);
         } else {
             return Base::retError('请设置要修改的内容!');
         }
@@ -316,10 +317,9 @@ class UsersController extends Controller
      * 团队列表
      *
      * @apiParam {Object} [sorts]               排序方式,格式:{key:'', order:''}
-     * - key: username|id(默认)
+     * - key: username|az|id(默认)
      * - order: asc|desc
      * @apiParam {String} [username]            指定获取某个成员(返回对象)
-     * @apiParam {Number} [firstchart]          是否获取首字母,1:获取
      * @apiParam {Number} [page]                当前页,默认:1
      * @apiParam {Number} [pagesize]            每页显示数量,默认:10,最大:100
      */
@@ -345,13 +345,13 @@ class UsersController extends Controller
                 case 'username':
                     $orderBy = '`' . $sorts['key'] . '` ' . $sorts['order'] . ',`id` DESC';
                     break;
-                case 'lists':
-                    $orderBy = '`nickname` ' . $sorts['order'] . ',`username` ' . $sorts['order'] . ',`id` DESC';
+                case 'az':
+                    $orderBy = '`' . $sorts['key'] . '` ' . $sorts['order'] . ',`username` ' . $sorts['order'] . ',`id` DESC';
                     break;
             }
         }
         //
-        $lists = DB::table('users')->where($whereArray)->select(['id', 'identity', 'username', 'nickname', 'userimg', 'profession', 'regdate'])->orderByRaw($orderBy)->paginate(Base::getPaginate(100, 10));
+        $lists = DB::table('users')->where($whereArray)->select(['id', 'identity', 'username', 'nickname', 'az', 'userimg', 'profession', 'regdate'])->orderByRaw($orderBy)->paginate(Base::getPaginate(100, 10));
         $lists = Base::getPageList($lists);
         if ($lists['total'] == 0) {
             return Base::retError('未找到任何相关的团队成员');
@@ -359,7 +359,6 @@ class UsersController extends Controller
         foreach ($lists['lists'] AS $key => $item) {
             $lists['lists'][$key]['identity'] = is_array($item['identity']) ? $item['identity'] : explode(",", trim($item['identity'], ","));
             $lists['lists'][$key]['userimg'] = Users::userimg($item['userimg']);
-            $lists['lists'][$key]['firstchart'] = Base::getFirstCharter($item['nickname'] ?: $item['username']);
         }
         if ($username) {
             return Base::retSuccess('success', $lists['lists'][0]);

+ 14 - 0
app/Module/Users.php

@@ -57,6 +57,7 @@ class Users
         if (empty($user)) {
             return Base::retError('注册失败,请稍后再试。');
         }
+        Users::AZUpdate($user['id']);
         return Base::retSuccess('success', $user);
     }
 
@@ -320,4 +321,17 @@ class Users
         }
         return $var ? Base::fillUrl($var) : url('images/other/avatar.png');
     }
+
+    /**
+     * 更新首字母
+     * @param $userid
+     */
+    public static function AZUpdate($userid) {
+        $row = DB::table('users')->where('id', $userid)->select(['username', 'nickname'])->first();
+        if ($row) {
+            DB::table('users')->where('id', $userid)->update([
+                'az' => Base::getFirstCharter($row['nickname'] ?: $row['username'])
+            ]);
+        }
+    }
 }

+ 1 - 1
database/migrations/2020_06_05_165357_create_pre_users_table.php

@@ -19,7 +19,7 @@ class CreatePreUsersTable extends Migration
 			$table->string('identity')->nullable()->default('')->comment('身份');
 			$table->string('token', 100)->nullable()->default('')->index('IDEX_token');
 			$table->string('username', 100)->nullable()->default('')->unique('IDEX_username')->comment('用户名');
-			$table->string('nickname')->nullable()->comment('昵称');
+			$table->string('nickname')->nullable()->default('')->comment('昵称');
 			$table->string('userimg')->nullable()->default('')->comment('已审核头像');
 			$table->string('profession')->nullable()->default('')->comment('职称/职位');
 			$table->string('encrypt', 50)->nullable()->default('');

+ 39 - 0
database/migrations/2020_08_20_140853_alter_pre_users.php

@@ -0,0 +1,39 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AlterPreUsers extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('users', function (Blueprint $table) {
+            $table->string('az', 10)->after('token')->nullable()->default('')->index('IDEX_az')->comment('A-Z');
+        });
+        //
+        $lists = \App\Module\Base::DBC2A(DB::table('users')->select(['id','username','nickname'])->where('az', '')->get());
+        foreach ($lists AS $item) {
+            DB::table('users')->where('id', $item['id'])->update([
+                'az' => \App\Module\Base::getFirstCharter($item['nickname'] ?: $item['username'])
+            ]);
+        }
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('users', function (Blueprint $table) {
+            $table->dropColumn('az');
+        });
+    }
+}

+ 39 - 0
database/migrations/2020_08_20_141250_create_chat_files_table.php

@@ -0,0 +1,39 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateChatFilesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('chat_files', function (Blueprint $table) {
+            $table->increments('id');
+            $table->integer('did')->nullable()->default(0)->comment('对话ID');
+            $table->string('group', 100)->nullable()->default('')->comment('群组');
+            $table->string('name', 100)->nullable()->default('')->comment('文件名称');
+            $table->integer('size')->nullable()->default(0)->comment('文件大小(B)');
+            $table->string('ext', 20)->nullable()->default('')->comment('文件格式');
+            $table->string('path')->nullable()->default('')->comment('文件地址');
+            $table->string('thumb')->nullable()->default('')->comment('缩略图');
+            $table->string('username')->nullable()->default('')->comment('上传用户');
+            $table->bigInteger('indate')->nullable()->default(0);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('chat_files');
+    }
+}

+ 1 - 1
package.json

@@ -1,5 +1,5 @@
 {
-    "version": "1.4.26",
+    "version": "1.4.27",
     "name": "wookteam",
     "private": true,
     "scripts": {

+ 4 - 5
resources/assets/js/main/components/chat/Index.vue

@@ -1267,10 +1267,9 @@
                     url: 'users/team/lists',
                     data: {
                         sorts: {
-                            key: 'lists',
+                            key: 'az',
                             order: 'asc'
                         },
-                        firstchart: 1,
                         page: this.teamCurrentPage,
                         pagesize: 100,
                     },
@@ -1283,10 +1282,10 @@
                     success: (res) => {
                         if (res.ret === 1) {
                             res.data.lists.forEach((item) => {
-                                if (typeof this.teamLists[item.firstchart] === "undefined") {
-                                    this.$set(this.teamLists, item.firstchart, []);
+                                if (typeof this.teamLists[item.az] === "undefined") {
+                                    this.$set(this.teamLists, item.az, []);
                                 }
-                                this.teamLists[item.firstchart].push(item);
+                                this.teamLists[item.az].push(item);
                             });
                             this.teamNoDataText = this.$L("没有相关的数据");
                             this.teamHasMorePages = res.data.hasMorePages;