love_php/app/Services/ConsultService.php
2026-04-02 09:20:51 +08:00

54 lines
1.9 KiB
PHP

<?php
namespace App\Services;
use App\Models\SaasReservationConsultScheduling;
use App\Models\SaasReservationTeacher;
class ConsultService
{
/**
* 获取咨询老师最近排班
*/
public function getLatelyScheduling($merchant_id, $consult_account_id, $lately_day = 7): array
{
$time = time();
$data = [];
for ($i = 1; $i <= $lately_day; $i++) {
$date = date('Y-m-d', strtotime('+' . ($i-1) . ' days', $time));
$data[] = ['date' => $date];
}
$reservation_teacher_id = SaasReservationTeacher::where('merchant_id',$merchant_id)
->where('consult_account_id',$consult_account_id)
->value('id');
$time = time();
foreach ($data as &$item) {
$item['residue_num'] = 0;
$scheduling = SaasReservationConsultScheduling::where('reservation_teacher_id',$reservation_teacher_id)
->selectRaw("*,left(date_range,5) as start_time,right(date_range,5) as end_time")
->where('merchant_id',$merchant_id)
->where('is_show',1)
->where('date',$item['date'])
->orderBy('start_time','asc')
->get()
->toArray();
// if ($merchant_id == 596){
foreach ($scheduling as $key => $item2) {
//过了预约开始时间隐藏
$start_time = strtotime($item2['date'] . ' ' . $item2['start_time']);
if ($time > $start_time) {
unset($scheduling[$key]);
}
}
$scheduling = array_values($scheduling);
// }
$item['scheduling'] = $scheduling;
if(!$scheduling){
continue;
}
$item['residue_num'] = array_sum(array_column($scheduling,'residue_num'));
}
return $data;
}
}