136 lines
4.0 KiB
PHP
136 lines
4.0 KiB
PHP
<?php
|
||
// +------------------------------------------------+
|
||
// |http://www.cjango.com |
|
||
// +------------------------------------------------+
|
||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||
// +------------------------------------------------+
|
||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||
// +------------------------------------------------+
|
||
namespace app\mobile\controller;
|
||
|
||
use app\common\model\Member;
|
||
use app\common\model\Permission;
|
||
use app\common\service\MemberInfo;
|
||
use app\common\service\Wechat as WechatService;
|
||
use tools\Initialize;
|
||
use tools\Str;
|
||
|
||
class _Init extends Initialize
|
||
{
|
||
|
||
public function _initialize()
|
||
{
|
||
define('UID', self::isLogin());
|
||
if (!UID) {
|
||
$this->redirect('login/wxLogin', 'callback=' . base64_encode(__SELF__));
|
||
}
|
||
$this->user = Member::get(UID);
|
||
if (empty($this->user->username)) {
|
||
$this->redirect('login/index');
|
||
}
|
||
$uid = $this->request->get('uid');
|
||
|
||
if ($uid) {
|
||
$this->shareUser = MemberInfo::show($uid);
|
||
}
|
||
|
||
// 判定vip权限
|
||
if (!self::checkAuth()) {
|
||
if (IS_AJAX) {
|
||
return $this->error('您没有权限', url('finance/vip'));
|
||
} else {
|
||
$this->redirect(url('finance/vip'));
|
||
}
|
||
}
|
||
//分享初始化
|
||
self::fenxiang();
|
||
}
|
||
|
||
protected function checkAuth()
|
||
{
|
||
$check = Permission::where('url', CONTROLLER_NAME . '/' . ACTION_NAME)->find();
|
||
if ($this->user->info->is_vip == 1 && strtotime($this->user->info->vip_time) > time()) {
|
||
return true;
|
||
} else {
|
||
if (!$check) {
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 操作成功跳转的快捷方法
|
||
* @access protected
|
||
* @param mixed $msg 提示信息
|
||
* @param string $url 跳转的URL地址
|
||
* @param mixed $data 返回的数据
|
||
* @param integer $wait 跳转等待时间
|
||
* @param array $header 发送的Header信息
|
||
* @return void
|
||
*/
|
||
protected function success($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
|
||
{
|
||
$msg = $msg ?: '操作成功';
|
||
return parent::success($msg, $url, $data, $wait, $header);
|
||
}
|
||
|
||
/**
|
||
* 操作错误跳转的快捷方法
|
||
* @access protected
|
||
* @param mixed $msg 提示信息
|
||
* @param string $url 跳转的URL地址
|
||
* @param mixed $data 返回的数据
|
||
* @param integer $wait 跳转等待时间
|
||
* @param array $header 发送的Header信息
|
||
* @return void
|
||
*/
|
||
protected function error($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
|
||
{
|
||
$msg = $msg ?: '未知错误';
|
||
return parent::error($msg, $url, $data, $wait, $header);
|
||
}
|
||
|
||
protected function back($result)
|
||
{
|
||
if ($result === true) {
|
||
return $this->success();
|
||
} else {
|
||
return $this->error($result);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 微信分享
|
||
* @return [type] [description]
|
||
*/
|
||
public function fenxiang()
|
||
{
|
||
$wx = WechatService::jsWechat();
|
||
|
||
// parent::initWechat();
|
||
// // 微信分享
|
||
// $ticket = Cache::get('Wechat_ticket');
|
||
// $config = Config::get('wechat');
|
||
|
||
// if (!$ticket) {
|
||
// $ticket = Token::ticket();
|
||
// Cache::set('Wechat_ticket', $ticket, 7000);
|
||
// }
|
||
// $wx['appid'] = $config['appid'];
|
||
// $wx['timestamp'] = time();
|
||
// $wx['noncestr'] = $noncestr = Str::random(32);
|
||
// $sign = array(
|
||
// 'noncestr' => $noncestr,
|
||
// 'jsapi_ticket' => $ticket,
|
||
// 'timestamp' => time(),
|
||
// 'url' => __SELF__,
|
||
// );
|
||
// ksort($sign);
|
||
// $signStr = sha1(urldecode(http_build_query($sign)));
|
||
// $wx['signature'] = $signStr;
|
||
$this->assign('wx', $wx);
|
||
}
|
||
}
|