<?php

namespace app\index\controller;
use app\common\controller\Frontend;
use think\Config;
use think\Hook;
use think\Db;
use think\Request;


class Circlehuifu extends Frontend
{

  protected $layout = 'default';
    protected $noNeedLogin = ['login', 'register', 'third'];
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
        $auth = $this->auth;

        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }

        //监听注册登录注销的事件
        Hook::add('user_login_successed', function ($user) use ($auth) {
            $expire = input('post.keeplogin') ? 30 * 86400 : 0;
            Cookie::set('uid', $user->id, $expire);
            Cookie::set('token', $auth->getToken(), $expire);
        });
        Hook::add('user_register_successed', function ($user) use ($auth) {
            Cookie::set('uid', $user->id);
            Cookie::set('token', $auth->getToken());
        });
        Hook::add('user_delete_successed', function ($user) use ($auth) {
            Cookie::delete('uid');
            Cookie::delete('token');
        });
        Hook::add('user_logout_successed', function ($user) use ($auth) {
            Cookie::delete('uid');
            Cookie::delete('token');
        });
    }

    /**
     * 空的请求
     * @param $name
     * @return mixed
     */
    public function _empty($name)
    {
        $data = Hook::listen("user_request_empty", $name);
        foreach ($data as $index => $datum) {
            $this->view->assign($datum);
        }
        return $this->view->fetch('user/' . $name);
    }

   
    

    //用户回复执行
    
public function getuserhuifu()
    {
        $getcircleid  =  input('get.contentid'); // 获取链接上面的文章的圈子ID
        $getuserfid  =  input('get.userfid'); //

        $userid = $this->auth->getUserinfo()['user_id'];//获取这个用户的ID

        $windsns_huifuadd['user_id']=  $userid; // 获取发布用户id
        $windsns_huifuadd['user_fid']=  $getuserfid; //
        $windsns_huifuadd['contentid']= $getcircleid; // 获取帖子的ID
        $windsns_huifuadd['circlehuifu_infos'] = input('post.circlehuifu_infos'); // 获取留言内容
        $windsns_huifuadd['circlehuifu_times'] = time();

        if (!$windsns_huifuadd['circlehuifu_infos']) {
            echo 'no';
            exit;
        } else {
            $sqladd = Db::name('circlehuifu')->insert($windsns_huifuadd); // 保存回复数据
            if ($getuserfid > 0) {
                $sqlupdate = Db::name('circlehuifu')
                    ->where('circlehuifu_id', $getuserfid)
                    ->setInc('replies', 1);
            }
            echo 'ok';
        }
    }
    
   
    
    

}
