db = \Zend_Registry::get('db'); }else{ $this->db = $db; } $this->config = \Zend_Registry::get('config'); } //提交申请 public function updateUserInfo(\Zend_EventManager_Event $e) { //根据pdflink字段,以判断是否已经提交 //在数据库中创建rules,在更新offlineapp表时同时更新users表中对应的信息 $formData = $e->getParam('formData'); $uid = $e->getParam('uid'); $returnid = $e->getParam('returnid'); try{ $sql="SELECT id FROM ".$this->tbl_offlineapp." WHERE userid=? AND (pdflink IS null OR pdflink='') AND (ts_approved IS null)"; $row = $this->db->fetchRow($sql,array($uid)); $dbh = new dbh($this->db); $formData['username'] = $formData['realname']; unset($formData['realname']); unset($formData['save']); unset($formData['submit']); if ($row) { $s = $dbh->update($this->tbl_offlineapp,$formData," id={$row['id']} "); if(empty($returnid)) { return $s; }else{ return $row['id']; } } else { if(empty($returnid)) { $s = $dbh->insert($this->tbl_offlineapp,$formData); return $s; }else{ $id = $dbh->insert($this->tbl_offlineapp,$formData,true); return $id; } } }catch(Exception $e) { return $e->getMessage(); } return true; } //申请成功提交之后 public function orderSubmited(\Zend_EventManager_Event $e) { $formData = $e->getParam('formData'); $uid = (int)$e->getParam('uid'); $oid = (int)$e->getParam('oid'); $pdf = $e->getParam('pdf'); try{ $sql="update dataorder set status=3, offlineappid=$oid where status=2 and userid=$uid"; if($this->db->exec($sql) < 0) { return "数据篮状态更新失败,请重试"; } $this->sendEmail($formData,$pdf); }catch(Exception $e) { return $e->getMessage(); } return true; } //发送邮件通知 public function sendEmail($formData,$pdf) { $data = array( "user"=>$formData['realname'], "datalist"=>str_replace(";","\n",$formData['datalist']) ); $mail = new Mail(); $mail->loadTemplate("offline-email",$data); $mail->addTo($formData['email'],$formData['realname']); $attach = $mail->mail->createAttachment($pdf->Output('applicant','S')); $attach->filename = '数据申请-'.$formData['realname'].'.pdf'; $mail->send(); } }