Commit 769d849d36a1d56b56c230ec433392682b5d589d

Authored by teemitop
1 parent 90bc3030

运营消息推送

@@ -5,21 +5,43 @@ use think\facade\Request; @@ -5,21 +5,43 @@ use think\facade\Request;
5 class Operational extends Common 5 class Operational extends Common
6 { 6 {
7 /********************************可发送消息列表*******************************/ 7 /********************************可发送消息列表*******************************/
8 - //打印机型号列表  
9 - public function messagelist($sys_id=1){  
10 - if(Request::isAjax()) {  
11 - $list= file_get_contents(ON_LINE.'App.Prints.QueryPrintsList'); 8 + public function messagelist(){
  9 + if(Request::isAjax()){
  10 + $data = Request::except('file');
  11 + $key= input('post.key') ? input('post.key') : "";
  12 + $channel = @$key['channel'] ? @$key['channel'] : 1;
  13 + $role = @$key['role'] ? @$key['role'] : '';
  14 + $limit = '&offset='.$data["page"].'&size='.$data["limit"].'&keywords='.@$key['id'].'&channel='.$channel.'&role='.$role;
  15 + $list= file_get_contents(ON_LINE.'App.Message.GetFormidList'.$limit);
12 $array = json_decode($list,TRUE); 16 $array = json_decode($list,TRUE);
  17 + $total = $array['data']['total'];
  18 + unset($array['data']['total']);
13 foreach ($array['data'] as $key => $value) { 19 foreach ($array['data'] as $key => $value) {
14 - if($value['type']==1)  
15 - $array['data'][$key]['type'] = '50';  
16 - elseif($value['type']==2)  
17 - $array['data'][$key]['type'] = '80';  
18 - $array['data'][$key]['cdate'] = date('Y-m-d H:i:s',$value['cdate']); 20 + $array['data'][$key]['sellerinfo'] = $value['id'].'-'.$value['sellername'];
  21 + $array['data'][$key]['expire_in'] = $value['expire_in'] ? date('Y-m-d H:i:s',$value['expire_in']) : '';
  22 + $array['data'][$key]['wx/app'] = $value['wx'].' / '.$value['app'];
19 } 23 }
20 - return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$array['data'],'rel'=>1]; 24 + return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$array['data'],'count'=>intval($total),'rel'=>1];
21 } 25 }
22 - $this->assign('title','打印机型号列表'); 26 + $this->assign ( 'title','运营消息推广');
23 return $this->fetch(); 27 return $this->fetch();
24 } 28 }
  29 +
  30 + /********************************消息推送*******************************/
  31 + public function sendmessagelist(){
  32 + if(Request::isAjax()){
  33 + $data = Request::except('file');
  34 + $list= file_get_contents(ON_LINE.'App.Message.SendMessage&openid='.json_encode($data['openid']));
  35 + $array = json_decode($list,TRUE);
  36 + if($array['ret']==200){
  37 + $result['code'] = 1;
  38 + $result['msg'] = 'SUCCESS!';
  39 + }else{
  40 + $result['code'] = 0;
  41 + $result['msg'] = '请求错误!';
  42 + }
  43 + return $result;
  44 + }
  45 + return view();
  46 + }
25 } 47 }
1 {include file="common/head"/} 1 {include file="common/head"/}
2 -<form class="layui-form layui-form-pane"> 2 +
3 <div class="admin-main layui-anim layui-anim-upbit"> 3 <div class="admin-main layui-anim layui-anim-upbit">
4 <fieldset class="layui-elem-field layui-field-title"> 4 <fieldset class="layui-elem-field layui-field-title">
5 <legend>{:$title}</legend> 5 <legend>{:$title}</legend>
6 </fieldset> 6 </fieldset>
  7 +
