$data
$data :
Model Class
<?php
use GuzzleHttp\json_decode;
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Webcommon_model extends CI_Model
{
private static $data = array();
public function __construct()
{
parent::__construct();
// $this->load->library('Session');
}
public function getsqldata($sql){
$query = $this->db->query($sql);
$row = $query->result();
$row = json_decode(json_encode($row),true);
return $row;
}
public function sendSms($phone='',$code='')
{
// $phone = $this->input->get_post('phone');
$host = "http://smsapi.api51.cn";
$path = "/code/";
$method = "GET";
$appcode = "af8a96add4bf4c31b992bc31aad30028";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
$querys = "code=$code&mobile=$phone";
$bodys = "";
$url = $host . $path . "?" . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$info = curl_exec($curl);
//$res=json_decode($info);
//var_dump($res);
/* if($info->success==true){
return true;
}else{
return false;
} */
}
/**
* 输出json字符串
* @author yxl
* @param array $array 要输出的数据
* @return string json字符串
* @2015-5-18 18:57:47
*/
public function getJsonOutput($array)
{
header("Content-Type:text/html;charset=utf-8");
// ob_end_clean();
return json_encode($array);
}
/**
* 返回值输出
* @author yxl
* @2015-5-19 18:58:23
* @param array $array 数据列表
* @param string $msg 返回信息文字描述
* @param number $code 返回代码 0是成功,1是参数不全或错误,2其它手机登录,
* 3服务器错误, 4花的数量不够,5角色选择,6没有权限查看班级,8防止二次提交
* 9未绑定孩子
* @return string json字符串
*/
public function returnArray($array, $msg = '操作成功', $code = 0)
{
$array = array('code' => $code, 'msg' => $msg, 'content' => $array);
//var_dump($array);exit;
return $this->getJsonOutput($array);
}
/**
* 检查用户是否与服务器一致,互踢
* @author yxl
* @2015-5-20 14:49:04
* @param Integer $userId
* @param string $token
* @return boolean
*/
public function getLoginStuate($userId = 0, $token = '')
{
if (empty($userId) || ($token == ''))
{
echo $this->returnArray(array('list' => '0'), '非法请求', 1);
exit;
}
$this->load->model('User_model', 'user');
$userData = $this->user->getUserRow($userId, 'token');
if ($token != $userData['token'])
{
echo $this->returnArray(array('list' => ''), '您的账号在其他手机登录', 2);
exit;
}else{
$this->load->model('Usercount_model', 'usercount');
$usercount = $this->usercount->getUserCountRow($userId);
$time =time()-604800;
if($time>$usercount['lastTime']){
echo $this->returnArray(array('list' => ''), '您的登录已过期,请重先登录', 2);
exit;
}else{
if(empty($userData['phone'])){
echo $this->common->returnArray(array('list' => ''), '尚未绑定手机号', 201);exit;
}
$countDatas = array(
'lastTime' => time(),
'lastIP' => "".$_SERVER['REMOTE_ADDR'].""
);
$this->usercount->updateData($countDatas,$userId);
}
}
}
/**
* 头部文件
* */
public function header( $title="",$description="",$keywords="",$menuId=1 )
{
// var_dump(self::$data);
$headUrl = $this->session->userdata('headUrl');
$this->load->model('Userinfo_model','userinfo');
$this->load->model('Appcate_model','cate');
$this->load->model('thirdlogin_model');
$userInfo = $this->userinfo->getUserInfoRow(self::$data['userId'],2);
if(empty($userInfo))
{
$userInfo = $this->userinfo->getUserInfoRow( self::$data['userId'] ,1 );//1是商城
if(empty($userInfo))
{
$userInfo = $this->userinfo->getUserInfoRow( self::$data['userId'] ,0 );//0是吉他网
}
}
if($menuId==1){
$sql = "select c.*,count(a.articleId) as co from appcate as c left join apparticle as a on a.cateId=c.cateId group by
a.cateId order by co desc limit 6";
$query = $this->db->query($sql);
$row = $query->result();
$cateList = json_decode(json_encode($row),true);
}elseif ($menuId==3) {
$sql = "select c.*,count(a.id) as co from appcate as c left join protfolio as a on a.category=c.cateId group by
a.category order by co desc limit 6";
$query = $this->db->query($sql);
$row = $query->result();
$cateList = json_decode(json_encode($row),true);
//获取分类(前六个)
// $cateList = $this->cate->getCateList(array('menuId'=>$menuId),6);
}
$cateListArray = array();
foreach($cateList as $key=>$value)
{
$cateListArray[$key]['cateId'] = $value['cateId'];
$cateListArray[$key]['cateName'] = $value['cateName'];
$cateListArray[$key]['imagePath'] = empty($value['imagePath'])?'':$this->config->item('hwclouds').$value['imagePath'];
}
//获取分类(六个以后的)
$cateList2 = $this->cate->getCateList(array('menuId'=>1),100,6);
$cateListArray2 = array();
foreach($cateList2 as $key=>$value)
{
$cateListArray2[$key]['cateId'] = $value['cateId'];
$cateListArray2[$key]['cateName'] = $value['cateName'];
$cateListArray2[$key]['imagePath'] = empty($value['imagePath'])?'':$this->config->item('hwclouds').$value['imagePath'];
}
//新浪第三方登录链接
$sina_url=$this->thirdlogin_model->sina_login();
self::$data['sina_url']=$sina_url;
self::$data['title'] = $title;
self::$data['description'] = $description;
self::$data['keywords'] = $keywords;
self::$data['nickName'] = $this->session->userdata('nickName');
self::$data['userInfo'] = $userInfo;
self::$data['cateList'] = $cateListArray;
self::$data['cateList_more'] = $cateListArray2;
$userInfo['headUrl'] = empty($userInfo['headUrl'])?$userInfo['thirdheadUrl']:$this->config->item('hwclouds').$userInfo['headUrl'];
self::$data['headUrl'] = empty($userInfo['headUrl'])?$this->config->item('base_url').'/public/web/images/use_tx_03.png':$userInfo['headUrl'];
return $this->load->view('web/header',self::$data, TRUE);
}
/**
* 底部
* */
public function footer()
{
return $this->load->view('web/footer', '', TRUE);
}
/**
* 左侧
* */
public function lefter($keyword)
{
$this->load->model('User_model','user');
$this->load->model('Userinfo_model','userinfo');
$this->load->model('Usercount_model','usercount');
$user=$this->user->getUserRow(self::$data['userId']);
$userInfo = $this->userinfo->getUserInfoRow( self::$data['userId'] ,2 );//2是APP
if(empty($userInfo))
{
$userInfo = $this->userinfo->getUserInfoRow( self::$data['userId'] ,1 );//1是商城
if(empty($userInfo))
{
$userInfo = $this->userinfo->getUserInfoRow( self::$data['userId'] ,0 );//0是吉他网
}
}
$brief = empty($userInfo['brief'])?'暂无简介':$userInfo['brief'];
$nickName = empty($userInfo['nickName'])?'暂无昵称':$userInfo['nickName'];
$userInfo['headUrl'] = empty($userInfo['headUrl'])?$userInfo['thirdheadUrl']:$this->config->item('hwclouds').$userInfo['headUrl'];
$headUrl = empty($userInfo['headUrl'])?$this->config->item('base_url').'/public/web/images/use_tx_03.png':$userInfo['headUrl'];
$usercount = $this->usercount->getUserCountRow( self::$data['userId'] );
$userinfo = $this->user->getUserRow( self::$data['userId'] );
$jifen = $usercount['jifenNum']-$usercount['jifenConsumptionNum'];
$leftData = array(
'nickName' => $nickName,
'headUrl' =>$headUrl,
'jifenNum' => $jifen,
'keyword' => $keyword,
'brief' => $brief,
'userFlag'=>@$user['userFlag'],
'is_singer'=>@$user['is_singer'],
'is_diantai'=>@$user['is_diantai']
);
self::$data['leftData'] = $leftData;
return $this->load->view('web/left', self::$data, TRUE);
}
/**
* 提示页
* */
public function message($title='',$url='',$isok=0,$header=array())
{
$data = array();
$data['header'] = $this->header($header);
$data['footer'] = $this->footer();
$data['title'] = $title;
$data['url'] = $url;
$data['isok'] = $isok;
return $this->load->view('web/message', $data,true);
}
/**
* 分页
*/
public function create_page($base_url, $count_all, $per_page, $uri_segment = 4, $num_links = 5)
{
$this->load->library('pagination');
$config['base_url'] = base_url($base_url); // 分页链接
$config['total_rows'] = $count_all; // 总数据条数
$config['per_page'] = $per_page; // 每页显示数量
$config['use_page_numbers'] = FALSE; // 默认分页URL中是显示每页记录数,启用use_page_numbers后显示的是当前页码
$config['first_link'] = ' '; // 自定义 首页名称
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['next_link'] = '>'; // 自定义 下一页名称
$config['next_tag_open'] = '<li style="cursor:pointer;" class="fadsfas">';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '<'; // 自定义 上一页名称
$config['prev_tag_open'] = '<li style="cursor:pointer;">';
$config['prev_tag_close'] = '</li>';
$config['last_link'] = ' '; // 自定义 末页名称
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['display_pages'] = TRUE; // 是否显示数字链接
$config['uri_segment'] = $uri_segment; // 指定index.php后第几位是分页数
$config['num_links'] = $num_links; // 指定当前页前后各显示几页
$config['cur_tag_open'] = '<li><a style="background:#2b2b2b;color:#fff" >'; // 选中页码标签开始
$config['cur_tag_close'] = '</a></li>'; // 选中页码标签结束
$config['num_tag_open'] = '<li style="cursor:pointer;">'; // 自定义数字链接
$config['num_tag_close'] = '</li>'; // 自定义数字链接
$this->pagination->initialize($config);
return true;
}
/**
* 处理参数
* */
public function dealparam($param)
{
$url = array();
if(!empty($param)){
foreach ($param as $k=>$v)
{
if($v !== '' &&$v!==false)
{
$url[] = $k.'='.$v;
}
}
}
return !empty($url) ? implode('&', $url) : '';
}
/**
* 登录验证
*/
public function authentication()
{
$userId = $this->session->userdata('userId');
if (empty($userId))
{
$url = $this->config->item('base_url').'/web/login';
header("Location: ".$url); exit;
}
}
}
?>