Browse Source

修改自动回复

Anyon 2 years ago
parent
commit
528b6dbeea

+ 9 - 4
app/wechat/controller/Auto.php

@@ -42,13 +42,18 @@ class Auto extends Controller
      * 关注自动回复
      * @auth true
      * @menu true
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
      */
     public function index()
     {
-        $this->title = '关注自动回复';
-        WechatAuto::mQuery(null, function (QueryHelper $query) {
-            $query->like('code,type')->equal('status');
-            $query->dateBetween('create_at')->order('time asc')->page();
+        $this->type = input('get.type', 'index');
+        WechatAuto::mQuery()->layTable(function () {
+            $this->title = '关注自动回复';
+        }, function (QueryHelper $query) {
+            $query->like('code,type#mtype')->dateBetween('create_at');
+            $query->where(['status' => intval($this->type === 'index')]);
         });
     }
 

+ 9 - 0
app/wechat/model/WechatAuto.php

@@ -25,4 +25,13 @@ use think\admin\Model;
  */
 class WechatAuto extends Model
 {
+    /**
+     * 格式化创建时间
+     * @param string $value
+     * @return string
+     */
+    public function getCreateAtAttr(string $value): string
+    {
+        return format_datetime($value);
+    }
 }

+ 97 - 71
app/wechat/view/auto/index.html

@@ -1,86 +1,112 @@
-{extend name="../../admin/view/main"}
+{extend name="../../admin/view/table"}
 
 {block name="button"}
-<!--{if auth("add")}-->
-<button data-open="{:url('add')}" class='layui-btn layui-btn-sm layui-btn-primary'>添加规则</button>
+<!--{if auth("add") and $type eq 'index'}-->
+<button class='layui-btn layui-btn-sm layui-btn-primary' data-open='{:url("add")}'>添加规则</button>
 <!--{/if}-->
 
-<!--{if auth("remove")}-->
-<button data-action='{:url("remove")}' data-rule="id#{key}" data-csrf="{:systoken('remove')}" data-confirm="确定要删除这些规则吗?" class='layui-btn layui-btn-sm layui-btn-primary'>删除规则</button>
+<!--{if auth("state") and $type eq 'index'}-->
+<button class='layui-btn layui-btn-sm layui-btn-primary' data-table-id="AutoTable" data-action='{:url("state")}' data-rule="id#{id};status#0">批量禁用</button>
+<!--{/if}-->
+
+<!--{if auth("state") and $type neq 'index'}-->
+<button class='layui-btn layui-btn-sm layui-btn-primary' data-table-id="AutoTable" data-action='{:url("state")}' data-rule="id#{id};status#1">批量启用</button>
+<!--{/if}-->
+
+<!--{if auth("remove") and $type neq 'index'}-->
+<button class='layui-btn layui-btn-sm layui-btn-primary' data-table-id="AutoTable" data-action='{:url("remove")}' data-rule="id#{id}">批量删除</button>
 <!--{/if}-->
 {/block}
 
-{block name='content'}
+{block name="content"}
 <div class="think-box-notify">
-    特别注意:关注自动回复使用微信客服消息接口发送,因此多图文只能发送每组图文的第一篇文章,另外还需要开启系统任务功能。
+    <b>特别注意:</b>关注自动回复使用微信客服消息接口发送,因此多图文只能发送每组图文的第一篇文章,另外还需要开启系统任务功能。
 </div>
 
-<div class="think-box-shadow">
-    {include file='auto/index_search'}
-    <table class="layui-table" lay-skin="line">
-        {notempty name='list'}
-        <thead>
-        <tr>
-            <th class='list-table-check-td think-checkbox'>
-                <label><input data-auto-none data-check-target='.list-check-box' type='checkbox'></label>
-            </th>
-            <th class="text-left nowrap">消息编号</th>
-            <th class="text-left nowrap">延迟时间</th>
-            <th class="text-center nowrap">消息类型</th>
-            <th class="text-center nowrap">预览</th>
-            <th class="text-left nowrap">添加时间</th>
-            <th class="text-left nowrap">状态</th>
-            <th></th>
-        </tr>
-        </thead>
-        {/notempty}
-        <tbody>
-        {foreach $list as $key=>$vo}
-        <tr>
-            <td class='list-table-check-td think-checkbox'>
-                <label><input class="list-check-box" value='{$vo.id}' type='checkbox'></label>
-            </td>
-            <td class="text-left nowrap">{$vo.code}</td>
-            <td class="text-left nowrap">{$vo.time}</td>
-            <td class="text-center nowrap">{$vo.type}</td>
-            <td class="text-center nowrap notselect">
-                {if $vo.type eq '音乐'}
-                <a data-phone-view='{:url("@wechat/api.view/music")}?title={$vo.music_title|urlencode}&desc={$vo.music_desc|urlencode}'>预览</a>
-                {elseif in_array($vo.type,['文字','转客服'])}
-                <a data-phone-view='{:url("@wechat/api.view/text")}?content={$vo.content|urlencode}'>预览</a>
-                {elseif $vo.type eq '图片'}
-                <a data-phone-view='{:url("@wechat/api.view/image")}?content={$vo.image_url|urlencode}'>预览</a>
-                {elseif $vo.type eq '图文'}
-                <a data-phone-view='{:url("@wechat/api.view/news")}?id={$vo.news_id}'>预览</a>
-                {elseif $vo.type eq '视频'}
-                <a data-phone-view='{:url("@wechat/api.view/video")}?title={$vo.video_title|urlencode}&desc={$vo.video_desc|urlencode}&url={$vo.video_url|urlencode}'>预览</a>
-                {elseif $vo.type eq '语音'}
-                <a data-phone-view='{:url("@wechat/api.view/voice")}?content={$vo.voice_url|urlencode}'>预览</a>
-                {else} {$vo.content} {/if}
-            </td>
-            <td class="text-left nowrap">{$vo.create_at|format_datetime}</td>
-            <td class='text-left nowrap'>{if $vo.status eq 0}<span class="color-red">已禁用</span>{elseif $vo.status eq 1}<span class="color-green">已激活</span>{/if}</td>
-            <td class='text-left nowrap'>
+<div class="layui-tab layui-tab-card think-bg-white">
+    <ul class="layui-tab-title">
+        {foreach ['index'=>'回复规则','recycle'=>'回 收 站'] as $k=>$v}
+        {if isset($type) and $type eq $k}
+        <li class="layui-this" data-open="{:url('index')}?type={$k}">{$v}</li>
+        {else}
+        <li data-open="{:url('index')}?type={$k}">{$v}</li>
+        {/if}{/foreach}
+    </ul>
+    <div class="layui-tab-content">
+        {include file='auto/index_search'}
+        <table id="AutoTable" data-url="{:sysuri()}" data-target-search="form.form-search"></table>
+    </div>
+</div>
+{/block}
 
-                <!--{if auth("edit")}-->
-                <a class="layui-btn layui-btn-sm" data-open='{:url("edit")}?id={$vo.id}'>编 辑</a>
-                <!--{/if}-->
+{block name='script'}
+<script>
+    $(function () {
+        $('#AutoTable').layTable({
+            even: true, height: 'full',
+            sort: {field: 'time', type: 'asc'},
+            where: {type: '{$type|default="index"}'},
+            cols: [[
+                {checkbox: true},
+                {field: 'code', title: '消息编号', align: "center", minWidth: 100},
+                {field: 'time', title: '延迟时间', align: "center", minWidth: 100},
+                {field: 'type', title: '消息类型', align: "center", minWidth: 100},
+                {field: 'code', title: '在线预览', align: "center", minWidth: 100, templet: '#PreViewTpl'},
+                {field: 'status', title: '使用状态', align: 'center', minWidth: 110, templet: '#StatusSwitchTpl'},
+                {field: 'create_at', title: '添加时间', align: 'center', minWidth: 170},
+                {toolbar: '#toolbar', title: '操作面板', align: 'center', fixed: 'right'}
+            ]]
+        });
 
-                <!--{if auth("state") and $vo.status eq 1}-->
-                <a class="layui-btn layui-btn-sm layui-btn-warm" data-action="{:url('state')}" data-value="id#{$vo.id};status#0" data-csrf="{:systoken('state')}">禁 用</a>
-                <!--{elseif auth("state") and $vo.status eq 0}-->
-                <a class="layui-btn layui-btn-sm layui-btn-warm" data-action="{:url('state')}" data-value="id#{$vo.id};status#1" data-csrf="{:systoken('state')}">激 活</a>
-                <!--{/if}-->
+        // 数据状态切换操作
+        layui.form.on('switch(StatusSwitch)', function (obj, data) {
+            data = {id: obj.value, status: obj.elem.checked > 0 ? 1 : 0};
+            $.form.load("{:url('state')}", data, 'post', function (ret) {
+                if (ret.code < 1) $.msg.error(ret.info, 3, function () {
+                    $('#AutoTable').trigger('reload');
+                }); else {
+                    $('#AutoTable').trigger('reload');
+                }
+                return false;
+            }, false);
+        });
+    });
+</script>
 
-                <!--{if auth("remove")}-->
-                <a class="layui-btn layui-btn-sm layui-btn-danger" data-confirm="确定要删除该规则吗?" data-action="{:url('remove')}" data-value="id#{$vo.id}" data-csrf="{:systoken('remove')}">删 除</a>
-                <!--{/if}-->
+<script type="text/html" id="PreViewTpl">
+    {{# if(d.type==='音乐'){ }}
+    <a data-phone-view='{:url("@wechat/api.view/music")}?title={{d.music_title}}&desc={{d.music_desc}}'>预览</a>
+    {{# }else if(d.type==='图片'){ }}
+    <a data-phone-view='{:url("@wechat/api.view/image")}?content={{d.image_url}}'>预览</a>
+    {{# }else if(d.type==='图文'){ }}
+    <a data-phone-view='{:url("@wechat/api.view/news")}?id={{d.news_id}}'>预览</a>
+    {{# }else if(d.type==='视频'){ }}
+    <a data-phone-view='{:url("@wechat/api.view/video")}?title={{d.video_title}}&desc={{d.video_desc}}&url={{d.video_url}}'>预览</a>
+    {{# }else if(d.type==='语音'){ }}
+    <a data-phone-view='{:url("@wechat/api.view/voice")}?content={{d.voice_url}}'>预览</a>
+    {{# }else if(d.type==='文字'||d.type==='转客服'){ }}
+    <a data-phone-view='{:url("@wechat/api.view/text")}?content={{d.content}}'>预览</a>
+    {{# }else{ }}
+    {{d.content}}
+    {{# } }}
+</script>
 
-            </td>
-        </tr>
-        {/foreach}
-        </tbody>
-    </table>
-    {empty name='list'}<span class="notdata">没有记录哦</span>{else}{$pagehtml|raw|default=''}{/empty}
-</div>
+<!-- 状态切换模板 -->
+<script type="text/html" id="StatusSwitchTpl">
+    <!--{if auth("state")}-->
+    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="已激活|已禁用" lay-filter="StatusSwitch" {{-d.status>0?'checked':''}}>
+    <!--{else}-->
+    {{-d.status ? '<b class="color-red">已激活</b>' : '<b class="color-green">已禁用</b>'}}
+    <!--{/if}-->
+</script>
+
+<!-- 操作面板模板 -->
+<script type="text/html" id="toolbar">
+    <!--{if auth("edit") and isset($type) and $type eq 'index'}-->
+    <a class="layui-btn layui-btn-sm" data-open="{:url('edit')}?id={{d.id}}" data-title="编辑回复规则">编 辑</a>
+    <!--{/if}-->
+    <!--{if auth("remove") and isset($type) and $type neq 'index'}-->
+    <a class="layui-btn layui-btn-sm layui-btn-danger" data-action="{:url('remove')}" data-value="id#{{d.id}}" data-confirm="确定要删除该用户吗?">删 除</a>
+    <!--{/if}-->
+</script>
 {/block}

+ 2 - 2
app/wechat/view/auto/index_search.html

@@ -12,9 +12,9 @@
         <div class="layui-form-item layui-inline">
             <label class="layui-form-label">消息类型</label>
             <div class="layui-input-inline">
-                <select class="layui-select" name="type">
+                <select class="layui-select" name="mtype">
                     <option value="">-- 全部 --</option>
-                    {foreach $types as $k => $v}{if $k.'' eq input('type')}
+                    {foreach $types as $k => $v}{if $k.'' eq input('mtype')}
                     <option selected value="{$k}">{$v}</option>
                     {else}
                     <option value="{$k}">{$v}</option>