From fb5c84652d16ee44c737f459a28c049f9c1e926b Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Sat, 4 Mar 2023 16:34:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addon/message/api/controller/Message.php | 69 +++++++ addon/message/model/Message.php | 70 +++++-- addon/message/model/MessageRead.php | 26 +++ addon/message/shop/controller/Message.php | 62 +++---- addon/message/shop/controller/Remark.php | 31 ++++ addon/message/shop/view/message/index.html | 171 +++++------------- .../shop/view/message/send_message.html | 13 +- addon/message/shop/view/remark/index.html | 168 +++++++++++++++++ 8 files changed, 428 insertions(+), 182 deletions(-) create mode 100644 addon/message/api/controller/Message.php create mode 100644 addon/message/model/MessageRead.php create mode 100644 addon/message/shop/controller/Remark.php create mode 100644 addon/message/shop/view/remark/index.html diff --git a/addon/message/api/controller/Message.php b/addon/message/api/controller/Message.php new file mode 100644 index 00000000..f0b53131 --- /dev/null +++ b/addon/message/api/controller/Message.php @@ -0,0 +1,69 @@ +checkToken(); + if ($token['code'] < 0) return $this->response($token); + // 参数获取 + $page = input('page', 1); + $page_size = input('page_size', PAGE_LIST_ROWS); + $message_type = input('message_type',0); + // 获取内容 + $field = [ + 'a.id', + 'a.is_see', + 'a.order_id', + 'a.created_time', + 'mc.type', + 'mc.message_title', + 'mc.message_content', + ]; + // 条件生成 + $condition = [ + ['a.site_id','=',$this->site_id], + ['a.member_id', '=', $this->member_id ], + ]; + if($message_type > 0) $condition[] = ['mc.type', '=', $message_type ]; + // 表关联 + $join = [ + ['message_center mc', 'mc.id = a.message_center_id', 'left'], + ]; + $list = (new MessageRead())->getPageList($condition, $page, $page_size, 'a.created_time desc,a.id desc', $field, 'a', $join); + + return $this->response($list); + } + /** + * Common: 消息查看 + * Author: wu-hui + * Time: 2023/03/04 16:31 + */ + public function see(){ + $id = input('id',0); + model('message_center_read')->update(['is_see'=>1], ['id'=>$id]); + + 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 c0fbe374..92e1adcb 100644 --- a/addon/message/model/Message.php +++ b/addon/message/model/Message.php @@ -8,19 +8,49 @@ use think\facade\Db; class Message extends BaseModel{ + private $types = [ + 1 => '交易信息', + 2 => '系统消息', + 3 => '通知消息', + 4 => '留言反馈', + ]; + /** - * 获取列表 - * @param array $condition - * @param int $page - * @param int $page_size - * @param string $order - * @param string $field - * @param string $alias - * @param array $join + * Common: 获取消息列表 + * Author: wu-hui + * Time: 2023/03/04 15:02 * @return array + * @throws \think\db\exception\DbException */ - public function getPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = 'a.*', $alias = 'a', $join = []){ - $list = model('message_center')->pageList($condition, $field, $order, $page, $page_size, $alias, $join); + public function getList($siteId){ + // 参数获取 + $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]], + ]; + if($title) $where[] = ['a.message_title','like',"%{$title}%"]; + if($type) $where[] = ['a.type','=',$type]; + // 列表获取 + $result = Db::name('message_center') + ->alias('a') + ->field('a.id,a.type,a.created_time,a.message_title,count(mcr.message_center_id) as total') + ->join('message_center_read mcr','mcr.message_center_id = a.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); } /** @@ -32,9 +62,10 @@ class Message extends BaseModel{ * @param int $type * @param string|int $member_id * @param int $orderId + * @param string $title * @return array */ - public function addMessage(int $siteId,string $content,int $type,$member_id = 'all',int $orderId = 0){ + public function addMessage(int $siteId,string $content,int $type,$member_id = 'all',int $orderId = 0,$title = ''){ if(!$content) return $this->error('','消息不能为空!'); // 记录消息信息 try{ @@ -42,6 +73,7 @@ class Message extends BaseModel{ ->insertGetId([ 'site_id' => $siteId, 'type' => $type, + 'message_title' => $title ?? $this->types[$type], 'message_content' => $content, 'created_time' => time() ]); @@ -76,9 +108,19 @@ class Message extends BaseModel{ } } + /** + * Common: 删除消息 + * Author: wu-hui + * Time: 2023/03/04 15:48 + * @param $id + * @return array + */ + public function delInfo($id){ + // 删除消息信息 + Model('message_center')->delete(['id'=>$id]); + Model('message_center_read')->delete(['message_center_id'=>$id]); - - - + return $this->success(); + } } \ No newline at end of file diff --git a/addon/message/model/MessageRead.php b/addon/message/model/MessageRead.php new file mode 100644 index 00000000..00018bb7 --- /dev/null +++ b/addon/message/model/MessageRead.php @@ -0,0 +1,26 @@ +pageList($condition, $field, $order, $page, $page_size, $alias, $join); + return $this->success($list); + } + + +} \ No newline at end of file diff --git a/addon/message/shop/controller/Message.php b/addon/message/shop/controller/Message.php index 17efaed1..53dbb712 100644 --- a/addon/message/shop/controller/Message.php +++ b/addon/message/shop/controller/Message.php @@ -17,47 +17,15 @@ use addon\message\model\Message as messageModel; use think\facade\Db; class Message extends BaseShop{ - // 进入消息中心 + /** + * Common: 进入消息中心 + * Author: wu-hui + * Time: 2023/03/04 15:03 + * @return array|mixed + * @throws \think\db\exception\DbException + */ public function index(){ - if(request()->isAjax()){ - - - - - } - - - debug(table('message_center_read')); - // 参数获取 - $page = input('page',1); - $pageSize = input('page_size',PAGE_LIST_ROWS); - // 获取内容 - $field = [ - 'a.id', - 'a.type', - 'a.created_time', - 'count(a.id) as total', - '(select count(id) from )', - - ]; - // 表关联 - $join = [ - ['message_center_read mcr', 'mcr.message_center_id = a.id', 'left'], - ]; - // 条件生成 - $condition = [ - ['a.site_id','=',$this->site_id] - ]; - $res = (new messageModel())->getPageList($condition, $page, $pageSize, 'a.created_time desc,a.id desc', $field, 'a', $join); - - debug($res); - - - - - - - + if(request()->isAjax()) return (new messageModel())->getList($this->site_id); $this->forthMenu(); return $this->fetch('message/index'); @@ -73,11 +41,23 @@ class Message extends BaseShop{ // 参数获取 $type = input('type',2); $content = input('message_content',''); + $title = input('title',''); - return (new messageModel())->addMessage($this->site_id,$content,$type); + return (new messageModel())->addMessage($this->site_id,$content,$type,'all',0,$title); } return $this->fetch('message/send_message'); } + /** + * Common: 删除信息 + * Author: wu-hui + * Time: 2023/03/04 15:48 + * @return array + */ + public function delMessage(){ + $id = input('id'); + + return (new messageModel())->delInfo($id); + } } \ No newline at end of file diff --git a/addon/message/shop/controller/Remark.php b/addon/message/shop/controller/Remark.php new file mode 100644 index 00000000..46404e4b --- /dev/null +++ b/addon/message/shop/controller/Remark.php @@ -0,0 +1,31 @@ +isAjax()) return (new messageModel())->getList($this->site_id); + + $this->forthMenu(); + return $this->fetch('remark/index'); + } + + + + + +} \ No newline at end of file diff --git a/addon/message/shop/view/message/index.html b/addon/message/shop/view/message/index.html index 815e5903..0b1233b4 100644 --- a/addon/message/shop/view/message/index.html +++ b/addon/message/shop/view/message/index.html @@ -5,7 +5,6 @@ background-color: #009688; color: #fff; } - {/block} @@ -16,51 +15,22 @@