ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

lingzhi. 邮件发送

2022-07-11 15:03:50  阅读:141  来源: 互联网

标签:status code lingzhi list value 发送 wo employee 邮件


<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

require_once __DIR__ . '/../../../../plugins/PHPMailer-6.1.7/src/Exception.php';
require_once __DIR__ . '/../../../../plugins/PHPMailer-6.1.7/src/PHPMailer.php';
require_once __DIR__ . '/../../../../plugins/PHPMailer-6.1.7/src/SMTP.php';
require_once __DIR__ . '/../../../../functions/_email_send.php';
require_once __DIR__ . '../../../../../api/v1/vendor/autoload.php';


// 这是记录日记
$log = new Logger('email');
$month = date('Y-m');
$log->pushHandler(new StreamHandler(__DIR__ . '/log/email_' . $month . '.log', Logger::DEBUG));










// 根据员工编码查询出设备主管
$equipment_supervisor = $DB->prepare("
     SELECT 
           employee_name,employee_email 
     FROM  admin_employee
     WHERE 
          employee_code = :employee_code
");
$employee_code = '00417046';

$str_employee_code = strval($employee_code);

$equipment_supervisor->bindValue('employee_code', $str_employee_code);

if (!$equipment_supervisor->execute()) {
    Flight::error(new RuntimeException(errorInfo($equipment_supervisor)));
} elseif ($equipment_supervisor->rowcount() == 0) {
    Flight::notFound();
} else {
    $result = $equipment_supervisor->fetch(PDO::FETCH_ASSOC);
    // 获取设备主管  00417046的邮箱 
    $equipment_supervisor_a = $result['employee_email'];
}

// 另一个设备主管 
$equipment_supervisor_b = $DB->prepare("
        SELECT 
             employee_name,employee_email 
        FROM admin_employee
        WHERE 
             employee_code = :employee_code
");

$employee_code_b = '00416788';

$strval_employee_code = strval($employee_code_b);

$equipment_supervisor_b->bindValue('employee_code', $strval_employee_code);

if (!$equipment_supervisor_b->execute()) {
    Flight::error(new RuntimeException(errorInfo($equipment_supervisor_b)));
} elseif ($equipment_supervisor_b->rowcount() == 0) {
    Flight::notFound();
}
$result = $equipment_supervisor_b->fetch(PDO::FETCH_ASSOC);
// 获取设备主管  00416788的邮箱    
$equipment_supervisor_b = $result['employee_email'];

// 这一步是获取工单延迟的wo_id
$query = $DB->prepare("
    SELECT
        COUNT(wo_list.wo_id) AS count_wo_id,
        admin_employee.employee_name,
        admin_employee.employee_email,
        wo_list.wo_id,
        wo_list.wo_name,
        asset_list.asset_code,
        asset_list.asset_name,
        asset_location.location_code,
        asset_location.location_name,
        wo_history.wo_responsible_name,
        wo_list.wo_target_time,
        wo_list.wo_status
    FROM wo_list
    INNER JOIN wo_list_employee ON wo_list.wo_id = wo_list_employee.wo_id
    INNER JOIN admin_employee ON wo_list_employee.employee_id = admin_employee.employee_id
    INNER JOIN asset_list ON wo_list.wo_responsible_id = asset_list.asset_responsible_id
    INNER JOIN asset_location ON asset_location.location_id = asset_list.location_id
    INNER JOIN wo_history ON wo_history.wo_id = wo_list.wo_id
    WHERE wo_list.wo_target_time <> '' 
    AND TIMESTAMPDIFF(HOUR, NOW(), wo_list.wo_target_time) <= 24 
    AND wo_list.wo_status < 6
    GROUP BY admin_employee.employee_id
");

if (!$query->execute()) {
    Flight::error(new RuntimeException(errorInfo($query)));
} elseif ($query->rowcount() == 0) {
    Flight::notFound();
} else {
    $row = $query->fetchAll(PDO::FETCH_ASSOC);

    // 发送的内容
    $output = <<< TABLE
 <table border="1px solid #777" cellspacing="0" cellpadding="0" align="center" width="100%" height:"50px" >
     <caption style="font-size:1.8rem">工单信息</caption>
     <thead bgcolor="skyblue">
         <th style=" width:50px">工单号</th>
         <th style=" width:50px">工单名称</th>
         <th style=" width:50px">资产编码</th>
         <th style=" width:50px">资产名称</th>
         <th style=" width:50px">设备</th>
         <th style=" width:50px">位置</th>
         <th style=" width:50px">负责人</th>
         <th style=" width:50px">目标时间</th>
         <th style=" width:50px">当前工单状态</th>
     </thead>
 TABLE;

    foreach ($row as $value) {

        // 工单的状态
        if ($value['wo_status'] == 0) {
            $wo_status = '已创建';
        } elseif ($value['wo_status'] == 1) {
            $wo_status = '等待备件';
        } elseif ($value['wo_status'] == 2) {
            $wo_status = '等待外委';
        } elseif ($value['wo_status'] == 3) {
            $wo_status = '已安排';
        } elseif ($value['wo_status'] == 4) {
            $wo_status = '已搁置';
        } elseif ($value['wo_status'] == 5) {
            $wo_status = '进行中';
        } elseif ($itval['wo_status'] == 6) {
            $wo_status = '已完成';
        } elseif ($value['wo_status'] == 7) {
            $wo_status = '已确认';
        }

        $output .= "<tr><td >{$value['wo_id']}</td>";
        $output .= "<td>{$value['wo_name']}</td>";
        $output .= "<td>{$value['asset_code']}</td>";
        $output .= "<td>{$value['asset_name']}</td>";
        $output .= "<td>{$value['location_code']}</td>";
        $output .= "<td>{$value['location_name']}</td>";
        $output .= "<td>{$value['wo_responsible_name']}</td>";
        $output .= "<td>{$value['wo_target_time']}</td>";
        $output .= "<td>$wo_status</td>";
        $output .= "</tr>";
    }
    $output .= "</table>";

    foreach ($row as $item) {
        // 发送的内容
        $msg = $output;
        // 发送的主题
        $email_subject =  "您有" . $item['count_wo_id'] . "个工单即将延迟,请及时关注!";
        try {
            // 这里是发送给工单负责人
            send_email('yanbing910624858@163.com', $email_subject, $msg, $msg);
            // 同时发送至设备主管
            send_email($equipment_supervisor_a, $email_subject, $msg, $msg);
            send_email($equipment_supervisor_b, $email_subject, $msg, $msg);
        } catch (Exception $e) {
            $error = $e->getMessage();
            $log->error($error);
        }

    }
}

 

标签:status,code,lingzhi,list,value,发送,wo,employee,邮件
来源: https://www.cnblogs.com/xiaoyantongxue/p/16466362.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有