chenhao 4 年之前
父节点
当前提交
1d6cdfa404

+ 5 - 10
application/admin/controller/EmailSend.php

@@ -420,22 +420,17 @@ class EmailSend extends Base
         return $this->fetch('draft');
     }
     /**
-     * 编辑发邮件
+     * 查看草稿箱
      */
     public function editEmail()
     {
-
-
-        $uni = input('uni');
-        $templateId = Db::name('email_send')->where('uni',$uni)->find();
+        $id = input('id');
         $template = Db::name('email_template')
-            ->where('id',$templateId['theme_id'])
+            ->where('id',$id)
             ->find();
-        $formId = Db::name('email_send')->where('uni',$uni)->group('email_id')->column('email_id');
-        $toId = Db::name('email_send')->where('uni',$uni)->group('customer_id')->column('customer_id');
         $this->assign('template',$template);
-        $this->assign('form_id',$formId);
-        $this->assign('to_id',$toId);
+        $this->assign('form_id',explode(',',$template['form']));
+        $this->assign('to_id',explode(',',$template['to']));
 
         $customer = Db::name('customer')->where('spread_id', session('uid'))->where('status','in','0,1,2')->field('id,email,name')->select();
         $this->assign('customer',$customer);

+ 32 - 0
application/admin/controller/EmailTemplate.php

@@ -108,5 +108,37 @@ class EmailTemplate extends Base
         return json(['code' => $flag['code'], 'msg' => $flag['msg']]);
     }
 
+    public function draft_index()
+    {
+        if (request()->isAjax()) {
+            extract(input());
+            $map = [];
+
+            if (isset($email) && $email != "") {
+                $map['email'] = ['like', "%" . $email . "%"];
+            }
+            $map['is_deleted'] = 0;
+            $map['type'] = 2;
+            $map['spread_id']=session('uid');
+
+            $Nowpage = input('page') ? input('page') : 1;
+            $limits = input("limit") ? input("limit") : 10;//获取总条数;
+            $field = input('field');//字段
+            $order = input('order');//排序方式
+            if ($field && $order) {
+                $od = $field . " " . $order;
+            } else {
+                $od = "create_time desc";
+            }
+            $emails =new EmailTemplateModel();
+
+            $count = $emails->getCount($map);
+            $lists = $emails->getByWhere($map, $od, $Nowpage, $limits);
+            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
+        }
+
+        $this->assign('status', 100);
+        return $this->fetch('draft_index');
+    }
 
 }

+ 5 - 3
application/admin/view/email_send/draft.html

@@ -72,6 +72,8 @@
 
                             <div class="layui-input-inline" id="LAY_editor" lay-verify="editor" style="width: 100%;"></div>
                             <input type="hidden"  value="{$templateId.content}" id="contents">
+                            <input type="hidden"  value="{$template.id}" id="themeid">
+                            <input type="hidden"  value="{$template.theme}" id="themes">
                         </div>
 
                     </div>
@@ -86,8 +88,8 @@
 {include file="public/footer" /}
 <script>
     var editor = wk.wang({elem:'#LAY_editor'});
-    var theme=0;
-    var theme_content='';
+    var theme=$('#themeid').val();
+    var theme_content=$('#themes').val();
     var contents = $('#contents').val()
     editor.txt.html(contents)
 
