You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
353 lines
12 KiB
353 lines
12 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | YFCMF [ WE CAN DO IT MORE SIMPLE ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Author: rainfer <81818832@qq.com>
|
|
// +----------------------------------------------------------------------
|
|
namespace app\home\controller;
|
|
|
|
use app\common\controller\Common;
|
|
use app\admin\model\Options;
|
|
use think\Db;
|
|
use think\captcha\Captcha;
|
|
use think\Validate;
|
|
use think\Cache;
|
|
use think\Request;
|
|
use think\Exception;
|
|
|
|
class Base extends Common
|
|
{
|
|
protected $view;
|
|
protected $user;
|
|
protected $yf_theme_path;
|
|
protected $site_options;
|
|
protected $curren_menu_id;
|
|
protected $menu_arr;
|
|
protected $menu_id;
|
|
protected function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
|
|
$this->curren_menu_id=7;
|
|
//菜单
|
|
$this->menu_id=input('id',0,'intval');
|
|
if($this->menu_id){
|
|
$this->menu_arr=get_menu_parents($this->menu_id);
|
|
if($this->menu_arr){
|
|
$this->curren_menu_id=$this->menu_arr[0];
|
|
}
|
|
}
|
|
$this->assign('curren_menu_id',$this->curren_menu_id);
|
|
$this->assign('menu_arr',$this->menu_arr);
|
|
//主题
|
|
$site_options=Options::get_options('site_options',$this->lang);
|
|
$this->site_options=$site_options;
|
|
$site_options['site_tongji']=htmlspecialchars_decode($site_options['site_tongji']);
|
|
$site_options['site_copyright']=htmlspecialchars_decode($site_options['site_copyright']);
|
|
$is_mobile=0;
|
|
if(request()->isMobile()){
|
|
$theme=$site_options['site_tpl_m']?:$site_options['site_tpl'];
|
|
$is_mobile=1;
|
|
}else{
|
|
$theme=$site_options['site_tpl'];
|
|
}
|
|
$this->view=$this->view->config('view_path',APP_PATH.request()->module().'/view/'.$theme.'/');
|
|
$yf_theme_path=__ROOT__.'/app/home/view/'.$theme.'/';
|
|
$this->assign($site_options);
|
|
$this->assign('yf_theme_path',$yf_theme_path);
|
|
$address='';
|
|
$this->user=array();
|
|
$uid=session('hid');
|
|
|
|
if(empty($uid)){
|
|
//检测cookies
|
|
$cookie = cookie('yf_logged_user');//'id'.'时间'
|
|
$cookie = explode(".", jiemi($cookie));
|
|
$uid=empty($cookie[0])?0:$cookie[0];
|
|
if($uid && !empty($cookie[1])){
|
|
//判断是否存在此用户
|
|
$member=Db::name("member_list")->find($uid);
|
|
if($member && (time()-intval($cookie[1]))<config('cookie.expire')){
|
|
//更新字段
|
|
$data = array(
|
|
'last_login_time' => time(),
|
|
'last_login_ip' => request()->ip(),
|
|
);
|
|
Db::name("member_list")->where(array('member_list_id'=>$member["member_list_id"]))->update($data);
|
|
$member['last_login_time']=$data['last_login_time'];
|
|
$member['last_login_ip']=$data['last_login_ip'];
|
|
//设置session
|
|
session('hid',$member['member_list_id']);
|
|
session('user',$member);
|
|
}
|
|
}
|
|
}
|
|
$is_admin=false;
|
|
if(session('hid')){
|
|
$this->user=Db::name('member_list')->find(session('hid'));
|
|
if(!empty($this->user['member_list_province'])){
|
|
$rst=Db::name('region')->field('name')->find($this->user['member_list_province']);
|
|
$address.=$rst?$rst['name'].lang('province'):'';
|
|
}
|
|
if(!empty($this->user['member_list_city'])){
|
|
$rst=Db::name('region')->field('name')->find($this->user['member_list_city']);
|
|
$address.=$rst?$rst['name'].lang('city'):'';
|
|
}
|
|
if(!empty($this->user['member_list_town'])){
|
|
$rst=Db::name('region')->field('name')->find($this->user['member_list_town']);
|
|
$address.=$rst?$rst['name']:'';
|
|
}
|
|
//未读通知数
|
|
$notice_unread=Db::name('cult4notice')->alias('a')
|
|
//->join(config('database.prefix').'cult4apply b','b.apply_id=a.apply_id')
|
|
->where(['a.user_id'=>session('hid'),'is_read'=>0])
|
|
->count();
|
|
$this->assign('notice_unread',$notice_unread);
|
|
}
|
|
//友情链接
|
|
$links=get_links(2);
|
|
|
|
$this->assign("links",$links);
|
|
$this->user['address']=$address;
|
|
$this->assign("user",$this->user);
|
|
$this->assign("is_admin",$is_admin);
|
|
$this->assign("is_mobile",$is_mobile);
|
|
|
|
//同意协议
|
|
$agreesys=Options::get_options('agree_options',$this->lang);
|
|
$this->assign("agreesys",$agreesys);
|
|
|
|
//托管同意协议
|
|
$tg_agreesys1=Options::get_options('agree_options1',$this->lang);
|
|
$this->assign("agreesys1",$tg_agreesys1);
|
|
|
|
$tg_agreesys2=Options::get_options('agree_options2',$this->lang);
|
|
$this->assign("agreesys2",$tg_agreesys2);
|
|
|
|
$tg_agreesys3=Options::get_options('agree_options3',$this->lang);
|
|
$this->assign("agreesys3",$tg_agreesys3);
|
|
|
|
$tg_agreesys4=Options::get_options('agree_options4',$this->lang);
|
|
$this->assign("agreesys4",$tg_agreesys4);
|
|
|
|
$tg_agreesys5=Options::get_options('agree_options5',$this->lang);
|
|
$this->assign("agreesys5",$tg_agreesys5);
|
|
|
|
|
|
//托管同意协议
|
|
$tg_agreesys1=Options::get_options('tgagree_options1',$this->lang);
|
|
$this->assign("tg_agreesys1",$tg_agreesys1);
|
|
|
|
$tg_agreesys2=Options::get_options('tgagree_options2',$this->lang);
|
|
$this->assign("tg_agreesys2",$tg_agreesys2);
|
|
|
|
$tg_agreesys3=Options::get_options('tgagree_options3',$this->lang);
|
|
$this->assign("tg_agreesys3",$tg_agreesys3);
|
|
|
|
$tg_agreesys4=Options::get_options('tgagree_options4',$this->lang);
|
|
$this->assign("tg_agreesys4",$tg_agreesys4);
|
|
|
|
$tg_agreesys5=Options::get_options('tgagree_options5',$this->lang);
|
|
$this->assign("tg_agreesys5",$tg_agreesys5);
|
|
|
|
//托管同意协议
|
|
$org_agreesys= Db::name('org_temp')->where(['code'=>'orgagree_options'])->find();
|
|
$this->assign("org_agreesys",$org_agreesys);
|
|
|
|
$tg_agreesys8=Options::get_options('tgagree_options9',$this->lang);
|
|
|
|
$this->assign("tg_agreesys6",$tg_agreesys8);
|
|
//文化和旅游产业专项债券
|
|
$ca_agreesys1=Options::get_options('tgagree_options6',$this->lang);
|
|
$this->assign("tgagree_options6",$ca_agreesys1);
|
|
|
|
$ca_agreesys2=Options::get_options('tgagree_options7',$this->lang);
|
|
$this->assign("tgagree_options7",$ca_agreesys2);
|
|
|
|
//登录掌柜文化金服token
|
|
$this->assign("user_token",session('user_token'));
|
|
|
|
|
|
//浏览器检测
|
|
$broswer=getBroswer(true);
|
|
$this->assign('broswer', $broswer);
|
|
//dump($broswer);
|
|
|
|
$list= Db::name('activity')->where(['status'=>1,'start_date'=>['elt',time()],'end_date'=>['gt',time()]])->order('sort desc')->select();
|
|
$this->assign("curlist",$list);
|
|
|
|
$list= Db::name('activity')->where(['status'=>1,'end_date'=>['lt',time()]])->order('sort desc')->select();
|
|
$this->assign("paslist",$list);
|
|
|
|
|
|
}
|
|
/**
|
|
* 检查用户登录
|
|
*/
|
|
protected function check_login()
|
|
{
|
|
if(!session('hid')){
|
|
$this->redirect(url('home/Login/index'));
|
|
}
|
|
}
|
|
/**
|
|
* 检查操作频率
|
|
* @param int $t_check 距离最后一次操作的时长
|
|
*/
|
|
protected function check_last_action($t_check)
|
|
{
|
|
$action=MODULE_NAME."-".CONTROLLER_NAME."-".ACTION_NAME;
|
|
$time=time();
|
|
$action_s=session('last_action.action');
|
|
if(!empty($action_s) && $action=$action_s){
|
|
$t=$time-session('last_action.time');
|
|
if($t_check>$t){
|
|
$this->error(lang('frequent operation'));
|
|
}else{
|
|
session('last_action.time',$time);
|
|
}
|
|
}else{
|
|
session('last_action.action',$action);
|
|
session('last_action.time',$time);
|
|
}
|
|
}
|
|
/**
|
|
* 验证码
|
|
* @return \think\Response
|
|
*/
|
|
public function verify_msg(){
|
|
return $this->verify_build('msg');
|
|
}
|
|
public function check_verify(){
|
|
$key=input('key');
|
|
return $this->verify_build($key);
|
|
}
|
|
/**
|
|
* 多语言选择
|
|
*/
|
|
public function lang(){
|
|
if (!request()->isAjax()){
|
|
$this->error(lang('submission mode incorrect'));
|
|
}else{
|
|
$lang=input('lang_s');
|
|
switch ($lang) {
|
|
case 'cn':
|
|
cookie('think_var', 'zh-cn');
|
|
break;
|
|
case 'en':
|
|
cookie('think_var', 'en-us');
|
|
break;
|
|
//其它语言
|
|
default:
|
|
cookie('think_var', 'zh-cn');
|
|
}
|
|
Cache::clear();
|
|
$this->success(lang('success'),url('home/Index/index'));
|
|
}
|
|
}
|
|
/**
|
|
* 上传方法
|
|
*/
|
|
public function upload(Request $request){
|
|
// 获取表单上传文件
|
|
$key=$request->param('key');
|
|
if(!$key)return $this->error('參數錯誤');
|
|
$file = request()->file($key);
|
|
// 移动到框架应用根目录/uploads/ 目录下
|
|
try {
|
|
$uploadpath=config('upload_path');
|
|
$path=ROOT_PATH . config('upload_path');
|
|
$validate = config('upload_validate');
|
|
if($key=='allpicbtn'||$key=='mortgagebtn'||$key=='ownerbtn'){
|
|
$validate['size']=10485760;
|
|
}
|
|
$info = $file->validate($validate)->move($path);
|
|
}catch (Exception $e){
|
|
return $this->error('上传失败');
|
|
}
|
|
if($info){
|
|
$data=array();
|
|
$data['ext']=$info->getExtension();
|
|
$data['path']=$uploadpath.DS.$info->getSaveName();
|
|
$data['filename']=$info->getFilename();
|
|
return $this->success('上传成功','',$data);
|
|
}else{
|
|
return $this->error($file->getError());
|
|
}
|
|
}
|
|
/**
|
|
* 预约登记
|
|
* @param array $params
|
|
* @return number|string
|
|
*/
|
|
protected function _checksub($params=array()){
|
|
$username=isset($params['username'])?$params['username']:'';
|
|
$mobile=isset($params['mobile'])?$params['mobile']:'';
|
|
$email=isset($params['email'])?$params['email']:'';
|
|
$kind=isset($params['kind'])?$params['kind']:'';
|
|
$pid=isset($params['c_id'])?$params['c_id']:'';
|
|
$type=isset($params['type'])?$params['type']:1;
|
|
$price=isset($params['price'])?$params['price']:'';
|
|
$prepay=isset($params['prepay'])?intval($params['prepay']):'';
|
|
$remark=isset($params['remark'])?$params['remark']:'';
|
|
$creditcard=isset($params['creditcard'])?$params['creditcard']:'';
|
|
$num=isset($params['num'])?intval($params['num']):0;
|
|
$role=isset($params['role'])?intval($params['role']):1;
|
|
|
|
if(in_array($type,[1,2])){
|
|
$validate=new Validate([
|
|
'__token__' => 'require|token',
|
|
]);
|
|
$post=input("post.");
|
|
if (!$validate->check($post)) {
|
|
$this->error('令牌失败,请刷新页面重新提交',url('news/finance',['c_id'=>$pid,'kind'=>$kind]));
|
|
}
|
|
}
|
|
if($type==2){
|
|
if(empty($price))$this->error('请输入价格');
|
|
}
|
|
if(isset($params['c_id'])){
|
|
if(empty($pid))$this->error('请输入产品id');
|
|
}
|
|
if(isset($params['num'])){
|
|
if(empty($num))$this->error('请输入出席人数');
|
|
}
|
|
if(isset($params['prepay'])){
|
|
if(empty($prepay))$this->error('请选择是否愿意交纳保证金');
|
|
}
|
|
if(isset($params['creditcard'])){
|
|
if(empty($creditcard))$this->error('请输入身份证号码');
|
|
}
|
|
if(!preg_match('/^[\x7f-\xff]+$/', $username))$this->error("请输入中文姓名");
|
|
if(empty($mobile))$this->error('请输入联系电话');
|
|
if(!preg_match("/^1[34578]\d{9}$/", $mobile)){
|
|
$this->error('请输入正确手机号码');
|
|
}
|
|
if(isset($params['email'])&&$kind!=4){
|
|
if(empty($email))$this->error('请输入邮箱');
|
|
$check=filter_var($email,FILTER_VALIDATE_EMAIL);
|
|
if(!$check)$this->error('请输入正确的邮箱');
|
|
}
|
|
$data=array();
|
|
$data['username']=$username;
|
|
if($type==2){
|
|
$data['price']=$price;
|
|
}
|
|
$data['type']=$type;
|
|
if($kind)$data['kind']=$kind;
|
|
$data['mobile']=$mobile;
|
|
$data['email']=$email;
|
|
$data['created_time']=time();
|
|
$data['productid']=$pid;
|
|
$data['prepay']=$prepay;
|
|
$data['remark']=$remark;
|
|
$data['creditcard']=$creditcard;
|
|
$data['num']=$num;
|
|
$data['role']=$role;
|
|
|
|
$query=Db::name('subscription')->insert($data);
|
|
return $query;
|
|
}
|
|
}
|
|
|