= 86400) { return $strtime = date('Y-m-d H:i', $time_s); } if ($time >= 3600) { $strtime .= intval($time / 3600) . '小时'; $time = $time % 3600; } else { $strtime .= ''; } if ($time >= 60) { $strtime .= intval($time / 60) . '分钟'; $time = $time % 60; } else { $strtime .= ''; } if ($time > 0) { $strtime .= intval($time) . '秒前'; } else { $strtime = '时间错误'; } return $strtime; } function getArticleList($limit = 3, $where = array(), $order = array()) { if (empty($limit)) { $limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 3; } $arg_where = array_merge( ['cid' => 16,'stat' => 0, 'country_code' => COUNTRY_CODE], $where); $arg_field = ['*']; $arg_order = ['createtime' => 'desc']; $result = Loader::model('Article')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); $arg_wheres = array_merge( ['cid' => 32,'stat' => 0, 'country_code' => COUNTRY_CODE], $where); $rest = Loader::model('Article')->getList($arg_wheres, array_merge($arg_order, $order), $arg_field, $limit); $array = array_merge($result, $rest); //echo Loader::model('Article')->getLastSQL();die; return $array; } /** * 计算剩余天时分。 * $unixEndTime string 终止日期的Unix时间 */ function getDHMtime($unixEndTime = 0) { if ($unixEndTime <= time()) { // 如果过了活动终止日期 return '0天0时0分'; } // 使用当前日期时间到活动截至日期时间的毫秒数来计算剩余天时分 $time = $unixEndTime - time(); $days = 0; if ($time >= 86400) { // 如果大于1天 $days = (int) ($time / 86400); $time = $time % 86400; // 计算天后剩余的毫秒数 } $xiaoshi = 0; if ($time >= 3600) { // 如果大于1小时 $xiaoshi = (int) ($time / 3600); $time = $time % 3600; // 计算小时后剩余的毫秒数 } $fen = (int) ($time / 60); // 剩下的毫秒数都算作分 return $days . '天' . $xiaoshi . '时' . $fen . '分'; } function getFaqList($limit = 6, $where = array(), $order = array()) { if (empty($limit)) { $limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 6; } $arg_where = array_merge(['stat' => 0,'is_home' => 1, 'country_code' => COUNTRY_CODE], $where); $arg_field = ['*']; $arg_order = ['sort' => 'asc', 'id' => 'desc']; $result = Loader::model('fq')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); return $result; } function getDifferentProduct($type, $limit = 12, $where = array(), $order = array()) { if (empty($limit)) { $limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12; } $arg_where = array_merge(['stat' => 0, 'is_show' => 0, 'country_code' => COUNTRY_CODE], $where);//print_r($where);die; $arg_field = ['id', 'cid', 'name', 'shortname', 'sort', 'ishot', 'isfeatured','isnew', 'recommend', 'viewcount', 'tags', 'description', 'picture', 'picture_back', 'bk_img', 'bk_img_back','list_bk_img', 'createtime']; $bkinfo = ['id','product_id','image_url','image_bk_color','image_color','original_url']; switch ($type) { case 'recommend': // $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $arg_where['recommend'] = 1; $result = Loader::model('Product')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); /*$bkid = Loader::model('Product')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);//print_r($bkid);die; $id = ''; $result = ''; foreach ($bkid as $v){ $where= $id['product_id'] = $v['id'];//print_r($where);die; $arr = Loader::model('ProductBkImg')->getList($where, array_merge($order), $bkinfo, $limit); $result[]= $arr; } $result['info'] = $bkid;*/ //print_r($result);die; break; case 'isfeatured': $arg_order['sort'] = 'asc'; $arg_order ['id'] = 'desc'; $arg_where['isfeatured'] = 1; $result = Loader::model('Product')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; case 'headline': $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $arg_where['headline'] = 1; $result = Loader::model('Product')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; case 'ishot': $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $arg_where['ishot'] = 1; $result = Loader::model('Product')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; case 'isnew': $arg_order['sort'] = 'asc'; $arg_order ['id'] = 'desc'; $arg_where['isnew'] = 1; $result = Loader::model('Product')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; default: if (!empty($order)) { $arg_order = $order; } $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $result = Loader::model('Product')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; } return $result; } function getDifferentArticle($type, $limit = 12, $where = array(), $order = array()) { if (empty($limit)) { $limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12; } $arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where); //$arg_where['is_onsale'] = 1; $arg_field = ['id', 'cid', 'name', 'sort', 'jump_link', 'headline', 'ishot', 'recommend', 'zancount', 'viewcount', 'description', 'picture', 'createtime']; switch ($type) { case 'recommend': $arg_order['createtime'] = 'desc'; $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $arg_where['recommend'] = 1; $result = Loader::model('Article')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; case 'headline': $arg_order['createtime'] = 'desc'; $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $arg_where['headline'] = 1; $result = Loader::model('Article')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; case 'ishot': $arg_order['createtime'] = 'desc'; $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $arg_where['ishot'] = 1; $result = Loader::model('Article')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; default: $arg_order['createtime'] = 'desc'; $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $result = Loader::model('Article')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; } return $result; } function getDifferentVideo($type, $limit = 12, $where = array(), $order = array()) { if (empty($limit)) { $limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12; } $arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where); //$arg_where['is_onsale'] = 1; $arg_field = ['id', 'cid', 'name', 'sort', 'headline', 'ishot', 'recommend', 'viewcount', 'videopath', 'videourl', 'description', 'picture', 'createtime']; switch ($type) { case 'recommend': $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $arg_where['recommend'] = 1; $result = Loader::model('Video')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; $arg_where['headline'] = 1; if (Config ::get('news_headline')) { $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; } else { $arg_order['id'] = 'desc'; } case 'headline': $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $arg_where['headline'] = 1; $result = Loader::model('Video')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; case 'ishot': $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $arg_where['ishot'] = 1; $result = Loader::model('Video')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; default: $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $result = Loader::model('Video')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; } return $result; } function getDifferentDownload($type, $limit = 12, $where = array(), $order = array()) { if (empty($limit)) { $limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12; } $arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where); //$arg_where['is_onsale'] = 1; $arg_field = ['id', 'cid', 'name', 'sort', 'headline', 'ishot', 'recommend', 'app_model', 'support_os', 'format', 'viewcount', 'downloadcount', 'description', 'picture', 'tags', 'downloadpath', 'downloadpath64', 'createtime']; switch ($type) { case 'recommend': $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $arg_where['recommend'] = 1; $result = Loader::model('Download')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; $arg_where['headline'] = 1; if (Config ::get('news_headline')) { $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; } else { $arg_order['id'] = 'desc'; } case 'headline': $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $arg_where['headline'] = 1; $result = Loader::model('Download')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; case 'ishot': $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $arg_where['ishot'] = 1; $result = Loader::model('Download')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; default: $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $result = Loader::model('Download')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; } return $result; } function getProductChildCate($pid, $limit = 12, $where = array(), $order = array()) { $argc_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where); $argc_field = ['id', 'pid', 'haschild', 'name', 'shortname', 'description', 'sort', 'isshow', 'recommend', 'picture', 'createtime']; $argc_order['sort'] = 'asc'; $argc_order['id'] = 'desc'; $argc_where['pid'] = $pid; $result = Loader::model('ProductCategory')->getList($argc_where, array_merge($argc_order, $order), $argc_field, $limit); return $result; } function getArticleChildCate($pid, $limit = 12, $where = array(), $order = array()) { $argc_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where); $argc_field = ['id', 'pid', 'haschild', 'name', 'shortname', 'description', 'sort', 'isshow', 'recommend', 'picture', 'createtime']; $argc_order['sort'] = 'asc'; $argc_order['id'] = 'desc'; $argc_where['pid'] = $pid; $result = Loader::model('ArticleCategory')->getList($argc_where, array_merge($argc_order, $order), $argc_field, $limit); return $result; } function getCateProduct($cid, $limit = 12, $where = array(), $haschild = false, $order = array()) { $arg_where = array_merge(['p.stat' => 0,'p.is_show' => 0, 'c.stat' => 0, 'p.country_code' => COUNTRY_CODE], $where); $arg_field = ['p.id', 'p.cid', 'p.name', 'p.shortname', 'p.sort', 'p.ishot', 'p.isnew', 'p.recommend', 'p.viewcount', 'p.tags', 'p.description', 'p.picture','p.list_bk_img', 'p.brand_id', 'p.picture_back', 'p.createtime', 'p.createtime', 'c.name' => 'categoryname', 'c.id' => 'categoryid']; $arg_order['p.sort'] = 'asc'; $arg_order['p.id'] = 'desc'; if ($haschild && $cid) { $cidarray = Loader::model('ProductCategory')->getChildIDArray($cid); $arg_where['p.cid'] = ['in', $cidarray]; } else { $arg_where['p.cid'] = $cid; } $result = Loader::model('Product')->getCateProductList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); return $result; } function getCateoneProduct($cid, $limit = 12, $where = array(), $haschild = false, $order = array()) { $arg_where = array_merge(['p.stat' => 0,'p.is_show' => 0, 'c.stat' => 0, 'p.country_code' => COUNTRY_CODE], $where); $arg_field = ['p.bk_img_back_color','p.bk_img_color','p.picture_back_color','p.picture_color','p.id', 'p.cid', 'p.name', 'p.shortname', 'p.sort', 'p.ishot', 'p.isnew','p.brand_id', 'p.recommend', 'p.viewcount', 'p.tags','p.list_bk_img', 'p.description', 'p.picture', 'p.picture_back', 'p.createtime', 'p.createtime', 'c.name' => 'categoryname', 'c.id' => 'categoryid']; $arg_order['p.sort'] = 'asc'; $arg_order['p.id'] = 'desc'; if ($haschild && $cid) { $cidarray = Loader::model('ProductCategory')->getChildIDArray($cid); $arg_where['p.cid'] = ['in', $cidarray]; } else { $arg_where['p.cid'] = $cid; } $result = Loader::model('Product')->getCateProductList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); // echo \think\Db::table('Product')->getLastSql();die; // 获取二级图片 foreach ($result as $key => $value) { $res = model('ProductTwoImg')->field('image_url,image_bk_color,image_color,original_url,product_id,id,image_color')->where(['product_id' => $value['id'], 'stat' => 0])->select(); $result[$key]['product_two_img'] = $res; } return $result; } function getCateArticle($cid, $limit = 12, $where = array(), $haschild = false, $order = array()) { $arg_where = array_merge(['stat' => 0, 'p.country_code' => COUNTRY_CODE], $where); $arg_field = ['id', 'cid', 'name', 'sort', 'headline', 'ishot', 'recommend', 'viewcount', 'description', 'picture', 'createtime']; $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; if ($haschild && $cid) { $cidarray = Loader::model('ArticleCategory')->getChildIDArray($cid); $arg_where['cid'] = ['in', $cidarray]; } else { $arg_where['cid'] = $cid; } $result = Loader::model('Article')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); return $result; } function getCateVideo($cid, $limit = 12, $where = array(), $haschild = false, $order = array()) { $arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where); $arg_field = ['id', 'cid', 'name', 'product', 'sort', 'headline', 'ishot', 'recommend', 'tags', 'playcount', 'description', 'picture', 'videopath', 'createtime']; $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; if ($haschild && $cid) { $cidarray = Loader::model('VideoCategory')->getChildIDArray($cid); $arg_where['cid'] = ['in', $cidarray]; } else { $arg_where['cid'] = $cid; } $result = Loader::model('Video')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); return $result; } function getVideoBannerList($tid = 0, $limit = 12, $where = array(), $field = array('*'), $order = array()) { $arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where); $arg_order = array_merge(['sort' => 'asc', 'id' => 'desc'], $order); $arg_field = $field; } function getBannerList($tid = 0, $limit = 12, $where = array(), $field = array('*'), $order = array()) { $arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where); $arg_order = ['sort' => 'asc', 'id' => 'desc']; $arg_field = $field; if ($tid) { $arg_where['typeid'] = $tid; } $result = Loader::model('Banner')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); return $result; } function getBanner($id = 0) { $result = Loader::model('Banner')->getRow($id); return $result; } function getFlink($tid = 0, $limit = 12, $where = array(), $field = array('*'), $order = array()) { $arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where); $arg_order = ['sort' => 'asc', 'id' => 'desc']; $arg_field = $field; if ($tid) { $arg_where['typeid'] = $tid; } $result = Loader::model('Flink')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); return $result; } function getBlogList($limit = 5, $where = array(), $order = array()) { if (empty($limit)) { $limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 6; } $arg_where = array_merge(['stat' => 1, 'country_code' => COUNTRY_CODE], $where); $arg_field = ['*']; $arg_order = ['id' => 'desc']; $result = Loader::model('Blog')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); return $result; } function getQuestion($limit = 12, $where = array(), $order = array()) { if (empty($limit)) { $limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12; } $arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where); $arg_field = ['*']; $arg_order = ['sort' => 'asc', 'id' => 'desc']; $result = Loader::model('Question')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); return $result; } function getProduct($id = 0) { $result = Loader::model('Product')->getRow(['id' => $id], ['id', 'name']); return $result; } function getProductCount($cid, $where = array(), $haschild = false) { $arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where); if ($haschild && $cid) { $cidarray = Loader::model('ProductCategory')->getChildIDArray($cid); $arg_where['cid' ] = ['in', $cidarray]; } else { $arg_where['cid'] = $cid; } $result = Loader::model('Product')->where($arg_where)->count(); return $result; } function getArticleCategory($id = 0) { $result = Loader::model('ArticleCategory')->getRow(['id' => $id ], ['id', 'name']); return $result; } function getSinglepageChild($pid, $limit = 12, $where = array(), $order = array()) { $argc_where = array_merge(['stat' => 0], $where); $argc_field = ['id', 'pid', 'name', 'description', 'sort', 'isshow', 'recommend', 'picture', 'content', 'createtime']; $argc_order['sort'] = 'asc'; $argc_order['id'] = 'desc'; $argc_where['pid'] = $pid; $result = Loader:: model('Singlepage')->getList($argc_where, array_merge($argc_order, $order), $argc_field, $limit); return $result; } function getSinglepage($id = 0) { $result = Loader::model('Singlepag e')->getRow($id, ['id', 'pid', 'name', 'description', 'sort', 'isshow', 'recommend', 'picture', 'content', 'createtime']); return $result; } function getDifferentPinglun($type, $limit = 12, $where = array(), $order = array()) { if (empty($limit)) { $limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12; } $arg_where = array_merge(['stat' => 0, 'display' => 1], $where); $arg_field = ['id', 'pid', 'customer_id', 'cname', 'content_id', 'typeid', 'ishot', 'content', 'tx', 'createtime', 'ip', 'display']; switch ($type) { case 'ishot': $arg_order['id'] = 'desc'; $arg_where['ishot'] = 1; $result = Loader::model('Pinglun')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; default: if (!empty($order)) { $arg_order = $order; } $arg_order['sort'] = 'asc'; $arg_order['id'] = 'desc'; $result = Loader::model('Pinglun')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit); break; } return $result; } function getBkImag($type, $limit = 12, $where = array(), $order = array()){ /*$result = \app\common\model\Product::where("recommend",1)->field('id,cid')->with("ProductImg")->limit($limit)->select();*/ //print_r($type);die; $where = ['recommend'=>1,'stat'=>0, 'country_code' => COUNTRY_CODE]; $result = \app\common\model\Product::where($where) ->field('id,cid,name,shortname') ->with(["ProductImg"=>function($query){ /** @var $query \think\db\Query */ $query->field('image_url,image_bk_color,image_color,original_url,product_id,id'); }]) // ->where('id', 130) ->order('id desc') ->select(); /** @var $result array */ $result = collection($result)->toArray(); return $result; } function getSonCategoryProduct($parent_id) { if (empty($parent_id)) { return "无父ID"; } $where = ['recommend'=>1,'stat'=>0,'is_show'=>0, 'country_code' => COUNTRY_CODE]; $result = \app\common\model\Product::where('cid', 'in', function ($query) use ($parent_id) { /** @var $query \think\db\Query */ $query->table('cod_product_category')->where('pid', $parent_id)->field('id'); })->with(["ProductImg"=>function($query){ /** @var $query \think\db\Query */ $query->field('image_url,image_bk_color,image_color,original_url,product_id,id'); }])->where($where) ->field('id,cid,name,shortname') ->select(); if (!empty($result)) { $result = collection($result)->toArray(); } return $result; } function getCateColor($cid, $limit, $where = array(), $haschild = false, $order = array()) { $where = ['stat'=>0,'cid'=>$cid, 'country_code' => COUNTRY_CODE]; $result = \app\common\model\Product::where($where) ->field('id,cid,name,brand_id') ->with(["ProductTwoImg"=>function($query){ /** @var $query \think\db\Query */ $query->where('stat',0)->field('image_url,image_bk_color,image_color,original_url,product_id,id,image_color'); }]) ->limit($limit) ->order($order) ->select(); /** @var $result array */ $result = collection($result)->toArray();//print_r($result);die; return $result; } function getProductReated($id,$limit = 12, $where = array(), $haschild = false, $order = array()){ $where = ['product_id'=>$id,'stat'=>0, 'country_code' => COUNTRY_CODE]; $result = Loader::model('ProductTwoImg')->where($where)->field('image_url')->select(); $result = collection($result)->toArray(); return $result; } /*没有上级分类的爆款查询*/ function getCategoryProduct($parent_id) { if (empty($parent_id)) { return "无父ID"; } $where = ['recommend'=>1,'stat'=>0,'cid'=>$parent_id, 'country_code' => COUNTRY_CODE]; $result = \app\common\model\Product::where($where) ->field('id,cid,name,shortname') ->with(["ProductImg"=>function($query){ /** @var $query \think\db\Query */ $query->field('image_url,image_bk_color,image_color,original_url,product_id,id'); }]) // ->limit('sort') ->order('id desc') ->select(); /** @var $result array */ $result = collection($result)->toArray(); return $result; } /*没有上级的产品查询*/ function getProductColor($pid,$limit){ if(empty($pid)){ return "无父级ID"; } $where = ['stat'=>0,'cid'=>$pid, 'country_code' => COUNTRY_CODE]; $result = \app\common\model\Product::where($where) ->field('id,cid,name,shortname') ->with(["ProductTwoImg"=>function($query){ /** @var $query \think\db\Query */ $query->where('stat',0)->field('image_url,image_bk_color,image_color,original_url,product_id,id,image_color'); }]) ->limit($limit) ->order('id desc') ->select(); /** @var $result array */ $result = collection($result)->toArray();//print_r($result);die; return $result; } // 计算中文字符串长度 function utf8_strlen($string = null) { // 将字符串分解为单元 preg_match_all("/./us", $string, $match); // 返回单元个数 return count($match[0]); } //获取当前IP地址 function getip() { static $ip = ''; $ip = $_SERVER['REMOTE_ADDR']; if(isset($_SERVER['HTTP_CDN_SRC_IP'])) { $ip = $_SERVER['HTTP_CDN_SRC_IP']; } elseif (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) { foreach ($matches[0] AS $xip) { if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) { $ip = $xip; break; } } } return $ip; } function get_os($agent) { $os = false; if (preg_match ( '/win/i', $agent ) && strpos ( $agent, '95' )) { $os = 'Windows 95'; } else if (preg_match ( '/win 9x/i', $agent ) && strpos ( $agent, '4.90' )) { $os = 'Windows ME'; } else if (preg_match ( '/win/i', $agent ) && preg_match ( '/98/i', $agent )) { $os = 'Windows 98'; } else if (preg_match ( '/win/i', $agent ) && preg_match ( '/nt 6.0/i', $agent )) { $os = 'Windows Vista'; } else if (preg_match ( '/win/i', $agent ) && preg_match ( '/nt 6.1/i', $agent )) { $os = 'Windows 7'; } else if (preg_match ( '/win/i', $agent ) && preg_match ( '/nt 6.2/i', $agent )) { $os = 'Windows 8'; } else if (preg_match ( '/win/i', $agent ) && preg_match ( '/nt 10.0/i', $agent )) { $os = 'Windows 10'; // 添加win10判断 } else if (preg_match ( '/win/i', $agent ) && preg_match ( '/nt 5.1/i', $agent )) { $os = 'Windows XP'; } else if (preg_match ( '/win/i', $agent ) && preg_match ( '/nt 5/i', $agent )) { $os = 'Windows 2000'; } else if (preg_match ( '/win/i', $agent ) && preg_match ( '/nt/i', $agent )) { $os = 'Windows NT'; } else if (preg_match ( '/win/i', $agent ) && preg_match ( '/32/i', $agent )) { $os = 'Windows 32'; } else if (preg_match ( '/linux/i', $agent )) { if(preg_match("/Mobile/", $agent)){ if(preg_match("/QQ/i", $agent)){ $os = "Android QQ Browser"; }else{ $os = "Android Browser"; } }else{ $os = 'PC-Linux'; } } else if (preg_match ( '/Mac/i', $agent )) { if(preg_match("/Mobile/", $agent)){ if(preg_match("/QQ/i", $agent)){ $os = "IPhone QQ Browser"; }else{ $os = "IPhone Browser"; } }else{ $os = 'Mac OS X'; } } else if (preg_match ( '/unix/i', $agent )) { $os = 'Unix'; } else if (preg_match ( '/sun/i', $agent ) && preg_match ( '/os/i', $agent )) { $os = 'SunOS'; } else if (preg_match ( '/ibm/i', $agent ) && preg_match ( '/os/i', $agent )) { $os = 'IBM OS/2'; } else if (preg_match ( '/Mac/i', $agent ) && preg_match ( '/PC/i', $agent )) { $os = 'Macintosh'; } else if (preg_match ( '/PowerPC/i', $agent )) { $os = 'PowerPC'; } else if (preg_match ( '/AIX/i', $agent )) { $os = 'AIX'; } else if (preg_match ( '/HPUX/i', $agent )) { $os = 'HPUX'; } else if (preg_match ( '/NetBSD/i', $agent )) { $os = 'NetBSD'; } else if (preg_match ( '/BSD/i', $agent )) { $os = 'BSD'; } else if (preg_match ( '/OSF1/i', $agent )) { $os = 'OSF1'; } else if (preg_match ( '/IRIX/i', $agent )) { $os = 'IRIX'; } else if (preg_match ( '/FreeBSD/i', $agent )) { $os = 'FreeBSD'; } else if (preg_match ( '/teleport/i', $agent )) { $os = 'teleport'; } else if (preg_match ( '/flashget/i', $agent )) { $os = 'flashget'; } else if (preg_match ( '/webzip/i', $agent )) { $os = 'webzip'; } else if (preg_match ( '/offline/i', $agent )) { $os = 'offline'; } else { $os = '未知操作系统'; } return $os; } /** * 获取 客户端的浏览器类型 * @return string */ function get_broswer($sys){ if (stripos($sys, "Firefox/") > 0) { preg_match("/Firefox\/([^;)]+)+/i", $sys, $b); $exp[0] = "Firefox"; $exp[1] = $b[1]; //获取火狐浏览器的版本号 } elseif (stripos($sys, "Maxthon") > 0) { preg_match("/Maxthon\/([\d\.]+)/", $sys, $aoyou); $exp[0] = "傲游"; $exp[1] = $aoyou[1]; } elseif (stripos($sys, "MSIE") > 0) { preg_match("/MSIE\s+([^;)]+)+/i", $sys, $ie); $exp[0] = "IE"; $exp[1] = $ie[1]; //获取IE的版本号 } elseif (stripos($sys, "OPR") > 0) { preg_match("/OPR\/([\d\.]+)/", $sys, $opera); $exp[0] = "Opera"; $exp[1] = $opera[1]; } elseif(stripos($sys, "Edge") > 0) { //win10 Edge浏览器 添加了chrome内核标记 在判断Chrome之前匹配 preg_match("/Edge\/([\d\.]+)/", $sys, $Edge); $exp[0] = "Edge"; $exp[1] = $Edge[1]; } elseif (stripos($sys, "Chrome") > 0) { preg_match("/Chrome\/([\d\.]+)/", $sys, $google); $exp[0] = "Chrome"; $exp[1] = $google[1]; //获取google chrome的版本号 } elseif(stripos($sys,'rv:')>0 && stripos($sys,'Gecko')>0){ preg_match("/rv:([\d\.]+)/", $sys, $IE); $exp[0] = "IE"; $exp[1] = $IE[1]; }else { $exp[0] = "未知浏览器"; $exp[1] = ""; } return $exp[0].'('.$exp[1].')'; } /** * 根据 客户端IP 获取到其具体的位置信息 * @param unknown $ip * @return string */ function get_address_by_ip($ip) { $url = "http://ip.taobao.com/service/getIpInfo.php?ip=".$ip; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $info = curl_exec($curl); curl_close($curl); return $info; } function clientlog() { $useragent = $_SERVER ['HTTP_USER_AGENT']; $clientip = $_SERVER ['REMOTE_ADDR']; $client_info = get_os ( $useragent ) . "---" . get_broswer ( $useragent ); $rawdata_position = get_address_by_ip ( $clientip ); $rawdata_position = json_decode($rawdata_position, true); $country = $rawdata_position['data']['country']; $province = $rawdata_position['data']['region']; $city = $rawdata_position['data']['city']; $nettype = $rawdata_position['data']['isp']; $time = date ( 'y-m-d h:m:s' ); $data = "来自{$country} {$province} {$city }{$nettype} 的客户端: {$client_info},IP为:{$clientip},在{$time}时刻访问"; return $data; }