|
@@ -2,14 +2,18 @@
|
|
|
|
|
|
|
|
namespace App\Service;
|
|
namespace App\Service;
|
|
|
|
|
|
|
|
|
|
+use App\Model\DailyDwOrder;
|
|
|
|
|
+use App\Model\DailyDwOrderDetails;
|
|
|
use App\Model\Device;
|
|
use App\Model\Device;
|
|
|
use App\Model\Employee;
|
|
use App\Model\Employee;
|
|
|
|
|
+use App\Model\Item;
|
|
|
use App\Model\MonthlyDwOrder;
|
|
use App\Model\MonthlyDwOrder;
|
|
|
use App\Model\MonthlyDwOrderDetails;
|
|
use App\Model\MonthlyDwOrderDetails;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
class DeviceWorkService extends Service
|
|
class DeviceWorkService extends Service
|
|
|
{
|
|
{
|
|
|
|
|
+ //设备月工时单--------------------------------------------
|
|
|
public function monthlyDwOrderEdit($data,$user){
|
|
public function monthlyDwOrderEdit($data,$user){
|
|
|
list($status,$msg) = $this->monthlyDwOrderRule($data, $user, false);
|
|
list($status,$msg) = $this->monthlyDwOrderRule($data, $user, false);
|
|
|
if(!$status) return [$status,$msg];
|
|
if(!$status) return [$status,$msg];
|
|
@@ -308,4 +312,403 @@ class DeviceWorkService extends Service
|
|
|
}
|
|
}
|
|
|
return $res; // 返回 [main_id => [detail_row, detail_row]]
|
|
return $res; // 返回 [main_id => [detail_row, detail_row]]
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ //设备日工时单----------------------------------------------
|
|
|
|
|
+ public function dailyDwOrderEdit($data,$user){
|
|
|
|
|
+ list($status,$msg) = $this->dailyDwOrderRule($data, $user, false);
|
|
|
|
|
+ if(!$status) return [$status,$msg];
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
|
+
|
|
|
|
|
+ $model = DailyDwOrder::where('id',$data['id'])->first();
|
|
|
|
|
+ $model->item_id = $data['item_id'] ?? 0;
|
|
|
|
|
+ $model->save();
|
|
|
|
|
+
|
|
|
|
|
+ $time = time();
|
|
|
|
|
+ DailyDwOrderDetails::where('del_time',0)
|
|
|
|
|
+ ->where('main_id', $model->id)
|
|
|
|
|
+ ->update(['del_time' => $time]);
|
|
|
|
|
+ $this->saveDetailDaily($model->id, $time, $data);
|
|
|
|
|
+
|
|
|
|
|
+ DB::commit();
|
|
|
|
|
+ }catch (\Exception $exception){
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ return [false,$exception->getMessage()];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return [true, ''];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function dailyDwOrderAdd($data,$user){
|
|
|
|
|
+ list($status,$msg) = $this->dailyDwOrderRule($data, $user);
|
|
|
|
|
+ if(!$status) return [$status,$msg];
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
|
+
|
|
|
|
|
+ $model = new DailyDwOrder();
|
|
|
|
|
+ $model->code = $this->generateBillNo([
|
|
|
|
|
+ 'top_depart_id' => $user['top_depart_id'],
|
|
|
|
|
+ 'type' => DailyDwOrder::Order_type,
|
|
|
|
|
+ 'period' => date("Ym", $data['order_time'])
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $model->order_time = $data['order_time'] ?? 0;
|
|
|
|
|
+ $model->item_id = $data['item_id'] ?? 0;
|
|
|
|
|
+ $model->crt_id = $user['id'];
|
|
|
|
|
+ $model->top_depart_id = $data['top_depart_id'];
|
|
|
|
|
+ $model->save();
|
|
|
|
|
+
|
|
|
|
|
+ $this->saveDetailDaily($model->id, time(), $data);
|
|
|
|
|
+
|
|
|
|
|
+ DB::commit();
|
|
|
|
|
+ }catch (\Exception $exception){
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ return [false,$exception->getMessage()];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return [true, ''];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function saveDetailDaily($id, $time, $data){
|
|
|
|
|
+ if(! empty($data['details'])){
|
|
|
|
|
+ $unit = [];
|
|
|
|
|
+ foreach ($data['details'] as $value){
|
|
|
|
|
+ $unit[] = [
|
|
|
|
|
+ 'main_id' => $id,
|
|
|
|
|
+ 'device_id' => $value['device_id'],
|
|
|
|
|
+ 'start_time_hour' => $value['start_time_hour'],
|
|
|
|
|
+ 'start_time_min' => $value['start_time_min'],
|
|
|
|
|
+ 'end_time_hour' => $value['end_time_hour'],
|
|
|
|
|
+ 'end_time_min' => $value['end_time_min'],
|
|
|
|
|
+ 'total_work_min' => $value['total_work_min'],
|
|
|
|
|
+ 'crt_time' => $time,
|
|
|
|
|
+ 'top_depart_id' => $value['top_depart_id'],
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ if(! empty($unit)) DailyDwOrderDetails::insert($unit);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function getDetailDaily($id){
|
|
|
|
|
+ $data = DailyDwOrderDetails::where('del_time',0)
|
|
|
|
|
+ ->where('main_id', $id)
|
|
|
|
|
+ ->select('device_id', 'start_time_hour', 'start_time_min', 'end_time_hour', 'end_time_min', 'total_work_min')
|
|
|
|
|
+ ->get()->toArray();
|
|
|
|
|
+
|
|
|
|
|
+ $id = array_column($data,'device_id');
|
|
|
|
|
+ $map = Device::whereIn('id',$id)
|
|
|
|
|
+ ->select('title','id','number')
|
|
|
|
|
+ ->get()
|
|
|
|
|
+ ->keyBy('id')
|
|
|
|
|
+ ->toArray();
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($data as $key => $value){
|
|
|
|
|
+ $tmp = $map[$value['device_id']] ?? [];
|
|
|
|
|
+ $merge = [];
|
|
|
|
|
+ $merge['device_title'] = $tmp['title'];
|
|
|
|
|
+ $merge['device_code'] = $tmp['code'];
|
|
|
|
|
+ $data[$key] = array_merge($value, $merge);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $detail = [
|
|
|
|
|
+ 'details' => $data,
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($detail as $key => $value) {
|
|
|
|
|
+ if (empty($value)) {
|
|
|
|
|
+ $detail[$key] = (object)[]; // 转成 stdClass 对象
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $detail;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function dailyDwOrderDel($data){
|
|
|
|
|
+ if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
|
+ $time = time();
|
|
|
|
|
+
|
|
|
|
|
+ DailyDwOrder::where('del_time',0)
|
|
|
|
|
+ ->whereIn('id',$data['id'])
|
|
|
|
|
+ ->update(['del_time' => $time]);
|
|
|
|
|
+
|
|
|
|
|
+ DailyDwOrderDetails::where('del_time',0)
|
|
|
|
|
+ ->whereIn('main_id', $data['id'])
|
|
|
|
|
+ ->update(['del_time' => $time]);
|
|
|
|
|
+
|
|
|
|
|
+ DB::commit();
|
|
|
|
|
+ }catch (\Exception $exception){
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ return [false,$exception->getMessage()];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return [true, ''];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function dailyDwOrderDetail($data, $user){
|
|
|
|
|
+ if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
|
|
|
|
|
+ $customer = DailyDwOrder::where('del_time',0)
|
|
|
|
|
+ ->where('id',$data['id'])
|
|
|
|
|
+ ->first();
|
|
|
|
|
+ if(empty($customer)) return [false,'设备日工时单不存在或已被删除'];
|
|
|
|
|
+ $customer = $customer->toArray();
|
|
|
|
|
+ $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('title');
|
|
|
|
|
+ $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
|
|
|
|
|
+ $item = Item::where('id', $customer['item_id'])->first();
|
|
|
|
|
+ $customer['item_title'] = $item->title;
|
|
|
|
|
+ $customer['item_code'] = $item->code;
|
|
|
|
|
+ $customer['order_time'] = $customer['order_time'] ? date("Y-m-d",$customer['order_time']): '';
|
|
|
|
|
+
|
|
|
|
|
+ $details = $this->getDetailDaily($data['id']);
|
|
|
|
|
+ $customer = array_merge($customer, $details);
|
|
|
|
|
+
|
|
|
|
|
+ return [true, $customer];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function dailyDwOrderCommon($data,$user, $field = []){
|
|
|
|
|
+ if(empty($field)) $field = DailyDwOrder::$field;
|
|
|
|
|
+
|
|
|
|
|
+ $model = DailyDwOrder::Clear($user,$data);
|
|
|
|
|
+ $model = $model->where('del_time',0)
|
|
|
|
|
+ ->select($field)
|
|
|
|
|
+ ->orderby('id', 'desc');
|
|
|
|
|
+
|
|
|
|
|
+ if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
|
|
|
|
|
+ if(! empty($data['id'])) $model->whereIn('id', $data['id']);
|
|
|
|
|
+ if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
|
|
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
|
|
|
|
|
+ $model->where('crt_time','>=',$return[0]);
|
|
|
|
|
+ $model->where('crt_time','<=',$return[1]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $model;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function dailyDwOrderList($data,$user){
|
|
|
|
|
+ $model = $this->dailyDwOrderCommon($data, $user);
|
|
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
|
|
+ $list = $this->fillDataDaily($list);
|
|
|
|
|
+
|
|
|
|
|
+ return [true, $list];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function dailyDwOrderRule(&$data, $user, $is_add = true){
|
|
|
|
|
+ if(empty($data['order_time'])) return [false, '单据日期不能为空'];
|
|
|
|
|
+ $data['order_time'] = $this->changeDateToDate($data['order_time']);
|
|
|
|
|
+ $orderTime = $data['order_time'];
|
|
|
|
|
+ $itemId = $data['item_id'] ?? 0;
|
|
|
|
|
+
|
|
|
|
|
+ if(empty($itemId)) return [false, '项目不能为空'];
|
|
|
|
|
+ $bool = Item::where('del_time',0)->where('id', $itemId)->exists();
|
|
|
|
|
+ if(!$bool) return [false, '项目不存在或已被删除'];
|
|
|
|
|
+
|
|
|
|
|
+ $data['top_depart_id'] = $user['top_depart_id'];
|
|
|
|
|
+ if(empty($data['details'])) return [false, '设备日工时单明细不能为空'];
|
|
|
|
|
+
|
|
|
|
|
+ // --- 1. 批量预获取人员信息,用于报错提示 ---
|
|
|
|
|
+ $allEmpIds = array_filter(array_unique(array_column($data['details'], 'device_id')));
|
|
|
|
|
+
|
|
|
|
|
+ $empDisplayMap = Device::whereIn('id', $allEmpIds)
|
|
|
|
|
+ ->get(['id', 'code', 'title'])
|
|
|
|
|
+ ->mapWithKeys(function($item){
|
|
|
|
|
+ return [$item->id => "[{$item->code}]{$item->title}"];
|
|
|
|
|
+ })->toArray();
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 本次提交内部重叠记录
|
|
|
|
|
+ $internalOverlap = [];
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($data['details'] as $key => $value){
|
|
|
|
|
+ $empId = $value['device_id'] ?? 0;
|
|
|
|
|
+ if(empty($empId)) return [false, '设备不能为空'];
|
|
|
|
|
+
|
|
|
|
|
+ $empName = $empDisplayMap[$empId] ?? "ID:{$empId}";
|
|
|
|
|
+
|
|
|
|
|
+ // 校验数字有效性 (修正为使用 $value)
|
|
|
|
|
+ $res = $this->checkNumber($value['start_time_hour'], 0, 'non-negative');
|
|
|
|
|
+ if(!$res['valid']) return [false, "设备{$empName}开始点:" . $res['error']];
|
|
|
|
|
+ $res = $this->checkNumber($value['start_time_min'], 0, 'non-negative');
|
|
|
|
|
+ if(!$res['valid']) return [false, "设备{$empName}开始分:" . $res['error']];
|
|
|
|
|
+ $res = $this->checkNumber($value['end_time_hour'], 0, 'non-negative');
|
|
|
|
|
+ if(!$res['valid']) return [false, "设备{$empName}结束点:" . $res['error']];
|
|
|
|
|
+ $res = $this->checkNumber($value['end_time_min'], 0, 'non-negative');
|
|
|
|
|
+ if(!$res['valid']) return [false, "设备{$empName}结束分:" . $res['error']];
|
|
|
|
|
+
|
|
|
|
|
+ $currentStart = $value['start_time_hour'] * 60 + $value['start_time_min'];
|
|
|
|
|
+ $currentEnd = $value['end_time_hour'] * 60 + $value['end_time_min'];
|
|
|
|
|
+
|
|
|
|
|
+ if ($currentStart >= $currentEnd) {
|
|
|
|
|
+ return [false, "设备{$empName}:开始时间必须早于结束时间"];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // --- 3. 内部重叠校验(防止一次提交多行重复) ---
|
|
|
|
|
+ if (isset($internalOverlap[$empId])) {
|
|
|
|
|
+ foreach ($internalOverlap[$empId] as $period) {
|
|
|
|
|
+ if ($currentStart < $period['e'] && $period['s'] < $currentEnd) {
|
|
|
|
|
+ return [false, "设备{$empName}在本次提交的多行明细中时间段重叠"];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $internalOverlap[$empId][] = ['s' => $currentStart, 'e' => $currentEnd];
|
|
|
|
|
+
|
|
|
|
|
+ $query = DB::table('daily_dw_order_details as d')
|
|
|
|
|
+ ->join('daily_dw_order as m', 'd.main_id', '=', 'm.id')
|
|
|
|
|
+ ->where('m.top_depart_id', $data['top_depart_id'])
|
|
|
|
|
+ ->where('m.order_time', $orderTime)
|
|
|
|
|
+ ->where('m.item_id', $itemId)
|
|
|
|
|
+ ->where('d.device_id', $empId)
|
|
|
|
|
+ ->where('m.del_time', 0)
|
|
|
|
|
+ ->where('d.del_time', 0);
|
|
|
|
|
+
|
|
|
|
|
+ if (!$is_add && !empty($data['id'])) {
|
|
|
|
|
+ $query->where('m.id', '<>', $data['id']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $existingPeriods = $query->select('d.start_time_hour', 'd.start_time_min', 'd.end_time_hour', 'd.end_time_min')->get();
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($existingPeriods as $p) {
|
|
|
|
|
+ $exStart = $p->start_time_hour * 60 + $p->start_time_min;
|
|
|
|
|
+ $exEnd = $p->end_time_hour * 60 + $p->end_time_min;
|
|
|
|
|
+
|
|
|
|
|
+ if ($currentStart < $exEnd && $exStart < $currentEnd) {
|
|
|
|
|
+ return [false, "设备{$empName}在该项目该日已有其他工时单创建重叠的时间段数据"];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $data['details'][$key]['top_depart_id'] = $data['top_depart_id'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(!$is_add){
|
|
|
|
|
+ if(empty($data['id'])) return [false,'ID不能为空'];
|
|
|
|
|
+ $bool = DailyDwOrder::where('top_depart_id', $data['top_depart_id'])
|
|
|
|
|
+ ->where('id',$data['id'])
|
|
|
|
|
+ ->where('del_time',0)
|
|
|
|
|
+ ->exists();
|
|
|
|
|
+ if(!$bool) return [false, '设备日工时单不存在或已被删除'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return [true, ''];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function fillDataDaily($data){
|
|
|
|
|
+ if(empty($data['data'])) return $data;
|
|
|
|
|
+
|
|
|
|
|
+ $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'],'crt_id')));
|
|
|
|
|
+ $item = (new ItemService())->getItemMap(array_unique(array_column($data['data'],'item_id')));
|
|
|
|
|
+ foreach ($data['data'] as $key => $value){
|
|
|
|
|
+ $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
|
|
|
|
|
+ $data['data'][$key]['order_time'] = $value['order_time'] ? date('Y-m-d',$value['order_time']) : '';
|
|
|
|
|
+ $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
|
|
|
|
|
+ $item_tmp = $item[$value['item_id']] ?? [];
|
|
|
|
|
+ $data['data'][$key]['item_title'] = $item_tmp['title'] ?? '';
|
|
|
|
|
+ $data['data'][$key]['item_code'] = $item_tmp['code'] ?? '';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $data;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function fillDataForExportDaily($data, $column, &$return)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (empty($data)) return;
|
|
|
|
|
+
|
|
|
|
|
+ $mainIds = array_column($data, 'id');
|
|
|
|
|
+ // 1. 获取详情及所有关联档案(项目、设备)的映射
|
|
|
|
|
+ $detailsMap = $this->getDwDailyDetailsMap($mainIds, $data);
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($data as $main) {
|
|
|
|
|
+ $mainId = $main['id'];
|
|
|
|
|
+ $details = $detailsMap[$mainId] ?? [];
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 提取并格式化主表共有信息
|
|
|
|
|
+ $mainInfo = [
|
|
|
|
|
+ 'code' => $main['code'],
|
|
|
|
|
+ 'order_time' => !empty($main['order_time']) ? date('Y-m-d', $main['order_time']) : '',
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($details)) {
|
|
|
|
|
+ // 无明细时只导出一行主表信息
|
|
|
|
|
+ $tempRow = [];
|
|
|
|
|
+ foreach ($column as $col) {
|
|
|
|
|
+ $tempRow[] = $mainInfo[$col] ?? '';
|
|
|
|
|
+ }
|
|
|
|
|
+ $return[] = $tempRow;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 3. 平铺:将设备明细信息、项目信息与主表信息合并
|
|
|
|
|
+ foreach ($details as $sub) {
|
|
|
|
|
+ $fullRowData = array_merge($mainInfo, $sub);
|
|
|
|
|
+ $tempRow = [];
|
|
|
|
|
+ foreach ($column as $col) {
|
|
|
|
|
+ $tempRow[] = $fullRowData[$col] ?? '';
|
|
|
|
|
+ }
|
|
|
|
|
+ $return[] = $tempRow;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function getDwDailyDetailsMap($mainIds, $mainData)
|
|
|
|
|
+ {
|
|
|
|
|
+ // 1. 获取设备工时子表记录
|
|
|
|
|
+ $details = DB::table('daily_dw_order_details')
|
|
|
|
|
+ ->where('del_time', 0)
|
|
|
|
|
+ ->whereIn('main_id', $mainIds)
|
|
|
|
|
+ ->get();
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 提取关联 ID(设备 ID 和 项目 ID)
|
|
|
|
|
+ $deviceIds = $details->pluck('device_id')->unique();
|
|
|
|
|
+ $itemIds = array_unique(array_column($mainData, 'item_id'));
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 批量获取设备档案和项目档案
|
|
|
|
|
+ $deviceMap = DB::table('device')
|
|
|
|
|
+ ->whereIn('id', $deviceIds)
|
|
|
|
|
+ ->get(['id', 'title', 'code'])
|
|
|
|
|
+ ->keyBy('id');
|
|
|
|
|
+
|
|
|
|
|
+ $itemMap = DB::table('item')
|
|
|
|
|
+ ->whereIn('id', $itemIds)
|
|
|
|
|
+ ->get(['id', 'title', 'code'])
|
|
|
|
|
+ ->keyBy('id');
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 预挂载主表的项目信息(item_code, item_title)
|
|
|
|
|
+ $mainItemInfo = [];
|
|
|
|
|
+ foreach ($mainData as $m) {
|
|
|
|
|
+ $proj = $itemMap[$m['item_id']] ?? null;
|
|
|
|
|
+ $mainItemInfo[$m['id']] = [
|
|
|
|
|
+ 'item_code' => $proj ? $proj->code : '',
|
|
|
|
|
+ 'item_title' => $proj ? $proj->title : '',
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $res = [];
|
|
|
|
|
+ // 如果没有详情,初始化空结构
|
|
|
|
|
+ if ($details->isEmpty()) {
|
|
|
|
|
+ foreach ($mainItemInfo as $mId => $info) {
|
|
|
|
|
+ $res[$mId] = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ return $res;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 循环子表,合并设备档案信息
|
|
|
|
|
+ foreach ($details as $item) {
|
|
|
|
|
+ $device = $deviceMap[$item->device_id] ?? null;
|
|
|
|
|
+
|
|
|
|
|
+ $detailRow = [
|
|
|
|
|
+ // 设备信息(对应 Excel 配置中的 key)
|
|
|
|
|
+ 'device_code' => $device ? $device->code : '',
|
|
|
|
|
+ 'device_title' => $device ? $device->title : '',
|
|
|
|
|
+ // 时间信息
|
|
|
|
|
+ 'start_time' => sprintf('%02d:%02d', $item->start_time_hour, $item->start_time_min),
|
|
|
|
|
+ 'end_time' => sprintf('%02d:%02d', $item->end_time_hour, $item->end_time_min),
|
|
|
|
|
+ // 项目信息(由主表平铺而来)
|
|
|
|
|
+ 'item_code' => $mainItemInfo[$item->main_id]['item_code'] ?? '',
|
|
|
|
|
+ 'item_title' => $mainItemInfo[$item->main_id]['item_title'] ?? '',
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ $res[$item->main_id][] = $detailRow;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $res;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|