function view($unit_id) { $app = get_app(); $unit = Unit::find_by_id($unit_id); if ($unit) { $app->render('Units/view.php', compact('unit')); } }
function import_from_lib($part_id, $file_id) { $file = File::find_by_id($file_id); $part = Part::find_by_id($part_id); if (empty($file)) { $results['is_success'] = false; $results['error'] = '对不起,工艺库中找不到您所指定的零件!'; } else { if (!count($file->units)) { $results['is_success'] = false; $results['error'] = '对不起,您所指定的零件不包含任何工序!'; } if (count($part->processes)) { $results['is_success'] = false; $results['error'] = '对不起,只能为没有制定任何工序的零件节点从工艺库中导入模板!'; } if (!isset($results['error'])) { $nodes = array(); $units = Unit::find_all_by_file_id($file->id, array('order' => 'priority asc')); // import lib parts model's procs foreach ($units as $unit) { // create db node $item = array(); $item['priority'] = $unit->priority; $item['name'] = $unit->name; $item['content'] = $unit->content; $item['part_id'] = $part->id; $item['takt_time'] = ''; //$unit->takt_time; $item['preparation_time'] = ''; // $unit->preparation_time; $item['price'] = $unit->price; $item['production_date'] = ''; $item['planned_completion_date'] = ''; $item['remark'] = $unit->remark; $item['is_done'] = 0; $item['count'] = $part->count; $item['count_done'] = 0; // save db node $_proc = Process::create($item); $_proc->save(); // create ztree node $node = array(); $node['id'] = $_proc->id; $node['priority'] = $_proc->priority; $node['name'] = $_proc->priority . '# ' . get_proc_name($_proc->name) . ' (0)'; $node['isParent'] = false; $node['type'] = 'proc'; $node['moveFirst'] = false; $node['icon'] = get_path('/webroot/css/img/diy/4.png', true); $nodes[] = $node; } $results['is_success'] = true; $results['nodes'] = $nodes; } } echo json_encode($results); }
function upload_for_unit($unit_id) { $app = get_app(); // GET if ($app->request()->isGet()) { $app->render('Images/upload.php', array('type' => 'unit', 'id' => $unit_id)); } // POST if ($app->request()->isPost()) { $unit = Unit::find_by_id($unit_id); if ($unit) { $results = \Controller\Images::upload(); if ($results['is_success']) { $unit->image = $results['md5_name']; $unit->save(); } echo json_encode($results); } } }
function import($folder_id, $part_id) { $folder = Folder::find_by_id($folder_id); $part = Part::find_by_id($part_id); if ($folder && $part) { // 复制零件节点 $file = File::create(array('folder_id' => $folder_id, 'name' => $part->name, 'graphic_num' => $part->graphic_num, 'image' => $part->image)); // 添加零件工序节点 foreach ($part->processes as $p) { $unit = Unit::create(array('file_id' => $file->id, 'priority' => $p->priority, 'name' => $p->name, 'content' => $p->content, 'price' => $p->price, 'image' => $p->image, 'takt_time' => $p->takt_time, 'preparation_time' => $p->preparation_time, 'remark' => $p->remark)); $unit->save(); } // $node = array('id' => $file->id, 'name' => $file->name . ' (' . count($file->units) . ')', 'type' => 'file', 'isParent' => count($file->units) ? true : false, 'icon' => get_path('/webroot/css/img/diy/3.png', true)); echo json_encode($node); } }