Initial commit
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
namespace Home\Model;
|
||||
use Think\Model\RelationModel;
|
||||
class FeedbackModel extends RelationModel{
|
||||
protected $_validate,$fieldarr;
|
||||
//关联模型
|
||||
protected $_link = array(
|
||||
//类别
|
||||
"feedback_cat"=>array(
|
||||
'mapping_type' => self::BELONGS_TO,
|
||||
'foreign_key' => 'catid',
|
||||
),
|
||||
//用户
|
||||
"member"=>array(
|
||||
'mapping_type' => self::BELONGS_TO,
|
||||
'mapping_fields' => "truename,member_id",
|
||||
'foreign_key' => 'member_id',
|
||||
)
|
||||
);
|
||||
public function __construct(){
|
||||
//模型id
|
||||
$catid=I("catid",0,"int");
|
||||
$this->cat=M("feedback_cat")->find($catid);
|
||||
if(!$this->cat){
|
||||
$this->error="分类不存在";
|
||||
return;
|
||||
}
|
||||
//录入项
|
||||
$is_enter=$this->cat["is_enter"];
|
||||
$is_enter_arr=explode(",",trim($is_enter,","));
|
||||
$this->fieldarr=M("feedback_field")->where(array("field"=>array('in',$is_enter_arr)))->order("sort asc,field_id asc")->select();
|
||||
//必填项
|
||||
$must_enter=$this->cat["must_enter"];
|
||||
$must_enter_arr=explode(",",trim($must_enter,","));
|
||||
$this->must_enter_arr=M("feedback_field")->where(array("field"=>array('in',$must_enter_arr)))->order("sort asc,field_id asc")->select();
|
||||
foreach($this->must_enter_arr as $v){
|
||||
//自动验证=======================================================================
|
||||
//array(验证字段,验证规则,错误提示,[验证条件,附加规则,验证时间])
|
||||
//必填项(不能为空验证)
|
||||
if(strstr($this->cat["is_enter"],",".$v[field].",")){
|
||||
$error_tips=$v[name]."必须填写!";
|
||||
//判断是不是checkbox,如果是执行函数验证
|
||||
if($v[formtype]=="checkbox"){
|
||||
$error_tips=$v[name]."必须勾选!";
|
||||
$this->_validate[]=array($v[field],'validate_checkbox',$error_tips,1,"callback");
|
||||
}
|
||||
else{
|
||||
$this->_validate[]=array($v[field],'require',$error_tips,1);
|
||||
}
|
||||
}
|
||||
//正则验证
|
||||
if($v[pattern]){
|
||||
$p_error_tips=$v[errortips]?$v[errortips]:$v[name]."验证不通过!";
|
||||
$this->_validate[]=array($v[field],$v[pattern],$p_error_tips,1,"regex");
|
||||
}
|
||||
//函数验证
|
||||
if($v[savefun]){
|
||||
$p_error_tips=$v[errortips]?$v[errortips]:$v[name]."验证不通过!";
|
||||
$this->_validate[]=array($v[field],$v[savefun],$p_error_tips,1,"function");
|
||||
}
|
||||
//值维一验证
|
||||
if($v[isunique]){
|
||||
$p_error_tips=$v[name]."对应的记录已存在!";
|
||||
$this->_validate[]=array($v[field],"",$p_error_tips,0,"unique");
|
||||
}
|
||||
}
|
||||
//注意,这里父类析构函数一定要放到最下面,否则框架自带的方法不能使用
|
||||
parent::__construct();
|
||||
}
|
||||
//自动验证的时候 验证checkbox
|
||||
protected function validate_checkbox($arr){
|
||||
if(count($arr)){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//数据完成
|
||||
protected function data_create(){
|
||||
$data=$this->create();
|
||||
$data[addtime]=time();
|
||||
$data[member_id]=intval(session("member_id"));
|
||||
$data[ip]= get_client_ip();
|
||||
foreach ($this->fieldarr as $v){
|
||||
//复选框
|
||||
if($v[formtype]=="checkbox"){
|
||||
$data[$v[field]]=implode("|",$data[$v[field]]);
|
||||
if($data[$v[field]]){
|
||||
$data[$v[field]]="|".$data[$v[field]]."|";
|
||||
}
|
||||
}
|
||||
//多图上传
|
||||
if($v[formtype]=="morepic"){
|
||||
$morepic_str="";
|
||||
$smallimg=$_POST[$v[field]."_smallimg"];
|
||||
$bigimg=$_POST[$v[field]."_bigimg"];
|
||||
$imgname=$_POST[$v[field]."_imgname"];
|
||||
foreach($smallimg as $key=>$val){
|
||||
$morepic_str.=$smallimg[$key]."||".$bigimg[$key]."||".$imgname[$key]."\r\n";
|
||||
}
|
||||
$morepic_str=trim($morepic_str,"\r\n");
|
||||
$data[$v[field]]=$morepic_str;
|
||||
}
|
||||
//如果是编辑器字段截取内容做为简介
|
||||
if($v[formtype]=="editor"){
|
||||
if(!$data[description]){
|
||||
$data[description]= mb_substr(strip_tags(htmlspecialchars_decode($data[$v[field]])),0,C("display.description_len"),'utf-8');
|
||||
}
|
||||
}
|
||||
//日期
|
||||
if($v[formtype]=="date"){
|
||||
$data[$v[field]]=$data[$v[field]]?strtotime($data[$v[field]]):"";
|
||||
}
|
||||
//未定义的数据设为空【否则mysql会报 cannot be null错误】
|
||||
$data[$v[field]]=isset($data[$v[field]])?$data[$v[field]]:"";
|
||||
//判断是否为 int smallint tinyint bigint
|
||||
if(in_array($v[fieldtype],array("tinyint","smallint","int","bigint"))){
|
||||
$data[$v[field]]=abs($data[$v[field]]);//禁止出现负数
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
//增加
|
||||
public function data_add(){
|
||||
$data=$this->data_create();
|
||||
$data['id']=$this->add($data);
|
||||
if($data['id']){
|
||||
return $data;
|
||||
}else{
|
||||
$this->error = '缺少字段id!';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace Home\Model;
|
||||
use Think\Model\RelationModel;
|
||||
class InfoModel extends RelationModel{
|
||||
protected $tableName,$_validate,$_link,$modelinfo,$modelid,$fieldarr;
|
||||
|
||||
public function __construct(){
|
||||
//模型id
|
||||
$catid=I("catid",0,"int");
|
||||
if($catid){
|
||||
$this->modelid=$GLOBALS['cat'][$catid]["modelid"];
|
||||
}else{
|
||||
$this->modelid=I("modelid",0,"int");
|
||||
}
|
||||
|
||||
//模型信息
|
||||
$modelinfo=$GLOBALS['model'][$this->modelid];
|
||||
if(!$modelinfo){
|
||||
return false;
|
||||
}
|
||||
$this->modelinfo=$modelinfo;
|
||||
//
|
||||
$this->_validate[]=array("catid","require","请选择分类",1);
|
||||
//对应数据表
|
||||
$this->tableName="cms_".$modelinfo['table_name'];
|
||||
//关联模型
|
||||
$this->_link = array(
|
||||
//对应栏目表
|
||||
"cat"=>array(
|
||||
'mapping_type' => self::BELONGS_TO,
|
||||
'foreign_key' => 'catid',
|
||||
),
|
||||
//【对应副表】
|
||||
$this->tableName."_data"=>array(
|
||||
'mapping_type' => self::HAS_ONE,
|
||||
'foreign_key' => 'id',
|
||||
),
|
||||
);
|
||||
//注意,这里父类析构函数一定要放到最下面,否则框架自带的方法不能使用
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace Home\Model;
|
||||
use Think\Model;
|
||||
class MemberModel extends Model{
|
||||
//验证
|
||||
protected $_validate=array(
|
||||
//array("字段","验证规则","错误提示",["验证条件","附加条件","验证时间"]),
|
||||
array("username","require","用户名不能为空"),
|
||||
array("username","5,40","用户名长度需要5位以上",2,"length"),
|
||||
array("username","","用户名已存在",0,"unique"),
|
||||
array("email","require","邮箱不能为空"),
|
||||
array("email","email","邮箱格式不正确"),
|
||||
array("email","","邮箱已存在",0,"unique"),
|
||||
array("password","require","密码不能为空"),
|
||||
array("password","6,40","密码长度需要6位以上",2,"length"),
|
||||
array('repassword','password','确认密码不正确',0,'confirm'), // 验证确认密码是否和密码一致
|
||||
);
|
||||
//保存注册信息
|
||||
public function data_save($site_id){
|
||||
//创建数据
|
||||
$data=$this->create();
|
||||
//
|
||||
$data[site_id]= $site_id;
|
||||
$data[password]= md6($data[password]);
|
||||
$data[status]=1;
|
||||
$data[token]=md6(time());
|
||||
$data[register_time]=time();
|
||||
$data[member_id]=$this->data($data)->add();
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
namespace Home\Model;
|
||||
class Tongji{
|
||||
private $search_engine_inc=array(
|
||||
"baidu." =>"baidu",
|
||||
"google." =>"google",
|
||||
"sogou." =>"sogou",
|
||||
"so." =>"360",
|
||||
"bing." =>"bing",
|
||||
);
|
||||
public function start(){
|
||||
$visit_userId =$_COOKIE["visit_userId"];
|
||||
if(!$visit_userId){
|
||||
$data=array();
|
||||
//进站方式
|
||||
$http_referer=$_SERVER['HTTP_REFERER'];
|
||||
if(!$http_referer){
|
||||
$data['visit_type']="website";
|
||||
}else{
|
||||
$searcn_engine=$this->search_engine();
|
||||
if($searcn_engine){
|
||||
$data['visit_type']="search";
|
||||
$data['search_engine']=$searcn_engine;
|
||||
}else{
|
||||
$data['visit_type']="link";
|
||||
}
|
||||
}
|
||||
//ip地址
|
||||
$data['ip']= get_client_ip(0,true);
|
||||
//访问时间
|
||||
$data['visit_time']=time();
|
||||
//先插入48小时的表
|
||||
M("visit_48")->add($data);
|
||||
//再插入visit表
|
||||
$today_start=strtotime(date("Y-m-d ")."00:00:00");
|
||||
$today_end=strtotime(date("Y-m-d ")."23:59:59");
|
||||
$where=array();
|
||||
$where["visit_time"]=array("between",array($today_start,$today_end));
|
||||
$data2=array();
|
||||
//时间
|
||||
$data2['daytime']=strtotime(date("Y-m-d"));
|
||||
//IP统计
|
||||
$ip_total=M("visit_48")->field("ip")->where($where)->group("ip")->select();
|
||||
$data2['ip']=count($ip_total);
|
||||
//pv统计
|
||||
$data2['pv']=M("visit_48")->where($where)->count();
|
||||
//visit_search 搜索进来的用户
|
||||
$where2=array();
|
||||
$where2=$where;
|
||||
$where2["visit_type"]="search";
|
||||
$data2['visit_search']=M("visit_48")->where($where2)->count();
|
||||
//website 输入网址进来的用户
|
||||
$where2=array();
|
||||
$where2=$where;
|
||||
$where2["visit_type"]="website";
|
||||
$data2['visit_website']=M("visit_48")->where($where2)->count();
|
||||
//link 通过链接跳转进来的用户
|
||||
$where2=array();
|
||||
$where2=$where;
|
||||
$where2["visit_type"]="link";
|
||||
$data2['visit_link']=M("visit_48")->where($where2)->count();
|
||||
//各大搜索引擎判断
|
||||
//baidu
|
||||
$where2=array();
|
||||
$where2=$where;
|
||||
$where2["visit_type"]="search";
|
||||
$where2["search_engine"]="baidu";
|
||||
$data2['engine_baidu']=M("visit_48")->where($where2)->count();
|
||||
//google
|
||||
$where2=array();
|
||||
$where2=$where;
|
||||
$where2["visit_type"]="search";
|
||||
$where2["search_engine"]="google";
|
||||
$data2['engine_google']=M("visit_48")->where($where2)->count();
|
||||
//sogou
|
||||
$where2=array();
|
||||
$where2=$where;
|
||||
$where2["visit_type"]="search";
|
||||
$where2["search_engine"]="sogou";
|
||||
$data2['engine_sogou']=M("visit_48")->where($where2)->count();
|
||||
//360
|
||||
$where2=array();
|
||||
$where2=$where;
|
||||
$where2["visit_type"]="search";
|
||||
$where2["search_engine"]="360";
|
||||
$data2['engine_360']=M("visit_48")->where($where2)->count();
|
||||
//bing
|
||||
$where2=array();
|
||||
$where2=$where;
|
||||
$where2["visit_type"]="search";
|
||||
$where2["search_engine"]="bing";
|
||||
$data2['engine_bing']=M("visit_48")->where($where2)->count();
|
||||
//
|
||||
$visit_id=M("visit")->where(array("daytime"=>$data2['daytime']))->getField("id");
|
||||
if($visit_id){
|
||||
$data2["id"]=$visit_id;
|
||||
M("visit")->save($data2);
|
||||
}else{
|
||||
M("visit")->add($data2);
|
||||
}
|
||||
//设置访问cookie,过期时间为今天23:59:59
|
||||
setcookie("visit_userId",time()+rand(10000,99999), strtotime(date("Y-d-m")." 23:59:59"));
|
||||
}
|
||||
}
|
||||
//判断搜索引擎
|
||||
private function search_engine(){
|
||||
foreach($this->search_engine_inc as $key=>$engine){
|
||||
if(strstr($_SERVER['HTTP_REFERER'],$key)){
|
||||
return $engine;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user