|
@@ -0,0 +1,159 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller;
|
|
|
+
|
|
|
+use app\common\controller\Api;
|
|
|
+use think\Db;
|
|
|
+/**
|
|
|
+ * 动态
|
|
|
+ */
|
|
|
+class Userdongtai extends Api
|
|
|
+{
|
|
|
+ protected $noNeedLogin = ['evaluate'];
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
+
|
|
|
+ //发布动态
|
|
|
+ public function addone(){
|
|
|
+ $title = input('title','');
|
|
|
+ $images = input('images','');
|
|
|
+ if(!$title && !$images){
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'title' => $title,
|
|
|
+ 'images' => $images,
|
|
|
+ 'createtime' => time(),
|
|
|
+ 'updatetime' => time(),
|
|
|
+ ];
|
|
|
+
|
|
|
+
|
|
|
+ $id = Db::name('user_dongtai')->insertGetId($data);
|
|
|
+
|
|
|
+ $this->success('success',$id);
|
|
|
+ }
|
|
|
+
|
|
|
+ //自己看列表
|
|
|
+ public function my_lists(){
|
|
|
+
|
|
|
+ $list = Db::name('user_dongtai')->alias('dt')
|
|
|
+ ->join('user','dt.user_id = user.id','LEFT')
|
|
|
+ ->field('dt.id,dt.title,dt.images,dt.createtime,dt.sharenum,dt.goodnum,user.nickname,user.avatar')
|
|
|
+ ->where('dt.user_id',$this->auth->id)
|
|
|
+ ->order('dt.id desc')->autopage()->select();
|
|
|
+ $list = list_domain_image($list,['images','avatar']);
|
|
|
+ /*foreach($list as $key => &$val){
|
|
|
+ if($val['images']){
|
|
|
+ $val['images'] = explode(',',$val['images']);
|
|
|
+ }else{
|
|
|
+ $val['images'] = [];
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+
|
|
|
+ $this->success('success',$list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //详情
|
|
|
+ public function info(){
|
|
|
+ $id = input('id');
|
|
|
+
|
|
|
+ $info = Db::name('user_dongtai')->alias('p')
|
|
|
+ ->join('user','p.user_id = user.id','LEFT')
|
|
|
+ ->field('p.id,p.title,p.images,p.createtime,p.sharenum,p.goodnum,user.nickname,user.avatar')
|
|
|
+ ->where('p.id',$id)->find();
|
|
|
+ $info = info_domain_image($info,['images','avatar']);
|
|
|
+
|
|
|
+ /*if($info['images']){
|
|
|
+ $info['images'] = explode(',',$info['images']);
|
|
|
+ }else{
|
|
|
+ $info['images'] = [];
|
|
|
+ }*/
|
|
|
+
|
|
|
+ //是否点赞过
|
|
|
+ if($info){
|
|
|
+ $where = [
|
|
|
+ 'dt_id' => $id,
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ ];
|
|
|
+ $check = Db::name('user_dongtai_good')->where($where)->find();
|
|
|
+
|
|
|
+ if($check){
|
|
|
+ $info['isgood'] = 1;
|
|
|
+ }else{
|
|
|
+ $info['isgood'] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //评论
|
|
|
+
|
|
|
+ $this->success('success',$info);
|
|
|
+ }
|
|
|
+
|
|
|
+ //评论
|
|
|
+ public function answer(){
|
|
|
+ $id = input('id');
|
|
|
+ $title = input('title','');
|
|
|
+ $to_user_id = input('to_user_id','');
|
|
|
+ $level = input('level',1);
|
|
|
+ if(!$title){
|
|
|
+ $this->error();
|
|
|
+ }
|
|
|
+
|
|
|
+ //最新楼层
|
|
|
+ $new_floor = 2;
|
|
|
+ $last_answer = Db::name('user_dongtai_answer')->where('dt_id',$id)->order('id desc')->value('floor');
|
|
|
+ if($last_answer){
|
|
|
+ $new_floor = $last_answer + 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ //data
|
|
|
+ $data = [
|
|
|
+ 'dt_id' => $id,
|
|
|
+ 'floor' => $new_floor,
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'title' => $title,
|
|
|
+ 'to_user_id' => $to_user_id,
|
|
|
+ 'level' => $level,
|
|
|
+ 'createtime' => time(),
|
|
|
+ 'updatetime' => time(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $rs = Db::name('user_dongtai_answer')->insertGetId($data);
|
|
|
+ $this->success('评价成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ //家长点赞
|
|
|
+ public function good(){
|
|
|
+ $id = input('id');
|
|
|
+
|
|
|
+ $where = [
|
|
|
+ 'dt_id' => $id,
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ ];
|
|
|
+ $check = Db::name('user_dongtai_good')->where($where)->find();
|
|
|
+
|
|
|
+ if($check){
|
|
|
+ $this->error('已经赞过了');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ $rs = Db::name('user_dongtai_good')->insertGetId($where);
|
|
|
+ $up = Db::name('user_dongtai')->where('id',$id)->setInc('goodnum');
|
|
|
+
|
|
|
+ if($rs && $up !== false){
|
|
|
+ Db::commit();
|
|
|
+ $this->success('点赞成功');
|
|
|
+ }
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('点赞失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ //分享
|
|
|
+ public function sharenum(){
|
|
|
+ $id = input('id');
|
|
|
+ $up = Db::name('user_dongtai')->where('id',$id)->setInc('sharenum');
|
|
|
+ $this->success('操作成功');
|
|
|
+ }
|
|
|
+
|
|
|
+}
|