function parse_production() { $head = $this->parse_terminal('token'); $this->parse_terminal('colon'); $body = $this->parse_body(); $p = new production($head); $p->add($body); while ($this->can_parse_terminal('union')) { $this->parse_terminal('union'); $p->add($this->parse_body()); } return $p; }
function add($part_id) { $app = get_app(); $part = Part::find_by_id($part_id); $post = $app->request()->post(); $post['part_id'] = $part->id; $post['user_id'] = $_SESSION['user_id']; $post['count'] = $part->count; // 外协 if (isset($post['is_outsourcing'])) { $post['is_outsourcing'] = 1; } // unset unset($post['proc_id']); // proc_id 只针对对 edit 方法 unset($post['_wysihtml5_mode']); unset($post['TolPN_1']); unset($post['TolPN_2']); // 创建工序节点 $proc_has_same_priority = Process::find('all', array('conditions' => array(' part_id = ? AND priority = ? ', $part_id, $post['priority']))); if (!has_perm(1, 4)) { $results['errors'] = array('对不起,您没有创建工序节点的权限!'); $results['is_success'] = false; } else { if (!empty($proc_has_same_priority)) { $results['errors'] = array('有相同序号的一条工序已经存在!'); $results['is_success'] = false; } else { $proc = Process::create($post); if (!$proc->is_valid()) { foreach ($proc->errors as $error) { $errors[] = $error; } $results['errors'] = $errors; $results['is_success'] = false; } else { $proc->save(); $results['newNode'] = $post; $results['newNode']['takt_time'] = $proc->takt_time ? $proc->takt_time : ''; $results['newNode']['preparation_time'] = $proc->preparation_time ? $proc->preparation_time : ''; $results['newNode']['count'] = $proc->count; $results['newNode']['price'] = $proc->price ? $proc->price : ''; // 因为在前面为了兼容表单提交空的 production_date 和 planned_completion_date; // 所以表单提交的这两个值在前面被unset掉了 // 这里要重新定义给newNode节点 // 2014-02-20 $results['newNode']['production_date'] = $proc->production_date ? date('Y-m-d', strtotime($proc->production_date)) : ''; $results['newNode']['planned_completion_date'] = $proc->planned_completion_date ? date('Y-m-d', strtotime($proc->planned_completion_date)) : ''; $results['newNode']['is_outsourcing'] = $proc->is_outsourcing; $results['newNode']['name_orig'] = $proc->name; $results['newNode']['name'] = get_proc_name($proc->name); $results['newNode']['name_with_count'] = $proc->priority . '# ' . get_proc_name($proc->name) . ' (0)'; $results['newNode']['id'] = $proc->id; $results['newNode']['isParent'] = false; $results['newNode']['type'] = 'proc'; $results['newNode']['moveFirst'] = false; $results['newNode']['icon'] = get_path('/webroot/css/img/diy/4.png', true); $results['newNode']['is_outsourcing'] = $proc->is_outsourcing; $results['is_success'] = true; // Part::update_count($proc->part); production::update_count($proc->part->production); } } } echo json_encode($results); }