From 7f390f5811731a320d172138d5271a9fcfc099d3 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 31 Jul 2023 17:09:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8C=E5=87=A0=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=80=9F=E9=98=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/library/Pass.php | 45 ++++++++++++++++ .../api/controller/pass/Create.php | 9 +++- source/application/common/logic/PassFlow.php | 53 ++++++++++++++++--- 3 files changed, 99 insertions(+), 8 deletions(-) diff --git a/source/application/api/controller/library/Pass.php b/source/application/api/controller/library/Pass.php index 50998ac..b62cb70 100644 --- a/source/application/api/controller/library/Pass.php +++ b/source/application/api/controller/library/Pass.php @@ -153,4 +153,49 @@ class Pass extends Controller 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')); + } } \ No newline at end of file diff --git a/source/application/api/controller/pass/Create.php b/source/application/api/controller/pass/Create.php index 61dce69..f9bb449 100644 --- a/source/application/api/controller/pass/Create.php +++ b/source/application/api/controller/pass/Create.php @@ -63,9 +63,11 @@ class Create extends Controller $queryWhere = ['groupId' => $val['groupId'],'granularity' => $val['granularity'],'statTime' => $val['statTime']]; $query = $dm->find('bt_passenger_flow',$queryWhere); + $groupRes = $dm->find('bt_passenger_monitor_group',['groupId' => $val['groupId']]); + $groupName = isset($groupRes['groupName']) ? $groupRes['groupName'] : $val['groupName']; $insert_arr = [ 'groupId' => $val['groupId'], - 'groupName' => $val['groupName'], + 'groupName' => $groupName, 'flowInNum' => $val['flowInNum'], 'flowOutNum' => $val['flowOutNum'], 'noRepeatInNum' => $val['noRepeatInNum'], @@ -109,9 +111,12 @@ class Create extends Controller $queryWhere = ['groupId' => $val['groupId'],'granularity' => $val['granularity'],'statTime' => $val['statTime']]; $query = $dm->find('bt_passenger_flow_all',$queryWhere); + $groupRes = $dm->find('bt_passenger_monitor_group',['groupId' => $val['groupId']]); + $groupName = isset($groupRes['groupName']) ? $groupRes['groupName'] : $val['groupName']; + $insert_arr = [ 'groupId' => $val['groupId'], - 'groupName' => $val['groupName'], + 'groupName' => $groupName, 'flowInNum' => $val['flowInNum'], 'flowOutNum' => $val['flowOutNum'], 'noRepeatInNum' => $val['noRepeatInNum'], diff --git a/source/application/common/logic/PassFlow.php b/source/application/common/logic/PassFlow.php index ba21ac4..70aadad 100644 --- a/source/application/common/logic/PassFlow.php +++ b/source/application/common/logic/PassFlow.php @@ -86,7 +86,7 @@ class PassFlow } if ($date == 'week' || $date == 'all') { $data['week'] = [ - 'start_time' => date("Y-m-d",strtotime("+".(date("w") - 7) . "day")) . 'T00:00:00.000+08:00', + 'start_time' => date("Y-m-d",strtotime('this week')) . 'T00:00:00.000+08:00', 'end_time' => date("Y-m-d",strtotime("-".(date("w") - 7) . "day")) . 'T23:59:59.000+08:00' ]; } @@ -260,6 +260,20 @@ class PassFlow $sumFind = $dm->find('bt_passenger_flow_all', $sumWhere,'SUM("flowInNum") as NUM'); $returnData['sumYear']['noRepeatInNum'] = isset($sumFind['NUM']) ? $sumFind['NUM'] : 0; + if (empty($param['groupsId'])) { + # 文化数据 + $mData = $dm->find('bt_library',['group_id' => 'lib001']); + $returnData['day']['noRepeatInNum'] += isset($mData['today_incount']) ? $mData['today_incount'] : 0; + $returnData['month']['noRepeatInNum'] += isset($mData['month_incount']) ? $mData['month_incount'] : 0; + $returnData['year']['noRepeatInNum'] += isset($mData['year_incount']) ? $mData['year_incount'] : 0; + $returnData['sumYear']['noRepeatInNum'] += isset($mData['year_incount']) ? $mData['year_incount'] : 0; + $week_start = date("Y-m-d 00:00:00",strtotime('this week')); + $week_end = date("Y-m-d 23:59:59",strtotime("-".(date("w") - 7) . "day")); + $weekDateWhere = ' "group_id" =' . "'lib001'" . ' and "create_time" >= ' . "'{$week_start}'" . ' and "create_time" <= ' . "'{$week_end}'"; + $weekDate = $dm->find('bt_library_hours',$weekDateWhere,'SUM("incount") as NUM'); + $returnData['week']['noRepeatInNum'] += isset($weekDate['NUM']) ? $weekDate['NUM'] : 0; + } + foreach ($returnData as &$val) { $val['noRepeatInNum'] = formatNumber($val['noRepeatInNum']); } @@ -409,6 +423,7 @@ class PassFlow 'list' => $listData ]; } + $data = self::getLibraryGroupHoursList($dm,false,$data); return $data; } @@ -621,15 +636,17 @@ class PassFlow * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ - public static function getLibraryGroupHoursList($dm = null) + public static function getLibraryGroupHoursList($dm = null,$is_group = true,$data = []) { if (empty($dm)) $dm = new Dm(); # 获取文化组id - $groupRes = $dm->select('bt_passenger_monitor_group',['type' => 2],'"groupId","groupName"'); - $groupsId = []; - foreach ($groupRes as $groupRow) $groupsId[] = $groupRow['groupId']; - $data = self::toDayGroupsEnterNum($dm,['groupsId' => implode("|",$groupsId)]); + if ($is_group) { + $groupRes = $dm->select('bt_passenger_monitor_group',['type' => 2],'"groupId","groupName"'); + $groupsId = []; + foreach ($groupRes as $groupRow) $groupsId[] = $groupRow['groupId']; + $data = self::toDayGroupsEnterNum($dm,['groupsId' => implode("|",$groupsId)]); + } # 图书、文化馆 $start_create_time = date("Y-m-d 00:00:00"); @@ -673,4 +690,28 @@ class PassFlow return $data; } + + /** + * 获取今日图书馆借阅、办证数据 + * @param $dm + * @return int[] + */ + public static function getLibraryLeaseData($dm = null) + { + if (empty($dm)) $dm = new Dm(); + + $today = date("Y-m-d 00:00:00"); + $LibLeaseRes = $dm->find('bt_library_lease',['library' => '044007','create_time' => ['>=',$today]]); + $data = [ + 'newreader' => 0, + 'servcount' => 0, + 'returncount' => 0 + ]; + if ($LibLeaseRes) { + $data['newreader'] = $LibLeaseRes['newreader']; # 今日借书册数 + $data['servcount'] = $LibLeaseRes['servcount']; # 今日办证人数 + $data['returncount'] = $LibLeaseRes['returncount']; # 今日还书册数 + } + return $data; + } } \ No newline at end of file