修复内容

This commit is contained in:
2026-01-16 18:26:15 +08:00
parent daae84b827
commit 41ad75af08
4 changed files with 81 additions and 41 deletions

View File

@@ -22,48 +22,47 @@ class Calendar extends ApiBase
$startDate = $month . '-01';
$endDate = date('Y-m-t', strtotime($startDate)); // 获取该月最后一天
// 查询该月份的所有服务数据
// 查询该月份的所有服务数据,关联商品表和员工表
$service = Db::name('order_exe')
->where('date', '>=', $startDate)
->where('date', '<=', $endDate)
->where('abnormal', 0)
->order('date asc, addtime asc')
->alias('oe')
->join('goods g', 'oe.goods_id = g.id', 'LEFT')
->join('staff s', 'oe.staff_id = s.id', 'LEFT')
->where('oe.date', '>=', $startDate)
->where('oe.date', '<=', $endDate)
->where('oe.abnormal', 0)
->where('s.onwork', 1)
->where('s.leave', 1)
->where('oe.staff_id', '<>', null)
->field('oe.date,oe.addtime,oe.start_time,oe.timeout,oe.xq,oe.staff_id,s.name as staff_name,g.name as goods_name')
->order('oe.date asc, oe.addtime asc')
->select();
$serviceDate = [];
if ($service) {
//查询到有数据,就去找服务人员
foreach ($service as $v) {
if ($v['staff_id'] != null) {
$staffName = Db::name('staff')->where('id', $v['staff_id'])
->where('onwork', 1)
->where('leave', 1)
->find();
if ($staffName){
// 处理服务时间
$timeRange = '';
if (!empty($v['start_time']) && !empty($v['timeout'])) {
// 判断是否为时间戳(数字)
$startTimestamp = is_numeric($v['start_time']) ? $v['start_time'] : strtotime($v['start_time']);
$timeoutTimestamp = is_numeric($v['timeout']) ? $v['timeout'] : strtotime($v['timeout']);
$startTime = date('H:i', $startTimestamp);
$timeoutTime = date('H:i', $timeoutTimestamp);
$timeRange = $startTime . '-' . $timeoutTime;
} elseif (!empty($v['start_time'])) {
$startTimestamp = is_numeric($v['start_time']) ? $v['start_time'] : strtotime($v['start_time']);
$startTime = date('H:i', $startTimestamp);
$timeRange = $startTime;
}
$serviceDate[] = [
'date' => $v['date'],
'staff_name' => $staffName['name'],
'addtime' => $v['addtime'] == 1 ? '上午' : ($v['addtime'] == 2 ? '下午' : ''), //1表示上午2表示下午
'serviceTime' => $timeRange,
'xq' => $v['xq'] ?? $this->getChineseWeekDay($v['date']), // 如果没有xq字段则根据日期计算
];
}
// 处理服务时间
$timeRange = '';
if (!empty($v['start_time']) && !empty($v['timeout'])) {
// 判断是否为时间戳(数字)
$startTimestamp = is_numeric($v['start_time']) ? $v['start_time'] : strtotime($v['start_time']);
$timeoutTimestamp = is_numeric($v['timeout']) ? $v['timeout'] : strtotime($v['timeout']);
$startTime = date('H:i', $startTimestamp);
$timeoutTime = date('H:i', $timeoutTimestamp);
$timeRange = $startTime . '-' . $timeoutTime;
} elseif (!empty($v['start_time'])) {
$startTimestamp = is_numeric($v['start_time']) ? $v['start_time'] : strtotime($v['start_time']);
$startTime = date('H:i', $startTimestamp);
$timeRange = $startTime;
}
$serviceDate[] = [
'date' => $v['date'],
'staff_name' => $v['staff_name'] ?? '',
'goods_name' => $v['goods_name'] ?? '',
'addtime' => $v['addtime'] == 1 ? '上午' : ($v['addtime'] == 2 ? '下午' : ''), //1表示上午2表示下午
'serviceTime' => $timeRange,
'xq' => $v['xq'] ?? $this->getChineseWeekDay($v['date']), // 如果没有xq字段则根据日期计算
];
}
}
return $this->_success("成功", $serviceDate);