| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\api\controller\service;
- use app\common\controller\Api;
- use think\Db;
- use think\Exception;
- /**
- * 首页接口
- */
- class Comment extends Api
- {
- protected $noNeedLogin = ['getList','totalComment','commentLabel','getInfo'];
- protected $noNeedRight = ['*'];
- /**
- * 查询评论列表
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getList()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- //$uid = $this->auth->isLogin()?$this->auth->id:'';
- $post = input('post.','','trim,strip_tags');
- $post['limit'] = 10;
- $post['page'] = input('page/d',1);
- $list = \app\api\model\service\Comment::searchComment($post);
- $this->success('信息列表返回成功',$list);
- }
- public function commentLabel()
- {
- $list = \app\api\model\service\CommentLabel::where(['state'=>1])->field('id,name')->select();
- $this->success('信息返回成功',$list);
- }
- /**
- * 统计评论数据
- * @return void
- */
- public function totalComment()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $post = input('post.','','trim,strip_tags');
- $data = '';
- try{
- $data = \app\api\model\service\Comment::totalComment($post);
- } catch (Exception $e) {
- $this->error('获取统计信息失败',$e->getMessage());
- }
- $this->success('信息列表返回成功',$data);
- }
- public function commentAdd()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $post = input('post.','','trim,strip_tags,htmlspecialchars,xss_clean');
- $post['user_id'] = $this->auth->id;
- Db::startTrans();
- try{
- \app\api\model\service\Comment::commentAdd($post);
- Db::commit();
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success('订单已评论');
- }
- public function getInfo()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $id = input('order_id','');
- $comment = \app\api\model\service\Comment::where('order_id',$id)->field('score,comment_label_ids,comment_label,content,images')->find();
- $comment['images'] = $comment['images']?explode(',',$comment['images']):'';
- $this->success('信息返回成功',$comment);
- }
- }
|