|
...
|
...
|
@@ -17,6 +17,7 @@ use App\Models\Inquiry\InquiryRelayDetail; |
|
|
|
use App\Models\Inquiry\InquiryRelayDetailLog;
|
|
|
|
use App\Models\Manage\Manage;
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
...
|
...
|
@@ -525,53 +526,60 @@ class InquiryForwardLogic extends BaseLogic |
|
|
|
*/
|
|
|
|
public function inquiryManageCount()
|
|
|
|
{
|
|
|
|
$manage_ids = ForwardCount::select('manage_id')->orderBy('manage_id', 'asc')->distinct()->pluck('manage_id')->toArray();
|
|
|
|
$manageModel = new Manage();
|
|
|
|
|
|
|
|
//月统计
|
|
|
|
$data_month = [];
|
|
|
|
$data_month_total = [];
|
|
|
|
$now_month = date('Y-m');
|
|
|
|
$last_year_month = date('Y-m', strtotime('-11 months'));
|
|
|
|
while ($last_year_month <= $now_month) {
|
|
|
|
$month_arr = explode('-', $last_year_month);
|
|
|
|
$year = $month_arr[0];
|
|
|
|
$month = $month_arr[1];
|
|
|
|
|
|
|
|
foreach ($manage_ids as $mid) {
|
|
|
|
$name = $manageModel->getName($mid);
|
|
|
|
$month_count = intval(ForwardCount::where('manage_id', $mid)->where('year', $year)->where('month', $month)->sum('count') ?? 0);
|
|
|
|
$data_month_total[$name] = ($data_month_total[$name] ?? 0) + $month_count;
|
|
|
|
$data_month[$last_year_month][$name] = $month_count;
|
|
|
|
$data = Cache::get('inquiry_manage_count');
|
|
|
|
if (!$data) {
|
|
|
|
$manage_ids = ForwardCount::select('manage_id')->orderBy('manage_id', 'asc')->distinct()->pluck('manage_id')->toArray();
|
|
|
|
$manageModel = new Manage();
|
|
|
|
|
|
|
|
//月统计
|
|
|
|
$data_month = [];
|
|
|
|
$data_month_total = [];
|
|
|
|
$now_month = date('Y-m');
|
|
|
|
$last_year_month = date('Y-m', strtotime('-11 months'));
|
|
|
|
while ($last_year_month <= $now_month) {
|
|
|
|
$month_arr = explode('-', $last_year_month);
|
|
|
|
$year = $month_arr[0];
|
|
|
|
$month = $month_arr[1];
|
|
|
|
|
|
|
|
foreach ($manage_ids as $mid) {
|
|
|
|
$name = $manageModel->getName($mid);
|
|
|
|
$month_count = intval(ForwardCount::where('manage_id', $mid)->where('year', $year)->where('month', $month)->sum('count') ?? 0);
|
|
|
|
$data_month_total[$name] = ($data_month_total[$name] ?? 0) + $month_count;
|
|
|
|
$data_month[$last_year_month][$name] = $month_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
$last_year_month = date('Y-m', strtotime($last_year_month . ' +1 month'));
|
|
|
|
}
|
|
|
|
$data_month['total'] = $data_month_total;
|
|
|
|
|
|
|
|
|
|
|
|
//周统计
|
|
|
|
$data_week = [];
|
|
|
|
$data_week_total = [];
|
|
|
|
$now_day = date('Y-m-d');
|
|
|
|
$last_week_day = date('Y-m-d', strtotime('-1 week'));
|
|
|
|
while ($last_week_day < $now_day) {
|
|
|
|
$day_arr = explode('-', $last_week_day);
|
|
|
|
$year = $day_arr[0];
|
|
|
|
$month = $day_arr[1];
|
|
|
|
$day = $day_arr[2];
|
|
|
|
|
|
|
|
foreach ($manage_ids as $mid) {
|
|
|
|
$name = $manageModel->getName($mid);
|
|
|
|
$day_count = ForwardCount::where('manage_id', $mid)->where('year', $year)->where('month', $month)->where('day', $day)->value('count') ?? 0;
|
|
|
|
$data_week_total[$name] = ($data_week_total[$name] ?? 0) + $day_count;
|
|
|
|
$data_week[substr($last_week_day, 5)][$name] = $day_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
$last_year_month = date('Y-m', strtotime($last_year_month . ' +1 month'));
|
|
|
|
}
|
|
|
|
$data_month['total'] = $data_month_total;
|
|
|
|
|
|
|
|
|
|
|
|
//周统计
|
|
|
|
$data_week = [];
|
|
|
|
$data_week_total = [];
|
|
|
|
$now_day = date('Y-m-d');
|
|
|
|
$last_week_day = date('Y-m-d', strtotime('-1 week'));
|
|
|
|
while ($last_week_day < $now_day) {
|
|
|
|
$day_arr = explode('-', $last_week_day);
|
|
|
|
$year = $day_arr[0];
|
|
|
|
$month = $day_arr[1];
|
|
|
|
$day = $day_arr[2];
|
|
|
|
|
|
|
|
foreach ($manage_ids as $mid) {
|
|
|
|
$name = $manageModel->getName($mid);
|
|
|
|
$day_count = ForwardCount::where('manage_id', $mid)->where('year', $year)->where('month', $month)->where('day', $day)->value('count') ?? 0;
|
|
|
|
$data_week_total[$name] = ($data_week_total[$name] ?? 0) + $day_count;
|
|
|
|
$data_week[substr($last_week_day, 5)][$name] = $day_count;
|
|
|
|
$last_week_day = date('Y-m-d', strtotime($last_week_day . ' +1 day'));
|
|
|
|
}
|
|
|
|
$data_week['total'] = $data_week_total;
|
|
|
|
|
|
|
|
$data = ['data_month' => $data_month, 'data_week' => $data_week];
|
|
|
|
|
|
|
|
$last_week_day = date('Y-m-d', strtotime($last_week_day . ' +1 day'));
|
|
|
|
Cache::add('inquiry_manage_count', $data);
|
|
|
|
}
|
|
|
|
$data_week['total'] = $data_week_total;
|
|
|
|
|
|
|
|
return $this->success(['data_month' => $data_month, 'data_week' => $data_week]);
|
|
|
|
return $this->success($data);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|