From 54fbc09803144c69c3990f8737d8ab3181fbb486 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Mon, 6 Mar 2023 10:39:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=95=99=E8=A8=80=E6=B7=BB=E5=8A=A0=E5=9B=9E=E5=A4=8D=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addon/message/api/controller/Message.php | 19 ++++ addon/message/model/Message.php | 84 ++++++++++++++-- addon/message/shop/controller/Remark.php | 40 +++++++- addon/message/shop/view/remark/index.html | 100 +++++++++---------- addon/message/shop/view/remark/see.html | 112 ++++++++++++++++++++++ 5 files changed, 292 insertions(+), 63 deletions(-) create mode 100644 addon/message/shop/view/remark/see.html diff --git a/addon/message/api/controller/Message.php b/addon/message/api/controller/Message.php index f0b53131..a50948db 100644 --- a/addon/message/api/controller/Message.php +++ b/addon/message/api/controller/Message.php @@ -12,6 +12,7 @@ */ namespace addon\message\api\controller; +use addon\message\model\Message as messageModel; use addon\message\model\MessageRead; use app\api\controller\BaseApi; @@ -36,6 +37,7 @@ class Message extends BaseApi{ 'a.is_see', 'a.order_id', 'a.created_time', + 'a.reply_content', 'mc.type', 'mc.message_title', 'mc.message_content', @@ -65,5 +67,22 @@ class Message extends BaseApi{ return $this->response($this->success()); } + /** + * Common: 留言信息 + * Author: wu-hui + * Time: 2023/03/04 18:04 + * @return false|string + */ + public function remarks(){ + // 用户登录 + $token = $this->checkToken(); + if ($token['code'] < 0) return $this->response($token); + // 记录留言信息 + (new messageModel())->addMessage($this->site_id,$this->params['remarks'],4,$this->member_id,0,'',$this->params['image_list']); + + return $this->response($this->success()); + } + + } \ No newline at end of file diff --git a/addon/message/model/Message.php b/addon/message/model/Message.php index 92e1adcb..c4addb23 100644 --- a/addon/message/model/Message.php +++ b/addon/message/model/Message.php @@ -24,15 +24,16 @@ class Message extends BaseModel{ */ public function getList($siteId){ // 参数获取 - $page = input('page',1); - $pageSize = input('page_size',PAGE_LIST_ROWS); - $title = input('title',''); - $type = input('type',''); + $page = input('page',1); + $pageSize = input('page_size',PAGE_LIST_ROWS); + $title = input('title',''); + $type = input('type',''); // 条件生成 $where = [ ['a.site_id','=',$siteId], - ['a.type','in',[2,3]], + ['a.type','in',[2,3]] ]; + // 其他条件 if($title) $where[] = ['a.message_title','like',"%{$title}%"]; if($type) $where[] = ['a.type','=',$type]; // 列表获取 @@ -65,7 +66,7 @@ class Message extends BaseModel{ * @param string $title * @return array */ - public function addMessage(int $siteId,string $content,int $type,$member_id = 'all',int $orderId = 0,$title = ''){ + public function addMessage(int $siteId,string $content,int $type,$member_id = 'all',int $orderId = 0,$title = '',$image = ''){ if(!$content) return $this->error('','消息不能为空!'); // 记录消息信息 try{ @@ -75,7 +76,8 @@ class Message extends BaseModel{ 'type' => $type, 'message_title' => $title ?? $this->types[$type], 'message_content' => $content, - 'created_time' => time() + 'created_time' => time(), + 'image_list' => $image, ]); // 关联用户信息 if($member_id == 'all'){ @@ -122,5 +124,73 @@ class Message extends BaseModel{ return $this->success(); } + /** + * Common: 获取留言信息 + * Author: wu-hui + * Time: 2023/03/04 18:07 + * @param $siteId + * @return array + * @throws \think\db\exception\DbException + */ + public function getRemarks($siteId){ + // 参数获取 + $page = input('page',1); + $pageSize = input('page_size',PAGE_LIST_ROWS); + $nickname = input('nickname',''); + $type = (int)input('type',0); + // 条件生成 + $where = [ + ['a.site_id','=',$siteId], + ['a.type','=',4] + ]; + if($nickname) $where[] = ['m.username|m.nickname','like',"%{$nickname}%"]; + if($type > 0) $where[] = ['mcr.is_see','=',$type == 1 ? 0 : 1];// 是否已读:0=未读,1=已读 + // 列表获取 + $result = Db::name('message_center') + ->alias('a') + ->field('a.id,a.type,a.created_time,mcr.member_id,mcr.is_see,m.username,m.nickname,m.headimg') + ->join('message_center_read mcr','mcr.message_center_id = a.id', 'left') + ->join('member m','m.member_id = mcr.member_id','left') + ->where($where) + ->group('a.id') + ->order('a.id','DESC') + ->paginate(['list_rows' => $pageSize,'page' => $page]); + if($result) $result = $result->toArray(); + + $list = [ + 'count' => $result['total'], + 'list' => $result['data'], + 'page_count' => $result['last_page'], + ]; + return $this->success($list); + } + + /** + * Common: 获取单条信息 + * Author: wu-hui + * Time: 2023/03/06 9:38 + * @param array $where + * @param string $field + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getInfo($where = [], $field = '*'){ + $result = Db::name('message_center') + ->alias('a') + ->field($field) + ->join('message_center_read mcr','mcr.message_center_id = a.id', 'left') + ->join('member m','m.member_id = mcr.member_id','left') + ->where($where) + ->find(); + + return $this->success($result); + } + + + + + } \ No newline at end of file diff --git a/addon/message/shop/controller/Remark.php b/addon/message/shop/controller/Remark.php index 46404e4b..a8debb10 100644 --- a/addon/message/shop/controller/Remark.php +++ b/addon/message/shop/controller/Remark.php @@ -16,15 +16,51 @@ use app\shop\controller\BaseShop; use addon\message\model\Message as messageModel; class Remark extends BaseShop{ - // 进入留言管理 + /** + * Common: 进入留言管理 + * Author: wu-hui + * Time: 2023/03/06 9:12 + * @return array|mixed + * @throws \think\db\exception\DbException + */ public function index(){ - if(request()->isAjax()) return (new messageModel())->getList($this->site_id); + if(request()->isAjax()) return (new messageModel())->getRemarks($this->site_id); $this->forthMenu(); return $this->fetch('remark/index'); } + /** + * Common: 查看详情&回复内容 + * Author: wu-hui + * Time: 2023/03/06 10:09 + * @return array|mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function seeInfo(){ + // 获取基本信息 + $messageCenterId = input('message_center_id'); + Model('message_center_read')->update(['is_see'=>1],['message_center_id'=>$messageCenterId]); + if(request()->isAjax()) { + // 回复内容 + $replyContent = input('reply_content'); + Model('message_center_read')->update(['reply_content'=>$replyContent],['message_center_id'=>$messageCenterId]); + return success(); + } + // 获取信息 + $where = [ + ['a.id','=',$messageCenterId] + ]; + $field = 'a.id,a.created_time,a.message_content,a.image_list,mcr.is_see,m.username,m.nickname,m.headimg'; + $info = (new messageModel())->getInfo($where,$field)['data']; + $info['image_list'] = $info['image_list'] ? explode(',',$info['image_list']) : []; + $this->assign('info',$info); + $this->assign('message_center_id',$messageCenterId); + return $this->fetch('remark/see'); + } diff --git a/addon/message/shop/view/remark/index.html b/addon/message/shop/view/remark/index.html index 275f910d..e7e4daaf 100644 --- a/addon/message/shop/view/remark/index.html +++ b/addon/message/shop/view/remark/index.html @@ -15,24 +15,23 @@
- +
- +
- +
-
@@ -44,7 +43,22 @@ + + {/block} @@ -74,41 +88,28 @@ // 内容获取 table = new Table({ elem: '#listContent', - url: ns.url("message://shop/message/index"), + url: ns.url("message://shop/remark/index"), cols: [[ {align: 'center', field: 'id', title: 'ID', width: '5%', unresize: 'false'}, - {align: 'center', title: '消息标题', field:'message_title', unresize: 'area'}, - {align: 'center', title: '接收人数', field: 'total',unresize: 'area'}, + {align: 'left', title: '留言用户', unresize: 'area',templet: '#memberInfo'}, { - align: 'center',width: '10%', templet: function (d) { - // 消息类型:1=交易信息,2=系统消息,3=通知消息,4=留言反馈 + align: 'center', templet: function (d) { + // 是否已读:0=未读,1=已读 let statusText = ''; - switch (parseInt(d.type)) { - case 1: statusText = '

交易信息

'; break; - case 2: statusText = '

系统消息

'; break; - case 3: statusText = '

通知消息

'; break; - case 4: statusText = '

留言反馈

'; break; + switch (parseInt(d.is_see)) { + case 0: statusText = '

未读

'; break; + case 1: statusText = '

已读

'; break; } - return statusText; - }, title: '消息类型', unresize: 'false' + }, title: '是否已读', unresize: 'false' }, + {align: 'center', title: '留言时间', field: 'created_time',unresize: 'area', + templet: function(data) { + return ns.time_to_date(data.created_time); + }}, {title: '操作', toolbar: '#operation', unresize: 'false', align: 'right'} ]], }); - // 点击发布 - form.on('submit(publish)', function(data) { - layer.open({ - type: 2, - title: '消息发布', - skin: 'layer-tips-class', - area: ['80%','90%'], - content: ns.url("message://shop/message/sendMessage"), - end: function(){ - table.reload(); - } - }); - }); // 点击搜索 form.on('submit(search)', function(data) { table.reload({ @@ -122,7 +123,7 @@ // 重置表单 form.on('submit(reset)', function(data) { let field = { - "title": "", + "nickname": "", "type": "", }; form.val("search_form", field); @@ -141,28 +142,19 @@ eval(obj.event)(data) }); }); - // 删除消息 - function deleteInfo(data){ - layer.confirm('确认删除当前消息?删除后所有已发送给用户当前消息将同步删除。', {icon: 3, title:'提示'}, function(index){ - layer.close(index); - $.ajax({ - type: 'POST', - dataType: 'JSON', - url: ns.url("message://shop/message/delMessage"), - data: { id: data.id }, - async: false, - success: function(res){ - if (res.code == 0) { - layer.alert('删除成功', function(index){ - layer.close(index); - table.reload(); - }); - }else{ - layer.msg(res.message); - } - } - }) + // 查看信息详情 + function seeInfo(data){ + layer.open({ + type: 2, + title: '消息发布', + skin: 'layer-tips-class', + area: ['80%','90%'], + content: ns.url("message://shop/remark/seeInfo",{ message_center_id: data.id }), + end: function(){ + table.reload(); + } }); } + {/block} \ No newline at end of file diff --git a/addon/message/shop/view/remark/see.html b/addon/message/shop/view/remark/see.html new file mode 100644 index 00000000..a05bfb9d --- /dev/null +++ b/addon/message/shop/view/remark/see.html @@ -0,0 +1,112 @@ +{extend name="app/shop/view/base.html"/} +{block name="resources"} + +{/block} + +{block name="body"} +
+
+ +
+ +
{$info['nickname'] ?? $info['username']}
+
+
+
+ +
+ {:date('Y-m-d H:i:s',$info['created_time'])} +
+
+
+ +
+ +
+
+
+ +
+ {foreach $info['image_list'] as $img} + + {/foreach} +
+
+
+ +
+ +
+
+ +
+ + + +
+
+{/block} +{block name="script"} + +{/block} \ No newline at end of file