From 926e78d6f547e64d51d9944323770f71fc43938e Mon Sep 17 00:00:00 2001 From: heshupeng <hsp@bronet.cn> Date: Sat, 10 Oct 2020 11:40:49 +0800 Subject: [PATCH] bug修改 --- application/mobile/controller/Topic.php | 57 ++++++++++++++++++++++++++++++++++++++++++--------------- application/mobile/controller/User.php | 40 +++++++++++++++++++++++++++------------- 2 files changed, 69 insertions(+), 28 deletions(-) diff --git a/application/mobile/controller/Topic.php b/application/mobile/controller/Topic.php index 28b6baa..5ccfe19 100644 --- a/application/mobile/controller/Topic.php +++ b/application/mobile/controller/Topic.php @@ -71,13 +71,20 @@ class Topic extends Api */ public function topicAdd() { - $post = $this->request->param(); - empty($post['topic_category_id']) && $this->error('请选择话题分类'); - empty($post['title']) && $this->error('请输入标题'); - empty($post['content']) && $this->error('请填写话题内容'); - $this->model->allowField(true)->save(array_merge([ - 'user_id' => $this->auth->id - ],$post)); + $topic_category_id = $this->request->param('topic_category_id'); + $title = $this->request->param('title'); + $cover = $this->request->param('cover'); + $content = $this->request->param('content','','htmlspecialchars_decode'); + empty($topic_category_id) && $this->error('请选择话题分类'); + empty($title) && $this->error('请输入标题'); + empty($content) && $this->error('请填写话题内容'); + $this->model->allowField(true)->save([ + 'user_id' => $this->auth->id, + 'topic_category_id' => $topic_category_id, + 'title' => $title, + 'cover' => $cover, + 'content' => $content + ]); $this->success('发帖成功'); } @@ -93,13 +100,14 @@ class Topic extends Api * @ApiReturn({ "code": 1, "msg": "成功", - "time": "1601349634", + "time": "1602300901", "data": { "total": 1, //数据总数 "list": [{ "id": 1, //话题ID "title": "公司即将上市", //话题标题 - "content": "这就是街舞", //话题内容 + "cover": "http://qizhibang.brotop.cn/uploads/20201009/9bc002db9517fe79f93478550a979768.jpg", //封面图 + "content": "他咯土佐玉木桶浴", //话题内容 "agree_num": 0, //赞同量 "download_num": 0, //下载量 "createtime": "2020.09.29 09:11", //发布时间 @@ -107,7 +115,10 @@ class Topic extends Api "id": 15, //用户ID "nickname": "", //昵称 "image": "" //头像 - } + }, + "imgs": [ //发布内容图片 + "http://qizhibang.brotop.cn/uploads/20201010/dd2b86d8186f0e89735798d6f9a8f56c.jpg" + ] }] } }) @@ -141,13 +152,19 @@ class Topic extends Api ->order($order) ->paginate($page_num,false,['page'=>$page]) ->each(function($v){ - $v->visible(['id','title','cover','content','createtime','agree_num','download_num','user']); // 发布时间格式化 $v->createtime = date('Y.m.d H:i',$v->createtime); // 过滤标签 $content1 = htmlspecialchars_decode($v->content); $content2 = str_replace([' ',' '],['',''],$content1); $v->content = strip_tags($content2); + // 拼装图片 + $imgs = strip_tags($content2, '<img>'); + //$matches[1] 为图片路径数组 + preg_match_all('/\<img\s+src\=\"([\w:\/\.]+)\"/', $imgs, $matches); + $v->imgs = $matches[1]; + // 显示数据 + $v->visible(['id','title','cover','content','createtime','agree_num','download_num','user'])->append(['imgs']); $v->getRelation('user')->visible(['id','image','nickname']); })->toArray(); $this->success('成功',['total'=>$data['total'],'list'=>$data['data']]); @@ -210,13 +227,14 @@ class Topic extends Api * @ApiReturn({ "code": 1, "msg": "成功", - "time": "1601349634", + "time": "1602300901", "data": { "total": 1, //数据总数 "list": [{ "id": 1, //话题ID "title": "公司即将上市", //话题标题 - "content": "这就是街舞", //话题内容 + "cover": "http://qizhibang.brotop.cn/uploads/20201009/9bc002db9517fe79f93478550a979768.jpg", //封面图 + "content": "他咯土佐玉木桶浴", //话题内容 "agree_num": 0, //赞同量 "download_num": 0, //下载量 "createtime": "2020.09.29 09:11", //发布时间 @@ -224,7 +242,10 @@ class Topic extends Api "id": 15, //用户ID "nickname": "", //昵称 "image": "" //头像 - } + }, + "imgs": [ //发布内容图片 + "http://qizhibang.brotop.cn/uploads/20201010/dd2b86d8186f0e89735798d6f9a8f56c.jpg" + ] }] } }) @@ -260,13 +281,19 @@ class Topic extends Api ->order(['hot_num'=>'desc']) ->paginate($page_num,false,['page'=>$page]) ->each(function($v){ - $v->visible(['id','title','cover','content','createtime','agree_num','download_num','user']); // 发布时间格式化 $v->createtime = date('Y.m.d H:i',$v->createtime); // 过滤标签 $content1 = htmlspecialchars_decode($v->content); $content2 = str_replace([' ',' '],['',''],$content1); $v->content = strip_tags($content2); + // 拼装图片 + $imgs = strip_tags($content2, '<img>'); + //$matches[1] 为图片路径数组 + preg_match_all('/\<img\s+src\=\"([\w:\/\.]+)\"/', $imgs, $matches); + $v->imgs = $matches[1]; + // 显示数据 + $v->visible(['id','title','cover','content','createtime','agree_num','download_num','user'])->append(['imgs']); $v->getRelation('user')->visible(['id','image','nickname']); })->toArray(); $this->success('成功',['total'=>$data['total'],'list'=>$data['data']]); diff --git a/application/mobile/controller/User.php b/application/mobile/controller/User.php index 9acb9d2..8fbc7d0 100644 --- a/application/mobile/controller/User.php +++ b/application/mobile/controller/User.php @@ -60,7 +60,7 @@ class User extends Api $ret = Sms::check($mobile, $code, 'register'); !$ret && $this->error('验证码不正确'); - $ret = $this->auth->register($username='', $password, $email='', $mobile, []); + $ret = $this->auth->register($username=get_order_sn(), $password, $email='', $mobile, []); if ($ret) { $this->auth->setAllowFields(['id', 'mobile', 'group_id']); $data = ['userinfo' => $this->auth->getUserinfo()]; @@ -124,7 +124,7 @@ class User extends Api Db::startTrans(); try { - $ret = $this->auth->register($username='', $password, $email='', $mobile, []); + $ret = $this->auth->register($username=get_order_sn(), $password, $email='', $mobile, []); if (!$ret) { $this->error($this->auth->getError()); } @@ -1153,22 +1153,25 @@ class User extends Api * @ApiReturn({ "code": 1, "msg": "成功", - "time": "1602292309", + "time": "1602300901", "data": { - "total": 1, //数据总条数 + "total": 1, //数据总数 "list": [{ - "id": 1, //帖子ID - "title": "公司即将上市", //标题 + "id": 1, //话题ID + "title": "公司即将上市", //话题标题 "cover": "http://qizhibang.brotop.cn/uploads/20201009/9bc002db9517fe79f93478550a979768.jpg", //封面图 - "content": "这就是街舞", //内容 + "content": "他咯土佐玉木桶浴", //话题内容 "agree_num": 0, //赞同量 "download_num": 0, //下载量 - "createtime": "2020.09.29 09:11", //发帖时间 - "user": { //用户信息 + "createtime": "2020.09.29 09:11", //发布时间 + "user": { //发布者信息 "id": 15, //用户ID - "nickname": "", //真实姓名 + "nickname": "", //昵称 "image": "" //头像 - } + }, + "imgs": [ //发布内容图片 + "http://qizhibang.brotop.cn/uploads/20201010/dd2b86d8186f0e89735798d6f9a8f56c.jpg" + ] }] } }) @@ -1183,8 +1186,19 @@ class User extends Api ->order('createtime desc') ->paginate($page_num,false,['page'=>$page]) ->each(function($v){ - $v->visible(['id','title','cover','content','createtime','agree_num','download_num','user']); - $v->createtime = date('Y.m.d H:i',$v['createtime']); + // 发布时间格式化 + $v->createtime = date('Y.m.d H:i',$v->createtime); + // 过滤标签 + $content1 = htmlspecialchars_decode($v->content); + $content2 = str_replace([' ',' '],['',''],$content1); + $v->content = strip_tags($content2); + // 拼装图片 + $imgs = strip_tags($content2, '<img>'); + //$matches[1] 为图片路径数组 + preg_match_all('/\<img\s+src\=\"([\w:\/\.]+)\"/', $imgs, $matches); + $v->imgs = $matches[1]; + // 显示数据 + $v->visible(['id','title','cover','content','createtime','agree_num','download_num','user'])->append(['imgs']); $v->getRelation('user')->visible(['id','image','nickname']); })->toArray(); $this->success('成功', ['total'=>$data['total'],'list'=>$data['data']]); -- libgit2 0.24.0