Browse Source

聊天模糊逻辑添加全流程

master
wanghongjun 5 months ago
parent
commit
2bcf535ff6
  1. 15
      app/common/controller/Upload.php
  2. 6
      app/enterprise/controller/Files.php
  3. 11
      app/enterprise/controller/Im.php
  4. 12
      app/enterprise/model/Message.php
  5. 48
      app/enterprise/model/MessageView.php
  6. 20
      public/sql/database.sql

15
app/common/controller/Upload.php

@ -522,21 +522,6 @@ class Upload extends BaseController
);
}
}
// 根据需要应用额外模糊
if ($blurStrength > 1) {
$blurRegion = imagecrop($image, ['x' => $x, 'y' => $y, 'width' => $width, 'height' => $height]);
if ($blurRegion !== false) {
// 应用模糊
for ($i = 0; $i < $blurStrength; $i++) {
imagefilter($blurRegion, IMG_FILTER_GAUSSIAN_BLUR);
}
// 将模糊后的区域放回原图
imagecopymerge($image, $blurRegion, $x, $y, 0, 0, $width, $height, 100);
imagedestroy($blurRegion);
}
}
}
/**

6
app/enterprise/controller/Files.php

@ -4,7 +4,7 @@ namespace app\enterprise\controller;
use app\BaseController;
use app\enterprise\model\{File,User,Message};
use app\enterprise\model\{File, MessageView, User, Message};
use think\facade\View;
class Files extends BaseController
{
@ -105,7 +105,7 @@ class Files extends BaseController
'file_id' => $file_id,
'msg_id' => $msg_id
];
$res = Message::where($where)->field('file_id')->find();
$res = Message::where($where)->field('file_id,content')->find();
if (!$res) {
return error(lang('system.error'));
}
@ -115,6 +115,8 @@ class Files extends BaseController
return error(lang('system.error'));
}
MessageView::addView($msg_id, $this->uid, $file_id, $res['content']);
return success('', ['src' => $res['src']]);
}
}

11
app/enterprise/controller/Im.php

@ -5,7 +5,7 @@ namespace app\enterprise\controller;
use app\BaseController;
use think\facade\Request;
use think\facade\Db;
use app\enterprise\model\{User, Message, GroupUser, Friend,Group};
use app\enterprise\model\{File, MessageView, User, Message, GroupUser, Friend, Group};
use GatewayClient\Gateway;
use Exception;
use League\Flysystem\Util;
@ -324,6 +324,12 @@ class Im extends BaseController
// $v['content']="删除了一条消息";
}
}
// 查询当前用户是否查看过原图
$is_view = MessageView::isView($v['msg_id'], $userInfo['user_id']);
if ($is_view && $v['file_id']) {
$src = File::where(['file_id'=>$v['file_id'],'delete_time' => 0])->value('src');
if ($src) $v['content'] = $src;
}
$content = str_encipher($v['content'],false);
$preview = '';
$ext='';
@ -373,7 +379,8 @@ class Im extends BaseController
'fileSize' => $v['file_size'],
'fromUser' => $fromUser,
'extUrl'=>$ext,
'extends'=>is_string($v['extends'])?json_decode($v['extends'],true) : $v['extends']
'extends'=>is_string($v['extends'])?json_decode($v['extends'],true) : $v['extends'],
'is_view' => $is_view
];
}
}

12
app/enterprise/model/Message.php

@ -288,6 +288,18 @@ class Message extends BaseModel
$sendData['contactInfo']=$user->setContact($sendData['toContactId'],$is_group,$sendData['type'],$sendData['content']);
// 向发送方发送消息
wsSendMsg($toContactId,$type,$sendData,$is_group);
// 判断图片查看
if ($param['file_id']) {
$res = MessageView::addView($message->msg_id,$param['user_id'],$param['file_id'], $data['content']);
if($res){
$src = File::where('file_id', $param['file_id'])->value('src');
if ($src) {
$sendData['content'] = getFileUrl($src);
$sendData['extUrl']= getExtUrl($src);
$sendData['preview']=previewUrl($src,$pre);
}
}
}
$sendData['toContactId']=$param['toContactId'];
return $sendData;
}

48
app/enterprise/model/MessageView.php

@ -0,0 +1,48 @@
<?php
namespace app\enterprise\model;
use think\Model;
class MessageView extends Model
{
public static function addView($msg_id, $user_id, $file_id, $src)
{
$where = [
'user_id' => $user_id,
'compress_img' => $src,
'file_id' => $file_id
];
$fileRes = File::where($where)->find();
if (!$fileRes) {
return false;
}
$data = [
'msg_id' => $msg_id,
'user_id' => $user_id,
];
$query = self::where($data)->field('id')->find();
if ($query) {
return false;
}
$data['type'] = 1;
$data['status'] = 1;
$data['create_time'] = time();
$data['view_time'] = time();
(new self())->save($data);
return true;
}
public static function isView($msg_id, $user_id)
{
$where = [
'msg_id' => $msg_id,
'user_id' => $user_id,
'type' => 1,
'status' => 1
];
$query = self::where($where)->field('id')->find();
return $query ? 1 : 0;
}
}

20
public/sql/database.sql

@ -52,7 +52,8 @@ CREATE TABLE `yu_file` (
`update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
`delete_time` int(11) NOT NULL DEFAULT '0' COMMENT '删除时间',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态',
`is_lock` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否锁定'
`is_lock` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否锁定',
`compress_img` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '压缩图片链接'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='文件库';
-- --------------------------------------------------------
@ -432,3 +433,20 @@ CREATE TABLE `yu_posts_notice` (
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='朋友圈消息通知'
--
-- 表的结构 `yu_message_view`
--
CREATE TABLE `yu_message_view` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`msg_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '消息id',
`user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '用户id',
`type` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '查看类型 1图片',
`status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '0未读 1已读',
`create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`view_time` int(11) NOT NULL DEFAULT '0' COMMENT '查看时间',
PRIMARY KEY (`id`),
KEY `msg_user` (`msg_id`,`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COMMENT='消息查看表';

Loading…
Cancel
Save