Beispiel #1
0
 /**
  * 保存任务
  */
 public function saveAction()
 {
     // 返回值数组
     $result = array('success' => true, 'result' => true, 'info' => '保存成功');
     $user_session = new Zend_Session_Namespace('user');
     $user = $user_session->user_info['employee_id'];
     $now = date('Y-m-d H:i:s');
     $task = new User_Model_Task();
     // Content-Type:application/json 不能直接到request里面读取
     $request_body = file_get_contents('php://input');
     $json = json_decode($request_body);
     if (isset($json->id) && $json->id > 0) {
         $where = "id = " . $json->id;
         $data = array('parent' => $json->Parent, 'start' => $json->StartDate, 'end' => $json->EndDate, 'title' => $json->Title, 'notes' => $json->Notes, 'content' => $json->Notes, 'responsible_id' => $json->Responsible_id, 'follow_id' => $json->Follow_id, 'priority' => $json->Priority ? $json->Priority : '紧急', 'important' => $json->Important ? $json->Important : '重要', 'type' => $json->Type ? $json->Type : '独立', 'update_user' => $user, 'update_time' => $now);
         try {
             $task->update($data, $where);
             $processData = array();
             if (isset($json->Process) && $json->Process) {
                 $pro = json_decode($json->Process);
                 $process = new User_Model_Process();
                 if ($pro && $pro != '[]') {
                     foreach ($pro as $val) {
                         $val = (array) $val;
                         $processData = array('task_id' => $json->id, 'employee_id' => $user, 'update_time' => $val['update_time'], 'rate' => $val['rate'], 'remark' => $val['remark'], 'status' => $val['status']);
                         $process->insert($processData);
                     }
                 }
             }
             if (count($processData) > 0) {
                 $state = $processData['status'];
                 $uData['state'] = $state;
                 if ($state == '取消' || $state == '完成') {
                     $uData = array('end' => $now);
                 }
                 $task->update($uData, $where);
             }
             $this->send($json->id, 'update');
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
     } else {
         $data = array('parent' => $json->Parent, 'start' => $json->StartDate, 'end' => $json->EndDate, 'title' => $json->Title, 'notes' => $json->Notes, 'content' => $json->Notes, 'responsible_id' => $json->Responsible_id, 'follow_id' => $json->Follow_id, 'priority' => $json->Priority ? $json->Priority : '紧急', 'important' => $json->Important ? $json->Important : '重要', 'type' => $json->Type ? $json->Type : '独立', 'create_user' => $user, 'update_user' => $user, 'create_time' => $now, 'update_time' => $now);
         try {
             $id = $task->insert($data);
             $result['info'] = $id;
             $processData = array();
             if (isset($json->Process) && $json->Process) {
                 $pro = $json->Process;
                 $process = new User_Model_Process();
                 if ($pro && $pro != '[]') {
                     foreach ($pro as $val) {
                         $val = (array) $val;
                         $processData = array('task_id' => $id, 'employee_id' => $user, 'update_time' => $val['update_time'], 'rate' => $val['rate'], 'remark' => $val['remark'], 'status' => $val['status']);
                         $process->insert($processData);
                     }
                 }
             }
             if (count($processData) > 0) {
                 $state = $processData['status'];
             } else {
                 $state = '发起';
             }
             $task->update(array('state' => $state), "id=" . $id);
             $this->send($id, 'add');
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }