/** * 回复留言信息 */ function do_edit($id) { //权限检查 得到所有可管理站点ID列表 role::check('contact_us_manage'); if (!$id) { remind::set(Kohana::lang('o_global.bad_request'), 'user/contact_us'); } if ($_POST) { //获取留言信息,发邮件 $contact_us = Mycontact_us::instance($id)->get(); $email_flag = 'contact_us'; $title_param = array(); $content_param = array(); $content_param['{message}'] = strip_tags($_POST['return_message']); if (mail::send_mail($email_flag, $contact_us['email'], $from_email = '', $title_param, $content_param)) { $is_receive = 1; remind::set(Kohana::lang('o_global.mail_send_success'), '', 'success'); } else { $is_receive = 0; remind::set(Kohana::lang('o_global.mail_send_error'), '', 'error'); } $data = $_POST; $data['active'] = 0; $data['is_receive'] = $is_receive; if (Mycontact_us::instance($id)->edit($data)) { remind::set(Kohana::lang('o_user.message_handle_success'), request::referrer(), 'success'); } else { remind::set(Kohana::lang('o_user.message_handle_error'), request::referrer(), 'error'); } } }
public function do_edit() { $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); try { //* 初始化返回数据 */ $return_data = array(); $request_data = $this->input->post(); /* 数据验证 ==根据业务逻辑定制== */ if (empty($request_data['id'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403); } $validResult = Validation::factory($request_data)->pre_filter('trim')->add_rules('id', 'required', 'digit')->add_rules('is_receive', 'digit')->add_rules('is_show', 'digit')->add_rules('reply_content', 'length[0,1024]'); if (!$validResult->validate()) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403); } //* 逻辑验证 ==根据业务逻辑定制== */ // 调用底层服务 $productinquiry_service = ProductinquiryService::get_instance(); //* 调用后端服务获取数据 */ try { $productinquiry = $productinquiry_service->get($request_data['id']); if (!isset($productinquiry) || empty($productinquiry)) { throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403); } $set_data = array('reply_content' => $request_data['reply_content'], 'is_show' => $request_data['is_show'], 'update_timestamp' => date('Y-m-d H:i:s'), 'status' => 1); if (!empty($request_data['is_receive']) && $productinquiry['is_receive'] != 1) { $product = ProductService::get_instance()->get($productinquiry['product_id']); if (!empty($productinquiry['user_id'])) { $email = Myuser::instance($productinquiry['user_id'])->get('email'); } else { $email = $productinquiry['email']; } $email_flag = 'reply_inquiry'; $title_param = array(); $title_param['{title}'] = strip_tags($product['title']); $content_param = array(); $content_param['{user_name}'] = strip_tags($productinquiry['user_name']); $content_param['{reply_content}'] = strip_tags($request_data['reply_content']); $content_param['{product_title}'] = strip_tags($product['title']); if (!mail::send_mail($email_flag, $email, '', $title_param, $content_param)) { throw new MyRuntimeException(Kohana::lang('o_global.mail_send_error'), 500); } else { $set_data['is_receive'] = 1; } //不套用邮件模板的方式 /* $subject = 'Reply to Inquiry About '.$product['title']; $content = ''; $content .= 'Dear '.$productinquiry['user_name'].' :<br>'; $content .= 'Having received your letter regarding the inquiry about '.$product['title'].'.<br>'; $content .= $productinquiry['reply_content'].'<br>'; $content .= 'If we may be of further service, please feel free to contact us.<br>'; $content .= 'Sincerely yours,<br>'; $content .= $site['name']; if(!mail::send($email,$subject,$content)) { throw new MyRuntimeException(Kohana::lang('o_global.mail_send_error'), 500); } else { $set_data['is_receive'] = 1; } */ } $productinquiry_service->set($productinquiry['id'], $set_data); } catch (MyRuntimeException $ex) { throw $ex; } //* 补充&修改返回结构体 */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = '操作成功'; $return_struct['content'] = $return_data; $return_struct['action'] = array('type' => 'location', 'url' => url::base() . 'product/' . $this->class_name . '/' . 'index'); //* 请求类型 */ if ($this->is_ajax_request()) { $this->template->content = $return_struct; } else { // html 输出 $this->template->return_struct = $return_struct; $content = new View('info'); $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; } // end of request type determine } catch (MyRuntimeException $ex) { $return_struct['status'] = 0; $return_struct['code'] = $ex->getCode(); $return_struct['msg'] = $ex->getMessage(); //TODO 异常处理 //throw $ex; if ($this->is_ajax_request()) { $this->template->content = $return_struct; } else { $this->template->return_struct = $return_struct; $content = new View('info'); $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; } } }
/** * 添加新用户 */ function add() { //权限检查 得到所有可管理站点ID列表 role::check('user_add'); $submit_target = intval($this->input->post('submit_target')); if ($_POST) { $data = $_POST; //标签过滤 tool::filter_strip_tags($data); $data['password'] = sha1($_POST['password']); $data['ip'] = tool::get_long_ip(); $data['active'] = 1; //默认未激活状态 $data['register_mail_active'] = 1; $user = Myuser::instance(); if ($user->user_exist($data)) { remind::set(Kohana::lang('o_user.user_email_has_exist'), request::referrer(), 'error'); } if ($user->add($data)) { //发邮件 if ($this->input->post('send_mail') == 1) { $email_flag = 'reg'; $title_param = array(); $content_param = array(); $content_param['{firstname}'] = $this->input->post('firstname'); $content_param['{password}'] = $this->input->post('password'); $content_param['{email}'] = $this->input->post('email'); if (mail::send_mail($email_flag, $this->input->post('email'), $from_email = '', $title_param, $content_param)) { //判断添加成功去向 switch ($submit_target) { case 1: remind::set(Kohana::lang('o_global.add_success'), 'user/user/add', 'success'); default: remind::set(Kohana::lang('o_global.add_success'), 'user/user', 'success'); } } else { remind::set(Kohana::lang('o_global.mail_send_error'), '', 'error'); } } //判断添加成功去向 switch ($submit_target) { case 1: remind::set(Kohana::lang('o_global.add_success'), 'user/user/add', 'success'); default: remind::set(Kohana::lang('o_global.add_success'), 'user/user', 'success'); } } else { $errors = $user->error(); remind::set(Kohana::lang('o_global.add_error'), request::referrer(), 'error'); } } $this->template->content = new View("user/user_add"); }