您的位置:首页 > 编程语言 > PHP开发

yii2短信消息队列

2017-04-11 00:00 162 查看


1、在backend\config\params-local.php中加入

<?php
return [
'order_file_sms_id'  => '121313',
'order_file_sms_preview'  => '您的文件请及时下载,签字后邮寄到:{1},收件人:{2},电话:{3}',
'send_invoice_sms_id' => '323232',//模板id
'send_invoice_sms_preview' => '[掘金企服】尊敬的客户您好,您的发票已寄出,快递公司:{1},快递单号:{2},预计到达时间:{3},请注意查收!如需帮助,请拨打400-900-6969.',//模板内容
];

2、在backend\views\invoice-list\list.php中引入

<!--已寄送start-->
<div class="modal fade" id="send-invoice-modal" tabindex="-1" role="dialog" aria-labelledby="modal-title">
<div class="modal-dialog" role="document">
<div class="modal-content">
<?php
$sendInvoiceForm = new \backend\models\SendInvoiceForm();
$form = \yii\bootstrap\ActiveForm::begin([
'action' => ['invoice-action/send'],
'id' => 'send-invoice-form',
'validationUrl' => ['invoice-action/send', 'is_validate' => 1],
'enableAjaxValidation' => true,
'layout' => 'horizontal',
'fieldConfig' => [
'horizontalCssClasses' => [
'label' => 'col-sm-3',
'offset' => 'col-sm-offset-3',
'wrapper' => 'col-sm-8',
],
],
]);
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">×</span></button>
<h4 class="modal-title">已寄送</h4>
</div>
<div class="modal-body">
<?= $form->field($sendInvoiceForm, 'express')->textInput() ?>
<?= $form->field($sendInvoiceForm, 'express_no')->textInput() ?>
<?= $form->field($sendInvoiceForm, 'send_time')->widget(DateTimePicker::className(), [
'clientOptions' => [
'format' => 'yyyy-mm-dd',//显示的时间格式,年-月-日
'language' => 'zh-CN',
'autoclose' => true,
'minView' => 'month',//设置时间插件的显示格式,根据不同的参数显示,这里month只显示天

],
'clientEvents' => [],
]) ?>
//引入短信队列 id:send_invoice_sms_id,内容:send_invoice_sms_preview
                <?php if(isset(Yii::$app->params['send_invoice_sms_id']) && isset(Yii::$app->params['send_invoice_sms_preview'])): ?>
<h4>将给客户发送以下信息:</h4>
<p id="sms-preview">
<?= str_replace(['{1}','{2}','{3}'], [$sendInvoiceForm->express, $sendInvoiceForm->express_no,
$sendInvoiceForm->send_time], Yii::$app->params['send_invoice_sms_preview'])?>
</p>
<?php endif; ?>
</div>
<div class="modal-footer">
<?= Html::activeHiddenInput($sendInvoiceForm, 'id', ['id' => 'send-invoice-form_id']); ?>
<span class="text-danger warning-active"></span>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-primary refund-sure-btn">确定</button>
</div>
<?php \yii\bootstrap\ActiveForm::end(); ?>
<?php
//上面输入框输入内容替换短信部分,其中"\n", "\r", "\n\r"], 用''替换,$smsPreview = str_replace(["\n", "\r", "\n\r"], '', Yii::$app->params['send_invoice_sms_preview']);
$this->registerJs(<<<JS
//3个输入框,只要改动任何一个就替换掉内容
$('#express, #express_no, #send_time').change(function(){
replaceSmsPreview();
});
//替换部分
function replaceSmsPreview()
{
var smsPreview = '{$smsPreview}';//必须用单引号,而且写在外面,否则js不识别
var express = $('#express').val();
var express_no = $('#express_no').val();
var send_time = $('#send_time').val();
//替换
smsPreview = smsPreview.replace('{1}', express).replace('{2}', express_no).replace('{3}', send_time);
$('#sms-preview').text(smsPreview);
}
$('.send-invoice-btn').on('click', function(){
var id = $(this).attr('data-id');
$('#send-invoice-form_id').val(id);
});
$('#send-invoice-form').on('beforeSubmit', function(){
var form = $(this);
$.post(form.attr('action'), form.serialize(), function(rs){
if(rs.status === 200)
{
form.trigger('reset.yiiActiveForm');
window.location.reload();
}
else
{
form.find('.warning-active').text(rs.message);
}
}, 'json');
return false;
});
JS
)?>
</div>
</div>
</div>
<!--已寄送end-->


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息