Browse Source

add: 后台增加会员通知管理,目前仅支持系统通知

joe 4 years ago
parent
commit
74848964de

+ 23 - 9
app/admin/controller/user/UserNotice.php

@@ -8,6 +8,7 @@ use think\facade\Route as Url;
 use app\admin\model\user\UserNotice as UserNoticeModel;
 use app\admin\model\user\UserNoticeSee as UserNoticeSeeModel;
 use app\admin\model\wechat\WechatUser as UserModel;
+use think\facade\Config;
 
 /**
  * 用户通知
@@ -41,11 +42,17 @@ class UserNotice extends AuthController
      */
     public function create()
     {
+        $sender = Config::get('app.notice_sender');
         $f = array();
-        $f[] = Form::input('user', '发送人', '系统管理员');
+        $f[] = Form::input('user', '发送人', $sender);
+        $f[] = Form::frameImageOne('icon', '图标', Url::buildUrl('admin/widget.images/index', array('fodder' => 'icon')))->icon('image')->width('100%')->height('500px');
         $f[] = Form::input('title', '通知标题');
-        $f[] = Form::input('content', '通知内容')->type('textarea');
-        $f[] = Form::radio('type', '消息类型', 1)->options([['label' => '系统消息', 'value' => 1], ['label' => '用户通知', 'value' => 2]]);
+        $f[] = Form::input('content', '通知内容')->type('textarea')->rows(10);
+        $f[] = Form::radio('type', '消息类型', 1)->options([
+            ['label' => '系统通知', 'value' => 0], 
+            // ['label' => '分组通知', 'value' => 1],
+            ['label' => '用户通知', 'value' => 2],
+            ]);
         $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('save'));
         $this->assign(compact('form'));
         return $this->fetch('public/form-builder');
@@ -82,9 +89,14 @@ class UserNotice extends AuthController
         if (!$notice) return Json::fail('数据不存在!');
         $f = array();
         $f[] = Form::input('user', '发送人', $notice["user"]);
+        $f[] = Form::frameImageOne('icon', '图标', Url::buildUrl('admin/widget.images/index', array('fodder' => 'icon')), $notice->getData('icon'))->icon('image')->width('100%')->height('500px');
         $f[] = Form::input('title', '通知标题', $notice["title"]);
-        $f[] = Form::input('content', '通知内容', $notice["content"])->type('textarea');
-        $f[] = Form::radio('type', '消息类型', $notice["type"])->options([['label' => '系统消息', 'value' => 1], ['label' => '用户通知', 'value' => 2]]);
+        $f[] = Form::input('content', '通知内容', $notice["content"])->type('textarea')->rows(10);
+        $f[] = Form::radio('type', '消息类型', $notice["type"])->options([
+            ['label' => '系统通知', 'value' => 0], 
+            // ['label' => '分组通知', 'value' => 1],
+            ['label' => '用户通知', 'value' => 2],
+            ]);
         $form = Form::make_post_form('编辑通知', $f, Url::buildUrl('update', ["id" => $id]), 2);
         $this->assign(compact('form'));
         return $this->fetch('public/form-builder');
