|
|
@@ -294,36 +294,113 @@ class Daily extends Base {
|
|
|
->where('org_id',$orgId)
|
|
|
->select();
|
|
|
|
|
|
- $list = $list?$list:array();
|
|
|
+ $list = $list?$list->toArray():array();
|
|
|
$count = $count1 = $count2 =$count3 = 0;
|
|
|
|
|
|
- foreach ($list as $k=>$v){
|
|
|
- $list[$k]['title'] = '';
|
|
|
- if($v['address_id'] >0){
|
|
|
- $list[$k]['title'] = Db::name('address')
|
|
|
- ->where('id',$v['address_id'])
|
|
|
- ->value('title');
|
|
|
+// foreach ($list as $k=>$v){
|
|
|
+// $list[$k]['title'] = '';
|
|
|
+// if($v['address_id'] >0){
|
|
|
+// $list[$k]['title'] = Db::name('address')
|
|
|
+// ->where('id',$v['address_id'])
|
|
|
+// ->value('title');
|
|
|
+// }
|
|
|
+// $query = Db::name('daily_record')
|
|
|
+// ->where('org_id',$orgId)
|
|
|
+// ->where('daily_id',$v['id']);
|
|
|
+// $list[$k]['count'] = $query
|
|
|
+// ->count();
|
|
|
+// $count += $list[$k]['count'];
|
|
|
+// //本月
|
|
|
+// $list[$k]['count1'] = $query
|
|
|
+// ->where('create_yyyymm',date('Ym'))
|
|
|
+// ->count();
|
|
|
+// $count1 += $list[$k]['count1'];
|
|
|
+// //本周
|
|
|
+// $list[$k]['count2'] = $query
|
|
|
+// ->whereIn('create_yyyymmdd',get_week_date())
|
|
|
+// ->count();
|
|
|
+// $count2 += $list[$k]['count2'];
|
|
|
+// //今天
|
|
|
+// $list[$k]['count3'] = $query
|
|
|
+// ->where('create_yyyymmdd',date('Ymd'))
|
|
|
+// ->count();
|
|
|
+// $count3 += $list[$k]['count3'];
|
|
|
+// }
|
|
|
+ $addressIds = array_column($list, 'address_id');
|
|
|
+ $addressIds = array_filter(array_unique($addressIds)); // 去重并过滤0值
|
|
|
+ $addressTitles = [];
|
|
|
+ if (!empty($addressIds)) {
|
|
|
+ $addressTitles = Db::name('address')
|
|
|
+ ->where('id', 'in', $addressIds)
|
|
|
+ ->column('title', 'id');
|
|
|
+ }
|
|
|
+
|
|
|
+ $dailyIds = array_column($list, 'id');
|
|
|
+
|
|
|
+ $totalCounts = [];
|
|
|
+ $totalResults = Db::name('daily_record')
|
|
|
+ ->where('org_id', $orgId)
|
|
|
+ ->where('daily_id', 'in', $dailyIds)
|
|
|
+ ->field('daily_id, COUNT(*) as count')
|
|
|
+ ->group('daily_id')
|
|
|
+ ->select();
|
|
|
+ foreach ($totalResults as $item) {
|
|
|
+ $totalCounts[$item['daily_id']] = $item['count'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $currentMonth = date('Ym');
|
|
|
+ $monthCounts = [];
|
|
|
+ $monthResults = Db::name('daily_record')
|
|
|
+ ->where('org_id', $orgId)
|
|
|
+ ->where('daily_id', 'in', $dailyIds)
|
|
|
+ ->where('create_yyyymm', $currentMonth)
|
|
|
+ ->field('daily_id, COUNT(*) as count')
|
|
|
+ ->group('daily_id')
|
|
|
+ ->select();
|
|
|
+ foreach ($monthResults as $item) {
|
|
|
+ $monthCounts[$item['daily_id']] = $item['count'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $weekDates = get_week_date();
|
|
|
+ $weekCounts = [];
|
|
|
+ if (!empty($weekDates)) {
|
|
|
+ $weekResults = Db::name('daily_record')
|
|
|
+ ->where('org_id', $orgId)
|
|
|
+ ->where('daily_id', 'in', $dailyIds)
|
|
|
+ ->where('create_yyyymmdd', 'in', $weekDates)
|
|
|
+ ->field('daily_id, COUNT(*) as count')
|
|
|
+ ->group('daily_id')
|
|
|
+ ->select();
|
|
|
+ foreach ($weekResults as $item) {
|
|
|
+ $weekCounts[$item['daily_id']] = $item['count'];
|
|
|
}
|
|
|
- $query = Db::name('daily_record')
|
|
|
- ->where('org_id',$orgId)
|
|
|
- ->where('daily_id',$v['id']);
|
|
|
- $list[$k]['count'] = $query
|
|
|
- ->count();
|
|
|
+ }
|
|
|
+
|
|
|
+ $today = date('Ymd');
|
|
|
+ $todayCounts = [];
|
|
|
+ $todayResults = Db::name('daily_record')
|
|
|
+ ->where('org_id', $orgId)
|
|
|
+ ->where('daily_id', 'in', $dailyIds)
|
|
|
+ ->where('create_yyyymmdd', $today)
|
|
|
+ ->field('daily_id, COUNT(*) as count')
|
|
|
+ ->group('daily_id')
|
|
|
+ ->select();
|
|
|
+ foreach ($todayResults as $item) {
|
|
|
+ $todayCounts[$item['daily_id']] = $item['count'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $count = $count1 = $count2 = $count3 = 0;
|
|
|
+ foreach ($list as $k => $v) {
|
|
|
+ $list[$k]['title'] = $addressTitles[$v['address_id']] ?? '';
|
|
|
+
|
|
|
+ $list[$k]['count'] = $totalCounts[$v['id']] ?? 0;
|
|
|
+ $list[$k]['count1'] = $monthCounts[$v['id']] ?? 0;
|
|
|
+ $list[$k]['count2'] = $weekCounts[$v['id']] ?? 0;
|
|
|
+ $list[$k]['count3'] = $todayCounts[$v['id']] ?? 0;
|
|
|
+
|
|
|
$count += $list[$k]['count'];
|
|
|
- //本月
|
|
|
- $list[$k]['count1'] = $query
|
|
|
- ->where('create_yyyymm',date('Ym'))
|
|
|
- ->count();
|
|
|
$count1 += $list[$k]['count1'];
|
|
|
- //本周
|
|
|
- $list[$k]['count2'] = $query
|
|
|
- ->whereIn('create_yyyymmdd',get_week_date())
|
|
|
- ->count();
|
|
|
$count2 += $list[$k]['count2'];
|
|
|
- //今天
|
|
|
- $list[$k]['count3'] = $query
|
|
|
- ->where('create_yyyymmdd',date('Ymd'))
|
|
|
- ->count();
|
|
|
$count3 += $list[$k]['count3'];
|
|
|
}
|
|
|
return array('list'=>$list,'count'=>$count,'count1'=>$count1,'count2'=>$count2,'count3'=>$count3);
|