<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +---------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace app\love\controller;

use app\common\Wechat;
use app\love\model\LotteryLogModel;
use app\love\model\UserModel;
use cmf\controller\HomeBaseController;
use think\facade\Request;
use think\facade\Session;

class LoveBaseController extends HomeBaseController
{
    protected $user = null;
    protected $mating = null;

    public function initialize()
    {
        parent::initialize();
        $userId = cmf_get_current_user_id();

        //记录回调
        $domain = $this->request->url(true);
        Session::set('domain', $domain);

        if (empty($userId)) {
            if ($this->request->isAjax()) {
                $this->error("您尚未登录", cmf_url("love/Login/index"));
            } else {
                $this->redirect(cmf_url("love/Login/index"));
            }
        }

        $this->user = UserModel::get($userId);
        if (empty($this->user)) {
            Session::destroy();
            $this->redirect(cmf_url("love/Login/index"));
        }
        //拉黑
        if ($this->user['user_status'] == 0) {
            $this->redirect(cmf_url('love/register/ban'));
        }
        //完善资料
        if ($this->user['is_complete'] == 2) {
            if (empty($this->user['sex'])) {
                $this->redirect(cmf_url('love/register/sex'));
            } else {
                $this->redirect(cmf_url('love/register/intro'));
            }
        }

        //分享页面
        $wx_api_sign = Wechat::instance()->getJsSign(Request::url(true));
        $this->assign('domain', $this->request->domain());
        $this->assign('wx_api_sign', json_encode($wx_api_sign));
    }

    /**
     * 会员状态
     */
    protected function checkStatus()
    {
        if ($this->user['check_status'] != 2) {
            $this->error('请等待审核！');
        }
    }
}