@@ -106,7 +108,7 @@
         form.on('submit(component-form-element)', function (data) {
             // $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
             var loading = layer.load(3,{time:20*1000});
-            console.log(data.field);
+            console.log(data);
 
             if(data.field.send_type==1){
                 layer.close(loading);

+ 269 - 0
application/admin/view/email_send/edit_email.html

@@ -0,0 +1,269 @@
+{include file="public/header" /}
+<body>
+<div class="layui-fluid">
+    <div class="layui-row layui-col-space15">
+        <div class="layui-col-md12">
+            <div class="layui-card">
+
+
+                <div class="layui-card-body">
+                    <div class="layui-form layui-form-pane">
+                        <div class="layui-form-item">
+<!--                            <button  class="layui-btn layui-btn-normal" style="margin: 0 10px;" onclick="save_teplate(2)">存草稿</button>-->
+                            <!--                            <button  class="layui-btn  layui-btn-normal" style="margin: 0 10px;" onclick="save_teplate(1)">存为模版</button>-->
+                            <!--                            <div class="layui-form-item">-->
+                            <!--                                <div class="layui-input-block">-->
+                            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="component-form-element" >点击发送
+                            </button>
+                            <!--                                </div>-->
+                            <!--                            </div>-->
+
+                            <div class="layui-input-inline" style="width: 520px;float: none;margin-right: 0px;">
+                                <label class="layui-form-label" style="background: none;border: 0px;">发送时间设置:</label>
+                                <input type="radio" name="send_type" value="0" title="立即" checked="" style="margin-left: 10px;">
+                                <input type="radio" name="send_type" value="1" title="定时批量发送开始时间" style="margin-left: 50px;">
+                            </div>
+
+                            <div class="layui-input-inline" style="float: none;">
+                                <input type="text" name="send_time" id="date"  placeholder="请选择时间" autocomplete="off" class="layui-input" style="height: 26px;margin-left: -100px">
+                            </div>
+
+                        </div>
+                        <hr>
+
+                        <div class="layui-form-item">
+                            <label class="layui-form-label">发件人</label>
+                            <div class="layui-input-block" style="width: 300px;">
+                                <select name="email_id" lay-verify="required" lay-filter="" xm-select="form" id = 'form'>
+                                    <option ></option>
+                                    {foreach name="emails" item="v"}
+                                    <option value="{$v.id}" {foreach name="form_id" item="form"}{if $v.id == $form} selected {/if} {/foreach}>{$v.email}</option>
+                                    {/foreach}
+                                </select>
+                            </div>
+                        </div>
+
+                        <div class="layui-form-item">
+                            <label class="layui-form-label">收件人</label>
+                            <div class="layui-input-inline" style="width: 300px;">
+                                <!--                                <input type="text" name="to" value="" class="layui-input" id="shoujian" lay-verify="required" placeholder="多个邮箱请用&符号隔开">-->
+                                <select name="to" lay-verify="required" lay-filter="" xm-select="to" id="to">
+                                    <option ></option>
+                                    {foreach name="customer" item="v"}
+                                    <option value="{$v.id}" {foreach name="to_id" item="to"} {if $v.id == $to} selected {/if} {/foreach} > {$v.email}</option>
+                                    {/foreach}
+                                </select>
+                            </div>
+                        </div>
+
+                        <div class="layui-form-item">
+                            <label class="layui-form-label">主题</label>
+                            <div class="layui-input-block" style="width: 300px;">
+                                <select name="theme" lay-verify="required" lay-filter="theme" id="theme">
+                                    <option value="{$template.id}">{$template.theme}</option>
+                                    {foreach name="templates" item="vv"}
+                                    <option value="{$vv.id}"  >{$vv.theme}</option>
+                                    {/foreach}
+                                </select>
+                            </div>
+                        </div>
+
+                        <div class="layui-form-item">
+
+                            <div class="layui-input-inline" id="LAY_editor" lay-verify="editor" style="width: 100%;"></div>
+                            <input type="hidden"  value="{$template.content}" id="contents">
+                        </div>
+
+                    </div>
+
+                </div>
+            </div>
+        </div>
+
+
+    </div>
+</div>
+{include file="public/footer" /}
+<script>
+    var editor = wk.wang({elem:'#LAY_editor'});
+    var theme=0;
+    var theme_content='';
+    var contents = $('#contents').val()
+    editor.txt.html(contents)
+
+    layui.use(['form','laydate'],function () {
+
+        laydate = layui.laydate;
+        //日期
+        laydate.render({
+            elem: '#date'
+            ,type: 'datetime'
+            ,theme: '#0080F6'
+        });
+        var form = layui.form
+
+
+        form.on('submit(component-form-element)', function (data) {
+            // $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
+            var loading = layer.load(3,{time:20*1000});
+            console.log(data.field);
+
+            if(data.field.send_type==1){
+                layer.close(loading);
+                if(!data.field.send_time){
+                    wk.msg('请先填写发送时间');
+                    return false;
+                }
+            }
+
+            if(data.field.email_id==0){
+                layer.close(loading);
+                wk.msg('请先选择发件人');
+                return false;
+            }
+
+            if(data.field.to=='' || !data.field.to){
+                layer.close(loading);
+                wk.msg('请先输入收件人邮箱');
+                return false;
+            }
+
+            if(data.field.theme==0 ){
+                layer.close(loading);
+                wk.msg('请先选择邮件主题');
+                return false;
+            }
+
+            if(editor.txt.html()=='' || !editor.txt.html()){
+                layer.close(loading);
+                wk.msg('请先填写邮件内容');
+                return false;
+            }
+
+            data.field.content=editor.txt.html()
+
+
+            $.ajax({
+                url:"{:url('add')}",
+                type:'post',
+                dataType:'json',
+                data:data.field,
+                timeout : 20000,
+                success:function(res){
+                    console.log(res);
+                    if (res.code == 200) {
+                        layer.close(loading);
+                        wk.success(res.msg,'$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\')');
+                    } else {
+                        layer.close(loading);
+                        wk.error(res.msg);
+                    }
+                },error:function () {
+                    layer.close(loading);
+                }
+            })
+        })
+
+        form.on('select(theme)', function(data){
+            if(data.value=='' || !data.value){
+                editor.txt.html('')
+                theme = 0
+                return false
+            }else{
+                theme = data.value
+
+
+            }
+            $.ajax({
+                url:"{:url('email_template_info')}",
+                type:'post',
+                dataType:'json',
+                data:{'id':data.value},
+                success:function(res){
+                    console.log(res)
+                    if (res.code == 200) {
+                        editor.txt.html(res.data.content)
+                        theme_content= res.data.theme;
+                    }
+                }
+            })
+        })
+
+    })
+
+    /*
+     *保存模版
+     */
+    function save_teplate(type){
+        var form = JSON.stringify(layui.formSelects.value('form', 'val'));//取值name数组
+        var to = JSON.stringify(layui.formSelects.value('to', 'val'));//取值name数组
+        new_id=0;
+        if(theme==0){
+            wk.error('请先选择主题');
+            return false;
+        }
+        $.ajax({
+            url:"{:url('EmailSend/editDraft')}",
+            type:'post',
+            dataType:'json',
+            data:{'theme':theme_content,'content': editor.txt.html(),'type':type,'form':form,to:to},
+            success:function(res){
+                if (res.code == 200) {
+                    select_(res.res)
+
+                    //wk.success(res.msg);
+                } else {
+                    wk.error(res.msg);
+                }
+            }
+        })
+    }
+
+    function select_(res){
+
+        if(res.type==1){
+            var html='<option value='+res.id+' selected>'+res.theme+'</option>';
+            $('#theme').append(html)
+            renderForm();
+        }
+
+        wk.success('保存成功');
+
+
+
+    }
+
+    function renderForm() {
+        layui.use('form', function () {
+            var form = layui.form;//高版本建议把括号去掉,有的低版本,需要加()
+            form.render();
+        });
+    }
+
+    /*
+     *保存草稿
+     */
+    function caogao(){
+        // alert(111)
+        if(theme==0){
+            wk.error('请先选择主题');
+            return false;
+        }
+
+        $.ajax({
+            url:"{:url('EmailTemplate/add')}",
+            type:'post',
+            dataType:'json',
+            data:{'theme':theme_content,'content': editor.txt.html()},
+            success:function(res){
+                if (res.code == 200) {
+                    wk.success(res.msg);
+                } else {
+                    wk.error(res.msg);
+                }
+            }
+        })
+    }
+</script>
+</body>
+</html>

+ 212 - 0
application/admin/view/email_template/draft_index.html

@@ -0,0 +1,212 @@
+{include file="public/header" /}
+<body>
+<div class="layui-fluid">
+    <div class="layui-card">
+        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
+            <!-- <form onsubmit="return false;">
+                 <div class="layui-form-item">
+                     <div class="layui-inline">
+                         <div class="layui-input-inline">
+                             <input type="text" id="email" class="layui-input" name="email" placeholder="输入邮箱"/>
+                         </div>
+                     </div>
+                     <div class="layui-inline">
+                         <div class="layui-input-inline">
+                             <button class="layui-btn" id="btn-search">立即搜索</button>
+                             <button type="reset" class="layui-btn layui-btn-normal" >重置</button>
+                         </div>
+                     </div>
+                 </div>
+             </form>-->
+            <div>
+<!--                <button class="layui-btn layui-btn-normal" data-type="add" onclick="wk.layer_show('','{:url('add')}')">-->
+<!--                    <i class="fa fa-plus"></i> 新建-->
+<!--                </button>-->
+                <button class="layui-btn layui-btn-normal  layuiBtn " data-type="getCheckData" >
+                    <i class="fa fa-trash-o"></i> 删除
+                </button>
+            </div>
+        </div>
+
+
+
+        <div class="layui-card-body">
+            <table id="LAY-table-manage" lay-filter="LAY-table-manage"></table>
+            <!--类型模板-->
+            <script type="text/html" id="typeTpl">
+                {{# if(d.type == 1){ }}
+                菜单
+                {{# }else{ }}
+                按钮
+                {{# } }}
+            </script>
+            <!--状态模板-->
+            <script type="text/html" id="staBar">
+                <input type="checkbox" value="{{d.id}}"  lay-skin="switch"  lay-text="ON|OFF" lay-filter="OnOff"{{ d.status == 1 ? 'checked' : '' }}  >
+            </script>
+            <!--操作模板-->
+        </div>
+        <script type="text/html" id="opeBar">
+            <a class="layui-btn layui-btn-xs layui-btn-normal" title="编辑" onclick="wk.layer_show('','{:url('EmailSend/editEmail')}?id={{d.id}}')">查看</a>
+            <!--<a class="layui-btn layui-btn-danger layui-btn-xs" id="del_{{d.id}}" title="删除" onclick="del_menu(this,{{d.id}})"><i class="fa fa-trash-o"></i></a>-->
+        </script>
+    </div>
+</div>
+{include file="public/footer" /}
+<script>
+    layui.use(['index', 'table','util'], function () {
+        var $ = layui.$
+            , form = layui.form
+            , table = layui.table
+            , util = layui.util
+        //固定块
+        util.fixbar({
+            css: {right: 20, bottom: 50}
+            ,bgcolor: '#393D49'
+        });
+        table.render({
+            elem: '#LAY-table-manage'
+            , url: '{:url("EmailTemplate/draft_index")}'
+            ,response: {
+                statusCode: 220 //成功的状态码,默认:0
+            }
+            , page: false
+            , even: false //开启隔行背景
+            , size: 'lg' //sm小尺寸的表格 lg大尺寸
+            // ,width:100
+            , autoSort: false
+            , cellMinWidth: 150
+            // , height: "full-220"
+            , limits: []
+            , limit: 1000
+            , loading: true
+            , id: 'LAY-table'
+            , cols: [[
+                {type: 'checkbox', fixed: 'left',}
+                , {type:'numbers', width: 80, title: '序号',align: 'center',}
+                , {field: 'theme', width: '' ,title: '主题', align: 'center',}
+                , {field: 'content', width: '', title: '内容', align: 'center',}
+                , {field: 'create_time', width: '', title: '创建时间', align: 'center',}
+                , {fixed: 'right', width: 140, title: '操作', align: 'center', toolbar: '#opeBar'}
+            ]]
+            ,done: function (res, curr, count) {
+                $('th').children().prop('align','center');
+            }
+        });
+        //监听状态开关操作
+        form.on('switch(OnOff)', function (obj) {
+            var num = '';
+            obj.elem.checked == true? num = 1: num = 2;
+            //菜单状态
+            wk.status(this.value,num, '{:url("rule_state")}',obj);
+        });
+
+        //监听单元格编辑
+        table.on('edit(LAY-table-manage)', function(obj){
+            var value = obj.value //得到修改后的值
+                ,data = obj.data //得到所在行所有键值
+                ,field = obj.field; //得到字段
+            // layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为:'+ value);
+            if(field == 'sort'){
+                if(!/^(0|[1-9]\d*)$/.test(value)){
+                    layer.msg('排序值只能为非负整数',{icon:2,time:1500,shade: 0.1},function(){
+                        //重载当前页表格
+                        $(".layui-laypage-btn").click();
+                    });
+                    return false;
+                }
+            }
+            wk.change(data.id,"{:url('editField')}",field,value,'auth_rule');
+        });
+
+        //事件
+        var active = {
+            getCheckData: function(){
+                //批量删除
+                layer.confirm('确认删除吗?', {icon: 7, title:'警告'}, function(index){
+                    $.ajax({
+                        url: "{:url('batchDelUser')}",
+                        type: "post",
+                        dataType: "json",
+                        data: 'ids='+getIds(),
+                        success: function (res) {
+                            if (res.code == 200) {
+                                // layer.msg(res.msg, {icon: 1, time: 1500, shade: 0.1},function(index){
+                                //     layer.close(index);
+                                //     if (res.data != "") {
+                                //         var num = res.data.split(',');
+                                //         $.each(num, function (index, item) {
+                                //             $('#del_' + item).parents("tr").remove();
+                                //         })
+                                //     }
+                                //     layui.table.reload('LAY-table');
+                                // });
+                                wk.success(res.msg,"layui.table.reload('LAY-table');")
+                            } else if (res.code == 100) {
+                                wk.error(res.msg,"layui.table.reload('LAY-table');");
+                            }
+                        }
+                    });
+                    layer.close(index);
+                })
+            }
+        };
+
+        $('.layuiBtn').on('click', function () {
+            var type = $(this).data('type');
+            active[type] ? active[type].call(this) : '';
+        });
+        var getIds = function () {
+            var ids = [];
+            var checkStatus = table.checkStatus('LAY-table')
+                ,data = checkStatus.data;
+            $.each(data,function(index,item){
+                ids.push(item['id'])
+            });
+            return ids;
+        }
+    });
+
+    /**
+     * [del_menu 删除菜单]
+     */
+    function del_menu(obj,id){
+
+        layer.confirm('确认删除吗?', {icon: 7, title:'警告'}, function(index){
+            //do something
+            $.getJSON('{:url("del")}', {'id' : id}, function(res){
+                if(res.code == 200){
+
+                    wk.success(res.msg,"layui.table.reload('LAY-table');")
+                }else if(res.code == 100){
+                    wk.error(res.msg,"layui.table.reload('LAY-table');");
+                }
+            });
+            layer.close(index);
+        })
+    }
+    // 模糊搜索表格
+    $('#btn-search').click(function () {
+        var keyword = $('#email').val();
+        var searchCount = 0;
+        $('#LAY-table-manage').next('.layui-table-view').find('.layui-table-body tbody tr td').each(function () {
+            $(this).css('background-color', 'transparent');
+            var text = $(this).text();
+            if (keyword != '' && text.indexOf(keyword) >= 0) {
+                $(this).css('background-color', 'rgba(250,230,160,0.5)');
+                if (searchCount == 0) {
+                    $('html,body').stop(true);
+                    $('html,body').animate({scrollTop: $(this).offset().top - 150}, 500);
+                }
+                searchCount++;
+            }
+        });
+        if (keyword == '') {
+            wk.error("请输入搜索内容");
+        } else if (searchCount == 0) {
+            wk.error("没有匹配结果");
+        }
+    });
+</script>
+</body>
+</html>