Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

测试提交 #2

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions Admin/Common/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// | Author: liu21st <[email protected]>
// +----------------------------------------------------------------------
// $Id$

require_once(LIB_PATH . 'ORG/PHPMailer/PHPMailerAutoload.php');
//公共函数
function toDate($time, $format = 'Y-m-d H:i:s') {
if (empty ( $time )) {
Expand Down Expand Up @@ -345,4 +345,60 @@ function isMobile(){

return false;
}
?>

/**
* @param string $title
* @param array $add
* @param string $context
*/
function sendEmail($title='', $add = array(), $context=''){

// 实例化PHPMailer核心类
$mail = new PHPMailer();

// 是否启用smtp的debug进行调试 开发环境建议开启 生产环境注释掉即可 默认关闭debug调试模式
//$mail->SMTPDebug = 1;
// 使用smtp鉴权方式发送邮件
$mail->isSMTP();
// smtp需要鉴权 这个必须是true
$mail->SMTPAuth = true;
// 链接qq域名邮箱的服务器地址
$mail->Host = 'smtp.qq.com';
// 设置使用ssl加密方式登录鉴权
$mail->SMTPSecure = 'ssl';
// 设置ssl连接smtp服务器的远程服务器端口号
$mail->Port = 465;
// 设置发送的邮件的编码
$mail->CharSet = 'UTF-8';
// 设置发件人昵称 显示在收件人邮件的发件人邮箱地址前的发件人姓名
$mail->FromName = C('MAIL_FROM_NICKNAME');
// smtp登录的账号 QQ邮箱即可
$mail->Username = C('MAIL_FROM_NAME');
// smtp登录的密码 使用生成的授权码
$mail->Password = C('MAIL_FROM_PASSWORD');
// 设置发件人邮箱地址 同登录账号
$mail->From = C('MAIL_FROM_ADDRESS');
// 邮件正文是否为html编码 注意此处是一个方法
$mail->isHTML(true);
// 设置收件人邮箱地址
foreach ($add as $akey => $aval){
$mail->addAddress($aval);
}
// 添加该邮件的主题
$mail->Subject = $title;
// 添加邮件正文
$mail->Body = $context;
// 为该邮件添加附件
//$mail->addAttachment('./example.pdf');
// 发送邮件 返回状态
$status = $mail->send();

$result['status'] = $status;
$result['msg'] = null;
if (!$status){
$result['msg'] = $mail->ErrorInfo;
}
return $result;
}
?>

9 changes: 8 additions & 1 deletion Admin/Conf/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'DB_HOST'=>'127.0.0.1',
'DB_NAME'=>'dwz_group',
'DB_USER'=>'root',
'DB_PWD'=>'123456',
'DB_PWD'=>'',
'DB_PORT'=>'3306',
'DB_PREFIX'=>'',

Expand Down Expand Up @@ -42,6 +42,13 @@
'RBAC_ACCESS_TABLE'=>'access',
'RBAC_NODE_TABLE'=>'node',

// 邮件配置信息
'MAIL_FROM_NICKNAME' => '周报系统',
'MAIL_FROM_NAME'=> '[email protected]',
'MAIL_FROM_ADDRESS'=> '[email protected]',
'MAIL_FROM_PASSWORD' => 'test',
'MAIL_DEPARTMENT_ADDRESS' => '[email protected]', // 部门邮箱地址

);

return array_merge($config,$siteconfig,$constants);
Expand Down
55 changes: 55 additions & 0 deletions Admin/Lib/Action/BranchAction.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
class BranchAction extends CommonAction {
public function _filter(&$map)
{
}

public function _before_index() {
}

// 获取配置类型
public function _before_add() {
$branch = M("Branch");
$branch->getById($_GET['id']);
$this->assign('id',$branch->id);
}

public function _before_patch() {
}
public function _before_edit() {
}
public function _before_delete() {
}

public function _before_foreverdelete() {
$model = M ('DailyTask');
$id = $_REQUEST ['id'];
$where ['bid'] = $id;
$info = $model->where ( $where )->select ();
if ($info){
$this->error('请先删除该业务下的周报');
}
}

/**
+----------------------------------------------------------
* 默认排序操作
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
*/
public function sort()
{
$node = M('Branch');
$map = array();
$map['status'] = 1;
$map['id'] = array('in',$_GET['sortId']);
$sortList = $node->where($map)->order('sort asc')->select();
$this->assign("sortList",$sortList);
$this->display();
return ;
}
}
?>
77 changes: 76 additions & 1 deletion Admin/Lib/Action/DailyTaskAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function index() {
}
$model = new DailyTaskViewModel();
$this->_list($model, $map, 'task_date', false, 'DailyTask.id');

$this->display();
}

Expand All @@ -49,6 +48,12 @@ function edit() {
$vo = $map;
}
}
// 查询业务分组
$branch = M('Branch');
$map = array();
$map['status'] = 1;
$sortList = $branch->where($map)->order('sort asc')->select();
$this->assign("branch",$sortList);