@@ -124,10 +136,12 @@ class UserNotice extends AuthController
      */
     public function delete($id)
     {
-        if (!UserNoticeModel::del($id))
+        if (!UserNoticeModel::del($id)) {
             return Json::fail(UserNoticeModel::getErrorInfo('删除失败,请稍候再试!'));
-        else
+        } else {
+            UserNoticeSeeModel::where('nid', $id)->delete();
             return Json::successful('删除成功!');
+        }
     }
 
     /**
@@ -142,7 +156,7 @@ class UserNotice extends AuthController
         $model = new UserModel;
         $model = $model::alias('A');
         $model = $model->field('A.*');
-        if ($notice["type"] == 2) {
+        if ($notice["type"] == 1) {
             if ($notice["uid"] != "") {
                 $uids = explode(",", $notice["uid"]);
                 array_splice($uids, 0, 1);
@@ -152,7 +166,7 @@ class UserNotice extends AuthController
                 $model = $model->where("A.uid", $notice['uid']);
             }
             $model->order('A.uid desc');
-        } else {
+        } else if($notice['type'] == 2) {
             $model = $model->join('UserNoticeSee B', 'A.uid = B.uid', 'RIGHT');
             $model = $model->where("B.nid", $notice['id']);
             $model->order('B.add_time desc');

+ 20 - 13
app/admin/view/user/user_notice/index.php

@@ -12,32 +12,37 @@
                     <table class="layui-hide" id="List" lay-filter="List"></table>
                     <!--消息状态-->
                     <script type="text/html" id="type">
-                        {{# if(d.type==1){ }}
-                            <p>系统消息</p>
+                        {{# if(d.type==0){ }}
+                            <p>系统通知</p>
                         {{# }else if(d.type==2){ }}
-                            <p>用户通知</p>
+                            <p>会员通知</p>
+                        {{# } else if(d.type == 1){ }}
+                            <p>分组通知</p>
                         {{# } }}
                     </script>
+                    <script type="text/html" id="add_time">
+                        <div>{{ layui.util.toDateString(d.add_time * 1000, 'yyyy-MM-dd HH:MM') }}</div>
+                    </script>
                     <!--消息状态-->
                     <script type="text/html" id="is_send">
-                        {{# if(d.is_send==1){ }}
-                        状态:<span style="color:green;">已发送</span><br />
-                        时间:{{d.send_time}}
+                        {{# if(d.del_time==0){ }}
+                        <span style="color:green;">否</span><br />
                         {{# }else{ }}
-                        状态:<span style="color:red;">未发送</span> <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event='send'>立即发送</a>
+                        <span style="color:red;">是</span> 
+                        <!-- <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event='send'>启用</a> -->
                         {{# } }}
                     </script>
                     <script type="text/html" id="act">
                         <button type="button" class="layui-btn layui-btn-xs" onclick="dropdown(this)">操作 <span class="caret"></span></button>
                         <ul class="layui-nav-child layui-anim layui-anim-upbit">
+                            {{# if(d.type==2){ }}
                             <li>
                                 <a href="javascript:;"  onclick="window.location.href='{:Url('user')}?id={{d.id}}'"><i class="fa fa-user"></i> 用户信息</a>
                             </li>
-                            {{# if(d.is_send==0){ }}
+                            {{# } }}
                             <li>
                                 <a href="javascript:;"  onclick="$eb.createModalFrame('编辑','{:Url('edit')}?id={{d.id}}')"><i class="fa fa-edit"></i> 编辑</a>
                             </li>
-                            {{# } }}
                             <li>
                                 <a href="javascript:;" lay-event='warning'><i class="fa fa-times"></i> 删除</a>
                             </li>
@@ -54,13 +59,15 @@
 <script>
     layList.tableList('List',"{:Url('index')}",function (){
         return [
-            {field: 'id', title: '编号',width:'6%', sort: true,event:'id',align:"center"},
+            {field: 'id', title: '编号',width:'4%', sort: true,event:'id',align:"center"},
+            {filed: 'icon', title: '图标',align:'center',templet:'<p><img class="avatar " style="cursor: pointer" data-image="{{d.icon}}" src="{{d.icon}}" alt="{{d.title}}"></p>', width:'6%'},
             {field: 'user', title: '发送人',align:"center",width:'10%'},
             {field: 'title', title: '通知标题',align:"center",width:'10%'},
+            {field: 'add_time', title: '添加时间',templet:'#add_time',align:'center',width:'12%'},
             {field: 'content', title: '通知内容',align:"center"},
-            {field: 'type', title: '消息类型',templet:'#type',align:"center",width:'6%'},
-            {field: 'is_send', title: '是否发送',templet:'#is_send',align:"center",width:'15%'},
-            {field: 'right', title: '操作',align:'center',toolbar:'#act',width:'10%'},
+            {field: 'type', title: '消息类型',templet:'#type',align:"center",width:'10%'},
+            //{field: 'is_send', title: '是否删除',templet:'#is_send',align:"center",width:'6%'},
+            {field: 'right', title: '操作',align:'center',toolbar:'#act',width:'6%'},
         ];
     });
     //下拉框

+ 7 - 7
app/admin/view/user/user_notice/user.php

@@ -6,7 +6,7 @@
 <script src="{__ADMIN_PATH}frame/js/plugins/iCheck/icheck.min.js"></script>
 <div class="row">
     <div class="col-sm-12">
-        {if condition="$notice['is_send'] eq 0 AND $notice['type'] eq 2"}
+        {if condition="$notice['del_time'] eq 0 AND $notice['type'] eq 2"}
             <div class="ibox-title">
                 <button type="button" class="btn btn-w-m btn-primary" onclick="$eb.createModalFrame(this.innerText,'{:Url('user_create',array('id'=>$notice['id']))}')">添加发送用户</button>
                 <button type="button" class="btn btn-w-m btn-primary select-delete" data-url="{:Url('user_select_delete',array('id'=>$notice['id']))}">选择删除</button>
@@ -17,20 +17,20 @@
                 <table class="table table-striped  table-bordered">
                     <thead>
                     <tr>
-                        {if condition="$notice['is_send'] eq 0 AND $notice['type'] eq 2"}<th class="text-center"></th>{/if}
+                        {if condition="$notice['del_time'] eq 0 AND $notice['type'] eq 2"}<th class="text-center"></th>{/if}
                         <th class="text-center">编号</th>
                         <th class="text-center">微信用户名称</th>
                         <th class="text-center">头像</th>
                         <th class="text-center">性别</th>
-                        {if condition="$notice['is_send'] eq 1 AND $notice['type'] eq 2"}<th class="text-center">是否查看</th>{/if}
-                        {if condition="$notice['is_send'] eq 0 AND $notice['type'] eq 2"}<th class="text-center">操作</th>{/if}
+                        {if condition="$notice['del_time'] eq 1 AND $notice['type'] eq 2"}<th class="text-center">是否查看</th>{/if}
+                        {if condition="$notice['del_time'] eq 0 AND $notice['type'] eq 2"}<th class="text-center">操作</th>{/if}
                     </tr>
                     </thead>
                     <tbody class="">
                         <form method="post" class="sub-save">
                             {volist name="list" id="vo"}
                             <tr>
-                                {if condition="$notice['is_send'] eq 0 AND $notice['type'] eq 2"}
+                                {if condition="$notice['del_time'] eq 0 AND $notice['type'] eq 2"}
                                     <td class="text-center">
                                         <label class="checkbox-inline i-checks">
                                             <input type="checkbox" name="ids[]" value="{$vo.uid}">
@@ -51,7 +51,7 @@
                                         保密
                                     {/if}
                                 </td>
-                                {if condition="$notice['is_send'] eq 1 AND $notice['type'] eq 2"}
+                                {if condition="$notice['del_time'] eq 1 AND $notice['type'] eq 2"}
                                     <td class="text-center">
                                         {if condition="$vo['is_see'] eq 1"}
                                             <span style="color:green">是</span>
@@ -60,7 +60,7 @@
                                         {/if}
                                     </td>
                                 {/if}
-                                {if condition="$notice['is_send'] eq 0 AND $notice['type'] eq 2"}
+                                {if condition="$notice['del_time'] eq 0 AND $notice['type'] eq 2"}
                                     <td class="text-center">
                                         <button class="btn btn-danger btn-xs " data-url="{:Url('user_delete',array('id'=>$notice['id'],'uid'=>$vo['uid']))}" type="button"><i class="fa fa-times"></i> 删除</button>
                                     </td>

+ 1 - 1
config/app.php

@@ -49,7 +49,7 @@ return [
     'qy_weixin_robot_aristotle' => 'a17b9d56-b566-404b-904e-4476b95dc8d7',
 
     /// 自动发消息的消息发送者
-    'notice_sender' => '运营管理员',
+    'notice_sender' => '运营中心',
 
     /// 挖矿配置, 每次更新币种后需要重新配置
     // 单次挖矿时长