创建版本

This commit is contained in:
2021-02-22 12:17:00 +08:00
commit af555f49c3
2332 changed files with 369202 additions and 0 deletions
@@ -0,0 +1,622 @@
<?php namespace Gdoo\Chat\Controllers;
use Illuminate\Http\Request;
use URL;
use DB;
use Log;
use Session;
use Config;
use Auth;
use App\Support\JWT;
use Gdoo\Chat\Models\History;
use Gdoo\Chat\Models\Message;
use Gdoo\Chat\Services\ChatService;
use Gdoo\Index\Controllers\Controller;
class ChatController extends Controller
{
public $user = null;
public function __construct()
{
parent::__construct();
$this->middleware(function ($request, $next) {
$this->user = $request->user();
$action = $request->action();
// 如果没有登录跳转到登录页面
if (Auth::guest()) {
if ($action == 'login' || $action == 'start') {
} else {
return redirect("/chat/chat/login");
}
} else {
// 已经登录了访问登录页面
if ($action == 'login') {
return redirect("/chat/chat/index");
}
}
return $next($request);
});
}
public function startAction()
{
return $this->return_json([
'title' => $this->setting['title'],
'auth_id' => (int)$this->user['id'],
]);
}
public function indexAction()
{
return $this->render([
'user' => $this->user,
]);
}
public function getServerURLAction()
{
return ChatService::getServerURL($this->user);
}
public function uploadAction(Request $request)
{
if ($request->method() == 'POST') {
$user = $this->user;
$file = $request->file('file');
$path = 'chat'.date('/Ym/');
$extension = $file->getClientOriginalExtension();
$upload_path = upload_path().'/'.$path;
// 文件新名字
$filename = date('dhis_').str_random(4).'.'.$extension;
$filename = mb_strtolower($filename);
$size = $file->getClientSize();
$name = mb_strtolower($file->getClientOriginalName());
$mime = $file->getMimeType();
if ($file->move($upload_path, $filename)) {
$data = [
'name' => $name,
'node' => 'chat',
'path' => $path.$filename,
'type' => $extension,
'key' => 'chat.file',
'size' => $size,
];
$insertId = DB::table('attachment')->insertGetId($data);
$src = url($path.$filename);
if (in_array($extension, ['jpg', 'gif', 'png', 'jpeg'])) {
list($picw, $pich, $t) = getimagesize($upload_path.$filename);
}
$json = [
"adddt" => date('Y-m-d H:i:s'),
"comid" => 1,
"fileext" => $extension,
"filename" => $name,
"filepath" => $src,
"filesize" => $size,
"filesizecn" => human_filesize($size),
"filetype" => $mime,
"id" => $insertId,
"ip" => $request->getClientIp(),
"mknum" => "",
"optid" => $user['id'],
"optname" => $user['name'],
"pich" => (int)$pich,
"picw" => (int)$picw,
"thumbpath" => $src,
"valid" => 1,
"web" => "Chrome",
];
return json_encode($json);
}
}
}
public function getHistoryAction()
{
$auth_id = $this->user['id'];
$json = ChatService::getHistory($auth_id);
return $this->return_json($json);
}
public function getMaxUploadAction()
{
return $this->return_json(['maxUpload' => $this->setting['upload_max']]);
}
public function getGroupUserAction(Request $request)
{
$gets = $request->all();
$auth_id = $this->user['id'];
$json = ChatService::getGroupUser($gets['gid'], $auth_id);
return $this->return_json($json);
}
public function clearRecordAction(Request $request)
{
$gets = $request->all();
$auth_id = $this->user['id'];
ChatService::clearRecord($gets['type'], $gets['gid'], $auth_id, $gets['ids']);
return $this->return_json('删除成功');
}
public function inviteUserAction(Request $request)
{
$gets = $request->all();
ChatService::inviteUser($this->user, $gets['gid'], $gets['val']);
return $this->return_json('邀请成功');
}
public function getReceiverAction(Request $request)
{
$gets = $request->all();
$auth_id = $this->user['id'];
$json = ChatService::getReceiver($gets['type'], $gets['gid'], $auth_id);
return $this->return_json(['receinfor' => $json]);
}
public function exitGroupAction(Request $request)
{
$gets = $request->all();
$auth_id = $this->user['id'];
ChatService::exitGroup($gets['gid'], $auth_id);
return $this->return_json('退出会话成功');
}
public function createGroupAction(Request $request)
{
$gets = $request->all();
$auth_id = $this->user['id'];
$group_id = DB::table('chat_group')->insertGetId([
'name' => $gets['val'],
'logo' => '/assets/chat/images/group.png',
]);
DB::table('chat_group_user')->insert([
'group_id' => $group_id,
'user_id' => $auth_id,
]);
return $this->return_json('创建会话成功');
}
public function clearHistoryAction(Request $request)
{
$gets = $request->all();
$auth_id = $this->user['id'];
ChatService::clearHistory($gets['type'], $gets['gid'], $auth_id);
return $this->return_json('退出会话成功');
}
public function getDepartmentUserDataAction()
{
$roles = DB::table('role')->get()->toNested();
$departments = DB::table('department')
->leftJoin(DB::raw('(select count(id) utotal, department_id
FROM [user]
GROUP BY department_id
) u
'), 'u.department_id', '=', 'department.id')
->selectRaw('department.*, isnull(u.utotal, 0) as ntotal')
->get()->toNested();
$deptjson = [];
foreach($departments as $department) {
$department['stotal'] = 0;
// 显示部门下的用户数
$department['ntotal'] = 0;
foreach($department['child'] as $child) {
$department['ntotal'] += $departments[$child]['ntotal'];
}
$department['pid'] = $department['parent_id'];
$deptjson[] = $department;
}
$users = ChatService::getUser(1, 1);
$userjson = [];
foreach($users as $user) {
$user['pingyin'] = '';
$user['deptname'] = $departments[$user['department_id']]['name'];
$user['deptallname'] = $departments[$user['department_id']]['text'];
$user['ranking'] = $roles[$user['role_id']]['name'];
$user['face'] = avatar($user['avatar']);
$userjson[] = $user;
}
$groupjson = [];
$json = [
'userjson' => $userjson,
'deptjson' => $deptjson,
'groupjson' => $groupjson,
];
return $this->return_json($json);
}
public function loginAction(Request $request)
{
if ($request->method() == 'POST') {
$gets = $request->all();
$credentials = [
'username' => $gets['adminuser'],
'password' => $gets['adminpass'],
'status' => 1,
];
if (Auth::attempt($credentials)) {
return $this->return_json('登录成功');
} else {
abort_error('成功失败,请检查用户名或者密码');
}
}
return $this->render();
}
public function logoutAction()
{
Auth::logout();
Session::flush();
return $this->return_json('登出成功');
}
/**
* 撤回消息功能
*/
public function recallMessageAction(Request $request)
{
$auth_id = $this->user['id'];
$gets = $request->all();
$json = ChatService::recallMessage($gets['type'], $auth_id, $gets['gid'], $gets['id']);
return $this->return_json($json);
}
public function sendMessageAction(Request $request)
{
$gets = $request->all();
$auth = $this->user;
$send_id = (int)$auth['id'];
$receive_id = (int)$gets['gid'];
$type = $gets['type'];
$json = ChatService::sendMessage($type, $send_id, $receive_id, $gets);
return $this->return_json($json);
}
public function getRecordAction(Request $request)
{
$auth = $this->user;
$auth_id = (int)$auth['id'];
$gid = (int)$request->get('gid');
$type = $request->get('type');
$page = $request->get('page');
$lastdt = $request->get('lastdt');
$minid = (int)$request->get('minid');
$roles = DB::table('role')->get()->toNested();
$departments = DB::table('department')->get()->toNested();
$json = [
"nowdt" => time(),
"servernow" => date('Y-m-d H:i:s'),
];
$receiver = $sender = [];
if ($type == 'user') {
$receiver = DB::table('user')
->where('id', $gid)
->selectRaw('id, name, role_id, department_id, department_id as deptid, avatar')
->first();
$receiver['ranking'] = $roles[$receiver['role_id']]['name'];
$receiver['unitname'] = $departments[$receiver['department_id']]['text'];
$receiver['deptname'] = $departments[$receiver['department_id']]['name'];
$receiver['face'] = avatar($receiver['avatar']);
$receiver['type'] = 'user';
$receiver['utotal'] = 0;
$receiver['gid'] = $receiver['id'];
$json['receinfor'] = $receiver;
}
else if ($type == 'group') {
$receiver = DB::table('chat_group')
->where('id', $gid)
->selectRaw('id, name, logo')
->first();
$receiver['face'] = $receiver['logo'];
$receiver['type'] = 'group';
// 查询用户数量
$receiver['utotal'] = DB::table('chat_group_user')
->where('group_id', $gid)
->count();
// 查询自己是否在组中
$receiver['innei'] = DB::table('chat_group_user')
->where('group_id', $gid)
->where('user_id', $auth_id)
->count();
$receiver['gid'] = $receiver['id'];
$json['receinfor'] = $receiver;
}
if ($page == 0) {
$sender = DB::table('user')
->where('id', $auth_id)
->selectRaw('id, name, role_id, department_id, department_id as deptid, avatar')
->first();
$sender['ranking'] = $roles[$sender['role_id']]['name'];
$sender['unitname'] = $departments[$sender['department_id']]['text'];
$sender['deptname'] = $departments[$sender['department_id']]['name'];
$sender['face'] = avatar($sender['avatar']);
$json['sendinfo'] = $sender;
}
$rows = [];
$unread_total = 0;
// 获取用户
if ($type == 'user') {
// 获取全部未读
$unread_total = DB::table('chat_message')
->whereRaw("(send_id = $gid and receive_id = $auth_id) and type = '$type' and id in(select message_id from chat_message_status where status = 0 and user_id = '$auth_id')")
->count();
$model = DB::table('chat_message as cm')
->leftJoin('user', 'user.id', '=', 'cm.send_id')
->leftJoin('chat_message_status as cms', 'cm.id', '=', 'cms.message_id')
->where('cm.type', $type)
->orderBy('cm.id', 'desc');
$model->whereRaw("((cm.send_id = '$gid' and cm.receive_id = '$auth_id') or (cm.receive_id = '$gid' and cm.send_id = '$auth_id')) and cms.user_id = '$auth_id'");
// 这里有一点bug,如果只有一条未读只能显示一条
if ($unread_total > 0) {
$model->where('cms.status', 0);
}
// 获取大于当前时间的记录
if ($lastdt > 0) {
$model->where('cm.created_dt', '>', date('Y-m-d H:i:s', $lastdt));
}
// 获取小于当前id的记录
if ($minid > 0) {
$model->where('cm.id', '<', $minid);
}
$messages = $model->selectRaw('
cm.*,
cm.send_id as sendid,
cm.content as cont,
cm.created_dt as optdt,
cms.status as zt,
[user].name as sendname,
[user].avatar
')
->limit(10)
->get();
$message_ids = [];
foreach($messages as $message) {
$message_ids[] = $message['id'];
$message['optdt'] = date('Y-m-d H:i:s', strtotime($message['created_dt']));
$message['face'] = avatar($message['avatar']);
$rows[] = $message;
$unread_total--;
}
// 设置已读
DB::table('chat_message_status')
->where('user_id', $auth_id)
->whereIn('message_id', $message_ids)
->update(['status' => 1]);
}
// 获取讨论组
else if ($type == 'group') {
// 获取全部未读
$unread_total = DB::table('chat_message')
->whereRaw("type = '$type' and receive_id = '$gid' and id in(select message_id from chat_message_status where status = 0 and user_id = '$auth_id')")
->count();
$model = DB::table('chat_message as cm')
->leftJoin('user', 'user.id', '=', 'cm.send_id')
->leftJoin('chat_message_status as cms', 'cm.id', '=', 'cms.message_id')
->where('cm.type', $type)
->orderBy('cm.id', 'desc');
$model->whereRaw("(cm.receive_id = '$gid') and cms.user_id = '$auth_id'");
// 这里有一点bug,如果只有一条未读只能显示一条
if ($unread_total > 0) {
$model->where('cms.status', 0);
}
//$model->whereRaw("(cm.receive_id = '$gid' and cm.id in(select message_id from chat_message_status where user_id = '$auth_id'))");
// 获取大于当前时间的记录
if ($lastdt > 0) {
$model->where('cm.created_dt', '>', date('Y-m-d H:i:s', $lastdt));
}
// 获取小于当前id的记录
if ($minid > 0) {
$model->where('cm.id', '<', $minid);
}
$messages = $model->selectRaw('
cm.*,
cm.send_id as sendid,
cm.content as cont,
cm.created_dt as optdt,
cms.status as zt,
[user].name as sendname,
[user].avatar
')
->limit(10)
->get();
$message_ids = [];
foreach($messages as $message) {
$message_ids[] = $message['id'];
$message['optdt'] = date('Y-m-d H:i:s', strtotime($message['created_dt']));
$message['face'] = avatar($message['avatar']);
$rows[] = $message;
$unread_total--;
}
// 设置未读为已读
DB::table('chat_message_status')
->where('group_id', $gid)
->where('user_id', $auth_id)
->whereIn('message_id', $message_ids)
->update(['status' => 1]);
}
$rows = ChatService::formatMessage($rows);
$unread_total = $unread_total < 0 ? 0 : $unread_total;
$json['wdtotal'] = $unread_total;
// 设置会话已读
DB::table('chat_history')
->where('send_id', $auth_id)
->where('receive_id', $gid)
->where('type', $type)
->update(['unread_total' => $unread_total]);
$json['rows'] = $rows;
return $this->return_json($json);
}
public function initAction(Request $request)
{
$auth_id = $this->user['id'];
$roles = DB::table('role')->get()->toNested();
$departments = DB::table('department')
->leftJoin(DB::raw('(select count(id) utotal, department_id
FROM [user]
GROUP BY department_id
) u
'), 'u.department_id', '=', 'department.id')
->selectRaw('department.*, isnull(u.utotal, 0) as ntotal')
->get()->toNested();
$deptjson = [];
foreach($departments as $department) {
$department['stotal'] = 0;
// 显示部门下的用户数
$department['ntotal'] = 0;
foreach($department['child'] as $child) {
$department['ntotal'] += $departments[$child]['ntotal'];
}
$department['pid'] = $department['parent_id'];
$deptjson[] = $department;
}
$users = ChatService::getUser(1, 1);
$userjson = [];
foreach($users as $user) {
$user['deptname'] = $departments[$user['department_id']]['name'];
$user['deptallname'] = $departments[$user['department_id']]['text'];
$user['ranking'] = $roles[$user['role_id']]['name'];
$user['face'] = avatar($user['avatar']);
$userjson[] = $user;
}
// 获取组
$groups = ChatService::getGroup($auth_id);
$groupjson = [];
foreach ($groups as $group) {
$group['deptid'] = $group['department_id'];
$groupjson[] = $group;
}
$agentjson = array(
array('id' => '1',
'name' => 'Gdoo Team',
'url' => 'link',
'face' => 'images/logo.png',
'num' => 'xinhu',
'pid' => '0',
'iconfont' => 'cf-c90',
'iconcolor' => '#1ABC9C',
'types' => '官网(1)',
'urlpc' => 'http://www.gdoo.net',
'urlm' => NULL,
'titles' => '',
'menu' => array(
array('pid' => '0', 'mid' => '1', 'id' => '18', 'name' => '最新信息', 'type' => '0', 'url' => 'new', 'num' => NULL, 'color' => NULL, 'receid' => NULL, 'submenu' => array()),
array('pid' => '0', 'mid' => '1', 'id' => '89', 'name' => '打开官网', 'type' => '1', 'url' => 'http://www.gdoo.net', 'num' => NULL, 'color' => NULL, 'receid' => NULL, 'submenu' => array(),),
array('pid' => '0', 'mid' => '1', 'id' => '19', 'name' => '+建议反馈', 'type' => '1', 'url' => 'http://www.gdoo.net/fankui.html', 'num' => NULL, 'color' => NULL, 'receid' => NULL, 'submenu' => array(),),
),
'stotal' => 0,
'totals' => 0
)
);
$agentjson = [];
$historyjson = ChatService::getHistory($auth_id);
$json = [
'deptjson' => $deptjson,
'userjson' => $userjson,
'groupjson' => $groupjson,
'agentjson' => $agentjson,
'historyjson' => $historyjson,
"modearr" => [],
"config" => [
"recid" => "gdoo",
"title" => "Gdoo",
"chehui" => 5,
"wsurl" => env('REALTIME_URL'),
],
"loaddt" => date('Y-m-d H:i:s'),
"ip" => $request->getClientIp(),
"editpass" => 1,
"companyinfo" => [
"id" => "1",
"logo" => "images/logo.png",
"name" => "Gdoo Team",
"nameen" => null,
"oaname" => null,
"oanemes" => null,
"tel" => "028-123456",
"fax" => "028-123456",
"pid" => "0",
"sort" => "0",
"fuzeid" => "5",
"fuzename" => "乐风",
"address" => "软件园",
"city" => "眉山",
"num" => null,
"comid" => "0"
]
];
return $this->return_json($json);
}
public function return_json($data, $success = true, $code = 200, $msg = '') {
$json = [
'data' => $data,
'success' => $success,
'code' => $code,
'msg' => $msg,
];
return $json;
}
}
+8
View File
@@ -0,0 +1,8 @@
<?php namespace Gdoo\Chat\Models;
use Gdoo\Index\Models\BaseModel;
class GroupUser extends BaseModel
{
protected $table = 'chat_group_user';
}
+8
View File
@@ -0,0 +1,8 @@
<?php namespace Gdoo\Chat\Models;
use Gdoo\Index\Models\BaseModel;
class History extends BaseModel
{
protected $table = 'chat_history';
}
+8
View File
@@ -0,0 +1,8 @@
<?php namespace Gdoo\Chat\Models;
use Gdoo\Index\Models\BaseModel;
class Message extends BaseModel
{
protected $table = 'chat_message';
}
+723
View File
@@ -0,0 +1,723 @@
<?php namespace Gdoo\Chat\Services;
use DB;
use URL;
use Gdoo\Chat\Models\History;
use Gdoo\Chat\Models\GroupUser;
use Gdoo\Chat\Models\Message;
class ChatService
{
/**
* 构建ws连接url
*
* @param array $user
* @access public
* @return array
*/
public static function getServerURL($user) {
$key = env('REALTIME_KEY');
$url = env('REALTIME_URL');
$timestamp = time();
$nonce = rand(10000, 99999);
$signature = hash_hmac('sha256', $key.$timestamp.$nonce, $key);
$query = [
'signature' => $signature,
'timestamp' => $timestamp,
'nonce' => $nonce,
'user_id' => $user['id'],
'user_name' => $user['name'],
];
return ['url' => $url. '?'. http_build_query($query)];
}
/**
* 获取组
*
* @param int $admin_id
* @access public
* @return array
*/
public static function getGroup($auth_id = 0, $admin_id = 0)
{
static $rows = null;
if ($rows == null) {
$model = DB::table('chat_group as cg')
->leftJoin('chat_group_user', 'chat_group_user.group_id', '=', 'cg.id');
if ($auth_id > 0) {
$model->where('chat_group_user.user_id', $auth_id);
}
if ($admin_id > 0) {
$model->whereRaw(db_instr('admin_ids', $admin_id));
}
$model->leftJoin(DB::raw('(select count(id) utotal, group_id
FROM chat_group_user
GROUP BY group_id
) cgu
'), 'cg.id', '=', 'cgu.group_id')
->selectRaw('cg.*, cgu.utotal, cg.logo as face');
$rows = $model->get()->keyBy('id');
}
return $rows;
}
/**
* 撤回消息
*
* @param int $type
* @param int $auth_id
* @param int $group_id
* @param int $id
* @access public
* @return array
*/
public static function recallMessage($type, $auth_id, $group_id, $id)
{
$chehui = 5;
if ($chehui <= 0) {
abort_error('没有开启此功能');
}
$message = DB::table('chat_message')->where('id', $id)->first();
if(!$message) {
abort_error('记录不存在了');
}
$outtime = time() - strtotime($message['created_dt']);
if($outtime > $chehui * 60) {
abort_error('已经超过'.$chehui.'分钟无法撤回');
}
if ($type == 'user') {
$receiver = [$auth_id, (int)$message['receive_id']];
} elseif ($type == 'group') {
$user_ids = DB::table('chat_group_user')->where('group_id', $group_id)->pluck('user_id');
foreach($user_ids as $user_id) {
$receiver[] = (int)$user_id;
}
}
$msg = '已撤回';
DB::table('chat_message')->where('id', $message['id'])->update([
'file_id' => 0,
'content' => $msg,
]);
$pushData = [
'send_id' => $auth_id,
'content' => $msg,
'event' => 'recallMessage',
'receive_ids' => $receiver,
'message_id' => (int)$message['id'],
];
$push = new PushService();
$push->send($pushData);
return $pushData;
}
/**
* 格式化消息
*
* @param array $rows
* @access public
* @return array
*/
public static function formatMessage($rows)
{
$file_ids = [];
foreach($rows as $row) {
if ($row['file_id'] > 0) {
$file_ids[] = $row['file_id'];
}
}
$imgext = ['gif','png','jpg','jpeg','bmp'];
if (count($file_ids) > 0) {
$model = DB::table('attachment');
$farr = [];
$files = $model->whereIn('id', $file_ids)->get();
foreach ($files as $file)
$farr[$file['id']] = $file;
if ($farr) {
foreach ($rows as $k => $row) {
$frs = [];
$fid = $row['file_id'];
if (isset($farr[$fid])) {
$frs = $farr[$fid];
$frs['fileext'] = $frs['type'];
$frs['fileid'] = $fid;
}
if ($frs) {
$type = $frs['type'];
$path = $frs['path'];
$boc = false;
if (substr($path, 0, 4) == 'http') {
$boc = true;
} else {
if (is_file(upload_path().'/'.$path)) {
$path = url('uploads/'.$path);
$frs['thumbpath'] = $path;
$frs['filepath'] = $path;
$frs['filesize'] = $frs['size'];
$frs['filesizecn'] = human_filesize($frs['size']);
$frs['filename'] = $frs['name'];
$boc = true;
}
}
if ($boc) {
if (in_array($type, $imgext)) {
// $frs['thumbpath'] = $fobj->getthumbpath($frs);
$rows[$k]['cont'] = '<img fid="'.$fid.'" src="'.$path.'">';
}
$rows[$k]['filers'] = $frs;
} else {
$rows[$k]['fileid'] = 0;
}
}
}
}
}
return $rows;
}
/**
* 获取用户
*
* @param int $user_id
* @param int $group_id
* @access public
* @return array
*/
public static function getUser($status = 1, $group_id = 1)
{
static $rows = null;
if ($rows == null) {
$model = DB::table('user');
if (is_numeric($status)) {
$model->where('status', $status);
}
if (is_numeric($group_id)) {
$model->where('group_id', $group_id);
}
$model->selectRaw("''as pingyin,tel,(CASE WHEN (gender = 1) THEN '男' ELSE '女' END) as sex, email, id, name, phone, phone as mobile, role_id, department_id, department_id as deptid");
$rows = $model->get()->keyBy('id');
}
return $rows;
}
/**
* 邀请用户到组
*
* @param string $ids
* @param int $group_id
*/
public static function inviteUser($auth, $group_id, $ids)
{
$user_ids = explode(',', $ids);
if (count($user_ids) > 0) {
foreach($user_ids as $index => $user_id) {
$model = GroupUser::firstOrNew([
'user_id' => $user_id,
'group_id' => $group_id,
]);
if ($model->exists == true) {
unset($user_ids[$index]);
}
$model->save();
}
if (count($user_ids) > 0) {
$users = DB::table('user')->whereIn('id', $user_ids)->get()->pluck('name')->implode(',');
$gets = [
"cont" => $auth['name'].'邀请['.$users.']加入本会话',
"sendid" => $auth['id'],
"receid" => $group_id,
"type" => 'group',
"optdt" => date('Y-m-d H:i:s'),
"zt" => 0,
"fileid" => '',
"msgid" => "",
"gid" => $group_id,
"nuid" => time(),
];
$json = ChatService::sendMessage('group', $auth['id'], $group_id, $gets);
}
}
}
/**
* 退出用户组
*
* @param int $group_id
* @param int $auth_id
* @access public
* @return void
*/
public static function exitGroup($group_id, $auth_id)
{
// 删除用户组权限
GroupUser::where('group_id', $group_id)
->where('user_id', $auth_id)
->delete();
// 删除组聊天记录
DB::table('chat_message_status')
->where('type', 'group')
->where('group_id', $group_id)
->where('user_id', $auth_id)
->delete();
// 删除会话记录
DB::table('chat_history')
->where('type', 'group')
->where('receive_id', $group_id)
->where('send_id', $auth_id)
->delete();
}
/**
* 删除服务器上记录
*
* @param string $type
* @param int $group_id
* @param int $auth_id
* @param string $ids
* @param int $day
* @access public
* @return void
*/
public static function clearRecord($type, $group_id, $auth_id, $ids = [], $day = 0)
{
DB::beginTransaction();
try {
// 获取聊天记录数量
$model = DB::table('chat_message_status')
->where('type', $type);
if (count($ids) > 0) {
$model->whereIn('message_id', $ids);
}
if ($type == 'group') {
$model->where('group_id', $group_id);
} else if ($type == 'user') {
$model->whereRaw("((group_id = '$group_id' and user_id = '$auth_id') or (group_id = '$auth_id' and user_id = '$group_id'))");
}
$messages = $model->groupBy('message_id')
->selectRaw('message_id, count(id) as count')
->get();
$model = DB::table('chat_message_status')
->where('group_id', $group_id)
->where('user_id', $auth_id);
if (count($ids) > 0) {
$model->whereIn('message_id', $ids);
}
$model->delete();
// 获取回话的最后消息id
$last_message_id = DB::table('chat_message_status')
->where('type', $type)
->where('group_id', $group_id)
->where('user_id', $auth_id)
->orderBy('message_id', 'desc')
->value('message_id');
// 更新回话的最后消息id
DB::table('chat_history')
->where('type', $type)
->where('receive_id', $group_id)
->where('send_id', $auth_id)
->update(['last_message_id' => (int)$last_message_id]);
// 删除消息状统计为1的数据
foreach($messages as $message) {
if ($message['count'] == 1) {
DB::table('chat_message')->where('id', $message['message_id'])->delete();
}
}
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
abort_error($e->getMessage());
}
}
/**
* 删除会话记录
*
* @param string $type
* @param int $group_id
* @param int $auth_id
* @access public
* @return void
*/
public static function clearHistory($type, $group_id, $auth_id)
{
DB::beginTransaction();
try {
// 获取聊天记录数量
$model = DB::table('chat_message_status')
->where('type', $type);
if ($type == 'group') {
$model->where('group_id', $group_id);
} else if ($type == 'user') {
$model->whereRaw("((group_id = '$group_id' and user_id = '$auth_id') or (group_id = '$auth_id' and user_id = '$group_id'))");
}
$messages = $model->groupBy('message_id')
->selectRaw('message_id, count(id) as count')
->get();
// 删除聊天记录
$model = DB::table('chat_message_status')
->where('type', $type)
->where('group_id', $group_id)
->where('user_id', $auth_id)
->delete();
// 删除会话记录
DB::table('chat_history')
->where('type', $type)
->where('receive_id', $group_id)
->where('send_id', $auth_id)
->delete();
// 删除消息状统计为1的数据
foreach($messages as $message) {
if ($message['count'] == 1) {
DB::table('chat_message')->where('id', $message['message_id'])->delete();
}
}
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
abort_error($e->getMessage());
}
}
/**
* 获取组和用户
*
* @param int $group_id
* @param int $auth_id
* @access public
* @return array
*/
public static function getGroupUser($group_id, $auth_id)
{
$group = DB::table('chat_group')->where('id', $group_id)->first();
$group['face'] = $group['logo'];
$group['deptid'] = $group['department_id'];
$group['utotal'] = DB::table('chat_group_user')->where('group_id', $group_id)->count();
$group['innei'] = DB::table('chat_group_user')->where('user_id', $auth_id)->count();
$rows = DB::table('chat_group_user as cgu')
->leftJoin('user', 'user.id', 'cgu.user_id')
->where('cgu.group_id', $group_id)
->get(['user.id', 'user.name', 'user.avatar as face']);
$users = [];
foreach($rows as $row) {
$row['face'] = avatar($row['avatar']);
$users[] = $row;
}
$json['infor'] = $group;
$json['uarr'] = $users;
return $json;
}
/**
* 获取发送者
* @access public
* @param int $type 回话类型
* @param int $send_id 发送人
* @param int $receive_id 接受者id,如果是group那就是group_id
* @param int $user_id group的user_id
* @param int $message_id 消息id
* @return array
*/
public static function getReceiver($type, $receive_id, $send_id)
{
if ($type == 'user') {
$receiver = DB::table('user')
->where('id', $receive_id)
->selectRaw('id, name, role_id, department_id as deptid, avatar')
->first();
$receiver['face'] = avatar($receiver['avatar']);
$receiver['type'] = 'user';
$receiver['utotal'] = 0;
$receiver['gid'] = $receiver['id'];
}
else if ($type == 'group') {
$receiver = DB::table('chat_group')
->where('id', $receive_id)
->selectRaw('id, name, logo')
->first();
$receiver['face'] = $receiver['logo'];
$receiver['type'] = 'group';
// 查询用户数量
$receiver['utotal'] = DB::table('chat_group_user')
->where('group_id', $receive_id)
->count();
// 查询自己是否在组中
$receiver['innei'] = DB::table('chat_group_user')
->where('group_id', $receive_id)
->where('user_id', $send_id)
->count();
$receiver['gid'] = $receiver['id'];
}
return $receiver;
}
/**
* 获取发送者
* @access public
* @param int $type 回话类型
* @param int $send_id 发送人
* @param int $receive_id 接受者id,如果是group那就是group_id
* @param array $data 发送内容
* @param int $client 0=app发送 1=web客户端
* @return array
*/
public static function sendMessage($type, $send_id, $receive_id, $data, $client = 1)
{
$gets = $data;
$data = [
'send_id' => $send_id,
'receive_id' => $receive_id,
"content" => $gets['cont'],
'type' => $type,
'url' => $gets['url'],
'file_id' => $gets['fileid'],
'created_dt' => date('Y-m-d H:i:s')
];
$message_id = Message::insertGetId($data);
// 返回数据
$json = [
"cont" => $gets['cont'],
"sendid" => $send_id,
"receid" => $receive_id,
"type" => $type,
"optdt" => date('Y-m-d H:i:s'),
"zt" => 0,
"fileid" => $gets['fileid'],
"msgid" => "",
"gid" => $receive_id,
"id" => $message_id,
"nuid" => $gets['nuid'],
];
$json['event'] = 'message';
$json['content'] = $gets['cont'];
$json['send_id'] = $send_id;
// 写入历史记录
$user_ids = ChatService::setHistory($type, $send_id, $receive_id, $message_id);
if ($type == 'user') {
// 写入已读(自己)
DB::table('chat_message_status')->insert([
'group_id' => $receive_id,
'user_id' => $send_id,
'message_id' => $message_id,
'status' => 1,
'type' => $type,
]);
// 写入未读(对方)
DB::table('chat_message_status')->insert([
'group_id' => $send_id,
'user_id' => $receive_id,
'message_id' => $message_id,
'status' => 0,
'type' => $type,
]);
} else if ($type == 'group') {
// 写入未读(讨论组)
foreach($user_ids as $user_id) {
// 设置为已读(自己)
$status = $send_id == $user_id ? 1 : 0;
DB::table('chat_message_status')->insert([
'group_id' => $receive_id,
'user_id' => $user_id,
'message_id' => $message_id,
'status' => $status,
'type' => $type,
]);
}
// 组的名称
$group = DB::table('chat_group')->where('id', $receive_id)->first();
$json['gname'] = $group['name'];
}
$json['receuid'] = join(',', $user_ids);
$json['receive_ids'] = $user_ids;
return $json;
}
/**
* 写入会话
* @access public
* @param int $type 会话类型
* @param int $send_id 发送人
* @param int $receive_id 接受者id,如果是group那就是group_id
* @param int $user_id group的user_id
* @param int $message_id 消息id
* @return array
*/
public static function setHistory($type, $send_id, $receive_id, $message_id)
{
$model = History::firstOrNew([
'send_id' => $send_id,
'receive_id' => $receive_id,
'type' => $type,
]);
$model->last_message_id = $message_id;
$model->updated_dt = date('Y-m-d H:i:s');
$model->save();
if ($type == 'user') {
$receive_ids = [$send_id, $receive_id];
$model = History::firstOrNew([
'send_id' => $receive_id,
'receive_id' => $send_id,
'type' => $type,
]);
$model->last_message_id = $message_id;
$model->updated_dt = date('Y-m-d H:i:s');
if ($send_id != $receive_id) {
$model->unread_total = $model->unread_total + 1;
}
$model->save();
} else if($type == 'group') {
$user_ids = DB::table('chat_group_user')
->where('group_id', $receive_id)
->pluck('user_id');
// 写入接收者历史记录
foreach($user_ids as $user_id) {
// 返回所有接受者
$receive_ids[] = (int)$user_id;
// 发送人和接收人相同
if ($send_id == $user_id) {
continue;
}
$model = History::firstOrNew([
'send_id' => $user_id,
'receive_id' => $receive_id,
'type' => $type,
]);
$model->last_message_id = $message_id;
$model->updated_dt = date('Y-m-d H:i:s');
if ($send_id != $user_id) {
$model->unread_total = $model->unread_total + 1;
}
$model->save();
}
}
return array_unique($receive_ids);
}
/**
* 获取回话历史
*
* @param int $user_id
* @param datetime $updated_dt
* @param int $unread
* @access public
* @return array
*/
public static function getHistory($user_id, $updated_dt = '', $unread = 0)
{
$model = DB::table('chat_history as ch')
->leftJoin('chat_message as cm', 'cm.id', '=', 'ch.last_message_id')
->where('ch.send_id', $user_id)
->orderBy('ch.updated_dt', 'desc')
->selectRaw("
ch.type type,
ch.send_id uid,
ch.receive_id receid,
ch.send_id sendid,
".sql_month_day('ch.updated_dt')." optdts,
cm.content cont,
cm.id messid,
cm.send_id,
ch.unread_total stotal,
0 utotal,
ch.updated_dt as optdt
");
if ($updated_dt) {
$model->where('ch.updated_dt', '>', $updated_dt);
}
if ($unread) {
$model->where('ch.unread_total', '>', $unread);
}
$rows = $model->get();
$users = static::getUser();
$groups = static::getGroup();
$historys = [];
foreach ($rows as $row) {
if ($row['type'] == 'user') {
$row['face'] = avatar($users[$row['receid']]['avatar']);
$row['name'] = $users[$row['receid']]['name'];
if (empty($row['cont'])) {
$row['cont'] = '';
}
}
if ($row['type'] == 'group') {
$row['deptid'] = $groups[$row['receid']]['department_id'];
$row['face'] = $groups[$row['receid']]['face'];
$row['name'] = $groups[$row['receid']]['name'];
if (empty($row['cont'])) {
$row['cont'] = '';
} else {
$row['cont'] = $users[$row['send_id']]['name'].':'.$row['cont'];
}
}
$historys[] = $row;
}
return $historys;
}
}
+100
View File
@@ -0,0 +1,100 @@
<?php namespace Gdoo\Chat\Services;
class PushService
{
private $api;
private $key;
private $cert;
private $caPath;
private $connectTimeout;
private $timeout;
private $useSSL = false;
public function __construct() {
$this->api = env('REALTIME_API');
$this->key = env('REALTIME_KEY');
$this->api = $this->api.'?'.$this->generateSignature();
}
public function generateSignature() {
$timestamp = time();
$nonce = rand(10000, 99999);
$signature = hash_hmac('sha256', $this->key.$timestamp.$nonce, $this->key);
$query = "signature={$signature}&amp;timestamp={$timestamp}&amp;nonce={$nonce}";
return $query;
}
public function send(array $data) {
return $this->request($data);
}
public function useSSL(bool $value) {
$this->useSSL = $value;
return $this;
}
public function setCert(string $cert) {
$this->cert = $cert;
return $this;
}
public function setCAPath(string $caPath) {
$this->caPath = $caPath;
return $this;
}
public function setConnectTimeout(int $connectTimeout) {
$this->connectTimeout = $connectTimeout;
return $this;
}
public function setTimeout(int $timeout) {
$this->timeout = $timeout;
return $this;
}
private function request(array $params) {
$ch = curl_init();
if ($this->connectTimeout) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
}
if ($this->timeout) {
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
}
if ($this->useSSL) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
if ($this->cert) {
curl_setopt($ch, CURLOPT_CAINFO, $this->cert);
}
if ($this->caPath) {
curl_setopt($ch, CURLOPT_CAPATH, $this->caPath);
}
} else {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
}
curl_setopt($ch, CURLOPT_USERAGENT, 'realtime/1.0');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getHeaders());
curl_setopt($ch, CURLOPT_URL, $this->api);
$data = curl_exec($ch);
$error = curl_error($ch);
$headers = curl_getinfo($ch);
curl_close($ch);
if (empty($headers["http_code"]) || ($headers["http_code"] != 200)) {
$data = '{"success":false,"code":'.$headers["http_code"].',"msg":"'.$error.'"}';
}
$json = json_decode($data, true);
return $json;
}
private function getHeaders() {
return [
'Content-Type: application/json',
];
}
}
+124
View File
@@ -0,0 +1,124 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>{{$setting['title']}}</title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<meta name="format-detection" content="telephone=no"/>
<meta name="format-detection" content="email=no"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"/>
<link rel="stylesheet" type="text/css" href="{{$asset_url}}/chat/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="{{$asset_url}}/chat/css/webimcss.css"/>
<link rel="stylesheet" type="text/css" href="{{$asset_url}}/chat/jquery/perfectscrollbar/perfect-scrollbar.css"/>
<link rel="stylesheet" type="text/css" href="{{$asset_url}}/chat/jquery/menu/jquery-rockmenu.css"/>
<link rel="stylesheet" type="text/css" href="{{$asset_url}}/chat/css/chat.css"/>
<link rel="shortcut icon" id="ico" href="{{$asset_url}}/chat/images/web/logo.png" />
<script type="text/javascript" src="{{$asset_url}}/vendor/jquery.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/js/js.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/js/nwjs.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/jquery/menu/jquery-rockmenu.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/js/notify.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/js/strformat.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/js/realtime.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/js/websocket.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/jquery/perfectscrollbar/perfect-scrollbar.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/jquery/perfectscrollbar/jquery.mousewheel.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/jquery/jquery-imgview.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/jquery/jquery-rockupload.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/jquery/jquery-rockmodels.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/jquery/jquery-changeuser.js"></script>
<script>
js.servernow = '{{date("Y-m-d H:i:s")}}';
companymode = false;
function globalbody() {
adminid = '{{$user["id"]}}';
adminface = '{{avatar($user["avatar"])}}';
adminname = '{{$user["name"]}}';
adminuser = '{{$user["username"]}}';
deptallname = '{{$user->department->name}}';
adminranking = '{{$user->role->name}}';
}
function initbody() {
reim.init();
}
function winfocus() {
window.focus();
}
</script>
</head>
<body style="overflow:hidden;" oncontextmenu="return true">
<div style="position:absolute;bottom:15px;left:0;width:60px;">
<div align="center" id="reimcog" class="cursor" style="color:#fff;font-size:16px">
<i class="fa fa-cog"></i>
</div>
</div>
<div id="mindivshow" style="height:538px;overflow:hidden;" class="mindivshow">
<table style="width:100%;" height="100%">
<tr valign="top">
<td height="100%" width="60" style="background:#1890ff;">
<div align="center" style="width:60px;overflow:hidden;">
<div style="margin-top:20px"><img title="{{$user['name']}}" onclick="reim.openmyinfo()" src="{{avatar($user['avatar'])}}" id="myface" style="border-radius:50%;" align="absmiddle" height="40" width="40">
</div>
<div style="margin-top:20px;">
<div class="cursor lefticons active" id="changetabs0" onclick="reim.changetabs(0)" title="消息">
<i class="fa fa-comments-o"></i>
<span id="chat_stotal" class="badge"></span>
</div>
</div>
<div style="margin-top:10px;">
<div class="cursor lefticons" id="changetabs1" onclick="reim.changetabs(1)" title="组织结构">
<i class="fa fa-sitemap"></i>
</div>
</div>
<div style="margin-top:10px;">
<div class="cursor lefticons" id="changetabs2" onclick="reim.changetabs(2)" title="应用">
<i class="fa fa-th-large"></i>
<span id="agenh_stotal" class="badge"></span>
</div>
</div>
</div>
</td>
<td width="220px" id="maincenter" style="background:#fff;border-right:1px solid #ddd">
<div class="chat_search">
<input id="reim_keysou" placeholder="搜索通讯录/会话/应用" class="msousou" />
<a class="plus" title="创建会话" onclick="reim.creategroup();">+</a>
</div>
<div id="centlist" style="height:300px;overflow:hidden;position:relative;">
<div id="centshow0">
<div id="historylist"></div>
<div id="historylist_tems" style="padding-top:150px;text-align:center;color:#ddd">
<span style="font-size:40px"><i class="fa fa-comment"></i></span><br>暂无消息
</div>
</div>
<div id="centshow1" style="display:none">
<div style="padding:5px;color:#aaaaaa;border-bottom:1px solid #f1f1f1">组织结构</div>
<div id="showdept"></div>
<div id="showgroup"></div>
<div align="center" style="padding:10px;"><a onclick="reim.initload(true)" style="font-size:12px;color:#bbbbbb" href="javascript:;"><i class="icon-refresh"></i> 刷新</a></div>
</div>
</div>
</td>
<td>
<div id="viewzhulist" style="height:300px;overflow:hidden;background:#f0f3f4;">
<div align="center" tabs="home" id="tabs_home" style="margin-top:100px;font-size:150px;color:#edf4fb">
<i class="fa fa-comment-o"></i>
</div>
</div>
</td>
</tr>
</table>
</div>
</body>
</html>
+347
View File
@@ -0,0 +1,347 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{{$setting['title']}}</title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection" content="telephone=no" />
<meta name="format-detection" content="email=no" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0" />
<link rel="stylesheet" type="text/css" href="{{$asset_url}}/chat/css/webimcss.css" />
<link rel="shortcut icon" id="icon_show" href="{{$asset_url}}/chat/images/web/logo.png" />
<script type="text/javascript" src="{{$asset_url}}/vendor/jquery.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/js/js.js"></script>
<script type="text/javascript" src="{{$asset_url}}/chat/js/nwjs.js"></script>
<style>
.lmaisft {
text-align: center;
-webkit-app-region: no-drag;
}
</style>
<script>
var temp_token = '';
var logifouct = false;
function initbody() {
js.xpbodysplit = 5;
nwjs.init();
resize();
$(window).resize(resize);
var face = js.getoption('loginface');
if (face) get('myface').src = face;
if (get('checkautologin')) {
get('checkautologin').checked = js.getoption('autologin') == '1';
form('adminuser').value = js.getoption('adminuser');
getpassobj().val(js.getoption('adminpass'));
autologin(3);
}
if (form('adminmobile')) form('adminmobile').value = js.getoption('adminmobile');
if (nwjsgui) {
$('#footerts').append('<a style="font-size:12px" onclick="return clearchater()" href="javascript:;">清缓存</a>');
}
// 禁止后退
try {
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function() {
history.pushState(null, null, document.URL);
});
} catch (e) {}
if (winWb() > 320) {
rewinheight(400, 300);
}
if (jisxobo()) {
js.xpbodysplit = 0;
get('mindivshowzhu').style.margin = '0px';
}
}
// 是不是xp和win7的版本
function jisxobo() {
var llq = navigator.userAgent.toLowerCase();
if (llq.indexOf('windows nt 5') > 0 || llq.indexOf('windows nt 6.1') > 0) {
return true;
}
return false;
}
function clearchater() {
nwjsgui.App.clearCache();
localStorage.clear();
var na = nwjsgui.App.manifest.name;
js.confirm('基本缓存已删除,更多缓存删除,是否打开对应[' + na + ']目录?需手动全部删除目录。', function(jg) {
if (jg == 'yes') {
var naea = nwjsgui.App.dataPath;
var oru = naea.split(na)[0] + na;
nwjsgui.Shell.openItem(oru);
nwjsgui.App.quit();
}
});
}
function autologin(ms) {
if (!logifouct && get('checkautologin') && get('checkautologin').checked && form('adminuser').value != '' && getpassobj().val()) {
form('submitbtn').value = ms + ' 秒后自动登录';
if (ms == 0) {
loginsubmit();
} else {
setTimeout('autologin(' + (ms - 1) + ')', 1000);
}
} else {
form('submitbtn').value = '登录';
}
}
function bodyunload() {
nwjs.removetray();
}
function resize() {
var tt = $(window).height() - $('.lmaisft').height();
var ts = (tt * 0.5) - 20;
if (ts < 10) ts = 10;
var lx1 = 0;
if (jisxobo()) lx1 = 10;
$('#mindivshow').css('height', (winHb() - 42 + lx1) + 'px');
}
var loginyzm = '';
function loginsubmit(lx) {
var ltype = form('logintype').value,
user = '',
pass = '';
if (ltype == '0') {
user = form('adminuser').value;
pass = getpassobj().val();
if (user == '') {
js.msg('msg', '用户名不能为空');
form('adminuser').focus();
return false;
}
if (pass == '') {
js.msg('msg', '密码不能为空');
getpassobj().focus();
return false;
}
} else {
user = form('adminmobile').value;
if (user == '') {
js.msg('msg', '手机号不能为空');
form('adminmobile').focus();
return false;
}
js.setoption('adminmobile', user);
loginyzm = form('adminmobileyzm').value;
if (loginyzm == '' || loginyzm.length != 6) {
js.msg('msg', '手机验证码格式不对');
form('adminmobileyzm').focus();
return false;
}
}
js.setoption('adminuser', user);
js.setoption('adminpass', pass);
var btnobj = form('submitbtn');
btnobj.value = '登录中...';
btnobj.disabled = true;
var data = {};
var base_url = "{{$public_url}}/";
data.device = device;
data.cfrom = 'reim';
data.ltype = ltype;
data.adminuser = user;
data.adminpass = pass;
data.yanzm = loginyzm;
js.bool = true;
loginyzm = '';
js.ajax(base_url + 'chat/chat/login', data, function(a) {
if (a.success) {
get('myface').src = a.face;
btnobj.value = '登录成功';
js.setoption('loginface', a.face);
var url = base_url + 'chat/chat/index';
loginsuccess(a);
js.location(url);
} else {
btnobj.value = '登录';
js.msg('msg', a.msg);
btnobj.disabled = false;
if (a.shouji) {
mobilejsho = a.mobile;
js.prompt('输入手机验证码', '手机号:' + a.shouji + '&nbsp;<span><a class="zhu" href="javascript:;" onclick="getcodes(this)">[获取验证码]</a></span>', function(jg, txt) {
if (jg == 'yes' && txt) {
loginyzm = txt;
loginsubmit();
}
});
}
}
}, 'post,json');
}
function loginsuccess(a) {
$('#mindivshows').hide();
if (nwjsgui) {
rewinheight(600, 900);
}
}
function getpassobj() {
return $('input[type=password]');
}
function changeauto(o) {
var oi = '0';
if (o.checked) oi = '1';
js.setoption('autologin', oi);
}
function winclose() {
nwjs.closebool = true;
nwjs.win.close();
}
function rewinheight(hei, wid) {
var l = (screen.width - wid) * 0.5;
var t = (screen.height - hei) * 0.5 - 20;
nwjs.win.moveTo(parseInt(l), parseInt(t));
nwjs.win.resizeTo(wid, hei);
}
function getcodes(o1) {
var da = {
'mobile': mobilejsho,
'device': device
};
var o2 = $(o1).parent();
o2.html(js.getmsg('获取中...'));
js.ajax('api.php?m=yanzm', da, function(a) {
if (a.success) {
o2.html(js.getmsg('获取成功', 'green'));
} else {
o2.html(js.getmsg(a.msg));
}
}, 'post,json');
}
// 获取验证码
function getyzm(o1) {
mobilejsho = form('adminmobile').value;
if (!mobilejsho) {
js.msg('msg', '请输入手机号');
form('adminmobile').focus();
return;
}
var da = {
'mobile': mobilejsho,
'device': device
};
o1.value = '获取中...';
js.setmsg();
o1.disabled = true;
js.ajax('api.php?m=yanzm&a=glogin', da, function(a) {
if (a.success) {
o1.value = '获取成功';
js.msg('success', '验证码已发送到手机上');
dshitime(60, o1);
} else {
o1.value = '重新获取';
o1.disabled = false;
js.msg('msg', a.msg);
}
}, 'post,json');
}
function dshitime(sj, o1) {
if (sj == 0) {
o1.disabled = false;
o1.value = '重新获取';
return;
}
o1.disabled = true;
o1.value = sj + '';
setTimeout(function() {
dshitime(sj - 1, o1)
}, 1000);
}
function changlogin() {
$('#loginview0').hide();
$('#loginview1').show();
form('logintype').value = '1';
}
</script>
</head>
<body style="overflow:hidden;">
<div id="mindivshowzhu" style="background:#f5f5f5;overflow:hidden;height:100vh;">
<div align="center" id="mindivshow" style="height:348px;overflow:hidden;margin-top:30px;">
<div id="mindivshows">
<div class="lmaisft">
<div id="topblank" style="height:5px;overflow:hidden"></div>
<div style="user-select:none;-webkit-user-select: none;" align="center"><img onclick="location.reload()" title="{{url()}}" src="{{$asset_url}}/chat/images/web/logo.png" id="myface" style="border-radius:50%;" align="absmiddle" height="80" width="80"></div>
<div class="blank10"></div>
<form style="padding:10px;" name="myform">
<div id="loginview0">
<div>
<div><input type="text" onfocus="logifouct=true" style="height:35px;width:190px;border-radius:5px" class="input" onKeyUp="if(event.keyCode==13)getpassobj().focus()" maxlength="20" placeholder="请输入用户名" id="adminuser" name="adminuser"></div>
</div>
<div class="blank20"></div>
<div>
<div><input onfocus="logifouct=true" style="height:35px;width:190px;border-radius:5px" class="input" onKeyUp="if(event.keyCode==13)loginsubmit(1)" value="" type="password" placeholder="请输入密码"></div>
</div>
<div class="blank10"></div>
<div align="center">
<div style="width:190px" align="left"><label><input onclick="changeauto(this)" id="checkautologin" type="checkbox">下次自动登录</label></div>
</div>
</div>
<div id="loginview1" style="display:none">
<input type="hidden" name="logintype" value="0">
<div>
<input type="text" style="height:35px;width:190px;border-radius:5px" class="input" onKeyUp="if(event.keyCode==13)get('adminmobileyzm').focus()" maxlength="11" name="adminmobile" placeholder="请输入手机号">
</div>
<div class="blank20"></div>
<div align="center">
<table>
<tr>
<td>
<input class="input" style="height:35px;width:100px;border-top-left-radius:5px;border-bottom-left-radius:5px" name="adminmobileyzm" id="adminmobileyzm" onKeyUp="if(event.keyCode==13)loginsubmit(1)" maxlength="6" placeholder="请输入验证码">
</td>
<td><input type="button" onclick="getyzm(this)" style="height:35px;width:90px;border-top-right-radius:5px;border-bottom-right-radius:5px" value="获取验证码" class="webbtn"></td>
</tr>
</table>
</div>
</div>
<div class="blank20"></div>
<div align="center">
<input type="button" id="btn0" style="height:35px;width:190px;border-radius:5px;font-size:16px" onClick="loginsubmit(1)" class="btn" name="submitbtn" value="登录">
</div>
<span id="msgview"></span>
</form>
</div>
<div align="center" id="footerts" style="color:#888888;font-size:12px"></div>
</div>
</div>
</div>
</body>
</html>