7 <div class="demoTable"> 8 <div class="demoTable">
8 - 商家:  
9 - <div class="layui-input-inline">  
10 - <input class="layui-input" name="key" id="key" placeholder="{:lang('pleaseEnter')}店铺名称" autocomplete="off">  
11 - </div>  
12 - 给谁发:  
13 - <div class="layui-input-inline" >  
14 - <input type="checkbox" name="role[write]" lay-skin="primary" title="客户经理">  
15 - <input type="checkbox" name="role[read]" lay-skin="primary" title="老板">  
16 - <input type="checkbox" name="role[game]" lay-skin="primary" title="前台"> 9 + <div class="layui-form">
  10 + 搜索商家:<div class="layui-inline">
  11 + <input class="layui-input" name="key" id="key" placeholder="{:lang('pleaseEnter')}店铺名称" autocomplete="off">
  12 + </div>
  13 + 角色选择: <div class="layui-inline">
  14 + <input type="checkbox" name="role[1]" value='管理员' title="管理员">
  15 + <input type="checkbox" name="role[2]" value="店长" title="店长">
  16 + <input type="checkbox" name="role[3]" value="收银员" title="收银员">
  17 + <input type="checkbox" name="role[4]" value="服务员" title="服务员">
  18 + <input type="checkbox" name="role[5]" value="客户经理" title="客户经理">
17 </div> 19 </div>
18 - 商家来源: 20 + 商家来源:
19 <div class="layui-input-inline layui-form"> 21 <div class="layui-input-inline layui-form">
20 <div class="layui-input-8"> 22 <div class="layui-input-8">
21 <select name="class" id="channel" lay-filter="myselect"> 23 <select name="class" id="channel" lay-filter="myselect">
@@ -25,75 +27,112 @@ @@ -25,75 +27,112 @@
25 </select> 27 </select>
26 </div> 28 </div>
27 </div> 29 </div>
28 - <button class="layui-btn" id="search" data-type="reload">查询统计</button> 30 + <button class="layui-btn" id="search" data-type="reload">搜索</button>
  31 + </div>
  32 +
29 </div> 33 </div>
30 - <table class="layui-table" id="list" lay-filter="list">  
31 - </table> 34 +
  35 + <table class="layui-table" id="list" lay-filter="list"></table>
32 </div> 36 </div>
33 -</form> 37 +<script type="text/html" id="toolbarDemo">
  38 + <div class="layui-btn-container">
  39 + <button class="layui-btn layui-btn-sm" lay-event="getCheckData">推送消息</button>
  40 + </div>
  41 +</script>
