304 lines
7.4 KiB
PHP
304 lines
7.4 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
/**
|
|
* 证书
|
|
* @author luoxuancai 2019/5/7
|
|
*/
|
|
class Cert extends CI_Controller {
|
|
|
|
const SESSION_KEY = 'device_id_cert';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('wx_token');
|
|
}
|
|
|
|
/**
|
|
* 验证查看权限
|
|
* 用户/手机号主人/超管可以看
|
|
**/
|
|
protected function _check_auth($device_id){
|
|
//未登录验证
|
|
if(in_array($device_id,$_SESSION[self::SESSION_KEY])){
|
|
return true;
|
|
}
|
|
//超级管理员可以查看任意证书
|
|
$isLoggedIn = $this->session->userdata ( 'isAdminLoggedIn' );
|
|
if (isset ( $isLoggedIn ) || $isLoggedIn == TRUE) {
|
|
return true;
|
|
}
|
|
//已登录查看自己的验证码
|
|
if(!empty($_SESSION['users_id'])){
|
|
$this->load->model('model_UsersInfo');
|
|
//检查信息是否能对应
|
|
$row = $this->model_UsersInfo->get(
|
|
$device_id,
|
|
'device_id'
|
|
);
|
|
if(!empty($row) && $row['users_id'] == $_SESSION['users_id']){
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
protected function _set_auth($device_id){
|
|
//未登录验证
|
|
$_SESSION[self::SESSION_KEY][] = $device_id;
|
|
}
|
|
|
|
// 验证短信验证码是否有效
|
|
public function send_sms_code(){
|
|
$this->load->model('sms_code');
|
|
$this->sms_code->test();
|
|
$mobile = $_POST['mobile'];
|
|
|
|
$data = [
|
|
'ret' => 1,
|
|
'msg' => ''
|
|
];
|
|
|
|
if(empty($mobile)){
|
|
$data['msg'] = '信息不完整';
|
|
}
|
|
$this->load->model('sms_code');
|
|
if($this->sms_code->send(
|
|
$mobile,
|
|
rand(0,9)
|
|
)){
|
|
$data['msg'] = '验证码错误或已过期,请重新获取';
|
|
}
|
|
|
|
}
|
|
|
|
// 验证短信验证码是否有效
|
|
public function check_sms_code(){
|
|
|
|
$mobile = $_POST['mobile'];
|
|
$device_id = $_POST['device_id'];
|
|
$code = $_POST['code'];
|
|
|
|
$data = [
|
|
'ret' => 1,
|
|
'msg' => ''
|
|
];
|
|
|
|
if(empty($mobile) or empty($device_id) or empty($code)){
|
|
$data['msg'] = '信息不完整';
|
|
}
|
|
|
|
|
|
//检查设备号对应情况,没有填手机号则报错
|
|
$this->load->model('Model_UsersInfo');
|
|
//检查信息是否能对应
|
|
$row = $this->model_UsersInfo->get(
|
|
$mobile,
|
|
'users_tel'
|
|
);
|
|
if(empty($row) or $row['device_id']!==$device_id){
|
|
$data['msg'] = '手机号或序列号错误';
|
|
}
|
|
|
|
//检查验证码
|
|
$this->load->model('sms_code');
|
|
if($this->sms_code->check(
|
|
$mobile,
|
|
$code
|
|
)){
|
|
$data['msg'] = '验证码错误或已过期,请重新获取';
|
|
}
|
|
echo json_encode($data,JSON_UNESCAPED_UNICODE);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 激活查询
|
|
*/
|
|
public function query()
|
|
{
|
|
$mobile = isset($_REQUEST['mobile']) ? $_REQUEST['mobile'] : 0;
|
|
$device_id = isset($_REQUEST['device_id']) ? $_REQUEST['device_id'] : 0;
|
|
$data = [
|
|
'info' => [],
|
|
'warning' => ''
|
|
];
|
|
if($mobile and $device_id){
|
|
//检查信息是否能对应
|
|
$row = $this->model_UsersInfo->get(
|
|
$mobile,
|
|
'users_tel'
|
|
);
|
|
if(empty($row) or $row['device_id']!==$device_id){
|
|
$data['warning'] = '手机号或序列号错误';
|
|
}else{
|
|
$data['info'] = $row;
|
|
}
|
|
}
|
|
$data['type'] = 'info';
|
|
$this->load->view('cert/index', $data);
|
|
}
|
|
|
|
/**
|
|
* 证书查询
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->load->model('model_UsersInfo');
|
|
$device_id = isset($_REQUEST['device_id']) ? $_REQUEST['device_id'] : 0;
|
|
$data = [
|
|
'info' => [],
|
|
'warning' => ''
|
|
];
|
|
if($device_id){
|
|
//检查信息是否能对应
|
|
$row = $this->model_UsersInfo->get(
|
|
$device_id,
|
|
'device_id'
|
|
);
|
|
if(empty($row)){
|
|
$data['warning'] = '序列号错误';
|
|
}else{
|
|
header('Location:/cert/id/'.trim($device_id));
|
|
$data['info'] = $row;
|
|
}
|
|
}
|
|
$data['type'] = 'cert';
|
|
$this->load->view('cert/index', $data);
|
|
}
|
|
|
|
/**
|
|
* 激活信息
|
|
*/
|
|
public function info($id)
|
|
{
|
|
|
|
if(empty($id)){
|
|
return $this->notify();
|
|
}
|
|
|
|
$this->load->model('Model_UsersInfo');
|
|
$this->load->model('report_model');
|
|
//报告文件
|
|
$file = $this->report_model->report_file_path(trim($id));
|
|
$reportJson = [];
|
|
if(file_exists($file)){
|
|
$a=filemtime($file);
|
|
$data['time'] = date("Y.m.d",$a);
|
|
//return $this->notify();
|
|
$reportJson = file_get_contents($file);
|
|
$reportJson = json_decode($reportJson,true);
|
|
}
|
|
|
|
//补充图片,物种
|
|
$info = $this->Model_UsersInfo->get_by_device_id($id);
|
|
if(!$info){
|
|
return $this->notify();
|
|
}
|
|
$data = array(
|
|
'owner'=>''
|
|
);
|
|
|
|
$data['device_id'] = $id;
|
|
//$data['name'] = $reportJson['header']['宠物名'];
|
|
//$data['wolf'] = isset($reportJson['进阶项目研究']['body']['狼性']['body'])?$reportJson['进阶项目研究']['body']['狼性']['body']:'未知';
|
|
if(!empty($reportJson)){
|
|
$data['mixed'] = isset($reportJson['血统分析']['body']['品系纯度'])?$reportJson['血统分析']['body']['品系纯度']:[];
|
|
}
|
|
//主人信息
|
|
$data['owner'] = $info['users_name'];
|
|
$data['name'] = $info['pet_name'];
|
|
$data['time'] = date("Y.m.d",$info['createtime']);
|
|
//预置血统信息优先
|
|
$data['mixed'] = ['未知'=>''];
|
|
if(!empty($info['lineage'])){
|
|
$data['mixed'] = [];
|
|
$lineage = explode(';',$info['lineage']);
|
|
foreach ($lineage as $val) {
|
|
$val = explode(':',$val);
|
|
if(count($val)<2){
|
|
continue;
|
|
}
|
|
$data['mixed'][$val[0]] = $val[1];
|
|
}
|
|
}
|
|
$this->load->view('user/includes/header', NULL);
|
|
$this->load->view('user/includes/nav', NULL);
|
|
$this->load->view('cert/id', $data);
|
|
$this->load->view('user/includes/footer', NULL);
|
|
}
|
|
|
|
/**
|
|
* 证书
|
|
*/
|
|
public function id($id)
|
|
{
|
|
|
|
if(empty($id)){
|
|
return $this->notify();
|
|
}
|
|
|
|
$this->load->model('Model_UsersInfo');
|
|
$this->load->model('report_model');
|
|
//报告文件
|
|
$file = $this->report_model->report_file_path(trim($id));
|
|
$reportJson = [];
|
|
if(file_exists($file)){
|
|
$a=filemtime($file);
|
|
$data['time'] = date("Y.m.d",$a);
|
|
//return $this->notify();
|
|
$reportJson = file_get_contents($file);
|
|
$reportJson = json_decode($reportJson,true);
|
|
}
|
|
|
|
//补充图片,物种
|
|
$info = $this->Model_UsersInfo->get_by_device_id($id);
|
|
if(!$info){
|
|
return $this->notify();
|
|
}
|
|
$data = array(
|
|
'owner'=>''
|
|
);
|
|
|
|
$data['device_id'] = $id;
|
|
//$data['name'] = $reportJson['header']['宠物名'];
|
|
//$data['wolf'] = isset($reportJson['进阶项目研究']['body']['狼性']['body'])?$reportJson['进阶项目研究']['body']['狼性']['body']:'未知';
|
|
if(!empty($reportJson)){
|
|
$data['mixed'] = isset($reportJson['血统分析']['body']['品系纯度'])?$reportJson['血统分析']['body']['品系纯度']:[];
|
|
}
|
|
//主人信息
|
|
$data['owner'] = $info['users_name'];
|
|
$data['name'] = $info['pet_name'];
|
|
$data['time'] = date("Y.m.d",$info['createtime']);
|
|
//预置血统信息优先
|
|
$data['mixed'] = ['未知'=>''];
|
|
if(!empty($info['lineage'])){
|
|
$data['mixed'] = [];
|
|
$lineage = explode(';',$info['lineage']);
|
|
foreach ($lineage as $val) {
|
|
$val = explode(':',$val);
|
|
if(count($val)<2){
|
|
continue;
|
|
}
|
|
$data['mixed'][$val[0]] = $val[1];
|
|
}
|
|
}
|
|
$data['test_date'] = $info['test_date'];
|
|
$data['birthday'] = $info['pet_birthday'];
|
|
$this->load->view('user/includes/header', NULL);
|
|
$this->load->view('user/includes/nav', NULL);
|
|
$this->load->view('cert/id', $data);
|
|
$this->load->view('user/includes/footer', NULL);
|
|
}
|
|
|
|
protected function notify(){
|
|
$this->load->view('user/includes/header', NULL);
|
|
$this->load->view('user/includes/nav', NULL);
|
|
$this->load->view('cert/notify', []);
|
|
$this->load->view('user/includes/footer', NULL);
|
|
}
|
|
|
|
|
|
}
|