$instance
$instance : object
Reference to the CI singleton
Application Controller Class
This class object is the super class that every library in CodeIgniter will be assigned to.
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* 用户报告管理
* */
use OSS\OssClient;
use OSS\Core\OssException;
require_once 'application/libraries/aliyun-oss/autoload.php';
class report extends CI_Controller
{
private static $data = array();
private static $classdefault = array();
private static $userId = 0;
public function __construct()
{
parent::__construct();
$this->load->model('Public_model', 'public');
$this->load->model('Webcommon_model', 'common');
$this->load->model('Appnotice_model', 'notice');
self::$data['header'] = $this->public->header('');
self::$data['left'] = $this->public->leftmenu('');
self::$data['footer'] = $this->public->footer();
$this->load->library('Session');
$this->public->authentication();
$this->load->model('Role_model', 'role');
$this->load->model('User_model', 'user');
$this->load->model('Agency_model', 'agency');//机构表
$this->load->model('Report_model', 'report');
$this->load->model('Userinfo_model', 'userinfo');//用户信息
$this->load->model('Photo_model', 'photo');//照片
$this->load->model('Symptom_model', 'symptom');//体质表
$roleId = $this->session->userdata('roleId');
$adminId = $this->getagencyadminId();
if ($roleId == $adminId) {
self::$data['roleId'] = $roleId;
}
}
public function editcity($a = 10)
{
set_time_limit(0);
$report_sql = 'select ip,id,city from report where id =' . $a;
$list = $this->common->getsqldata($report_sql);
foreach ($list as $value) {
$city = $this->getCity($value['ip']);
$sql = 'UPDATE report SET city = \'' . $city . '\' WHERE id =' . $value['id'];
$this->common->getsqlupdate($sql);
}
echo '<pre>';
var_dump($list);
exit('成功');
}
/**
* 报告列表
* */
public function index($agency_id = '')
{
if ($_GET) {
//获取Datatables发送的参数 必要
$draw = $_GET['draw'];//这个值作者会直接返回给前台
//排序
$order_column = $_GET['order']['0']['column'];//那一列排序,从0开始
$order_dir = $_GET['order']['0']['dir'];//ase desc 升序或者降序
//拼接排序sql
$orderSql = "";
if (isset($order_column)) {
$i = intval($order_column);
switch ($i) {
case 0;
$orderSql = " order by id " . $order_dir;
break; //ID
case 1;
$orderSql = " order by agency_id " . $order_dir;
break; //ID
case 2;
$orderSql = " order by owner_id " . $order_dir;
break; //ID
case 3;
$orderSql = " order by articleid " . $order_dir;
break; //分类
case 13;
$orderSql = " order by health_score " . $order_dir;
break;
case 12;
$orderSql = " order by health_score " . $order_dir;
break;
case 7;
$orderSql = " order by city " . $order_dir;
break;
case 8;
$orderSql = " order by time " . $order_dir;
break;
case 9;
$orderSql = " order by adminId " . $order_dir;
break;
default;
$orderSql = '';
}
}
//搜索
$search = $_GET['search']['value'];//获取前台传过来的过滤条件
//分页
$start = $_GET['start'];//从多少开始
$length = $_GET['length'];//数据长度
$limitSql = '';
$limitFlag = isset($_GET['start']) && $length != -1;
if ($limitFlag) {
$limitSql = " LIMIT " . intval($start) . ", " . intval($length);
}
$where = "";
if (isset($_GET['agencyname']) && !empty($_GET['agencyname'])) {
$where .= ' AND ag.login_name ="' . $_GET['agencyname'] . '"';
}
if (isset($_GET['shealth_score']) && !empty($_GET['shealth_score'])) {
$where .= ' AND a.health_score >="' . $_GET['shealth_score'] . '"';
}
if (isset($_GET['ehealth_score']) && !empty($_GET['ehealth_score'])) {
$where .= ' AND a.health_score <="' . $_GET['ehealth_score'] . '"';
}
if (isset($_GET['name']) && !empty($_GET['name'])) {
$where .= ' AND ui.name ="' . $_GET['name'] . '"';
}
if (isset($_GET['cellphone']) && !empty($_GET['cellphone'])) {
$where .= ' AND u.cellphone ="' . $_GET['cellphone'] . '"';
}
if (isset($_GET['sex']) && !empty($_GET['sex'])) {
$where .= ' AND ui.gender ="' . $_GET['sex'] . '"';
}
$agency_id = $this->session->userdata('agency_id');
if (isset($agency_id) && $agency_id != '') {
$where .= " AND a.agency_id =" . $agency_id;
}
if (isset($_GET['stime']) && $_GET['stime'] != 'all') {
date_default_timezone_set('PRC');
$stime = strtotime($_GET['stime']);
date_default_timezone_set('UTC');
$stime = date('Y-m-d H:i:s', $stime);
$where .= " AND a.time >='" . $stime . "'";
}
//状态查询
if (isset($_GET['etime']) && $_GET['etime'] != 'all') {
date_default_timezone_set('PRC');
$etime = strtotime($_GET['etime']);
date_default_timezone_set('UTC');
$etime = date('Y-m-d H:i:s', $etime);
$where .= " AND a.time <='" . $etime . "'";
}
//定义查询数据总记录数sql
$sumSql = "SELECT count(*) as sum FROM report as a
left join agency ag on ag.id=a.agency_id
left join user u on a.owner_id = u.id
left join user_info_history ui on a.user_info_id = ui.id WHERE a.id>0 " . $where;
//定义过滤条件查询过滤后的记录数sql
$sumSqlWhere = ' AND a.id LIKE "%' . $search . '%"';
//条件过滤后记录数 必要
$recordsFiltered = 0;
//表的总记录数 必要
$recordsTotal = 0;
//查询总数
$total = $this->common->getsqldata($sumSql);
// var_dump($total);exit;
$recordsTotal = $total[0]['sum'];
$totalResultSql = "SELECT a.*,fr.photo_id,tr.photo_id tphoto_id,sr.key,ag.login_name agencyname FROM report a
left join face_result fr on a.face_result_id = fr.id
left join tongue_result tr on a.tongue_result_id = tr.id
left join share sr on a.id=sr.report_id
left join user_info_history ui on a.user_info_id = ui.id
left join user u on a.owner_id = u.id
left join agency ag on ag.id=a.agency_id
WHERE a.id>0 " . $where;
if (strlen($search) > 0) {
//记录总数
$total = $this->common->getsqldata($sumSql . $sumSqlWhere);
$recordsFiltered = $total[0]['sum'];
$list = $this->common->getsqldata($totalResultSql . $sumSqlWhere . $orderSql . $limitSql);
} else {
//记录总数
$recordsFiltered = $recordsTotal;
$list = $this->common->getsqldata($totalResultSql . $orderSql . $limitSql);
}
header("Content-Type:text/html;charset=utf-8");
foreach ($list as $k => $v) {
date_default_timezone_set('UTC');
$v['time'] = strtotime($v['time']);
date_default_timezone_set('PRC');
$list[$k]['time'] = date('Y-m-d H:i:s', $v['time']);
if (empty($v['user_info_id'])) {
$list[$k]['name'] = 'B无';
$list[$k]['age'] = 'B无';
$list[$k]['sex'] = 'B无';
$list[$k]['cellphone'] = 'B无';
} else {
$userinfo = $this->userinfo->getUserInfoRow($v['user_info_id']);
$list[$k]['name'] = $userinfo['name'];
if (!empty($userinfo['birthday'])) {
$list[$k]['age'] = date('Y') - substr($userinfo['birthday'], 0, 4);
} else {
$list[$k]['age'] = '无';
}
$list[$k]['sex'] = $userinfo['gender'] == 'male' ? '男' : '女';
$userphone = $this->user->getUserRow($v['owner_id']);
$list[$k]['cellphone'] = $userphone['cellphone'];
}
$facephoto = $this->photo->getUserRow($v['photo_id']);
// $memcache = new Memcache; //创建一个memcache对象
// $memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器
// $get_value = $memcache->get($facephoto['oss_id']);
// if($get_value){
// $list[$k]['faceimg'] = $get_value;
// }else {
$list[$k]['faceimg'] = $this->getouturl($facephoto['oss_id']);
// $memcache->set($facephoto['oss_id'], $list[$k]['faceimg']);
// }
$tonphoto = $this->photo->getUserRow($v['tphoto_id']);
// $get_value1 = $memcache->get($tonphoto['oss_id']);
// if($get_value1){
// $list[$k]['tongueimg'] = $get_value1;
// }else {
$list[$k]['tongueimg'] = $this->getouturl($tonphoto['oss_id']);
// $memcache->set($tonphoto['oss_id'], $list[$k]['tongueimg']);
// }
$list[$k]['tongueimg'] = $this->getouturl($tonphoto['oss_id']);
$symptomarr = $this->symptom->getsymptomRow($v['id']);
if ($symptomarr) {
foreach ($symptomarr as $key => $value) {
$symptomarr1[$k][] = $value['name'];
}
$list[$k]['tizhi'] = implode('丶', $symptomarr1[$k]);
} else {
$list[$k]['tizhi'] = '无';
}
// $list[$k]['city'] = $this->getCity($v['ip']);
// $list[$k]['city'] = '上海';
}
exit(json_encode(array(
"draw" => intval($draw),
"recordsTotal" => intval($recordsTotal),
"recordsFiltered" => intval($recordsFiltered),
"data" => $list
)));
} else {
if (empty($agency_id)) {
$roleId = $this->session->userdata('roleId');
$roleId1 = $this->getagencyadminId();
if ($roleId != $roleId1) {
$this->session->set_userdata(array('agency_id' => ''));
}
} else {
$this->session->set_userdata(array('agency_id' => $agency_id));
}
$this->load->view('admincp/report/index', self::$data);
}
}
//获得机构角色的adminId
public function getagencyadminId()
{
$roledata = $this->role->checkUnique('机构');
if ($roledata) {
return $roledata['roleId'];
} else {
return 0;
}
}
public function getouturl($object = '')
{
// $this->load->library('aliyun-oss/autoload.php');
$accessKeyId = "LTAIqV3JYBM0f8Hc";
$accessKeySecret = "7Rp2MsLIHXSzocECZuMzMUFB571WQm";
$endpoint = "http://oss-cn-shanghai.aliyuncs.com/";
$bucket = "zy-dev-photo";
// $bucket = "zy-test-photo";
try {
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
// $object = "test/test-signature-test-upload-and-download.txt";
$timeout = 3600; // URL的有效期是3600秒
try {
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
return $signedUrl;
} catch (OssException $e) {
print $e->getMessage();
}
}
/**
* 通过ip获取地址
* @param $ip
* @return bool|string
*/
function getCity($ip)
{
// $memcache = new Memcache; //创建一个memcache对象
// $memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器
// $get_value = $memcache->get($ip);
// if($get_value){
// return $get_value;
// }else{
$url = "http://ip.taobao.com/service/getIpInfo.php?ip=" . $ip;
$ipinfo = json_decode(file_get_contents($url));
if ($ipinfo->code == '1') {
return false;
}
var_dump($ipinfo);
$city = $ipinfo->data->city;
// $memcache->set($ip, $city);
if ($city == 'XX') {
return $ipinfo->data->country;
}
return $city;
// }
}
/**
* 处理完成
* */
public function ajaxSetLog()
{
$cId = trim($this->input->get_post('cId'));
$userId = $this->session->userdata('adminId');
$data = array(
'status' => 1,
'finishTime' => time(),
'adminUserId' => $userId
);
$cInfo = $this->report->getReportRow($cId);
//修改积分流水表userpoints
$countdata = array(
'userId' => $userId,
'operandType' => '提现扣除' . $cInfo['jifen'] . '积分',
'listId' => 0,
'operandNum' => $cInfo['jifen'],
'changeTime' => time(),
'typeFlag' => 9,
'flag' => 2
);
$this->userpoints->insertData($countdata);
//管理操作记录
$logmsg = '完成提现。提现扣除' . $cInfo['jifen'] . '积分';
$this->public->writeLog($logmsg);
$bool = $this->report->setReport($cId, $data);
$res = array();
$res['err'] = $bool ? 0 : 1;
$res['msg'] = $bool ? '操作成功' : '操作失败';
echo json_encode($res);
}
/**
* 删除举报
*/
public function deletereport()
{
$res = array(
'err' => 1,
'msg' => '系统错误'
);
$topicId = trim($this->input->get_post('id'));
$bool = $this->report->delete($topicId);
$res['err'] = $bool ? 0 : 1;
$res['msg'] = $bool ? '删除成功' : '删除失败';
echo json_encode($res);
exit();
}
//回复举报
public function edit()
{
$res = array(
'err' => 1,
'msg' => '系统错误'
);
$id = $this->input->get_post('id');
$reportdata = $this->report->getRow($id);
if (empty($reportdata)) {
$res['msg'] = "数据错误";
echo json_encode($res);
exit();
}
$replycontent = $this->input->get_post('replycontent');
$userId = $this->session->userdata('adminId');
$replyarr = array(
'replycontent' => $replycontent,
'adminId' => $userId,
'replytime' => time(),
'isreply' => 1
);
$bool = $this->report->updateData($replyarr, $id);
$res['err'] = $bool ? 0 : 1;
$res['msg'] = $bool ? '处理成功' : '处理失败';
//发送通知
$content = '<p>您的举报管理员已回复:';
$content .= $replycontent . '</p>';
$content = addslashes($content);
$adminId = $this->session->userdata('adminId');//发布人
$noticeType = 0;
$noticeData = array(
'noticeContent' => $content,
'adminId' => $adminId,
'userId' => $reportdata['userid'],
'noticeType' => 1,
'createTime' => time()
);
$this->notice->insertData($noticeData);
echo json_encode($res);
exit();
}
//问题
public function question()
{
$question = '{
"data": [
{
"id": 1,
"label": "您自己觉得容易疲劳或乏力吗?",
"options": [
"是",
"否"
],
"exclusiveOption": 1,
"multiple": false
},
{
"id": 2,
"label": "您平时容易怕冷、怕热、或手足心热吗?",
"options": [
"怕冷(或手脚冰凉)",
"怕热",
"手足心热",
"正常"
],
"exclusiveOption": 3,
"multiple": true
},
{
"id": 3,
"label": "您平时容易出汗或晚上睡觉易出汗吗? ",
"options": [
"活动汗出",
"夜间出汗",
"正常"
],
"exclusiveOption": 2,
"multiple": true
},
{
"id": 4,
"label": "您平时小便怎么样?",
"options": [
"偏黄",
"清长(色清,量多)",
"夜尿频多",
"正常"
],
"exclusiveOption": 3,
"multiple": true
},
{
"id": 5,
"label": "您平时大便怎么样?",
"options": [
"偏干",
"偏黏",
"偏稀(或大便溏)",
"正常"
],
"exclusiveOption": 3,
"multiple": true
},
{
"id": 6,
"label": "您平时胃口怎么样?",
"options": [
"不好",
"正常"
],
"exclusiveOption": 1,
"multiple": false
},
{
"id": 7,
"label": "您平时容易口渴或口干吗?",
"options": [
"是",
"否"
],
"exclusiveOption": 1,
"multiple": false
},
{
"id": 8,
"label": "您平时觉得口中有异样的味道吗?",
"options": [
"甜",
"苦",
"黏",
"口淡",
"正常"
],
"exclusiveOption": 4,
"multiple": true
},
{
"id": 9,
"label": "您平时容易心烦、情绪低落吗?",
"options": [
"是",
"否"
],
"exclusiveOption": 1,
"multiple": false
},
{
"id": 10,
"label": "您容易掉头发吗?",
"options": [
"是",
"否"
],
"exclusiveOption": 1,
"multiple": false
},
{
"id": 11,
"label": "您平时容易失眠吗?",
"options": [
"是",
"否"
],
"exclusiveOption": 1,
"multiple": false
},
{
"id": 12,
"label": "您平时身体有胀满不适吗?",
"options": [
"乳房胀",
"食后腹胀",
"胸胁胀满",
"无"
],
"exclusiveOption": 3,
"multiple": true
},
{
"id": 13,
"label": "您自己感觉腰膝酸软、腿脚无力吗?",
"options": [
"是",
"否"
],
"exclusiveOption": 1,
"multiple": false
}
]
}';
$question = json_decode($question, true);
self::$data['question'] = $question['data'];
$id = $this->input->get_post('id');
$reportInfo = $this->report->getquesttionRow($id);
$answer = json_decode($reportInfo['answer'], true);
foreach ($answer as $key => $val) {
$tmp[$key] = $val['id'];
}
array_multisort($tmp, SORT_ASC, $answer);
$arr = range('A', 'Z');
self::$data['answer'] = $answer;
self::$data['arr'] = $arr;
$comment = $this->load->view('admincp/report/question', self::$data, true);
// var_dump($comment);
$res['num'] = 0;
$res['data'] = $comment;
echo json_encode($res);
exit;
}
//问题
public function questionList($request = array())
{
$question = '{
"data": [
{
"id": 1,
"label": "您自己觉得容易疲劳或乏力吗?",
"options": [
"是",
"否"
],
"exclusiveOption": 1,
"multiple": false
},
{
"id": 2,
"label": "您平时容易怕冷、怕热、或手足心热吗?",
"options": [
"怕冷(或手脚冰凉)",
"怕热",
"手足心热",
"正常"
],
"exclusiveOption": 3,
"multiple": true
},
{
"id": 3,
"label": "您平时容易出汗或晚上睡觉易出汗吗? ",
"options": [
"活动汗出",
"夜间出汗",
"正常"
],
"exclusiveOption": 2,
"multiple": true
},
{
"id": 4,
"label": "您平时小便怎么样?",
"options": [
"偏黄",
"清长(色清,量多)",
"夜尿频多",
"正常"
],
"exclusiveOption": 3,
"multiple": true
},
{
"id": 5,
"label": "您平时大便怎么样?",
"options": [
"偏干",
"偏黏",
"偏稀(或大便溏)",
"正常"
],
"exclusiveOption": 3,
"multiple": true
},
{
"id": 6,
"label": "您平时胃口怎么样?",
"options": [
"不好",
"正常"
],
"exclusiveOption": 1,
"multiple": false
},
{
"id": 7,
"label": "您平时容易口渴或口干吗?",
"options": [
"是",
"否"
],
"exclusiveOption": 1,
"multiple": false
},
{
"id": 8,
"label": "您平时觉得口中有异样的味道吗?",
"options": [
"甜",
"苦",
"黏",
"口淡",
"正常"
],
"exclusiveOption": 4,
"multiple": true
},
{
"id": 9,
"label": "您平时容易心烦、情绪低落吗?",
"options": [
"是",
"否"
],
"exclusiveOption": 1,
"multiple": false
},
{
"id": 10,
"label": "您容易掉头发吗?",
"options": [
"是",
"否"
],
"exclusiveOption": 1,
"multiple": false
},
{
"id": 11,
"label": "您平时容易失眠吗?",
"options": [
"是",
"否"
],
"exclusiveOption": 1,
"multiple": false
},
{
"id": 12,
"label": "您平时身体有胀满不适吗?",
"options": [
"乳房胀",
"食后腹胀",
"胸胁胀满",
"无"
],
"exclusiveOption": 3,
"multiple": true
},
{
"id": 13,
"label": "您自己感觉腰膝酸软、腿脚无力吗?",
"options": [
"是",
"否"
],
"exclusiveOption": 1,
"multiple": false
}
]
}';
$question = json_decode($question, true);
set_time_limit(0);
$where = "";
if ($request['stime']) {
$stime = date('Y-m-d H:i:s', strtotime($request['stime']));
$where .= " AND f.time >='" . $request['stime'] . "'";
}
if ($request['etime']) {
$etime = date('Y-m-d H:i:s', strtotime($request['etime']));
$where .= " AND f.time <='" . $request['etime'] . "'";
}
if ($request['reportid']) {
$totalResultSql = "SELECT f.answer,r.id FROM question_result f
right join report r on r.question_result_id = f.id
WHERE r.id =" . $request['reportid'];
} else {
$roleId = $this->session->userdata('roleId');
$roleId1 = $this->getagencyadminId();
if ($roleId != $roleId1) {
$agencyInfo = $this->agency->getagencybykey($_POST['agencyName']);
$where .= " AND r.agency_id =" . $agencyInfo['id'];
} else {
$agency_id = $this->session->userdata('agency_id');
if (isset($agency_id) && $agency_id != '') {
$where .= " AND r.agency_id =" . $agency_id;
}
}
$totalResultSql = "SELECT f.answer,r.id FROM question_result f
right join report r on r.question_result_id = f.id
WHERE f.id>0 " . $where;
}
$list = $this->common->getsqldata($totalResultSql);
$id = $this->input->get_post('id');
$reportInfo = $this->report->getquesttionRow($id);
foreach ($list as $k => $v) {
$list[$k]['answer'] = json_decode($v['answer'], true);
foreach ($list[$k]['answer'] as $key => $val) {
$tmp[$key] = $val['id'];
}
array_multisort($tmp, SORT_ASC, $list[$k]['answer']);
}
$arr = range('A', 'Z');
// echo '<pre>';
// var_dump($question);
// exit();
$str = "报告编号,第1题,第2题,第3题,第4题,第5题,第6题,第7题,第8题,第9题,第10题,第11题,第12题,第13题,";
foreach ($list as $k => $v) {
$report[$k][] = $v['id'];
foreach ($v['answer'] as $key => $value) {
$report[$k][] = implode(',', $value['answer']);
}
}
$exl11 = explode(',', $str);
$this->exportToExcel('问诊记录_' . time() . '.csv', $exl11, $report);
exit();
}
//download
public function download()
{
$res = array(
'err' => 1,
'msg' => '系统错误'
);
$referer = $this->config->item('base_url') . '/admincp/report/download';
if ($_POST) {
if (!$_POST['reportid']) {
if (!empty($_POST['agencyName'])) {
$agencyInfo = $this->agency->getagencybykey($_POST['agencyName']);
if ($agencyInfo) {
} else {
if (($_POST['inlineRadioOptions'] == 'data') || ($_POST['inlineRadioOptions'] == 'question')) {
echo "<script>alert('机构帐户错误');window.history.back(-1);</script>";
exit();
} else {
$res['msg'] = '机构帐户错误';
echo json_encode($res);
exit;
}
}
} else {
if (($_POST['inlineRadioOptions'] == 'data') || ($_POST['inlineRadioOptions'] == 'question')) {
echo "<script>alert('机构帐户不能为空');window.history.back(-1);</script>";
exit();
} else {
$res['msg'] = '机构帐户不能为空';
echo json_encode($res);
exit;
}
}
}
switch ($_POST['inlineRadioOptions']) {
case "face":
$this->facephoto($_POST);
break;
case "tongue":
$this->tonguephoto($_POST);
break;
case "fact_fail":
$this->facefailphoto($_POST);
break;
case "tongue_fail":
$this->tonguefailphoto($_POST);
break;
case "data":
$this->reportdata($_POST);
break;
case "report":
$this->reportInfo();
break;
case "question":
$this->questionList($_POST);
break;
default:
echo "你喜欢的颜色不是 红, 蓝, 或绿色!";
}
} else {
$this->load->view('admincp/report/download', self::$data);
}
}
//面诊图片下载
public function facephoto($request)
{
$res = array(
'err' => 1,
'msg' => '系统错误'
);
set_time_limit(0);
$where = "";
if ($request['stime']) {
$stime = date('Y-m-d H:i:s', strtotime($request['stime']));
$where .= " AND f.time >='" . $request['stime'] . "'";
}
if ($request['etime']) {
$etime = date('Y-m-d H:i:s', strtotime($request['etime']));
$where .= " AND f.time <='" . $request['etime'] . "'";
}
if ($request['reportid']) {
$totalResultSql = "SELECT f.photo_id,p.oss_id FROM face_result f
left join photo p on f.photo_id = p.id
right join report r on r.face_result_id = f.id
WHERE r.id =" . $request['reportid'];
} else {
$roleId = $this->session->userdata('roleId');
$roleId1 = $this->getagencyadminId();
if ($roleId != $roleId1) {
$agencyInfo = $this->agency->getagencybykey($_POST['agencyName']);
$where .= " AND f.agency_id =" . $agencyInfo['id'];
} else {
$agency_id = $this->session->userdata('agency_id');
if (isset($agency_id) && $agency_id != '') {
$where .= " AND f.agency_id =" . $agency_id;
}
}
$totalResultSql = "SELECT f.photo_id,p.oss_id FROM face_result f
left join photo p on f.photo_id = p.id
WHERE f.faceDetectRes=1 " . $where;
}
$list = $this->common->getsqldata($totalResultSql);
header('Content-Type: text/html;charset=utf-8');
if (empty($list)) {
$res['msg'] = '没有符合条件的图片';
echo json_encode($res);
exit;
}
$dir = iconv("UTF-8", "GBK", 'face' . date("Y-m-d"));
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
foreach ($list as $k => $v) {
$file_url = $this->getouturl($v['oss_id']);
if ($this->isphoto($file_url)) {
$this->dlfile($file_url, 'face' . date("Y-m-d") . '/face_' . $v['photo_id'] . '.png');
$files[] = 'face' . date("Y-m-d") . '/face_' . $v['photo_id'] . '.png';
}
}
$this->createzip('face' . date("Y-m-d") . '/face_' . time() . '.zip', $files, 'face_' . time() . '.zip');
}
public function isphoto($url)
{
if (@fopen($url, 'r')) {
return true;
} else {
return false;
}
}
//面诊图片下载
public function facefailphoto($request)
{
$res = array(
'err' => 1,
'msg' => '系统错误'
);
set_time_limit(0);
$where = "";
if ($request['stime']) {
$stime = date('Y-m-d H:i:s', strtotime($request['stime']));
$where .= " AND f.time >='" . $request['stime'] . "'";
}
if ($request['etime']) {
$etime = date('Y-m-d H:i:s', strtotime($request['etime']));
$where .= " AND f.time <='" . $request['etime'] . "'";
}
if ($request['reportid']) {
$totalResultSql = "SELECT f.photo_id,p.oss_id FROM face_result f
left join photo p on f.photo_id = p.id
right join report r on r.face_result_id = f.id
WHERE r.id =" . $request['reportid'];
} else {
$roleId = $this->session->userdata('roleId');
$roleId1 = $this->getagencyadminId();
if ($roleId != $roleId1) {
$agencyInfo = $this->agency->getagencybykey($_POST['agencyName']);
$where .= " AND f.agency_id =" . $agencyInfo['id'];
} else {
$agency_id = $this->session->userdata('agency_id');
if (isset($agency_id) && $agency_id != '') {
$where .= " AND f.agency_id =" . $agency_id;
}
}
$totalResultSql = "SELECT f.photo_id,p.oss_id FROM face_result f
left join photo p on f.photo_id = p.id
WHERE f.faceDetectRes=0 " . $where;
}
$list = $this->common->getsqldata($totalResultSql);
if (empty($list)) {
$res['msg'] = '没有符合条件的图片';
echo json_encode($res);
exit;
}
$dir = iconv("UTF-8", "GBK", 'facefail' . date("Y-m-d"));
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
foreach ($list as $k => $v) {
$file_url = $this->getouturl($v['oss_id']);
if ($this->isphoto($file_url)) {
$this->dlfile($file_url, 'facefail' . date("Y-m-d") . '/facefail_' . $v['photo_id'] . '.png');
$files[] = 'facefail' . date("Y-m-d") . '/facefail_' . $v['photo_id'] . '.png';
}
}
$this->createzip('facefail' . date("Y-m-d") . '/facefail_' . time() . '.zip', $files, 'facefail_' . time() . '.zip');
}
/**
* 舌诊图片下载
* @param $request
*/
public function tonguephoto($request)
{
$res = array(
'err' => 1,
'msg' => '系统错误'
);
set_time_limit(0);
$where = "";
if ($request['stime']) {
$stime = date('Y-m-d H:i:s', strtotime($request['stime']));
$where .= " AND f.time >='" . $request['stime'] . "'";
}
if ($request['etime']) {
$etime = date('Y-m-d H:i:s', strtotime($request['etime']));
$where .= " AND f.time <='" . $request['etime'] . "'";
}
if ($request['reportid']) {
$totalResultSql = "SELECT f.photo_id,p.oss_id FROM tongue_result f
left join photo p on f.photo_id = p.id
right join report r on r.tongue_result_id = f.id
WHERE r.id =" . $request['reportid'];
} else {
$roleId = $this->session->userdata('roleId');
$roleId1 = $this->getagencyadminId();
if ($roleId != $roleId1) {
$agencyInfo = $this->agency->getagencybykey($_POST['agencyName']);
$where .= " AND f.agency_id =" . $agencyInfo['id'];
} else {
$agency_id = $this->session->userdata('agency_id');
if (isset($agency_id) && $agency_id != '') {
$where .= " AND f.agency_id =" . $agency_id;
}
}
$totalResultSql = "SELECT f.photo_id,p.oss_id FROM tongue_result f
left join photo p on f.photo_id = p.id
WHERE f.tongueDetectRes=1 " . $where;
}
$list = $this->common->getsqldata($totalResultSql);
if (empty($list)) {
$res['msg'] = '没有符合条件的图片';
echo json_encode($res);
exit;
}
$dir = iconv("UTF-8", "GBK", 'tongue' . date("Y-m-d"));
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
foreach ($list as $k => $v) {
$file_url = $this->getouturl($v['oss_id']);
if ($this->isphoto($file_url)) {
$this->dlfile($file_url, 'tongue' . date("Y-m-d") . '/tongue_' . $v['photo_id'] . '.png');
$files[] = 'tongue' . date("Y-m-d") . '/tongue_' . $v['photo_id'] . '.png';
}
}
$this->createzip('tongue' . date("Y-m-d") . '/tongue_' . time() . '.zip', $files, 'tongue_' . time() . '.zip');
}
public function createzip($zipname, $files, $download)
{
//这里需要注意该目录是否存在,并且有创建的权限
// $zipname = 'path/test.zip';
//这是要打包的文件地址数组
// $files = array("mypath/test1.txt", "mypath/test2.pdf");
$zip = new ZipArchive();
$res = $zip->open($zipname, ZipArchive::CREATE);
if ($res === TRUE) {
foreach ($files as $file) {
//这里直接用原文件的名字进行打包,也可以直接命名,需要注意如果文件名字一样会导致后面文件覆盖前面的文件,所以建议重新命名
$new_filename = substr($file, strrpos($file, '/') + 1);
$zip->addFile($file, $new_filename);
}
//关闭文件
$zip->close();
foreach ($files as $v) {
unlink($v);
}
// //这里是下载zip文件
//
// header("Content-Type: application/zip");
// header("Content-Type: application/force-download");
// header("Content-Transfer-Encoding: Binary");
// header("Content-Length: " . filesize($zipname));
// header("Content-Disposition: attachment; filename=\"" . basename($zipname) . "\"");
//
// echo @readfile($zipname);
$res1['msg'] = '图片文件已压缩完成,点击链接下载';
$res1['err'] = '0';
$res1['data'] = $zipname;
echo json_encode($res1);
exit;
}
}
public function tonguefailphoto($request)
{
$res = array(
'err' => 1,
'msg' => '系统错误'
);
set_time_limit(0);
$where = "";
if ($request['stime']) {
$where .= " AND f.time >='" . $request['stime'] . "'";
}
if ($request['etime']) {
$where .= " AND f.time <='" . $request['etime'] . "'";
}
if ($request['reportid']) {
$totalResultSql = "SELECT f.photo_id,p.oss_id FROM tongue_result f
left join photo p on f.photo_id = p.id
right join report r on r.tongue_result_id = f.id
WHERE r.id =" . $request['reportid'];
} else {
$roleId = $this->session->userdata('roleId');
$roleId1 = $this->getagencyadminId();
if ($roleId != $roleId1) {
$agencyInfo = $this->agency->getagencybykey($_POST['agencyName']);
$where .= " AND f.agency_id =" . $agencyInfo['id'];
} else {
$agency_id = $this->session->userdata('agency_id');
if (isset($agency_id) && $agency_id != '') {
$where .= " AND f.agency_id =" . $agency_id;
}
}
$totalResultSql = "SELECT f.photo_id,p.oss_id FROM tongue_result f
left join photo p on f.photo_id = p.id
WHERE f.tongueDetectRes=0 " . $where;
}
$list = $this->common->getsqldata($totalResultSql);
if (empty($list)) {
$res['msg'] = '没有符合条件的图片';
echo json_encode($res);
exit;
}
$dir = iconv("UTF-8", "GBK", 'tonguefail' . date("Y-m-d"));
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
foreach ($list as $k => $v) {
$file_url = $this->getouturl($v['oss_id']);
if ($this->isphoto($file_url)) {
$this->dlfile($file_url, 'tonguefail' . date("Y-m-d") . '/tonguefail_' . $v['photo_id'] . '.png');
$files[] = 'tonguefail' . date("Y-m-d") . '/tonguefail_' . $v['photo_id'] . '.png';
}
}
$this->createzip('tonguefail' . date("Y-m-d") . '/tonguefail_' . time() . '.zip', $files, 'tonguefail_' . time() . '.zip');
}
function dlfile($file_url, $save_to)
{
$content = file_get_contents($file_url);
file_put_contents($save_to, $content);
}
//数据
function reportdata($request)
{
set_time_limit(0);
$where = "";
if ($request['stime']) {
$stime = date('Y-m-d H:i:s', strtotime($request['stime']));
$where .= " AND r.time >='" . $request['stime'] . "'";
}
if ($request['etime']) {
$etime = date('Y-m-d H:i:s', strtotime($request['etime']));
$where .= " AND r.time <='" . $request['etime'] . "'";
}
if ($request['reportid']) {
$totalResultSql = "SELECT r.* FROM report r
WHERE r.id= " . $request['reportid'];
} else {
$roleId = $this->session->userdata('roleId');
$roleId1 = $this->getagencyadminId();
if ($roleId != $roleId1) {
$agencyInfo = $this->agency->getagencybykey($_POST['agencyName']);
$where .= " AND r.agency_id =" . $agencyInfo['id'];
} else {
$agency_id = $this->session->userdata('agency_id');
if (isset($agency_id) && $agency_id != '') {
$where .= " AND r.agency_id =" . $agency_id;
}
}
$totalResultSql = "SELECT r.* FROM report r
WHERE r.id>0 " . $where;
}
$list = $this->common->getsqldata($totalResultSql);
$str = "报告编号,报告生成时间,面诊图片编号,面部颜色,面色L值,面色A值,面色B值,嘴唇颜色,嘴唇L值,嘴唇A值,嘴唇B值,光泽判断结果,有光泽指数,少光泽指数,无光泽指数,舌诊图片编号,苔色,苔色L值,苔色A值,苔色B值,胖瘦指数,厚薄指数,舌色,舌色L值,舌色A值,舌色B值,裂纹,裂纹指数,性别,身高,体重,用户姓名,生日,病史,手机号";
foreach ($list as $k => $v) {
$facearr = $this->report->getfaceresult($v['face_result_id']);
$tonguearr = $this->report->gettongueresult($v['tongue_result_id']);
$userinfoarr = $this->report->getuserinfo($v['user_info_id']);
$userphone = $this->user->getUserRow($v['owner_id']);
date_default_timezone_set('UTC');
$v['time'] = strtotime($v['time']);
date_default_timezone_set('PRC');
$v['time'] = date('Y-m-d H:i:s', $v['time']);
$report[$k] = array(
$v['id'], $v['time'], $facearr['photo_id'], $facearr['faceColor'], $facearr['face_L'], $facearr['face_a'], $facearr['face_b'], $facearr['lipColor'], $facearr['lip_L'], $facearr['lip_a'], $facearr['lip_b'], $facearr['faceGloss'],
$facearr['gloss'], $facearr['less_gloss'], $facearr['none_gloss'], $tonguearr['photo_id'], $tonguearr['tongueCoatColor'], $tonguearr['coat_L'], $tonguearr['coat_a'], $tonguearr['coat_b'], $tonguearr['tongueFatThin'], $tonguearr['tongueCoatThickness'],
$tonguearr['tongueNatureColor'], $tonguearr['nature_L'], $tonguearr['nature_a'], $tonguearr['nature_b'], $tonguearr['crack'], $tonguearr['tongueCrack'], $userinfoarr['gender'], $userinfoarr['height'], $userinfoarr['weight'],
$userinfoarr['name'], $userinfoarr['birthday'], $userinfoarr['medical_history'], $userphone['cellphone']
);
}
$exl11 = explode(',', $str);
$this->exportToExcel('报告数据_' . time() . '.csv', $exl11, $report);
exit();
}
/**
* @creator Jimmy
* @data 2018/1/05
* @desc 数据导出到excel(csv文件)
* @param $filename 导出的csv文件名称 如date("Y年m月j日").'-test.csv'
* @param array $tileArray 所有列名称
* @param array $dataArray 所有列数据
*/
public function exportToExcel($filename, $tileArray = array(), $dataArray = array())
{
ini_set('memory_limit', '512M');
ini_set('max_execution_time', 0);
ob_end_clean();
ob_start();
header("Content-Type: text/csv");
header("Content-Disposition:filename=" . $filename);
$fp = fopen('php://output', 'w');
fwrite($fp, chr(0xEF) . chr(0xBB) . chr(0xBF));//转码 防止乱码(比如微信昵称(乱七八糟的))
fputcsv($fp, $tileArray);
$index = 0;
foreach ($dataArray as $item) {
if ($index == 1000) {
$index = 0;
ob_flush();
flush();
}
$index++;
fputcsv($fp, $item);
}
ob_flush();
flush();
ob_end_clean();
}
//面诊信息
public function facereport()
{
if ($_GET) {
//获取Datatables发送的参数 必要
$draw = $_GET['draw'];//这个值作者会直接返回给前台
//排序
$order_column = $_GET['order']['0']['column'];//那一列排序,从0开始
$order_dir = $_GET['order']['0']['dir'];//ase desc 升序或者降序
//拼接排序sql
$orderSql = "";
if (isset($order_column)) {
$i = intval($order_column);
switch ($i) {
case 0;
$orderSql = " order by id " . $order_dir;
break; //ID
case 1;
$orderSql = " order by agency_id " . $order_dir;
break; //ID
case 2;
$orderSql = " order by time " . $order_dir;
break; //ID
case 4;
$orderSql = " order by faceColor " . $order_dir;
break; //分类
case 5;
$orderSql = " order by face_L " . $order_dir;
break;
case 6;
$orderSql = " order by face_a " . $order_dir;
break;
case 7;
$orderSql = " order by face_b " . $order_dir;
break;
case 8;
$orderSql = " order by lipColor " . $order_dir;
break;
case 9;
$orderSql = " order by lip_L " . $order_dir;
break;
case 10;
$orderSql = " order by lip_a " . $order_dir;
break;
case 11;
$orderSql = " order by lip_b " . $order_dir;
break;
case 12;
$orderSql = " order by faceGloss " . $order_dir;
break;
case 13;
$orderSql = " order by gloss " . $order_dir;
break;
case 14;
$orderSql = " order by less_gloss " . $order_dir;
break;
case 15;
$orderSql = " order by none_gloss " . $order_dir;
break;
case 16;
$orderSql = " order by faceDetectRes " . $order_dir;
break;
case 17;
$orderSql = " order by lipDetectRes " . $order_dir;
break;
default;
$orderSql = '';
}
}
//搜索
$search = $_GET['search']['value'];//获取前台传过来的过滤条件
//分页
$start = $_GET['start'];//从多少开始
$length = $_GET['length'];//数据长度
$limitSql = '';
$limitFlag = isset($_GET['start']) && $length != -1;
if ($limitFlag) {
$limitSql = " LIMIT " . intval($start) . ", " . intval($length);
}
$where = "";
if (isset($_GET['agencyname']) && !empty($_GET['agencyname'])) {
$where .= ' AND ag.login_name ="' . $_GET['agencyname'] . '"';
}
if (isset($_GET['stime']) && $_GET['stime'] != 'all') {
$stime = strtotime($_GET['stime']);
$where .= " AND a.time >=" . $stime;
}
//状态查询
if (isset($_GET['etime']) && $_GET['etime'] != 'all') {
$etime = strtotime($_GET['etime']);
$where .= " AND a.time <=" . $etime;
}
$agency_id = $this->session->userdata('agency_id');
if (isset($agency_id) && $agency_id != '') {
$where .= " AND a.agency_id =" . $agency_id;
}
//定义查询数据总记录数sql
$sumSql = "SELECT count(*) as sum FROM face_result as a left join agency ag on ag.id=a.agency_id WHERE a.id>0 " . $where;
//定义过滤条件查询过滤后的记录数sql
$sumSqlWhere = ' AND a.id LIKE "%' . $search . '%"';
//条件过滤后记录数 必要
$recordsFiltered = 0;
//表的总记录数 必要
$recordsTotal = 0;
//查询总数
$total = $this->common->getsqldata($sumSql);
// var_dump($total);exit;
$recordsTotal = $total[0]['sum'];
$totalResultSql = "SELECT a.*,ag.login_name FROM face_result a
left join agency ag on ag.id=a.agency_id
WHERE a.id>0 " . $where;
if (strlen($search) > 0) {
//记录总数
$total = $this->common->getsqldata($sumSql . $sumSqlWhere);
$recordsFiltered = $total[0]['sum'];
$list = $this->common->getsqldata($totalResultSql . $sumSqlWhere . $orderSql . $limitSql);
} else {
//记录总数
$recordsFiltered = $recordsTotal;
$list = $this->common->getsqldata($totalResultSql . $orderSql . $limitSql);
}
header("Content-Type:text/html;charset=utf-8");
foreach ($list as $k => $v) {
$facephoto = $this->photo->getUserRow($v['photo_id']);
$list[$k]['faceimg'] = $this->getouturl($facephoto['oss_id']);
date_default_timezone_set('UTC');
$v['time'] = strtotime($v['time']);
date_default_timezone_set('PRC');
$list[$k]['time'] = date('Y-m-d H:i:s', $v['time']);
}
exit(json_encode(array(
"draw" => intval($draw),
"recordsTotal" => intval($recordsTotal),
"recordsFiltered" => intval($recordsFiltered),
"data" => $list
)));
} else {
$roleId = $this->session->userdata('roleId');
$roleId1 = $this->getagencyadminId();
if ($roleId != $roleId1) {
$this->session->set_userdata(array('agency_id' => ''));
}
$this->load->view('admincp/report/facereport', self::$data);
}
}
//舌诊结果
public function tonguereport()
{
if ($_GET) {
//获取Datatables发送的参数 必要
$draw = $_GET['draw'];//这个值作者会直接返回给前台
//排序
$order_column = $_GET['order']['0']['column'];//那一列排序,从0开始
$order_dir = $_GET['order']['0']['dir'];//ase desc 升序或者降序
//拼接排序sql
$orderSql = "";
if (isset($order_column)) {
$i = intval($order_column);
switch ($i) {
case 0;
$orderSql = " order by id " . $order_dir;
break; //ID
case 1;
$orderSql = " order by agency_id " . $order_dir;
break; //ID
case 2;
$orderSql = " order by time " . $order_dir;
break; //ID
case 4;
$orderSql = " order by tongueCoatColor " . $order_dir;
break; //分类
case 5;
$orderSql = " order by coat_L " . $order_dir;
break;
case 6;
$orderSql = " order by coat_a " . $order_dir;
break;
case 7;
$orderSql = " order by coat_b " . $order_dir;
break;
case 8;
$orderSql = " order by tongueNatureColor " . $order_dir;
break;
case 9;
$orderSql = " order by nature_L " . $order_dir;
break;
case 10;
$orderSql = " order by nature_a " . $order_dir;
break;
case 11;
$orderSql = " order by nature_b " . $order_dir;
break;
case 12;
$orderSql = " order by tongueFatThin " . $order_dir;
break;
case 13;
$orderSql = " order by tongueCoatThickness " . $order_dir;
break;
case 14;
$orderSql = " order by crack " . $order_dir;
break;
case 15;
$orderSql = " order by tongueCrack " . $order_dir;
break;
case 16;
$orderSql = " order by tongueDetectRes " . $order_dir;
break;
default;
$orderSql = '';
}
}
//搜索
$search = $_GET['search']['value'];//获取前台传过来的过滤条件
//分页
$start = $_GET['start'];//从多少开始
$length = $_GET['length'];//数据长度
$limitSql = '';
$limitFlag = isset($_GET['start']) && $length != -1;
if ($limitFlag) {
$limitSql = " LIMIT " . intval($start) . ", " . intval($length);
}
$where = "";
if (isset($_GET['agencyname']) && !empty($_GET['agencyname'])) {
$where .= ' AND ag.login_name ="' . $_GET['agencyname'] . '"';
}
if (isset($_GET['stime']) && $_GET['stime'] != 'all') {
$stime = strtotime($_GET['stime']);
$where .= " AND a.time >=" . $stime;
}
//状态查询
if (isset($_GET['etime']) && $_GET['etime'] != 'all') {
$etime = strtotime($_GET['etime']);
$where .= " AND a.time <=" . $etime;
}
$agency_id = $this->session->userdata('agency_id');
if (isset($agency_id) && $agency_id != '') {
$where .= " AND a.agency_id =" . $agency_id;
}
//定义查询数据总记录数sql
$sumSql = "SELECT count(*) as sum FROM tongue_result as a left join agency ag on ag.id=a.agency_id WHERE a.id>0 " . $where;
//定义过滤条件查询过滤后的记录数sql
$sumSqlWhere = ' AND a.id LIKE "%' . $search . '%"';
//条件过滤后记录数 必要
$recordsFiltered = 0;
//表的总记录数 必要
$recordsTotal = 0;
//查询总数
$total = $this->common->getsqldata($sumSql);
// var_dump($total);exit;
$recordsTotal = $total[0]['sum'];
$totalResultSql = "SELECT a.*,ag.login_name FROM tongue_result a
left join agency ag on ag.id=a.agency_id
WHERE a.id>0 " . $where;
if (strlen($search) > 0) {
//记录总数
$total = $this->common->getsqldata($sumSql . $sumSqlWhere);
$recordsFiltered = $total[0]['sum'];
$list = $this->common->getsqldata($totalResultSql . $sumSqlWhere . $orderSql . $limitSql);
} else {
//记录总数
$recordsFiltered = $recordsTotal;
$list = $this->common->getsqldata($totalResultSql . $orderSql . $limitSql);
}
header("Content-Type:text/html;charset=utf-8");
foreach ($list as $k => $v) {
$tonphoto = $this->photo->getUserRow($v['photo_id']);
$list[$k]['tongueimg'] = $this->getouturl($tonphoto['oss_id']);
date_default_timezone_set('UTC');
$v['time'] = strtotime($v['time']);
date_default_timezone_set('PRC');
$list[$k]['time'] = date('Y-m-d H:i:s', $v['time']);
}
exit(json_encode(array(
"draw" => intval($draw),
"recordsTotal" => intval($recordsTotal),
"recordsFiltered" => intval($recordsFiltered),
"data" => $list
)));
} else {
$roleId = $this->session->userdata('roleId');
$roleId1 = $this->getagencyadminId();
if ($roleId != $roleId1) {
$this->session->set_userdata(array('agency_id' => ''));
}
$this->load->view('admincp/report/tonguereport', self::$data);
}
}
}