yii2短信消息队列

105657_boTT_2854024.png

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">&times;</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-->

115353_oBRZ_2854024.png

转载于:https://my.oschina.net/botkenni/blog/876651

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值