<?php
// +----------------------------------------------------------------------
// | WindSNS 国内领先企业级社交开源SNS框架系统
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://windsns.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 常州微诺信息科技有限公司 http://www.weinuo.net
// +----------------------------------------------------------------------
// | E-mail: open@weinuo.net
// +----------------------------------------------------------------------
namespace app\index\controller;
use app\common\controller\Frontend;
use think\Config;
use think\Hook;
use think\Db;
use think\Request;
use think\Session;
class Windsnsuservideos 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);
    }

	/**
	 * 协议
	 * @author   Devil
	 * @blog     http://www.weinuo.net
	 * @version  0.0.1
	 * @datetime 2020-03-04
	 */
    public function index()
    {
    $this->view->assign('title', __('我的视频-用户中心'));
    $windsns_userid = $this->auth->getUserinfo()['user_id'];;
	$windsnspaylist = Db::name('admin_videospaylist')->alias('a') -> join('user w','a.user_id = w.id') -> join('admin_videos e','a.videospay_videosid = e.videosid') -> where(['user_id'=>$windsns_userid,'videospay_del'=>1]) ->  order('videospayid', 'desc') -> paginate(20); 
	$windsnspaysum  = Db::name('admin_videospaylist')->where(['user_id' => $windsns_userid,'videospay_del'=>1])->count();
	$page = $windsnspaylist->render();
	$this->assign('windsnspaylist', $windsnspaylist);
	$this->assign('page', $page);
	 if($windsnspaysum > 1 or $windsnspaysum == 1){
        	return $this->view->fetch('windsns_videopaylist');
        }else{
          return $this->view->fetch('errors_paynoinfos');
        }

    }


      public function windsnsdeldo($videospayid)
    {
         $urlvideospayid  =  input('get.videospayid'); 
         $sqlwindsns = Db::name('admin_videospaylist')->where(['videospayid'=>$urlvideospayid,'videospay_del'=>2])->find();
         if($sqlwindsns){
         return $this->view->fetch('errors_windsnsnull');
         }else{
          $data['videospay_del'] =  2; 
          $xiugaizhuangtai = Db::name('admin_videospaylist')->where('videospayid', $urlvideospayid)->update($data);// 
          return $this->view->fetch('errors_windsnsnoinfos');
         }
        
   }  



}
