Example #1
0
 function submit($submit, $id, $button_id = NULL)
 {
     parent::submit($submit, $id, $button_id);
     try {
         if ($submit == 'indicator') {
             $indicator = $this->input->sessionPost('indicator');
             $evaluation_indicator = $this->input->sessionPost('evaluation_indicator');
             $this->evaluation->addIndicator($this->evaluation->id, $indicator, $evaluation_indicator);
             $this->output->setData($this->indicatorList(), 'indicator-list', 'content-table', '.item[name="indicator"]>.contentTable', 'replace');
             unsetPost('indicator');
             unsetPost('evaluation_indicator');
         } elseif ($submit == 'apply_model') {
             if (!$this->input->post('indicator_model')) {
                 $this->output->message('请选择模版', 'warning');
                 throw new Exception();
             }
             $this->evaluation->applyModel($this->evaluation->id, $this->input->post('indicator_model'));
             $this->output->message('评价模版已应用');
             $this->output->setData($this->indicatorList(), 'indicator-list', 'content-table', '.item[name="indicator"]>.contentTable', 'replace');
             $this->output->setData($this->peopleList(), 'people-list', 'content-table', '.item[name="people"]>.contentTable', 'replace');
         }
     } catch (Exception $e) {
         $e->getMessage() && $this->output->message($e->getMessage(), 'warning');
         $this->output->status = 'fail';
     }
 }