34 {include file="common/foot"/} 42 {include file="common/foot"/}
35 <script> 43 <script>
36 - layui.use(['table','form','laydate'], function() {  
37 - var table = layui.table,laydate = layui.laydate,$ = layui.jquery;  
38 - console.log(layui); 44 + layui.use(['table','form'], function() {
  45 + var table = layui.table,$ = layui.jquery;
39 var tableIn = table.render({ 46 var tableIn = table.render({
40 elem: '#list', 47 elem: '#list',
41 url: '{:url("messagelist")}', 48 url: '{:url("messagelist")}',
  49 + toolbar: '#toolbarDemo',
42 method: 'post', 50 method: 'post',
43 - title: '预定订单统计',  
44 page:true, 51 page:true,
45 cols: [[ 52 cols: [[
46 {checkbox:true,fixed: true}, 53 {checkbox:true,fixed: true},
47 - {field: 'sellername', title: 'FORMID'},  
48 - {field: 'reserve_count_sort', title: 'OPENID'},  
49 - {field: 'reserve_count', title: '失效时间'},  
50 - {field: 'sms_send_count_sort',title: '可发送总数'},  
51 - {field: 'sms_send_count',title: 'ID-商家'},  
52 - {field: 'inviting',title: '角色'},  
53 - {field: 'inviting',title: '昵称'},  
54 - {field: 'inviting',title: '最后预定时间(小程序/电话机)'},  
55 - ]],  
56 - done: function(res, curr, count){  
57 - } 54 + {field: 'formid', title: 'FORMID'},
  55 + {field: 'seat_openid', title: 'OPENID'},
  56 + {field: 'expire_in', title: '失效时间'},
  57 + {field: 'count', align: 'center',title: '可发送总数'},
  58 + {field: 'sellerinfo', align: 'center',title: 'ID-商家名称'},
  59 + {field: 'role_name', align: 'center',title: '角色'},
  60 + {field: 'nick_name', align: 'center', title: '昵称'},
  61 + {field: 'wx/app', align: 'center', width:300, title: '最后预定时间(小程序/电话机)'}
  62 + ]]
58 ,id: 'testReload' 63 ,id: 'testReload'
59 ,page: true 64 ,page: true
60 - ,limit:20 65 + ,limit:15
61 }); 66 });
62 67
63 - //日期时间范围  
64 - laydate.render({  
65 - elem: '#time'  
66 - ,type: 'datetime'  
67 - ,range: true 68 + //头工具栏事件
  69 + table.on('toolbar(list)', function(obj){
  70 + var checkStatus = table.checkStatus(obj.config.id);
  71 + switch(obj.event){
  72 + case 'getCheckData':
  73 + var arr = [];
  74 + var lists = [];
  75 + var data = checkStatus.data;
  76 + //data = JSON.stringify(data);
  77 + console.log(data);
  78 + console.log(data.length);
  79 + //判断是否选中发送目标
  80 + if(data.length==0){
  81 + layer.msg('请选择发送目标!');return;
  82 + }
  83 + //数据填充
  84 + for(var i=0;i<data.length;i++){
  85 + arr.push(data[i].count);
  86 + lists.push(data[i].seat_openid);
  87 + }
  88 + //判断用户是否可发送
  89 + if(arr.indexOf('0')!=-1){
  90 + layer.msg('该用户可发送记条数为0');return;
  91 + }
  92 + //请求后台
  93 + layer.confirm('确定要推送消息吗?', {
  94 + btn: ['确定','取消'] //按钮
  95 + }, function(index){
  96 + $.post("{:url('sendmessagelist')}",{openid:lists},function(res){
  97 + if(res.code==1){
  98 + layer.msg(res.msg,{time:1000,icon:1});
  99 + }else{
  100 + layer.msg(res.msg,{time:1000,icon:2});
  101 + }
  102 + });
  103 + layer.close(index);
  104 + }, function(){
  105 + layer.msg('操作已取消', {});
  106 + });
  107 + break;
  108 + };
68 }); 109 });
69 110
  111 +
70 //搜索 112 //搜索
71 $('#search').on('click', function() { 113 $('#search').on('click', function() {
72 - //关键字  
73 var key = $('#key').val(); 114 var key = $('#key').val();
74 - //选中的商家ID  
75 - var checkStatus = table.checkStatus('testReload'); //test即为参数id设定的值  
76 - var a = [];  
77 - $(checkStatus.data).each(function(i,o){  
78 - a.push(o.id); 115 + /*if($.trim(key)==='') {
  116 + layer.msg('{:lang("pleaseEnter")}店铺名称!',{icon:0});
  117 + return;
  118 + }*/
  119 + var arr = new Array();
  120 + $.each($('input:checkbox:checked'),function(i){
  121 + arr[i] = $(this).val();
79 }); 122 });
80 - console.log(a);  
81 -  
82 - var time = $('#time').val();  
83 - console.log(time);  
84 - //商家来源  
85 - var channel = $('#channel').val();  
86 - console.log(channel);  
87 - //筛选条件  
88 - var time_type = $('#time_type').val();  
89 - console.log(time_type);  
90 - //传参  
91 - tableIn.reload({ page: {page: 1},where: {key: key,sid: a,time_type: time_type,time: time,channel: channel}}); 123 + role = arr.join(",");//将数组合并成字符串
  124 + tableIn.reload({ page: {page: 1},where: {key: key,channel: $('#channel').val(),role: role}});
92 }); 125 });
93 126
94 var $ = layui.$, active = { 127 var $ = layui.$, active = {
95 reload: function(){ 128 reload: function(){
96 - var key = $('#key'); 129 + var key = $('#key');
  130 + var channel = $('#channel');
  131 + var arr = new Array();
  132 + $.each($('input:checkbox:checked'),function(i){
  133 + arr[i] = $(this).val();
  134 + });
  135 + role = arr.join(",");//将数组合并成字符串
97 //执行重载 136 //执行重载
98 table.reload('testReload', { 137 table.reload('testReload', {
99 page: { 138 page: {
@@ -101,11 +140,18 @@ @@ -101,11 +140,18 @@
101 } 140 }
102 ,where: { 141 ,where: {
103 key: { 142 key: {
104 - id: key.val() 143 + id: key.val(),
  144 + channel: channel.val(),
  145 + role:role,
105 } 146 }
106 } 147 }
107 }); 148 });
108 } 149 }
109 }; 150 };
  151 +
  152 + $('.demoTable .layui-btn').on('click', function(){
  153 + var type = $(this).data('type');
  154 + active[type] ? active[type].call(this) : '';
  155 + });
110 }) 156 })
111 </script> 157 </script>