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.
216 lines
6.8 KiB
216 lines
6.8 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\member\controller;
|
|
|
|
use app\common\controller\Common;
|
|
use app\admin\model\Options;
|
|
use think\Db;
|
|
use think\Validate;
|
|
use think\Cache;
|
|
use think\Request;
|
|
use think\Exception;
|
|
use think\captcha\Captcha;
|
|
|
|
class Base extends Common
|
|
{
|
|
protected $view;
|
|
protected $user;
|
|
protected $yf_theme_path;
|
|
protected $site_options;
|
|
protected function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
|
|
//主题
|
|
$site_options=Options::get_options('site_options',$this->lang);
|
|
|
|
$this->site_options=$site_options;
|
|
$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/member/view/'.$theme.'/';
|
|
$this->assign($site_options);
|
|
|
|
$this->assign('yf_theme_path',$yf_theme_path);
|
|
$address='';
|
|
if(session('mhid')){
|
|
$this->user=Db::name('member_list')->find(session('mhid'));
|
|
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']:'';
|
|
}
|
|
}
|
|
|
|
$this->user['address']=$address;
|
|
$this->assign("user",$this->user);
|
|
|
|
|
|
}
|
|
/**
|
|
* 检查用户登录
|
|
*/
|
|
protected function check_login()
|
|
{
|
|
if(!session('mhid')){
|
|
$this->redirect(url('Login/index'));
|
|
}
|
|
}
|
|
/**
|
|
* 验证码
|
|
* @return \think\Response
|
|
*/
|
|
public function check_verify(){
|
|
$key=input('key');
|
|
ob_end_clean();
|
|
$verify = new Captcha(config('verify'));
|
|
|
|
return $verify->entry($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('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'){
|
|
$validate['size']=10485760;
|
|
$validate['size']=512000;
|
|
}
|
|
$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(empty($username))$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;
|
|
$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;
|
|
}
|
|
}
|