Example #2
0
 function submit($submit, $id, $button_id = NULL)
 {
     parent::submit($submit, $id, $button_id);
     try {
         if ($submit == 'project') {
             if ($this->cases->data['type'] === 'cases' && !$this->cases->data['num']) {
                 $this->output->message('尚未获取案号,请选择案件领域和分类后获取案号', 'warning');
                 throw new Exception();
             }
             if (isset($this->cases->labels['分类']) && $this->cases->data['type'] === 'cases' && !$this->cases->data['focus']) {
                 if ($this->cases->labels['分类'] === '争议') {
                     $this->output->message('请填写案件争议焦点', 'warning');
                     throw new Exception();
                 } elseif ($this->cases->labels['分类'] === '非争议') {
                     $this->output->message('请填写案件标的', 'warning');
                     throw new Exception();
                 }
             }
         } elseif ($submit == 'client') {
             $this->load->model('client_model', 'client');
             //这样对数组做加法,后者同名键不会替换前者,即后者是前者的补充,而非更新
             $project_client = $this->input->sessionPost('case_client');
             $client = $this->input->sessionPost('client');
             $client_profiles = $this->input->sessionPost('client_profiles');
             $client_labels = $this->input->sessionPost('client_labels');
             if (!$project_client['role']) {
                 $this->output->message('请选择本案地位', 'warning');
                 throw new Exception();
             }
             if ($project_client['client']) {
                 if ($project_client['role'] === '主委托人') {
                     $recent_case_of_client = $this->cases->getRow(array('people' => $project_client['client'], 'role' => '主委托人', 'before' => $this->cases->id, 'order_by' => 'time_contract desc'));
                     $recent_case_of_client_relative = $this->cases->getRow(array('people_is_relative_of' => $project_client['client'], 'role' => '主委托人', 'before' => $this->cases->id, 'order_by' => 'time_contract desc'));
                     $recent_case_of_client_arelative = $this->cases->getRow(array('people_has_relative_like' => $project_client['client'], 'role' => '主委托人', 'before' => $this->cases->id, 'order_by' => 'time_contract desc'));
                     if ($recent_case_of_client) {
                         $recent_case = $recent_case_of_client;
                     }
                     if ($recent_case_of_client_relative && (!isset($recent_case) || $recent_case_of_client_relative['time_contract'] > $recent_case['time_contract'])) {
                         $recent_case = $recent_case_of_client_relative;
                     }
                     if ($recent_case_of_client_arelative && (!isset($recent_case) || $recent_case_of_client_arelative['time_contract'] > $recent_case['time_contract'])) {
                         $recent_case = $recent_case_of_client_arelative;
                     }
                     if (isset($recent_case)) {
                         $this->cases->addLabel($this->cases->id, '再成案');
                         $this->cases->addRelative($this->cases->id, $recent_case['id'], '上次签约案件');
                         $previous_roles = $this->cases->getRolesPeople($recent_case['id']);
                         $recent_case_profiles = array_sub($this->cases->getProfiles($recent_case['id']), 'content', 'name');
                         foreach (array('案源人') as $role) {
                             if (isset($previous_roles[$role])) {
                                 foreach ($previous_roles[$role] as $people) {
                                     $this->cases->addStaff($this->cases->id, $people['people'], $role, $people['weight'] / 2);
                                 }
                             }
                         }
                         $this->cases->addProfile($this->cases->id, '案源系数', 0.2 - (0.2 - $recent_case_profiles['案源系数']) / 2);
                         $this->cases->addProfile($this->cases->id, '案源类型', $recent_case_profiles['案源类型']);
                         $this->output->setData($this->relativeList(), 'relative-list', 'content-table', '.item[name="relative"]>.contentTable', 'replace');
                         $this->output->setData($this->staffList(), 'staff-list', 'content-table', '.item[name="staff"]>.contentTable', 'replace');
                     } else {
                         $this->cases->profiles['案源类型'] = array_sub($this->client->getProfiles($project_client['client']), 'content', 'name')['来源类型'] === '亲友介绍' ? '个人案源' : '所内案源';
                         if ($this->cases->profiles['案源类型'] === '所内案源') {
                             $this->cases->addProfile($this->cases->id, '案源系数', 0.08);
                         } else {
                             $this->cases->addProfile($this->cases->id, '案源系数', 0.2);
                         }
                         $this->cases->addProfile($this->cases->id, '案源类型', $this->cases->profiles['案源类型']);
                     }
                 }
             } else {
                 //添加新客户
                 if (!$client['name']) {
                     $this->output->message('请输入客户或相关人名称', 'warning');
                     throw new Exception();
                 }
                 $new_client = array('name' => $client['name'], 'character' => isset($client['character']) && $client['character'] == '单位' ? '单位' : '个人', 'type' => $client['type'], 'labels' => $client_labels);
                 if (!$client_profiles['电话'] && !$client_profiles['电子邮件']) {
                     $this->output->message('至少输入一种联系方式', 'warning');
                     throw new Exception();
                 }
                 foreach ($client_profiles as $name => $content) {
                     if ($name == '电话') {
                         if ($this->client->isMobileNumber($content)) {
                             $new_client['profiles']['手机'] = $content;
                         } else {
                             $new_client['profiles']['电话'] = $content;
                         }
                         $new_client['phone'] = $content;
                     } elseif ($name == '电子邮件' && $content) {
                         if (!$this->form_validation->valid_email($content)) {
                             $this->output->message('请填写正确的Email地址', 'warning');
                             throw new Exception();
                         }
                         $new_client['email'] = $content;
                     } else {
                         $new_client['profiles'][$name] = $content;
                     }
                 }
                 if ($client['type'] == 'client') {
                     //客户必须输入来源
                     if (empty($client_profiles['来源类型'])) {
                         $this->output->message('请选择客户来源类型', 'warning');
                         throw new Exception();
                     }
                     $this->load->model('staff_model', 'staff');
                     $client['staff'] = $this->staff->check($client['staff_name']);
                     $new_client['staff'] = $client['staff'];
                 } else {
                     //非客户必须输入工作单位
                     if (!$client['work_for']) {
                         $this->output->message('请输入工作单位', 'warning');
                         throw new Exception();
                     }
                 }
                 if ($client['work_for']) {
                     $new_client['work_for'] = $client['work_for'];
                 }
                 $new_client['display'] = true;
                 $project_client['client'] = $this->client->add($new_client);
                 $this->output->message('<a href="#' . $client['type'] . '/' . $project_client['client'] . '">新' . lang($client['type']) . ' ' . $client['name'] . ' 已经添加,点击编辑详细信息</a>');
             }
             if ($this->cases->addPeople($this->cases->id, $project_client['client'], 'client', $project_client['role'])) {
                 $this->output->setData($this->clientList(), 'client-list', 'content-table', '.item[name="client"]>.contentTable', 'replace');
             } else {
                 $this->output->message('客户添加错误', 'warning');
                 throw new Exception();
             }
             unsetPost('case_client');
             $this->session->unset_userdata();
             unsetPost('case_client');
             unsetPost('client');
             unsetPost('client_profiles');
             unsetPost('client_labels');
         } elseif ($submit == 'remove_client') {
             if ($this->cases->removePeople($this->cases->id, $button_id)) {
                 $this->output->setData($this->clientList(), 'client-list', 'content-table', '.item[name="client"]>.contentTable', 'replace');
             }
         } elseif ($submit == 'staff') {
             $this->load->model('staff_model', 'staff');
             $staff = $this->input->sessionPost('staff');
             if (!$staff['id']) {
                 $staff['id'] = $this->staff->check($staff['name']);
                 if (!$staff['id']) {
                     $this->output->message('请输入职员名称', 'warning');
                     throw new Exception();
                 }
             }
             if (!$staff['role']) {
                 $this->output->message('未选择本案职务', 'warning');
                 throw new Exception();
             }
             if (in_array($staff['role'], array('案源人', '接洽律师', '主办律师')) && !$staff['weight']) {
                 $staff['weight'] = 100;
             }
             if ($staff['weight'] === '') {
                 $staff['weight'] = NULL;
             } else {
                 $staff['weight'] /= 100;
             }
             if ($this->cases->addStaff($this->cases->id, $staff['id'], $staff['role'], $staff['weight'])) {
                 $this->message->send('将你加入<a href="#' . $this->cases->data['type'] . '/' . $this->cases->data['id'] . '">案件:' . $this->cases->data['name'] . '</a>', $staff['id']);
                 $this->output->setData($this->staffList(), 'staff-list', 'content-table', '.item[name="staff"]>.contentTable', 'replace');
                 unsetPost('staff/id');
             } else {
                 $this->output->message('人员添加错误', 'warning');
             }
             unsetPost('staff');
         } elseif ($submit == 'remove_staff') {
             if ($this->cases->removePeople($this->cases->id, $button_id)) {
                 $this->output->setData($this->staffList(), 'staff-list', 'content-table', '.item[name="staff"]>.contentTable', 'replace');
             }
         } elseif ($submit == 'fee') {
             $this->load->model('account_model', 'account');
             $fee = $this->input->sessionPost('fee');
             if (!is_numeric($fee['amount'])) {
                 $this->output->message('请预估收费金额(数值)', 'warning');
             }
             if (!$fee['comment']) {
                 $this->output->message('请填写付款条件', 'warning');
             }
             if (!$fee['date']) {
                 $this->output->message('请预估收费时间', 'warning');
             }
             if (count($this->output->message['warning']) > 0) {
                 throw new Exception();
             }
             $this->account->add($fee + array('project' => $this->project->id, 'display' => true));
             $this->output->setData($this->feeList(), 'fee-list', 'content-table', '.item[name="fee"]>.contentTable', 'replace');
             unsetPost('fee');
         } elseif ($submit == 'review') {
             $this->cases->removeLabel($this->cases->id, '等待立案审核');
             $this->cases->addLabel($this->cases->id, '在办');
             $this->output->status = 'refresh';
             $this->output->message('通过立案审核');
         } elseif ($submit == 'apply_lock') {
             //@TODO申请锁定,通过标签和消息系统来解决
         } elseif ($submit == 'lock_client') {
             $this->cases->addLabel($this->cases->id, '客户已锁定');
             $this->output->status = 'refresh';
         } elseif ($submit == 'lock_staff') {
             $this->cases->addLabel($this->cases->id, '职员已锁定');
             $this->output->status = 'refresh';
         } elseif ($submit == 'lock_fee') {
             $this->cases->addLabel($this->cases->id, '费用已锁定');
             $this->output->status = 'refresh';
         } elseif ($submit == 'unlock_client') {
             $this->cases->removeLabel($this->cases->id, '客户已锁定');
             $this->output->status = 'refresh';
         } elseif ($submit == 'unlock_staff') {
             $this->cases->removeLabel($this->cases->id, '职员已锁定');
             $this->output->status = 'refresh';
         } elseif ($submit == 'unlock_fee') {
             $this->cases->removeLabel($this->cases->id, '费用已锁定');
             $this->output->status = 'refresh';
         } elseif ($submit == 'apply_file') {
             $this->cases->addLabel($this->cases->id, '已申请归档');
             $this->cases->update($this->cases->id, array('end' => $this->date->today));
             $this->output->message('归档申请已接受');
         } elseif ($submit == 'review_finance') {
             $this->cases->addLabel($this->cases->id, '通过财务审核');
             $this->output->status = 'refresh';
             $this->output->message('结案财务状况已经审核');
         } elseif ($submit == 'review_info') {
             $this->cases->addLabel($this->cases->id, '通过信息审核');
             $this->output->status = 'refresh';
             $this->output->message('案件信息已经审核');
         } elseif ($submit == 'review_manager') {
             $this->cases->addLabel($this->cases->id, '通过主管审核');
             $this->cases->update($this->cases->id, array('end' => $this->date->today));
             $this->output->status = 'refresh';
             $this->output->message('案件已经审核,已正式归档');
         } elseif ($submit == 'file' && $this->cases->data['type'] === 'cases') {
             $this->cases->removeLabel($this->cases->id, '已申请归档');
             $this->cases->addLabel($this->cases->id, '案卷已归档');
             $this->cases->update($this->cases->id, array('active', false));
             $this->output->status = 'refresh';
             $this->output->message('案卷归档归档完成');
         } elseif ($submit == 'apply_num') {
             if (empty($this->cases->labels['领域'])) {
                 $this->output->message('获得案号前要先选择案件领域', 'warning');
                 throw new Exception();
             }
             if (empty($this->cases->labels['分类'])) {
                 $this->output->message('获得案号前要先选择案件分类', 'warning');
                 throw new Exception();
             }
             if (!$this->cases->data['name']) {
                 $this->output->message('获得案号前要先填写案件名称', 'warning');
                 throw new Exception();
             }
             $this->cases->data['num'] = $this->cases->getNum($this->cases->labels);
             $this->cases->data['display'] = true;
             $this->cases->update($this->cases->id, $this->cases->data);
             $this->cases->updateLabels($this->cases->id, $this->cases->labels);
             $this->output->status = 'redirect';
             $this->output->data = 'cases/' . $this->cases->id;
         }
     } catch (Exception $e) {
         $e->getMessage() && $this->output->message($e->getMessage(), 'warning');
         $this->output->status = 'fail';
     }
 }