$this->assign ( 'vo', $vo );
$this->display ();
Expand All @@ -57,9 +62,15 @@ function edit() {
function update() {
$user_id = $_REQUEST ['user_id'];
$task_date = $_REQUEST ['task_date'];
$bid = $_REQUEST['bid'];

if (empty($user_id)) $this->error('用户ID必须');
if (empty($task_date)) $this->error('Task日期必须');
if (empty($bid)) $this->error('请选择业务');

$branch = M('branch');
$where = array('id' => $bid, 'status' => 1);
$res = $branch->where($where)->field('id,title')->find();

if (! D('User')->isSameDepartment($user_id)) {
$this->error('不能修改其它部门工作日志');
Expand All @@ -76,6 +87,8 @@ function update() {
if (false === $model->create ()) {
$this->error ( $model->getError () );
}

$model->btmp_title = $res['title'];
$list = $model->add ();
} else { // 更新数据
$_POST ['id'] = $po['id'];
Expand All @@ -84,6 +97,7 @@ function update() {
$this->error ( $model->getError () );
}

$model->btmp_title = $res['title'];
$list = $model->save ();
}

Expand Down Expand Up @@ -296,5 +310,66 @@ private function _getWeekTerm($weekMonday, $dateField='task_date'){

return $map;
}

/**
* 汇总周报信息
*/
function weeklyReportSummary(){
$department = $_GET['department'] ? $_GET['department'] : 1;
// 时间
$ownAddress = isset($_SESSION['email']) ? $_SESSION['email'] : null;
$week_date = $_REQUEST['week_date']; // 时间格式
$timeArr = explode("-", $week_date);
$year = $timeArr[0];
$weeks = $this->_allWeeksByYear($year); // 获取全部
$weekArr = array_column($weeks, 'date', 'sn');
$week = array_search(strtotime($week_date), $weekArr);
if (!$week){
$this->error ( '获取周信息失败!' );
}
// 周报
$model = new DailyTaskViewModel();
//$map = array ('user_id' => $_SESSION['authId']);
$startDate = $weekArr[$week];
$endDate = $weekArr[($week + 1)];
if (!empty($startDate) && !empty($endDate)){
$map['task_date'] = array(array('egt', date("Y-m-d",$startDate)), array('elt', date("Y-m-d",$endDate)));
} else if (!empty($startDate)) {
$map['task_date'] = array('egt', date("Y-m-d",$startDate));
} else if (!empty($endDate)) {
$map['task_date'] = array('elt', date("Y-m-d",$endDate));
}
$map['department'] = $department;
$po = $model->where ( $map )->order('user_id asc')->select();
// 邮件地址
$address = [
C('MAIL_DEPARTMENT_ADDRESS'),
$ownAddress
];

$this->assign ( 'model', $po);
$this->assign ( 'address', $address );
$this->assign ( 'week', $week );
$this->display ();
}
/**
* 发送邮件方法
*/
function sendWeeklyEmail() {
$week = $_REQUEST['week'];
$email = $_REQUEST['bid'];
$context = $_REQUEST['content'];
$context = str_replace("\r\n", "<br>", $context);
$context = str_replace("\t", "&emsp;&emsp;&emsp;&emsp;", $context);
$title = 'W' . $week . "周报";

$res = sendEmail($title, array($email), $context);

if ($res['status']){
$this->success('成功');
}else{
$this->error($res['msg']);
}
}
}
?>
22 changes: 22 additions & 0 deletions Admin/Lib/Model/BranchModel.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
// 节点模型
class BranchModel extends CommonModel {
protected $_validate = array(
array('name','checkBranch','节点已经存在',0,'callback'),
);

public function checkBranch() {
$map['name'] = $_POST['name'];
$map['status'] = 1;
if(!empty($_POST['id'])) {
$map['id'] = array('neq',$_POST['id']);
}
$result = $this->where($map)->field('id')->find();
if($result) {
return false;
}else{
return true;
}
}
}
?>
5 changes: 3 additions & 2 deletions Admin/Lib/Model/DailyTaskViewModel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ class DailyTaskViewModel extends ViewModel {

public $viewFields = array(
'User'=>array('nickname'=>'nickname','email'=>'email','account'=>'account', 'department'=>'department'),
'DailyTask'=>array('id', 'user_id', 'content','task_date','create_time','day_num',
'_on'=>'User.id=DailyTask.user_id')
'DailyTask'=>array('id', 'user_id', 'content','task_date','create_time','day_num','bid','btmp_title',
'_on'=>'User.id=DailyTask.user_id'),
'Branch'=>array('id'=>'bid','username'=>'username','_on'=>'Branch.id=DailyTask.bid'),
);
}
?>
49 changes: 49 additions & 0 deletions Admin/Lib/ORG/PHPMailer/PHPMailerAutoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* PHPMailer SPL autoloader.
* PHP Version 5
* @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
* @author Marcus Bointon (Synchro/coolbru) <[email protected]>
* @author Jim Jagielski (jimjag) <[email protected]>
* @author Andy Prevost (codeworxtech) <[email protected]>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2014 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/

/**
* PHPMailer SPL autoloader.
* @param string $classname The name of the class to load
*/
function PHPMailerAutoload($classname)
{
//Can't use __DIR__ as it's only in PHP 5.3+
$filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php';
if (is_readable($filename)) {
require $filename;
}
}

if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
//SPL autoloading was introduced in PHP 5.1.2
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
spl_autoload_register('PHPMailerAutoload', true, true);
} else {
spl_autoload_register('PHPMailerAutoload');
}
} else {
/**
* Fall back to traditional autoload for old PHP versions
* @param string $classname The name of the class to load
*/
function __autoload($classname)
{
PHPMailerAutoload($classname);
}
}
Loading