示例#1
0
 /**
  * 文件发送
  */
 public function sendAction()
 {
     // 返回值数组
     $result = array('success' => true, 'result' => true, 'info' => '发送成功');
     $request = $this->getRequest()->getParams();
     $now = date('Y-m-d H:i:s');
     $user_session = new Zend_Session_Namespace('user');
     $user = $user_session->user_info['employee_id'];
     $val = (object) $request;
     $upload = new Dcc_Model_Upload();
     $doc_ids = "";
     $doc_names = "";
     if ($val->exfile_ids) {
         // 根据文件id获取归档文件id
         $tmp = $upload->getAdapter()->query("select group_concat(id) as doc_ids, group_concat(code) as doc_names from oa_doc_files where (state = 'Active') and name != '' and file_ids in ( " . $val->exfile_ids . ")")->fetchObject();
         $doc_ids = $tmp->doc_ids;
         $doc_names = $tmp->doc_names;
         $row = $upload->getFileByIds($val->exfile_ids);
         $names = $row['name'];
         $paths = $row['path'];
     }
     if ($paths) {
         foreach (explode(',', $paths) as $path) {
             if (!is_file($path)) {
                 $result['result'] = false;
                 $result['info'] = "文件不存在";
                 echo Zend_Json::encode($result);
                 exit;
             }
         }
         $employee = new Hra_Model_Employee();
         $to = array();
         if ($val->to_id) {
             $toUser = str_replace('E', '', $val->to_id);
             $to = $employee->getInfosByOneLine($toUser);
             $to = explode(',', $to['email']);
         }
         if (isset($val->custom_linkman) && $val->custom_linkman) {
             $to[] = $val->custom_linkman;
         }
         if (isset($val->supply_linkman) && $val->supply_linkman) {
             $to[] = $val->supply_linkman;
         }
         $dept = '';
         if (isset($val->innerdept_id) && $val->innerdept_id) {
             $dept = str_replace('D', '', $val->innerdept_id);
             $sql = "select group_concat(email) as email from oa_employee where dept_id in ({$dept})";
             $data = $employee->getAdapter()->query($sql)->fetchObject();
             if ($data && $data->email) {
                 $toemail = $data->email;
                 foreach (explode(',', $toemail) as $t) {
                     $to[] = $t;
                 }
             }
         }
         $cc = array();
         if ($val->cc_id) {
             $ccUser = str_replace('E', '', $val->cc_id);
             $cc = $employee->getInfosByOneLine($ccUser);
             $cc = explode(',', $cc['email']);
         }
         $u = $employee->getInfosByOneLine($user);
         $cc[] = $u->email;
         if (isset($val->personal_linkman) && $val->personal_linkman) {
             foreach (explode(',', $val->personal_linkman) as $m) {
                 if (strpos($m, '@') != false) {
                     $to[] = $m;
                 }
             }
         }
         $mailData = array('type' => $val->sendtype == '外发' ? "文件外发" : "文件发放", 'subject' => $val->subject, 'to' => implode(',', $to), 'cc' => implode(',', $cc), 'content' => $val->content, 'attachment_name' => $names, 'attachment_path' => $paths, 'send_time' => $now, 'add_date' => $now);
         $mail = new Application_Model_Log_Mail();
         try {
             $mailId = $mail->insert($mailData);
             if ($mailId) {
                 $sendResult = $mail->send($mailId, 0, $val->to_name, $val->footer, true);
             }
             $error_info = "";
             $success = false;
             if ($sendResult) {
                 ${$error_info} = $sendResult['info'];
                 $success = $sendResult['success'];
             }
             $result['result'] = $success;
             $result['info'] = ${$error_info};
             if (isset($val->out_sendtype)) {
                 $outsend = $val->out_sendtype;
             } else {
                 $outsend = "";
             }
             if (isset($val->out_custom)) {
                 $partner = $val->out_custom;
             } else {
                 if (isset($val->out_supply)) {
                     $partner = $val->out_supply;
                 } else {
                     $partner = '';
                 }
             }
             if (isset($val->custom_linkman)) {
                 $linkman = $val->custom_linkman;
             } else {
                 if (isset($val->supply_linkman)) {
                     $linkman = $val->supply_linkman;
                 } else {
                     $linkman = '';
                 }
             }
             // 获取发放编号
             $code = $this->getSendCode();
             // 记录
             $to = $val->to;
             if (isset($val->personal_linkman) && $val->personal_linkman) {
                 $to .= $val->personal_linkman;
             }
             $data = array('code' => $code, 'dept' => $dept, 'partner' => $partner, 'linkman' => $linkman, 'sendtype' => $val->sendtype, 'to_name' => $val->to_name, 'footer' => $val->footer, 'remark' => $val->remark, 'outsendtype' => $outsend, 'to' => $to, 'cc' => $val->cc, 'subject' => $val->subject, 'content' => $val->content, 'doc_ids' => $doc_ids, 'doc_names' => $doc_names, 'file_ids' => $val->exfile_ids, 'file_names' => $names, 'error_info' => $error_info, 'result' => $success, 'handle_time' => $now, 'handle_user' => $user);
             $send = new Dcc_Model_Send();
             $send->insert($data);
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         if (!$result['info']) {
             $result['info'] = "发送成功";
         }
         echo Zend_Json::encode($result);
         exit;
     } else {
         $result['result'] = false;
         $result['info'] = "文件不存在";
         echo Zend_Json::encode($result);
         exit;
     }
 }