$params['project_id'], 'company_id' => $params['company_id'], 'theme' => $params['theme'], 'code' => data_unique_code('CLJC'), 'enter_time' => !empty($params['enter_time']) ? strtotime($params['enter_time']) : 0, 'co_participant' => $params['co_participant'], 'enter_result' => $params['enter_result'], 'parallel_test' => $params['parallel_test'], 'remark' => $params['remark'], 'create_user' => $admin_id, ]); if(!empty($params['entry_detail'])){ foreach($params['entry_detail'] as $v) { SupervisionMaterialEntryDetail::create([ 'material_entry_id' => $res->id, 'name' => $v['name'], 'brand' => $v['brand'], 'model' => $v['model'], 'unit' => $v['unit'], 'contract_brand' => $v['contract_brand'], 'entry_number' => $v['entry_number'] ]); } } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 编辑材料进场 * @param array $params * @return bool * @author likeadmin * @date 2024/02/28 13:41 */ public static function edit(array $params): bool { Db::startTrans(); try { SupervisionMaterialEntry::where('id', $params['id'])->update([ 'project_id' => $params['project_id'], 'company_id' => $params['company_id'], 'theme' => $params['theme'], 'enter_time' => !empty($params['enter_time']) ? strtotime($params['enter_time']) : 0, 'co_participant' => $params['co_participant'], 'enter_result' => $params['enter_result'], 'parallel_test' => $params['parallel_test'], 'remark' => $params['remark'], 'update_time' => time(), ]); if(!empty($params['entry_detail'])){ foreach($params['entry_detail'] as $v) { if(!empty($v['id'])){ SupervisionMaterialEntryDetail::where('id',$v['id'])->update([ 'material_entry_id' => $params['id'], 'name' => $v['name'], 'brand' => $v['brand'], 'model' => $v['model'], 'unit' => $v['unit'], 'contract_brand' => $v['contract_brand'], 'entry_number' => $v['entry_number'], 'update_time' => time() ]); }else{ SupervisionMaterialEntryDetail::create([ 'material_entry_id' => $params['id'], 'name' => $v['name'], 'brand' => $v['brand'], 'model' => $v['model'], 'unit' => $v['unit'], 'contract_brand' => $v['contract_brand'], 'entry_number' => $v['entry_number'] ]); } } } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 删除材料进场 * @param array $params * @return bool * @author likeadmin * @date 2024/02/28 13:41 */ public static function delete(array $params): bool { $entry_detail = SupervisionMaterialEntryDetail::where('material_entry_id',$params['id'])->findOrEmpty(); if(!$entry_detail->isEmpty()){ self::setError('当前数据下存在材料信息记录,请先删除材料信息记录'); return false; } return SupervisionMaterialEntry::destroy($params['id']); } /** * @notes 获取材料进场详情 * @param $params * @return array * @author likeadmin * @date 2024/02/28 13:41 */ public static function detail($params): array { $data = SupervisionMaterialEntry::withoutField('update_time,delete_time')->findOrEmpty($params['id']); $create_user = Admin::field('name')->where('id',$data['create_user'])->findOrEmpty(); $data['create_user_name'] = $create_user['name']; $data['enter_result_text'] = $data->enter_result_text; $data['parallel_test_text'] = $data->parallel_test_text; return $data->toArray(); } }