优化代码

main
gzydong 2021-07-30 23:23:48 +08:00
parent 2104cf3684
commit b9d08f843a
4 changed files with 35 additions and 17 deletions

View File

@ -22,11 +22,14 @@ ALTER TABLE `lar_emoticon` ADD `updated_at` datetime DEFAULT NULL COMMENT '更
ALTER TABLE `lar_emoticon` DROP INDEX `name`; ALTER TABLE `lar_emoticon` DROP INDEX `name`;
ALTER TABLE `lar_emoticon` ADD UNIQUE uk_name (`name`); ALTER TABLE `lar_emoticon` ADD UNIQUE uk_name (`name`);
# lar_emoticon_details 数据表同步SQL # lar_emoticon_details 数据表同步SQL
ALTER TABLE `lar_emoticon_details` RENAME `lar_emoticon_item`; ALTER TABLE `lar_emoticon_details` RENAME `lar_emoticon_item`;
ALTER TABLE `lar_emoticon_item` MODIFY `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '表情包详情ID'; ALTER TABLE `lar_emoticon_item` MODIFY `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '表情包详情ID';
ALTER TABLE `lar_emoticon_item` MODIFY `describe` varchar(20) DEFAULT '' COMMENT '表情描述'; ALTER TABLE `lar_emoticon_item` MODIFY `describe` varchar(20) DEFAULT '' COMMENT '表情描述';
ALTER TABLE `lar_emoticon_item` MODIFY `url` varchar(255) DEFAULT '' COMMENT '图片链接'; ALTER TABLE `lar_emoticon_item` MODIFY `url` varchar(255) DEFAULT '' COMMENT '图片链接';
ALTER TABLE `lar_emoticon_item` DROP COLUMN `created_at`;
ALTER TABLE `lar_emoticon_item` ADD `created_at` datetime DEFAULT NULL COMMENT '创建时间';
ALTER TABLE `lar_emoticon_item` ADD `updated_at` datetime DEFAULT NULL COMMENT '更新时间'; ALTER TABLE `lar_emoticon_item` ADD `updated_at` datetime DEFAULT NULL COMMENT '更新时间';
ALTER TABLE `lar_emoticon_item` comment '表情包详情表'; ALTER TABLE `lar_emoticon_item` comment '表情包详情表';
@ -68,7 +71,9 @@ ALTER TABLE `lar_users_friends` DROP COLUMN `active`;
ALTER TABLE `lar_users_friends` DROP COLUMN `user2_remark`; ALTER TABLE `lar_users_friends` DROP COLUMN `user2_remark`;
# lar_users_friends_apply 数据表同步SQL # lar_users_friends_apply 数据表同步SQL
ALTER TABLE `lar_users_friends_apply` MODIFY `status` tinyint(4) unsigned DEFAULT '0' COMMENT '申请状态[0:等待处理;1:已同意;2:已拒绝;]'; ALTER TABLE `lar_users_friends_apply` CHANGE `remarks` `remark` varchar(50) DEFAULT '' COMMENT '申请备注';
ALTER TABLE `lar_users_friends_apply` DROP COLUMN `updated_at`;
ALTER TABLE `lar_users_friends_apply` DROP COLUMN `status`;
-- ---------------------------- -- ----------------------------
-- 以下是新增数据表 -- 以下是新增数据表

View File

@ -6,6 +6,7 @@ namespace App\Command;
use App\Cache\VoteStatisticsCache; use App\Cache\VoteStatisticsCache;
use App\Model\Talk\TalkRecordsVote; use App\Model\Talk\TalkRecordsVote;
use App\Model\UsersFriend;
use Hyperf\Command\Command as HyperfCommand; use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command; use Hyperf\Command\Annotation\Command;
use Hyperf\DbConnection\Db; use Hyperf\DbConnection\Db;
@ -39,18 +40,8 @@ class TestCommand extends HyperfCommand
public function handle() public function handle()
{ {
//VoteStatisticsCache::getInstance()->updateVoteCache(15);
$this->updateData();
$array = [
'name' => 'yuandong',
'sex' => 1,
'age' => 18
];
var_dump(Arr::only($array,['name','age','tt']));
//$api = config('juhe_api.ip'); //$api = config('juhe_api.ip');
//$options = []; //$options = [];
@ -72,4 +63,26 @@ class TestCommand extends HyperfCommand
// //
//var_dump($address); //var_dump($address);
} }
// 更新好友表数据
public function updateData()
{
$max = UsersFriend::max('id');
UsersFriend::where('id', '<=', $max)->chunk(1000, function ($rows) {
$arr = [];
foreach ($rows as $row) {
$arr[] = [
'user_id' => $row->friend_id,
'friend_id' => $row->user_id,
'status' => 1,
'remark' => '',
'updated_at' => date('Y-m-d H:i:s'),
'created_at' => date('Y-m-d H:i:s'),
];
}
UsersFriend::insert($arr);
});
}
} }

View File

@ -86,7 +86,7 @@ class TalkController extends CController
]); ]);
$user_id = $this->uid(); $user_id = $this->uid();
$string = join('-', [$user_id, $params['receiver_id'], $params['talk_type'], md5($request->getHeaderLine('user-agent'))]); $string = join('-', [$user_id, $params['receiver_id'], $params['talk_type'], md5($this->request->getHeaderLine('user-agent'))]);
$lock = 'talk:list:' . $string; $lock = 'talk:list:' . $string;
// 防止前端并发请求 // 防止前端并发请求

View File

@ -82,11 +82,11 @@ class GroupService extends BaseService
]; ];
} }
if (!Db::table('group_member')->insert($groupMember)) { if (!GroupMember::insert($groupMember)) {
throw new Exception('创建群成员信息失败'); throw new Exception('创建群成员信息失败');
} }
if (!Db::table('talk_list')->insert($chatList)) { if (!TalkList::insert($chatList)) {
throw new Exception('创建群成员的聊天列表失败'); throw new Exception('创建群成员的聊天列表失败');
} }
@ -249,7 +249,7 @@ class GroupService extends BaseService
} }
if ($insertArr) { if ($insertArr) {
Db::table('group_member')->insert($insertArr); GroupMember::insert($insertArr);
} }
if ($updateArr1) { if ($updateArr1) {
@ -260,7 +260,7 @@ class GroupService extends BaseService
} }
if ($insertArr1) { if ($insertArr1) {
Db::table('talk_list')->insert($insertArr1); TalkList::insert($insertArr1);
} }
$result = TalkRecords::create([ $result = TalkRecords::create([