mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 19:35:50 +00:00
perf:代码整理
This commit is contained in:
parent
847d7f98fc
commit
40d5c1f11e
@ -824,66 +824,13 @@ class DialogController extends AbstractController
|
||||
public function msg__sendfile()
|
||||
{
|
||||
$user = User::auth();
|
||||
//
|
||||
$dialog_id = intval(Request::input('dialog_id'));
|
||||
$reply_id = intval(Request::input('reply_id'));
|
||||
$image_attachment = intval(Request::input('image_attachment'));
|
||||
//
|
||||
$dialog = WebSocketDialog::checkDialog($dialog_id);
|
||||
//
|
||||
$action = $reply_id > 0 ? "reply-$reply_id" : "";
|
||||
$path = "uploads/chat/" . date("Ym") . "/" . $dialog_id . "/";
|
||||
$dialogIds = [intval(Request::input('dialog_id'))];
|
||||
$replyId = intval(Request::input('reply_id'));
|
||||
$imageAttachment = intval(Request::input('image_attachment'));
|
||||
$files = Request::file('files');
|
||||
$image64 = Request::input('image64');
|
||||
$fileName = Request::input('filename');
|
||||
if ($image64) {
|
||||
$data = Base::image64save([
|
||||
"image64" => $image64,
|
||||
"path" => $path,
|
||||
"fileName" => $fileName,
|
||||
]);
|
||||
} else {
|
||||
$data = Base::upload([
|
||||
"file" => Request::file('files'),
|
||||
"type" => 'more',
|
||||
"path" => $path,
|
||||
"fileName" => $fileName,
|
||||
]);
|
||||
}
|
||||
//
|
||||
if (Base::isError($data)) {
|
||||
return Base::retError($data['msg']);
|
||||
} else {
|
||||
$fileData = $data['data'];
|
||||
$fileData['thumb'] = Base::unFillUrl($fileData['thumb']);
|
||||
$fileData['size'] *= 1024;
|
||||
//
|
||||
if ($dialog->type === 'group' && $dialog->group_type === 'task') { // 任务群组保存文件
|
||||
if ($image_attachment || !in_array($fileData['ext'], File::imageExt)) { // 如果是图片不保存
|
||||
$task = ProjectTask::whereDialogId($dialog->id)->first();
|
||||
if ($task) {
|
||||
$file = ProjectTaskFile::createInstance([
|
||||
'project_id' => $task->project_id,
|
||||
'task_id' => $task->id,
|
||||
'name' => $fileData['name'],
|
||||
'size' => $fileData['size'],
|
||||
'ext' => $fileData['ext'],
|
||||
'path' => $fileData['path'],
|
||||
'thumb' => $fileData['thumb'],
|
||||
'userid' => $user->userid,
|
||||
]);
|
||||
$file->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
$result = WebSocketDialogMsg::sendMsg($action, $dialog_id, 'file', $fileData, $user->userid);
|
||||
if (Base::isSuccess($result)) {
|
||||
if (isset($task)) {
|
||||
$result['data']['task_id'] = $task->id;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
return WebSocketDialog::sendMsgFiles($user,$dialogIds,$files,$image64,$fileName,$replyId,$imageAttachment);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1812,7 +1759,7 @@ class DialogController extends AbstractController
|
||||
|
||||
|
||||
/**
|
||||
* @api {post} api/dialog/msg/sendfiles 16. 文件上传
|
||||
* @api {post} api/dialog/msg/sendfiles 38. 群发文件上传
|
||||
*
|
||||
* @apiDescription 需要token身份
|
||||
* @apiVersion 1.0.0
|
||||
@ -1834,8 +1781,12 @@ class DialogController extends AbstractController
|
||||
public function msg__sendfiles()
|
||||
{
|
||||
$user = User::auth();
|
||||
$files = Request::file('files');
|
||||
$image64 = Request::input('image64');
|
||||
$fileName = Request::input('filename');
|
||||
$replyId = intval(Request::input('reply_id'));
|
||||
$imageAttachment = intval(Request::input('image_attachment'));
|
||||
//
|
||||
$results = [];
|
||||
$dialogIds = trim(Request::input('dialog_ids'));
|
||||
if($dialogIds){
|
||||
$dialogIds = explode(',',$dialogIds);
|
||||
@ -1859,74 +1810,6 @@ class DialogController extends AbstractController
|
||||
return Base::retError('找不到会话');
|
||||
}
|
||||
//
|
||||
$files = Request::file('files');
|
||||
$image64 = Request::input('image64');
|
||||
$fileName = Request::input('filename');
|
||||
$filePath = '';
|
||||
foreach($dialogIds as $dialog_id){
|
||||
$reply_id = intval(Request::input('reply_id'));
|
||||
$image_attachment = intval(Request::input('image_attachment'));
|
||||
//
|
||||
$dialog = WebSocketDialog::checkDialog($dialog_id);
|
||||
//
|
||||
$action = $reply_id > 0 ? "reply-$reply_id" : "";
|
||||
$path = "uploads/chat/" . date("Ym") . "/" . $dialog_id . "/";
|
||||
if ($image64) {
|
||||
$data = Base::image64save([
|
||||
"image64" => $image64,
|
||||
"path" => $path,
|
||||
"fileName" => $fileName,
|
||||
]);
|
||||
}else if($filePath){
|
||||
Base::makeDir(public_path($path));
|
||||
copy($filePath, public_path($path).basename($filePath));
|
||||
} else {
|
||||
$data = Base::upload([
|
||||
"file" => $files,
|
||||
"type" => 'more',
|
||||
"path" => $path,
|
||||
"fileName" => $fileName,
|
||||
]);
|
||||
}
|
||||
//
|
||||
if (Base::isError($data)) {
|
||||
return Base::retError($data['msg']);
|
||||
} else {
|
||||
$fileData = $data['data'];
|
||||
$filePath = $fileData['file'];
|
||||
$fileName = $fileData['name'];
|
||||
$fileData['thumb'] = Base::unFillUrl($fileData['thumb']);
|
||||
$fileData['size'] *= 1024;
|
||||
//
|
||||
if ($dialog->type === 'group' && $dialog->group_type === 'task') { // 任务群组保存文件
|
||||
if ($image_attachment || !in_array($fileData['ext'], File::imageExt)) { // 如果是图片不保存
|
||||
$task = ProjectTask::whereDialogId($dialog->id)->first();
|
||||
if ($task) {
|
||||
$file = ProjectTaskFile::createInstance([
|
||||
'project_id' => $task->project_id,
|
||||
'task_id' => $task->id,
|
||||
'name' => $fileData['name'],
|
||||
'size' => $fileData['size'],
|
||||
'ext' => $fileData['ext'],
|
||||
'path' => $fileData['path'],
|
||||
'thumb' => $fileData['thumb'],
|
||||
'userid' => $user->userid,
|
||||
]);
|
||||
$file->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
$result = WebSocketDialogMsg::sendMsg($action, $dialog_id, 'file', $fileData, $user->userid);
|
||||
if (Base::isSuccess($result)) {
|
||||
if (isset($task)) {
|
||||
$result['data']['task_id'] = $task->id;
|
||||
}
|
||||
}
|
||||
$results = $result;
|
||||
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
return WebSocketDialog::sendMsgFiles($user,$dialogIds,$files,$image64,$fileName,$replyId,$imageAttachment);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,6 @@ use Response;
|
||||
use Madzipper;
|
||||
use Carbon\Carbon;
|
||||
use App\Module\Doo;
|
||||
use App\Models\File;
|
||||
use App\Models\User;
|
||||
use App\Module\Base;
|
||||
use App\Models\Setting;
|
||||
@ -16,10 +15,8 @@ use App\Module\Extranet;
|
||||
use LdapRecord\Container;
|
||||
use App\Module\BillExport;
|
||||
use Guanguans\Notify\Factory;
|
||||
use App\Models\WebSocketDialog;
|
||||
use App\Models\UserCheckinRecord;
|
||||
use App\Module\BillMultipleExport;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use LdapRecord\LdapRecordException;
|
||||
use Guanguans\Notify\Messages\EmailMessage;
|
||||
|
||||
@ -1204,72 +1201,4 @@ class SystemController extends AbstractController
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/system/getChatAndDirList 25. 获取聊天与用户列表
|
||||
*
|
||||
* @apiVersion 1.0.0
|
||||
* @apiGroup system
|
||||
* @apiName getChatAndDirList
|
||||
*
|
||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||
* @apiSuccess {Object} data 返回数据
|
||||
*/
|
||||
public function getChatAndDirList()
|
||||
{
|
||||
$user = User::auth();
|
||||
$userids = $user->isTemp() ? [$user->userid] : [0, $user->userid];
|
||||
//目录列表
|
||||
$dir = Base::list2Tree(
|
||||
File::select('files.id','files.pid','files.name')
|
||||
->leftJoin('file_users', 'files.id', '=', 'file_users.file_id')
|
||||
->where('files.type','folder')
|
||||
->where(function ($q) use ($userids) {
|
||||
$q->whereIn('files.userid',$userids);
|
||||
$q->orWhere(function ($qq) use ($userids) {
|
||||
$qq->where('file_users.permission',1);
|
||||
$qq->whereIn('file_users.userid',$userids);
|
||||
});
|
||||
})
|
||||
->get()
|
||||
->toArray()
|
||||
);
|
||||
//聊天列表
|
||||
$chatList = WebSocketDialog::select(['web_socket_dialogs.*', 'u.top_at', 'u.silence', 'u.updated_at as user_at'])
|
||||
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
|
||||
->where('u.userid', $user->userid)
|
||||
->orderByDesc('u.top_at')
|
||||
->orderByDesc('web_socket_dialogs.last_at')
|
||||
->get()
|
||||
->transform(function (WebSocketDialog $item) use ($user) {
|
||||
$item = $item->formatData($user->userid);
|
||||
$item->last_msg = [];
|
||||
if(!$item->avatar){
|
||||
$item->avatar = 'avatar/'.$item->name.'.png';
|
||||
}
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
// 用户列表
|
||||
$notUserIds = [$user->userid];
|
||||
foreach($chatList as $chat){
|
||||
if($chat['type'] == 'user'){
|
||||
$notUserIds[] = $chat['dialog_user']['userid'];
|
||||
}
|
||||
}
|
||||
$userList = User::select('userid','email','nickname','userimg')
|
||||
->where('bot',0)
|
||||
->where('changepass',0)
|
||||
->whereNull('disable_at')
|
||||
->whereNotIn('userid',$notUserIds)
|
||||
->get()
|
||||
->transform(function (User $item) {
|
||||
$item->name = $item->nickname;
|
||||
$item->avatar = $item->userimg;
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
// 返回
|
||||
return Base::retSuccess('success', ["dir"=>$dir,"chatList"=>$chatList,"userList"=>$userList]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,30 +2,31 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Ldap\LdapUser;
|
||||
use App\Models\AbstractModel;
|
||||
use App\Models\Meeting;
|
||||
use App\Models\Project;
|
||||
use App\Models\UmengAlias;
|
||||
use App\Models\User;
|
||||
use App\Models\UserBot;
|
||||
use App\Models\UserCheckinMac;
|
||||
use App\Models\UserCheckinRecord;
|
||||
use App\Models\UserDelete;
|
||||
use App\Models\UserDepartment;
|
||||
use App\Models\UserEmailVerification;
|
||||
use App\Models\UserTransfer;
|
||||
use App\Models\WebSocket;
|
||||
use App\Models\WebSocketDialog;
|
||||
use App\Models\WebSocketDialogMsg;
|
||||
use App\Module\AgoraIO\AgoraTokenGenerator;
|
||||
use App\Module\Base;
|
||||
use App\Module\Doo;
|
||||
use Arr;
|
||||
use Cache;
|
||||
use Captcha;
|
||||
use Carbon\Carbon;
|
||||
use Request;
|
||||
use Carbon\Carbon;
|
||||
use App\Module\Doo;
|
||||
use App\Models\File;
|
||||
use App\Models\User;
|
||||
use App\Module\Base;
|
||||
use App\Ldap\LdapUser;
|
||||
use App\Models\Meeting;
|
||||
use App\Models\Project;
|
||||
use App\Models\UserBot;
|
||||
use App\Models\WebSocket;
|
||||
use App\Models\UmengAlias;
|
||||
use App\Models\UserDelete;
|
||||
use App\Models\UserTransfer;
|
||||
use App\Models\AbstractModel;
|
||||
use App\Models\UserCheckinMac;
|
||||
use App\Models\UserDepartment;
|
||||
use App\Models\WebSocketDialog;
|
||||
use App\Models\UserCheckinRecord;
|
||||
use App\Models\WebSocketDialogMsg;
|
||||
use App\Models\UserEmailVerification;
|
||||
use App\Module\AgoraIO\AgoraTokenGenerator;
|
||||
|
||||
/**
|
||||
* @apiDefine users
|
||||
@ -1800,4 +1801,73 @@ class UsersController extends AbstractController
|
||||
'webhook_url' => $userBot->webhook_url,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/users/share/list 25. 获取分享列表
|
||||
*
|
||||
* @apiVersion 1.0.0
|
||||
* @apiGroup system
|
||||
* @apiName share__list
|
||||
*
|
||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||
* @apiSuccess {Object} data 返回数据
|
||||
*/
|
||||
public function share__list()
|
||||
{
|
||||
$user = User::auth();
|
||||
$userids = $user->isTemp() ? [$user->userid] : [0, $user->userid];
|
||||
//目录列表
|
||||
$dir = Base::list2Tree(
|
||||
File::select('files.id','files.pid','files.name')
|
||||
->leftJoin('file_users', 'files.id', '=', 'file_users.file_id')
|
||||
->where('files.type','folder')
|
||||
->where(function ($q) use ($userids) {
|
||||
$q->whereIn('files.userid',$userids);
|
||||
$q->orWhere(function ($qq) use ($userids) {
|
||||
$qq->where('file_users.permission',1);
|
||||
$qq->whereIn('file_users.userid',$userids);
|
||||
});
|
||||
})
|
||||
->get()
|
||||
->toArray()
|
||||
);
|
||||
//聊天列表
|
||||
$chatList = WebSocketDialog::select(['web_socket_dialogs.*', 'u.top_at', 'u.silence', 'u.updated_at as user_at'])
|
||||
->join('web_socket_dialog_users as u', 'web_socket_dialogs.id', '=', 'u.dialog_id')
|
||||
->where('u.userid', $user->userid)
|
||||
->orderByDesc('u.top_at')
|
||||
->orderByDesc('web_socket_dialogs.last_at')
|
||||
->get()
|
||||
->transform(function (WebSocketDialog $item) use ($user) {
|
||||
$item = $item->formatData($user->userid);
|
||||
$item->last_msg = [];
|
||||
if(!$item->avatar){
|
||||
$item->avatar = 'avatar/'.$item->name.'.png';
|
||||
}
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
// 用户列表
|
||||
$notUserIds = [$user->userid];
|
||||
foreach($chatList as $chat){
|
||||
if($chat['type'] == 'user'){
|
||||
$notUserIds[] = $chat['dialog_user']['userid'];
|
||||
}
|
||||
}
|
||||
$userList = User::select('userid','email','nickname','userimg')
|
||||
->where('bot',0)
|
||||
->where('changepass',0)
|
||||
->whereNull('disable_at')
|
||||
->whereNotIn('userid',$notUserIds)
|
||||
->get()
|
||||
->transform(function (User $item) {
|
||||
$item->name = $item->nickname;
|
||||
$item->avatar = $item->userimg;
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
// 返回
|
||||
return Base::retSuccess('success', ["dir"=>$dir,"chatList"=>$chatList,"userList"=>$userList]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -540,4 +540,82 @@ class WebSocketDialog extends AbstractModel
|
||||
return $dialog;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息文件
|
||||
*
|
||||
* @param User $user 发起会话的会员
|
||||
* @param array $dialogIds 对话id
|
||||
* @param file $files 文件对象
|
||||
* @param string $image64 base64文件
|
||||
* @param string $fileName 文件名称
|
||||
* @param int $replyId 恢复id
|
||||
* @param int $imageAttachment
|
||||
* @return array
|
||||
*/
|
||||
public static function sendMsgFiles($user,$dialogIds,$files,$image64,$fileName,$replyId,$imageAttachment)
|
||||
{
|
||||
$filePath = '';
|
||||
$result = [];
|
||||
foreach($dialogIds as $dialog_id){
|
||||
$dialog = WebSocketDialog::checkDialog($dialog_id);
|
||||
//
|
||||
$action = $replyId > 0 ? "reply-$replyId" : "";
|
||||
$path = "uploads/chat/" . date("Ym") . "/" . $dialog_id . "/";
|
||||
if ($image64) {
|
||||
$data = Base::image64save([
|
||||
"image64" => $image64,
|
||||
"path" => $path,
|
||||
"fileName" => $fileName,
|
||||
]);
|
||||
}else if($filePath){
|
||||
Base::makeDir(public_path($path));
|
||||
copy($filePath, public_path($path).basename($filePath));
|
||||
} else {
|
||||
$data = Base::upload([
|
||||
"file" => $files,
|
||||
"type" => 'more',
|
||||
"path" => $path,
|
||||
"fileName" => $fileName,
|
||||
]);
|
||||
}
|
||||
//
|
||||
if (Base::isError($data)) {
|
||||
throw new ApiException($data['msg']);
|
||||
} else {
|
||||
$fileData = $data['data'];
|
||||
$filePath = $fileData['file'];
|
||||
$fileName = $fileData['name'];
|
||||
$fileData['thumb'] = Base::unFillUrl($fileData['thumb']);
|
||||
$fileData['size'] *= 1024;
|
||||
//
|
||||
if ($dialog->type === 'group' && $dialog->group_type === 'task') { // 任务群组保存文件
|
||||
if ($imageAttachment || !in_array($fileData['ext'], File::imageExt)) { // 如果是图片不保存
|
||||
$task = ProjectTask::whereDialogId($dialog->id)->first();
|
||||
if ($task) {
|
||||
$file = ProjectTaskFile::createInstance([
|
||||
'project_id' => $task->project_id,
|
||||
'task_id' => $task->id,
|
||||
'name' => $fileData['name'],
|
||||
'size' => $fileData['size'],
|
||||
'ext' => $fileData['ext'],
|
||||
'path' => $fileData['path'],
|
||||
'thumb' => $fileData['thumb'],
|
||||
'userid' => $user->userid,
|
||||
]);
|
||||
$file->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
$result = WebSocketDialogMsg::sendMsg($action, $dialog_id, 'file', $fileData, $user->userid);
|
||||
if (Base::isSuccess($result)) {
|
||||
if (isset($task)) {
|
||||
$result['data']['task_id'] = $task->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
2
resources/assets/js/store/actions.js
vendored
2
resources/assets/js/store/actions.js
vendored
@ -562,7 +562,7 @@ export default {
|
||||
$A.eeuiAppSendMessage({
|
||||
action: 'userChatList',
|
||||
token: state.userToken,
|
||||
url: $A.apiUrl('../api/system/getChatAndDirList') + `?token=${state.userToken}`
|
||||
url: $A.apiUrl('../api/users/share/list') + `?token=${state.userToken}`
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user