model = new \app\admin\model\csminvite\Notify(); $this->view->assign("notifywayList", $this->model->getNotifywayList()); $this->view->assign("statusList", $this->model->getStatusList()); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 添加 */ public function add() { if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { $params = $this->preExcludeFields($params); if ($this->dataLimit && $this->dataLimitFieldAutoFill) { $params[$this->dataLimitField] = $this->auth->id; } $result = false; Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; $this->model->validateFailException(true)->validate($validate); } $params['invitekey'] = md5(time() . mt_rand(1,1000000)); $result = $this->model->allowField(true)->save($params); Db::commit(); } catch (ValidateException $e) { Db::rollback(); $this->error($e->getMessage()); } catch (PDOException $e) { Db::rollback(); $this->error($e->getMessage()); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result !== false) { $this->success(); } else { $this->error(__('No rows were inserted')); } } $this->error(__('Parameter %s can not be empty', '')); } return $this->view->fetch(); } public function notifyUserajax($ids = null) { $row = $this->model->where("id", "=", $ids)->find(); if (! $row) { return; } if($row->effectendtimeerror("活动已过期,无法发送邮件通知。"); } $dao = new \app\admin\model\csminvite\Notifyuser(); $list = $dao->alias("t") ->where("csminvite_notify_id", "=", $row->id) ->where("status", "=", "normal") ->where("userstatus", "=", "unnotify") ->select(); $emailtitle = $row->emailtitle; $emailcontent = $row->content; if(count($list)==0){ $this->error("没有需要发送邮件通知"); } $obj = \app\common\library\Email::instance(); // echo $dao->getLastSql(); // echo("sendmail"); foreach ($list as $item) { //var_dump($item->email . ' ' . $this->convertMailContent($emailtitle, $row,$item) . ' ' . $this->convertMailContent($emailcontent, $row,$item)); $obj->to($item->email) ->subject($this->convertMailContent($emailtitle, $row,$item)) ->message($this->convertMailContent($emailcontent, $row,$item)) ->send(); $param = [ "userstatus" => "nofitied", "notifytime" => time(), "updatetime" => time() ]; $dao->where("id", "=", $item->id)->update($param); } $this->success(); } private function convertMailContent($str, $row,$rowuser) { $str = str_replace(array("\r\n", "\r", "\n"), "
", $str); $str = str_replace('%username%', $rowuser->username, $str); $str = str_replace('%email%', $rowuser->email, $str); $csminvite = "notify_".$row->invitekey."_".$rowuser->id; $csminvitesign = Csminvite::generateSign($csminvite); $loginurl = $_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["SERVER_NAME"] .config('view_replace_str.__PUBLIC__') . "index/user/register.html?csminvite={$csminvite}&csminvitesign={$csminvitesign}"; $str = str_replace('%register_url%', $loginurl, $str); return $str; } }