宝体数据调用接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

201 lines
6.9 KiB

<?php
namespace app\api\controller\library;
use app\api\controller\Controller;
use app\common\dm\Dm;
use app\common\logic\PassFlow;
class Pass extends Controller
{
protected $url = 'http://balib.cn:8999';
/**
* 图书管数据接口
* @return array
* 返回数据:today.incount=今天进 month.incount=本月进 year.incount=今年进 day30.incount=近30天近 outcount=出
* 不传参数就是所有摄像头,传cameraid就是按传的摄像头ID
* cameraid = 宝安图书馆9,7,6,4,2,1,67,3 1990分馆134、 135
*/
public function allFlowTrends()
{
$data = PassFlow::allFlowTrends();
return $this->renderSuccess(compact('data'));
}
/**
* 借阅,办证
* 分馆年借还,今日借、还,今日办证
* @return array
*/
public function getLibraryService()
{
$library = $this->request->param('library') ?: '044007';
$url = $this->url . "/SSBusiness/monitor/getLibraryService?library={$library}";
$result = curlPost($url);
$data = json_decode($result,true);
return $this->renderSuccess(compact('data'));
}
/**
* 创建数据接口
* @return array
*/
public function create()
{
$data_json = $this->request->param('data');
$data = json_decode(html_entity_decode($data_json),true);
$hour = date("H:00");
$last_hour = date("H:00",strtotime('-1 hour'));
$dm = new Dm();
foreach ($data as $val) {
$query = $dm->find('bt_library',['group_id' => $val['group_id']]);
$opData = [
'day30_incount' => $val['day30_incount'],
'day30_outcount' => $val['day30_outcount'],
'today_incount' => $val['today_incount'],
'today_outcount' => $val['today_outcount'],
'month_incount' => $val['month_incount'],
'month_outcount' => $val['month_outcount'],
'year_incount' => $val['year_incount'],
'year_outcount' => $val['year_outcount'],
];
if ($query) {
$opData['update_time'] = date("Y-m-d H:i:s",time());
$dm->update('bt_library',$opData,['id' => $query['id']]);
} else {
$opData['group_id'] = $val['group_id'];
$opData['group_name'] = base64_decode($val['group_name']);
$opData['create_time'] = date("Y-m-d H:i:s",time());
$dm->insert('bt_library',$opData);
}
// --------------------- 小时数据 --------------------- //
$hoursQueryWhere = ['hour_time' => $hour, 'group_id' => $val['group_id']];
$hoursQuery = $dm->find("bt_library_hours",$hoursQueryWhere);
# 默认单天数据
$incount = 0;
$outcount = 0;
if ($hoursQuery) {
# 存在的数量 + (这次天数数量 - 上次天数数量) = 当前小时数量
$incount = $hoursQuery['incount'] + ($val['today_incount'] - $hoursQuery['target_today_incount']);
$outcount = $hoursQuery['outcount'] + ($val['today_outcount'] - $hoursQuery['target_today_outcount']);
$update = [
'incount' => $incount,
'outcount' => $outcount,
'target_today_incount' => $val['today_incount'],
'target_today_outcount' => $val['today_outcount'],
'update_time' => date("Y-m-d H:i:s",time())
];
$dm->update('bt_library_hours',$update,['id' => $hoursQuery['id']]);
} else {
# 查看该组是否存在上一条数据
$lastHoursWhere = ['hour_time' => $last_hour, 'group_id' => $val['group_id']];
$lastHours = $dm->find('bt_library_hours',$lastHoursWhere,'*','id DESC');
if ($lastHours) {
$incount = $val['today_incount'] - $lastHours['target_today_incount'];
$incount = $incount > 0 ? $incount : 0;
$outcount = $val['today_outcount'] - $lastHours['target_today_outcount'];
$outcount = $outcount > 0 ? $outcount : 0;
}
# 创建数据
$insert = [
'group_id' => $val['group_id'],
'group_name' => base64_decode($val['group_name']),
'incount' => $incount,
'outcount' => $outcount,
'target_today_incount' => $val['today_incount'],
'target_today_outcount' => $val['today_outcount'],
'hour_time' => $hour,
'create_time' => date("Y-m-d H:i:s",time())
];
$dm->insert("bt_library_hours",$insert);
}
// --------------------- end --------------------- //
}
return $this->renderSuccess();
}
/**
* 文化 - 24小时 柱状图 数据
* @return array
*/
public function getLibraryHours24List()
{
$data = PassFlow::getLibraryHours24List();
return $this->renderSuccess(compact('data'));
}
/**
* 今日个场馆数据
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getLibraryGroupHoursList()
{
$data = PassFlow::getLibraryGroupHoursList();
return $this->renderSuccess(compact('data'));
}
/**
* 创建图书馆 借阅 办证数据
* @return array
*/
public function createLibraryLease()
{
$data_json = $this->request->param('data');
$data = json_decode(html_entity_decode($data_json),true);
$dm = new Dm();
$today_start_time = date("Y-m-d 00:00:00",time());
foreach ($data as $val) {
$library = $val['library'];
$query = $dm->find("bt_library_lease",['library' => $library,'create_time' => ['>=',$today_start_time]]);
$arr = [
'newreader' => $val['newreader'],
'servcount' => $val['servcount'],
'returncount' => $val['returncount']
];
if ($query) {
$arr['update_time'] = date("Y-m-d H:i:s",time());
$dm->update('bt_library_lease',$arr,['id' => $query['id']]);
} else {
$arr['library'] = $library;
$arr['create_time'] = date("Y-m-d H:i:s",time());
$dm->insert('bt_library_lease',$arr);
}
}
return $this->renderSuccess();
}
/**
* 获取今日借阅办证数据
* @return array
*/
public function getLibraryLeaseData()
{
$data = PassFlow::getLibraryLeaseData();
return $this->renderSuccess(compact('data'));
}
}