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']; $formData['userid'] = $uid; unset($formData['realname']); unset($formData['save']); unset($formData['submit']); unset($formData['id']); if ($row) { $s = $dbh->update($this->tbl_offlineapp,$formData," id={$row['id']} "); $this->updateToUserTable($formData,$row['id']); if(empty($returnid)) { return $s; }else{ return $row['id']; } } else { $id = $dbh->insert($this->tbl_offlineapp,$formData,true); $this->updateToUserTable($formData,$uid); if(empty($returnid)) { if($id > 0) { return true; }else{ return "保存失败,请重试"; } }else{ return $id; } } }catch(Exception $e) { return $e->getMessage(); } return true; } //将项目信息更新到用户表 public function updateToUserTable($formData,$id) { $data = array( 'address' => $formData['address'], 'phone' => $formData['phone'], 'postcode' => $formData['postcode'], 'unit' => $formData['unit'], 'project_id' => $formData['project_id'], 'project_type' => $formData['project_type'], 'project_title' => $formData['project_title'], 'project_leader' => $formData['project_leader'], 'project' => $formData['project'] ); $dbh = new dbh($this->db); @$dbh->update('users',$data," id=$id "); } //申请成功提交之后 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 offlineappid=$oid where status=2 and userid=$uid"; if($this->db->exec($sql) < 0) { return "数据篮状态更新失败,请重试"; } $sql = "UPDATE offlineapp SET pdflink='".$pdf->pdflink."',status=2 WHERE id=$oid "; 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']), "orderlink"=> view::getHostLink() . '/data/order/ac/offline2' ); $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(); } }