Commit 81946166 by Joneq

系统公告开发-基本页面完成

parent c436018b
...@@ -112,6 +112,19 @@ class MessageApiController extends Controller ...@@ -112,6 +112,19 @@ class MessageApiController extends Controller
} }
} }
//发送公告信息
private function sendNotice($request)
{
$data = $request->all();
try{
(new SystemNoticeLogic())->sendNotice($data);
$this->Export(0, '操作成功');
}catch(\Exception $e){
$this->Export(400, $e->getMessage());
}
}
//删除消息模板 //删除消息模板
public function deletetemplate($request){ public function deletetemplate($request){
$data = $request->input(); $data = $request->input();
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Logic\SystemNoticeLogic;
use ClassPreloader\Config; use ClassPreloader\Config;
use function GuzzleHttp\Psr7\str; use function GuzzleHttp\Psr7\str;
use Illuminate\Http\Request; use Illuminate\Http\Request;
...@@ -693,6 +694,7 @@ class MessageController extends Controller ...@@ -693,6 +694,7 @@ class MessageController extends Controller
{ {
$data=[ $data=[
'id'=>$id, 'id'=>$id,
'user'=>SystemNoticeLogic::getAllUser()
]; ];
return view('common', $data); return view('common', $data);
} }
...@@ -702,6 +704,7 @@ class MessageController extends Controller ...@@ -702,6 +704,7 @@ class MessageController extends Controller
{ {
$data=[ $data=[
'id'=>$id, 'id'=>$id,
'user'=>SystemNoticeLogic::getAllUser()
]; ];
return view('common', $data); return view('common', $data);
} }
......
<?php
/**
* Created by 2022/12/3.
* User: Jone
* Info: 2022/12/3
* Time: 下午3:52
*/
namespace App\Http\Controllers;
use App\Logic\SystemNoticeLogic;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
//TODO 上线之后去除注释这个notice ,5。0版本的缺陷 https://blog.csdn.net/weixin_44251615/article/details/93710829
ini_set("error_reporting","E_ALL & ~E_NOTICE");
class NoticeController extends Controller
{
public function getNotice(Request $request)
{
$data = $request->all();
try{
(new SystemNoticeLogic())->getRabbitMq($data);
$this->Export(0, '操作成功');
}catch(\Exception $e){
$this->Export(400, $e->getMessage());
}
}
private function Export($errcode=0,$errmsg='成功',$data=''){
echo json_encode(['errcode'=>$errcode,'errmsg'=>$errmsg,'data'=>$data]);
exit();
}
}
\ No newline at end of file
...@@ -81,6 +81,9 @@ Route::group(['middleware' => 'web'], function () { ...@@ -81,6 +81,9 @@ Route::group(['middleware' => 'web'], function () {
Route::resource('batchapi', 'BatchapiController'); Route::resource('batchapi', 'BatchapiController');
Route::get ('/notice/getNotice','NoticeController@getNotice');
Route::group(['middleware' => 'webapi'], function () { Route::group(['middleware' => 'webapi'], function () {
Route::match(['get', 'post'],'/webapi/{key}', 'WebApiController@Entrance'); Route::match(['get', 'post'],'/webapi/{key}', 'WebApiController@Entrance');
}); });
\ No newline at end of file
<?php
/**
* Created by 2022/12/3.
* User: Jone
* Info: 2022/12/3
* Time: 下午4:08
*/
namespace App\Logic;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
class MqLogic
{
public function pushAmq($exchange, $route_key, $queue_name, $content='')
{
$connection = new AMQPStreamConnection(env('RABBITMQ_HOST'), env('RABBITMQ_PORT'), env('RABBITMQ_LOGIN'), env('RABBITMQ_PASSWORD'), env('RABBITMQ_VHOST')); // 创建连接
$channel = $connection->channel();
$channel->exchange_declare($exchange, 'direct', false, true, false); // 初始化交换机
$channel->queue_declare($queue_name, false, true, false, false); // 初始化队列
$channel->queue_bind($queue_name, $exchange, $route_key); // 将队列与某个交换机进行绑定,并使用路由关键字
$message = new AMQPMessage($content);
$channel->basic_publish($message, '', $queue_name); // 推送消息
$channel->close();
$connection->close();
}
public function pullAmq($queue_name='')
{
$connection = new AMQPStreamConnection(env('RABBITMQ_HOST'), env('RABBITMQ_PORT'), env('RABBITMQ_LOGIN'), env('RABBITMQ_PASSWORD'), env('RABBITMQ_VHOST')); // 创建连接
$channel = $connection->channel();
$message = $channel->basic_get($queue_name); // 取出消息
$channel->basic_ack($message->delivery_info['delivery_tag']); // 确认取出消息后会发送一个ack来确认取出来了,然后会从rabbitmq中将这个消息移除,如果删掉这段代码,会发现rabbitmq中的消息还是没有减少
$channel->close();
$connection->close();
return $message;
}
}
\ No newline at end of file
...@@ -13,6 +13,7 @@ use App\Model\SystemBulletinModel; ...@@ -13,6 +13,7 @@ use App\Model\SystemBulletinModel;
use App\Model\SystemPreachModel; use App\Model\SystemPreachModel;
use App\Model\SystemUpdateModel; use App\Model\SystemUpdateModel;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Mail;
//TODO 上线之后去除注释这个notice ,5。0版本的缺陷 https://blog.csdn.net/weixin_44251615/article/details/93710829 //TODO 上线之后去除注释这个notice ,5。0版本的缺陷 https://blog.csdn.net/weixin_44251615/article/details/93710829
ini_set("error_reporting","E_ALL & ~E_NOTICE"); ini_set("error_reporting","E_ALL & ~E_NOTICE");
...@@ -134,6 +135,80 @@ class SystemNoticeLogic ...@@ -134,6 +135,80 @@ class SystemNoticeLogic
} }
//发送通知
//两种类型,邮件和生成队列信息
public function sendNotice($data)
{
if (!isset($data['notice_type']) || empty($data['notice_type'])){
throw new \Exception('请至少选择一个发送选项');
}
// notice_type 1 是邮件,2是系统内的通知,用rabbitmq推送
$sendData['user'] = [];
$sendData['title'] = '';
$sendData['content'] = '';
$time = date('Y-m-d');
if ($data['type'] == 'system_update'){
$sendInfo = (new SystemUpdateModel())->where('smue_id',$data['id'])->first();
$sendData['user'] = DB::table('t_user_perm')->where('begDate','<=',$time)
->where('endDate','>=',$time)
->where('bid',$sendInfo->system_id)
->pluck('username');
$sendData['title'] = $sendInfo->update_title;
$sendData['content'] = $sendInfo->update_content;
}else if ($data['type'] == 'system_preach'){
}else{
}
foreach ($data['notice_type'] as $value){
if (intval($value) === 1){
$this->sendEmail($sendData);
}else{
//rabbitmq 方法不行
//$this->sendRabbitmq($sendData);
}
}
}
//发送邮件
//user 用户数组,title 标题,content 内容
public function sendEmail($sendData)
{
$sendData['user'] = ['gy@ichunt.com'];
Mail::send('emails.default', ["sendData"=>$sendData], function ($m) use($sendData) {
$m->from(env('MAIL_USERNAME'), $sendData['title']);
$m->to($sendData['user']);
$m->subject($sendData['title']);
});
}
//生成rabbitmq信息
public function sendRabbitmq($sendData)
{
$mqLogic = new MqLogic();
$routeKey = 'ichunt_system_notice_route_key';
$queueName = 'ichunt_system_notice_queue_name';
$sendData = ['user_id'=>1,'content'=>'abc'];
$mqLogic->pushAmq('ichunt_system_notice', $routeKey, $queueName, json_encode($sendData));
}
public function getRabbitMq($requestData)
{
$mqLogic = new MqLogic();
dd($mqLogic->pullAmq('ichunt_system_notice_queue_name'));
}
static public function getAllSystemSelect() static public function getAllSystemSelect()
{ {
...@@ -145,11 +220,16 @@ class SystemNoticeLogic ...@@ -145,11 +220,16 @@ class SystemNoticeLogic
return DB::table('user_department')->orderBy('department_id','desc')->pluck('department_name','department_id'); return DB::table('user_department')->orderBy('department_id','desc')->pluck('department_name','department_id');
} }
static public function getAllUser()
{
return DB::table('user_info')->orderBy('userId','desc')->pluck('name','name');
}
static public function setSystemInfo($data) static public function setSystemInfo($data)
{ {
$systemInfo = DB::table('t_business_config')->where('bid',$data['system_id'])->first(); $systemInfo = DB::table('t_business_config')->where('bid',$data['system_id'])->first();
$data['system_name'] = $systemInfo->title; $data['system_name'] = $systemInfo->title;
$data['system_url'] = $systemInfo->url; $data['system_url'] = parse_url($systemInfo->url)['host'];
return $data; return $data;
} }
......
layui.use(['layer'], function(){
var $ = layui.$;
var layer = layui.layer;
function getNotice(){
var uid = getcookie('oa_user_id');
var host = window.location.host;
var requestUrl = '';
//测试的是liexindev.net 正式的是ichunt.net
if (host.indexOf('ichunt.net') != -1) {
requestUrl = 'http://message.ichunt.net/notice/getNotice'
}else{
requestUrl = 'http://message.liexin.net/notice/getNotice'
}
layer.alert();
$.ajax({
url: requestUrl,
type: 'get',
data: {user_id:uid,host:host},
dataType:'json',
success: function (resp) {
if (resp.errcode == 0) {
layer.msg(resp.errmsg);
return false;
}
layer.msg(resp.errmsg);
},
error: function (err) {
console.log(err)
}
});
}
function getcookie(objname){//获取指定名称的cookie的值
var arrstr = document.cookie.split("; ");
for(var i = 0;i < arrstr.length;i ++){
var temp = arrstr[i].split("=");
if(temp[0] == objname) return unescape(temp[1]);
}
}
});
...@@ -133,6 +133,55 @@ layui.use(['jquery','element', 'layer', 'form','table','laypage','laydate'], fun ...@@ -133,6 +133,55 @@ layui.use(['jquery','element', 'layer', 'form','table','laypage','laydate'], fun
$(document).on('click', '.sendNotice', function () {
$("#id").val($(this).data('id'));
layer.open({
area: ['400px', '200px'],
title: '保存数据',
type: 1,
content: $("#notice_form_show"),
btn: ['确认发送', '取消'],
offset:['30px','300px'],
yes: function (index) {
$("#notice_form_click").click();
},
cancel: function (index) {
layer.close(index);
}
});
});
form.on('submit(notice_form)', function (data) {
data.field.id = $("#id").val();
data.field.type = 'system_update';
$.ajax({
url: '/msgapi/sendNotice',
type: 'post',
data: data.field,
dataType:'json',
success: function (resp) {
if (resp.errcode == 0) {
layer.msg(resp.errmsg);
window.location.reload();
return false;
}
layer.msg(resp.errmsg);
},
error: function (err) {
console.log(err)
}
});
return false;
});
}); });
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
<script src="/js/Message/common.min.js"></script> <script src="/js/Message/common.min.js"></script>
@if(empty($into)) @if(empty($into))
<script src="/js/Message/{{$id}}.js"></script> <script src="/js/Message/{{$id}}.js"></script>
<script src="/js/Message/getNotice.js"></script>
@endif @endif
</body> </body>
</html> </html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ $sendData['title'] }}</title>
<link href="/js/Message/layui/css/layui.css" rel="stylesheet">
</head>
<body>
<div class="layui-card">
<div class="layui-card-header">{{$sendData['title']}}</div>
<div class="layui-card-body">
{{$sendData['content']}}
</div>
</div>
</body>
</html>
...@@ -138,7 +138,14 @@ ...@@ -138,7 +138,14 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">宣讲人</label> <label class="layui-form-label">宣讲人</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input type="text" name="preach_user" placeholder="填写宣讲人" autocomplete="off" class="layui-input" lay-verify="required"> <select name="preach_user" lay-search lay-verify="required">
<option value=""></option>
@foreach($user as $key=>$value)
<option value="{{$key}}">{{$value}}</option>
@endforeach
</select>
</div> </div>
</div> </div>
......
...@@ -94,9 +94,40 @@ ...@@ -94,9 +94,40 @@
<script type="text/html" id="active"> <script type="text/html" id="active">
<a class="layui-btn layui-btn-xs layui-btn-normal editData" data-json='@{{d.data_json}}' ><strong>编辑</strong></a> <a class="layui-btn layui-btn-xs layui-btn-normal editData" data-json='@{{d.data_json}}' ><strong>编辑</strong></a>
<a class="layui-btn layui-btn-xs layui-btn-normal " ><strong>立即发送</strong></a> <a class="layui-btn layui-btn-xs layui-btn-normal sendNotice" data-id='@{{d.smue_id}}' ><strong>立即发送</strong></a>
</script> </script>
{{--发送信息--}}
<div id="notice_form_show" style="display: none;margin-top: 30px;">
<style>
.fgh .layui-form-label{position: relative;top:5px;width: 100px;}
</style>
<form class="layui-form fgh" >
<div class="layui-form-item">
<div class="layui-inline ">
<label class="layui-form-label">更新时间:</label>
<div class="layui-input-inline">
<input type="checkbox" class="layui-input" lay-verify="required" name="notice_type[]" value="1" title="邮件" >
<input type="checkbox" class="layui-input" lay-verify="required" name="notice_type[]" value="2" title="通知" >
</div>
</div>
</div>
<input type="hidden" id="id" value="0">
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" style="display: none;" id="notice_form_click" lay-filter="notice_form" lay-submit >提交</button>
</div>
</div>
</form>
</div>
{{--新增数据--}} {{--新增数据--}}
<div id="save_form_show" style="display: none;margin-top: 30px;"> <div id="save_form_show" style="display: none;margin-top: 30px;">
<style> <style>
...@@ -170,22 +201,40 @@ ...@@ -170,22 +201,40 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">产品负责人</label> <label class="layui-form-label">产品负责人</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input type="text" name="product_user" lay-filter="product_user" placeholder="填写产品负责人" autocomplete="off" class="layui-input" lay-verify="required"> <select name="product_user" lay-search lay-verify="required">
<option value=""></option>
@foreach($user as $key=>$value)
<option value="{{$key}}">{{$value}}</option>
@endforeach
</select>
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">技术负责人</label> <label class="layui-form-label">技术负责人</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input type="text" name="code_user" lay-filter="code_user" placeholder="填写技术负责人" autocomplete="off" class="layui-input" lay-verify="required"> <select name="code_user" lay-search lay-verify="required">
<option value=""></option>
@foreach($user as $key=>$value)
<option value="{{$key}}">{{$value}}</option>
@endforeach
</select>
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">测试负责人</label> <label class="layui-form-label">测试负责人</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input type="text" name="test_user" lay-filter="test_user" placeholder="填写测试负责人" autocomplete="off" class="layui-input" lay-verify="required"> <option value=""></option>
<select name="test_user" lay-search lay-verify="required">
@foreach($user as $key=>$value)
<option value="{{$key}}">{{$value}}</option>
@endforeach
</select>
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment