diff --git a/addon/article/model/Article.php b/addon/article/model/Article.php index c8697dcd..b7e79e11 100644 --- a/addon/article/model/Article.php +++ b/addon/article/model/Article.php @@ -25,7 +25,9 @@ class Article extends NewBaseModel{ protected $append = [ 'category_name' ]; - + protected $autoWriteTimestamp = 'int'; // 开启自动时间戳 + protected $createTime = 'create_time'; // 默认添加时间字段 + protected $updateTime = 'update_time'; // 默认编辑时间字段 /** * Common: 列表获取 diff --git a/addon/article/model/ArticleCategory.php b/addon/article/model/ArticleCategory.php index 02dd10ef..673fbab0 100644 --- a/addon/article/model/ArticleCategory.php +++ b/addon/article/model/ArticleCategory.php @@ -17,6 +17,9 @@ use app\model\NewBaseModel; class ArticleCategory extends NewBaseModel{ protected $pk = 'category_id'; + protected $autoWriteTimestamp = 'int'; // 开启自动时间戳 + protected $createTime = 'create_time'; // 默认添加时间字段 + protected $updateTime = 'update_time'; // 默认编辑时间字段 /** * Common: 列表获取 * Author: wu-hui diff --git a/addon/article/model/ArticleHistory.php b/addon/article/model/ArticleHistory.php index 7304f3c0..274a8545 100644 --- a/addon/article/model/ArticleHistory.php +++ b/addon/article/model/ArticleHistory.php @@ -18,6 +18,7 @@ class ArticleHistory extends NewBaseModel{ protected $pk = 'id'; //protected $autoWriteTimestamp = false; // 开启自动时间戳 + protected $autoWriteTimestamp = 'int'; // 开启自动时间戳 protected $createTime = 'create_time'; // 默认添加时间字段 protected $updateTime = 'update_time'; // 默认编辑时间字段 protected $deleteTime = false; // 软删除字段 diff --git a/addon/message/api/controller/Message.php b/addon/message/api/controller/Message.php new file mode 100644 index 00000000..a50948db --- /dev/null +++ b/addon/message/api/controller/Message.php @@ -0,0 +1,88 @@ +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', + 'a.reply_content', + '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()); + } + /** + * 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 c0fbe374..c4addb23 100644 --- a/addon/message/model/Message.php +++ b/addon/message/model/Message.php @@ -8,19 +8,50 @@ 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 +63,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 = '',$image = ''){ if(!$content) return $this->error('','消息不能为空!'); // 记录消息信息 try{ @@ -42,8 +74,10 @@ class Message extends BaseModel{ ->insertGetId([ 'site_id' => $siteId, 'type' => $type, + 'message_title' => $title ?? $this->types[$type], 'message_content' => $content, - 'created_time' => time() + 'created_time' => time(), + 'image_list' => $image, ]); // 关联用户信息 if($member_id == 'all'){ @@ -76,6 +110,84 @@ 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(); + } + /** + * 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); + } + 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..a8debb10 --- /dev/null +++ b/addon/message/shop/controller/Remark.php @@ -0,0 +1,67 @@ +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'); + } + + + +} \ 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 @@