123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- <?php
- namespace app\api\controller;
- use app\api\controller\Base;
- use think\Db;
- use think\Model;
- class Operation extends Base
- {
- function initialize()
- {
- $this->check_login();
- }
-
- public function attention(){
- $uid = $this->uid;
- $user_id = input('user_id');
- $type = input('operation_type');
- if(empty($user_id) || !isset($type)){
- $this->error('参数错误');
- }
- if($uid == $user_id){
- $this->error('不能操作自己');
- }
- $attention = Db::name('store_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->find();
- $msg = '关注成功';
- if($type == 0){
- if(empty($attention['status'])){
- $this->error('没关注无需取消');
- }
- Db::name('store_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->update(array('status'=>0));
- $msg = '取消成功';
- }else{
- if(!empty($attention['status'])){
- $this->error('已关注无需继续关注');
- }
- if($attention['id']){
- Db::name('store_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->update(array('status'=>1));
- }else{
- $data = array(
- 'user_id' => $uid,
- 'from_user_id' => $user_id,
- 'type' => user_type($user_id),
- 'status' => 1
- );
- Db::name('store_attention')->insert($data);
- }
- }
- $this->success($msg);
- }
-
- public function submit_comment(){
- $uid = $this->uid;
- $type = input('type');
- $id = input('id');
- $content = input('content');
- if(empty($type) || empty($id) || empty($content)){
- $this->error('参数错误');
- }
- $table_nme = $type==1?'store_goods':'store_consult';
- $type_name = $type==1?'新闻':'咨询';
- $info = Db::name($table_nme)->field('user_id,title')->where('id',$id)->where('status',1)->where('is_deleted',0)->find();
- if(empty($info)){
- $this->error($type_name.'信息有误');
- }
- if($uid == $info['user_id']){
- $this->error('不能操作自己');
- }
- $comment_info = Db::name('store_comment')->field('id')->where('user_id',$uid)->where('forum_id',$id)->where('type',1)->where('forum_type',$type)->find();
- if(!empty($comment_info)){
- $this->error('已评论过该'.$type_name);
- }
- $comment_data = array(
- 'user_id' => $uid,
- 'from_user_id' => $info['user_id'],
- 'forum_id' => $id,
- 'content' => $content,
- 'forum_type' => $type,
- 'type' => 1
- );
- Db::name('store_comment')->insert($comment_data);
- $comment_id = Db::name('store_comment')->getLastInsID();
- Db::name('store_comment')->where('id',$comment_id)->update(array('root_comment_id'=>$comment_id));
- $user_type = user_type($info['user_id']);
- if($user_type == 1){
- $user_name = Db::name('store_member')->where('id',$uid)->value('name');
- $news_data = array(
- 'user_id' => $info['user_id'],
- 'content' => $user_name.'评论了你发表的['.$info['title'].']咨询',
- 'comment_user_id' => $uid,
- 'type' => 2,
- );
- Db::name('store_news')->insert($news_data);
- }
- $this->success('评论成功');
- }
-
- public function reply_comment(){
- $uid = $this->uid;
- $comment_id = input('comment_id');
- $content = input('content');
- if(empty($content) || empty($comment_id)){
- $this->error('参数错误');
- }
- $comment = Db::name('store_comment')->field('forum_id,user_id,root_comment_id,forum_type')->where('id',$comment_id)->find();
- if(empty($comment)){
- $this->error('要回复的评论信息有误');
- }
- if($comment['user_id'] == $uid){
- $this->error('不能回复自己的评论');
- }
-
- $reply_comment = Db::name('store_comment')->field('id')->where('user_id',$uid)->where('type',2)->where('comment_id',$comment_id)->find();
- if(!empty($reply_comment)){
- $this->error('已回复过此评论');
- }
- $root_comment_id = $comment['root_comment_id']?$comment['root_comment_id']:$comment_id;
- $comment_data = array(
- 'forum_id' => $comment['forum_id'],
- 'user_id' => $uid,
- 'from_user_id' => $comment['user_id'],
- 'content' => $content,
- 'comment_id' => $comment_id,
- 'forum_type' => $comment['forum_type'],
- 'root_comment_id' => $root_comment_id,
- 'type' => 2
- );
- Db::name('store_comment')->insert($comment_data);
-
- $user_name = Db::name('store_member')->where('id',$uid)->value('name');
- $news_data = array(
- 'user_id' => $comment['user_id'],
- 'content' => $user_name.'回复的你的评论',
- 'comment_user_id' => $uid,
- 'type' => 2,
- );
- Db::name('store_news')->insert($news_data);
- $this->success('回复评论成功');
- }
-
- public function like(){
- $uid = $this->uid;
- $id = input('id');
- $operation_type = input('operation_type');
- $type = input('type');
- if(empty($id) || !isset($operation_type) || empty($type)){
- $this->error('参数错误');
- }
- $table_nme = $type==1?'store_goods':'store_consult';
- $type_name = $type==1?'新闻':'咨询';
- $info = Db::name($table_nme)->field('user_id')->where('id',$id)->where('status',1)->where('is_deleted',0)->find();
- if(empty($info)){
- $this->error($type_name.'信息有误');
- }
- if($uid == $info['user_id']){
- $this->error('不能操作自己');
- }
- $like = Db::name('store_like')->where('user_id',$uid)->where('forum_id',$id)->where('user_id',$uid)->find();
- $msg = '点赞成功';
- if($operation_type == 0){
- if(empty($like['status'])){
- $this->error('没点赞无需取消');
- }
- Db::name('store_like')->where('user_id',$uid)->where('forum_id',$id)->update(array('status'=>0));
- $msg = '取消成功';
- }else{
- if(!empty($like['status'])){
- $this->error('已点赞无需继续点赞');
- }
- if($like['id']){
- Db::name('store_like')->where('user_id',$uid)->where('forum_id',$id)->where('type',$type)->update(array('status'=>1));
- }else{
- $data = array(
- 'user_id' => $uid,
- 'from_user_id' => $info['user_id'],
- 'forum_id' => $id,
- 'type' => $type,
- 'status' => 1
- );
- Db::name('store_like')->insert($data);
- }
- }
- $this->success($msg);
- }
-
- public function collect(){
- $uid = $this->uid;
- $id = input('id');
- $operation_type = input('operation_type');
- $type = input('type');
- if(empty($id) || !isset($operation_type) || empty($type)){
- $this->error('参数错误');
- }
- $table_nme = $type==1?'store_goods':'store_consult';
- $type_name = $type==1?'新闻':'咨询';
- $info = Db::name($table_nme)->field('user_id')->where('id',$id)->where('status',1)->where('is_deleted',0)->find();
- if(empty($info)){
- $this->error($type_name.'信息有误');
- }
- if($uid == $info['user_id']){
- $this->error('不能操作自己');
- }
- $collect = Db::name('store_collect')->where('user_id',$uid)->where('forum_id',$id)->where('type',$type)->find();
- $msg = '收藏成功';
- if($operation_type == 0){
- if(empty($collect['status'])){
- $this->error('没收藏无需取消');
- }
- Db::name('store_collect')->where('user_id',$uid)->where('forum_id',$id)->where('type',$type)->update(array('status'=>0));
- $msg = '取消成功';
- }else{
- if(!empty($collect['status'])){
- $this->error('已收藏无需继续点赞');
- }
- if($collect['id']){
- Db::name('store_collect')->where('user_id',$uid)->where('forum_id',$id)->where('type',$type)->update(array('status'=>1));
- }else{
- $data = array(
- 'user_id' => $uid,
- 'from_user_id' => $info['user_id'],
- 'forum_id' => $id,
- 'type' => $type,
- 'status' => 1
- );
- Db::name('store_collect')->insert($data);
- }
- }
- $this->success($msg);
- }
-
- public function transpond(){
- $uid = $this->uid;
- $id = input('id');
- $type = input('type');
- if(empty($id) || empty($type)){
- $this->error('参数错误');
- }
- $table_nme = $type==1?'store_goods':'store_consult';
- $type_name = $type==1?'新闻':'咨询';
- $info = Db::name($table_nme)->field('user_id')->where('id',$id)->where('status',1)->where('is_deleted',0)->find();
- if(empty($info)){
- $this->error($type_name.'信息有误');
- }
- if($uid == $info['user_id']){
- $this->error('不能操作自己');
- }
- $data = array(
- 'user_id' => $uid,
- 'forum_id' => $id,
- 'type' => $type
- );
- Db::name('store_transpond')->insert($data);
- $this->success('操作成功');
- }
- }
|