Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
李洋
/
消息系统
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
17da21a7
authored
Jun 03, 2019
by
孙龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
批量发送邮件短信
parent
075fab9f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
9 deletions
app/Http/Controllers/MessageApiController.php
resources/views/message/sendmanualmessage.blade.php
app/Http/Controllers/MessageApiController.php
View file @
17da21a7
...
@@ -546,7 +546,7 @@ class MessageApiController extends Controller
...
@@ -546,7 +546,7 @@ class MessageApiController extends Controller
$info
=
DB
::
connection
(
"message"
)
->
table
(
"lie_msg_tpl"
)
->
where
(
"tpl_id"
,
intval
(
$tp_id
))
->
select
(
"tpl_id"
,
"channels"
,
"description"
)
->
first
();
$info
=
DB
::
connection
(
"message"
)
->
table
(
"lie_msg_tpl"
)
->
where
(
"tpl_id"
,
intval
(
$tp_id
))
->
select
(
"tpl_id"
,
"channels"
,
"description"
)
->
first
();
if
(
!
$info
)
return
back
()
->
with
(
"error_batch_msg"
,
"没找到对应消息模板"
);
if
(
!
$info
)
return
back
()
->
with
(
"error_batch_msg"
,
"没找到对应消息模板"
);
if
(
count
(
explode
(
","
,
$info
->
channels
))
>
1
)
return
back
()
->
with
(
"error_batch_msg"
,
"暂只支持一种渠道消息,请完善模板消息后再来"
);
if
(
count
(
explode
(
","
,
$info
->
channels
))
>
1
)
return
back
()
->
with
(
"error_batch_msg"
,
"暂只支持一种渠道消息,请完善模板消息后再来"
);
if
(
$info
->
channels
!=
3
)
return
back
()
->
with
(
"error_batch_msg"
,
"暂只支持邮件
"
);
if
(
!
in_array
(
$info
->
channels
,[
2
,
3
]))
return
back
()
->
with
(
"error_batch_msg"
,
"暂支持单独发送邮件或短信
"
);
if
(
$file
){
if
(
$file
){
try
{
try
{
$excel_file_path
=
$file
->
getRealPath
();
$excel_file_path
=
$file
->
getRealPath
();
...
@@ -555,9 +555,13 @@ class MessageApiController extends Controller
...
@@ -555,9 +555,13 @@ class MessageApiController extends Controller
Excel
::
load
(
$excel_file_path
,
function
(
$reader
)
use
(
&
$res
,
&
$title
)
{
Excel
::
load
(
$excel_file_path
,
function
(
$reader
)
use
(
&
$res
,
&
$title
)
{
$reader
=
$reader
->
getSheet
(
0
);
$reader
=
$reader
->
getSheet
(
0
);
$res
=
$reader
->
toArray
();
$res
=
$reader
->
toArray
();
$title
=
$res
[
0
];
unset
(
$res
[
0
]);
},
'GBK'
);
},
'GBK'
);
$title
=
$res
[
0
];
unset
(
$res
[
0
]);
$title
=
array_filter
(
$title
,
function
(
$val
){
if
(
$val
)
return
true
;
});
$exchange
=
Config
(
"website.msg_exchange"
);
// 交换器,在我理解,如果两个队列使用一个交换器就代表着两个队列是同步的,这个队列里存在的消息,在另一个队列里也会存在
$exchange
=
Config
(
"website.msg_exchange"
);
// 交换器,在我理解,如果两个队列使用一个交换器就代表着两个队列是同步的,这个队列里存在的消息,在另一个队列里也会存在
$queue
=
Config
(
"website.msg_queue"
);
// 队列名称
$queue
=
Config
(
"website.msg_queue"
);
// 队列名称
$connection
=
new
AMQPStreamConnection
(
Config
(
"website.rabbitmq.host"
),
$connection
=
new
AMQPStreamConnection
(
Config
(
"website.rabbitmq.host"
),
...
@@ -568,19 +572,29 @@ class MessageApiController extends Controller
...
@@ -568,19 +572,29 @@ class MessageApiController extends Controller
$channel
->
queue_bind
(
$queue
,
$exchange
);
// 队列和交换器绑定
$channel
->
queue_bind
(
$queue
,
$exchange
);
// 队列和交换器绑定
$channel
->
tx_select
();
//开启事务
$channel
->
tx_select
();
//开启事务
foreach
(
$res
as
$key
=>
$val
){
foreach
(
$res
as
$key
=>
$val
){
//$val[0] 为接收者
if
(
!
$val
[
0
])
continue
;
$params
=
[];
$params
=
[];
$touser
=
$val
[
0
];
$touser
=
$val
[
0
];
unset
(
$val
[
0
]);
unset
(
$val
[
0
]);
foreach
(
$val
as
$kk
=>
$vv
){
//循环参数
$params
[
array_get
(
$title
,
$kk
)]
=
$vv
;
$_params
=
array_filter
(
$val
,
function
(
$_v
){
if
(
$_v
)
return
true
;
});
if
(
count
(
$_params
)
!=
count
(
$title
)
-
1
)
throw
new
\Exception
(
sprintf
(
"第%s行参数不一致"
,
$key
+
1
));
foreach
(
$_params
as
$kk
=>
$vv
){
if
(
!
$vv
)
break
;
$params
[
array_get
(
$title
,
$kk
)]
=
strval
(
$vv
);
}
}
if
(
!
$touser
)
throw
new
\Exception
(
'接收者不能为空'
);
if
(
count
(
$params
)
<=
0
)
throw
new
\Exception
(
'没找到对应参数'
);
$msg_arr
=
[];
$msg_arr
=
[];
$msg_arr
[
'job'
]
=
'msg.batch.send'
;
$msg_arr
[
'job'
]
=
'msg.batch.send'
;
$_data
[
'is_oversea'
]
=
false
;
$_data
[
'is_oversea'
]
=
false
;
$_data
[
'template_id'
]
=
$info
->
tpl_id
;
$_data
[
'template_id'
]
=
$info
->
tpl_id
;
$_data
[
'keyword'
]
=
$info
->
description
;
$_data
[
'keyword'
]
=
$info
->
description
;
$_data
[
'channel_type'
]
=
$info
->
channels
;
$_data
[
'channel_type'
]
=
$info
->
channels
;
$_data
[
'touser'
]
=
$touser
;
$_data
[
'touser'
]
=
strval
(
$touser
)
;
$_data
[
'data'
]
=
$params
;
$_data
[
'data'
]
=
$params
;
$_data
[
'url'
]
=
''
;
$_data
[
'url'
]
=
''
;
$_data
[
'wechat_data'
]
=
null
;
$_data
[
'wechat_data'
]
=
null
;
...
@@ -593,7 +607,6 @@ class MessageApiController extends Controller
...
@@ -593,7 +607,6 @@ class MessageApiController extends Controller
$_data
[
'rbmq'
]
=
[
$_data
[
'rbmq'
]
=
[
'expire_time'
=>
time
()
+
3600
*
2
'expire_time'
=>
time
()
+
3600
*
2
];
];
// dump($_data);
$msg_arr
[
'data'
]
=
json_encode
(
$_data
);
$msg_arr
[
'data'
]
=
json_encode
(
$_data
);
$msg
=
new
AMQPMessage
(
json_encode
(
$msg_arr
));
$msg
=
new
AMQPMessage
(
json_encode
(
$msg_arr
));
$channel
->
basic_publish
(
$msg
,
$exchange
);
$channel
->
basic_publish
(
$msg
,
$exchange
);
...
@@ -601,11 +614,12 @@ class MessageApiController extends Controller
...
@@ -601,11 +614,12 @@ class MessageApiController extends Controller
$channel
->
tx_commit
();
//提交事务
$channel
->
tx_commit
();
//提交事务
$channel
->
close
();
$channel
->
close
();
$connection
->
close
();
$connection
->
close
();
// exit;
return
back
()
->
with
(
"success_batch_msg"
,
"上传成功"
);
return
back
()
->
with
(
"success_batch_msg"
,
"上传成功"
);
}
catch
(
\Exception
$e
){
}
catch
(
\Exception
$e
){
dump
(
$e
->
getMessage
());
//
dump($e->getMessage());
$channel
->
tx_rollback
();
$channel
->
tx_rollback
();
return
back
()
->
with
(
"error_batch_msg"
,
"请选择对应消息模板"
);
return
back
()
->
with
(
"error_batch_msg"
,
$e
->
getMessage
()
);
}
}
}
}
...
...
resources/views/message/sendmanualmessage.blade.php
View file @
17da21a7
...
@@ -226,6 +226,7 @@
...
@@ -226,6 +226,7 @@
return
false
;
return
false
;
}
}
$
(
"#postForm"
).
submit
();
$
(
"#postForm"
).
submit
();
var
index
=
layer
.
load
(
0
,
{
shade
:
false
});
});
});
});
});
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment