Notices.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <?php
  2. if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  3. require_once("Aliyunsms.php");
  4. /**
  5. * 消息发送类
  6. * Class Notices
  7. */
  8. class Notices{
  9. private $CI;
  10. private $setting;
  11. private $Aliyunsms;
  12. public $warning_type = array(
  13. "10" => "失陷事件",
  14. "20" => "脆弱性",
  15. "30" => "残余攻击"
  16. );
  17. public $warning_level = array(
  18. "10" => "已失陷",
  19. "20" => "高可疑",
  20. "30" => "低可疑",
  21. "40" => "高危",
  22. "50" => "中危",
  23. "60" => "低危"
  24. );
  25. function __construct()
  26. {
  27. $this->CI = & get_instance();
  28. $this->CI->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
  29. $this->setting = $this->CI->cache->get('setting');
  30. $this->CI->load->helper(array('sms','date'));
  31. $this->CI->load->library('mailer');
  32. $this->CI->mailer->set_config($this->setting);
  33. $this->CI->load->model("noticeslog_model");
  34. $this->CI->load->model("user_model");
  35. if($this->setting['is_sms'] == "1" && $this->setting['sms_type'] == '20' && $this->setting['product'] =='Dysmsapi'){
  36. $this->Aliyunsms = new Aliyunsms();
  37. }
  38. }
  39. /**
  40. * 生成工单
  41. * @param $workorder
  42. */
  43. public function create_workorder($workorder){
  44. $receive_user = $this->CI->user_model->get_user_with_user_id($workorder['receive_user_id']);
  45. if($this->setting['is_sms'] && in_array("10",$workorder['send_type'])){
  46. $sms_content = '你有新工单需要处理,工单ID:'.$workorder['workorder_id'].',工单名称:'.$workorder['workorder_name'].',类型:'.$workorder['type'].',备注:'.$workorder['remark_list'][count($workorder['remark_list'])-1]['remark_content'];
  47. $notices_log = $this->CI->noticeslog_model->get_model();
  48. $notices_log['log_id'] = $this->create_id();
  49. $notices_log['type'] = "sms";
  50. $notices_log['mobile'] = $receive_user['mobile'];
  51. $notices_log['content'] = $sms_content;
  52. if($this->setting['sms_type'] == '10' ){
  53. if(send_by_modem($this->setting,$receive_user['mobile'],$sms_content)){
  54. $notices_log['status'] = "1";
  55. }else{
  56. $notices_log['status'] = "0";
  57. }
  58. }elseif($this->setting['sms_type'] == '20' ){
  59. $sms_content = array(
  60. "workorder_id"=>$workorder['workorder_id'],
  61. "workorder_name"=>$workorder['workorder_name'],
  62. "workorder_type"=>$workorder['type'],
  63. "remark_content"=>$workorder['remark_list'][count($workorder['remark_list'])-1]['remark_content']
  64. );
  65. $resp = $this->Aliyunsms->sendSms($receive_user['mobile'],$this->setting['template_codes'][0],$sms_content);
  66. if($resp['Code'] == 'OK'){
  67. $notices_log['status'] = "1";
  68. }else{
  69. $notices_log['status'] = "0";
  70. }
  71. }
  72. $notices_log['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  73. $this->CI->noticeslog_model->save_notices_log($notices_log);
  74. }
  75. if($this->setting['is_email'] && in_array("20",$workorder['send_type'])){
  76. $notices_log = $this->CI->noticeslog_model->get_model();
  77. $notices_log['log_id'] = $this->create_id();
  78. $notices_log['type'] = "email";
  79. $notices_log['recipient'] = $receive_user['email'];
  80. $notices_log['subject'] = "系统有新工单请处理,工单ID:".$workorder['workorder_id'];
  81. $email_content = '<div style="font-size:12px;">';
  82. $email_content .='<p style="white-space: normal; background-color: rgb(255, 255, 255);">'.$receive_user['name'].',您好!</p>';
  83. $email_content .='<p style="white-space: normal; background-color: rgb(255, 255, 255); text-indent: 2em;">系统有新工单请处理:</p>';
  84. $email_content .='<table align="left" border="1" cellspacing="0" cellpadding="0" style="font-size:12px;"><thead>';
  85. $email_content .='<tr class="firstRow"><td valign="top" rowspan="1" colspan="5" style="word-break: break-all;">';
  86. $email_content .='<strong>工单ID:'.$workorder['workorder_id'].'</strong><strong>工单名称:'.$workorder['workorder_name'].'</strong>';
  87. $email_content .='</td></tr>';
  88. $email_content .='<tr>';
  89. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>工单名称</strong></th>';
  90. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>类型</strong></th>';
  91. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>等级</strong></th>';
  92. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>时间</strong></th>';
  93. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>告警详情</strong></th>';
  94. $email_content .='</tr></thead><tbody>';
  95. foreach($workorder['warning_list'] as $key=>$val) {
  96. $email_content .= '<tr>';
  97. $email_content .= '<td valign="top" colspan="1" rowspan="1">'.$val['warning_name'].'</td>';
  98. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.$this->warning_type[$val['type']].'</td>';
  99. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.$this->warning_level[$val['level']].'</td>';
  100. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.date("Y-m-d H:i:s",$val['create_time']->toDateTime()->getTimestamp()).'</td>';
  101. $email_content .= '<td valign="top" colspan="1" rowspan="1">'.$val['content'].'</td>';
  102. $email_content .= '</tr>';
  103. }
  104. $email_content .='<tr>';
  105. $email_content .='<td valign="top" rowspan="1" colspan="5" style="word-break: break-all;"><strong>备注:</strong>'.$workorder['remark_list'][count($workorder['remark_list'])-1]['remark_content'].'</td>';
  106. $email_content .='</tr>';
  107. $email_content .='</tbody></table>';
  108. $email_content .='<p><br/>&nbsp;</p><p><br/>&nbsp;</p>';
  109. $email_content .='<p style="text-align: right;">系统管理员&nbsp;&nbsp;<br>';
  110. $email_content .=date("Y年m月d日",time()).'</p>';
  111. $email_content .='</div>';
  112. $notices_log['content'] = $email_content;
  113. if($this->CI->mailer->send_email($receive_user['email'],$notices_log['subject'],$notices_log['content'])){
  114. $notices_log['status'] = "1";
  115. }else{
  116. $notices_log['status'] = "0";
  117. }
  118. $notices_log['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  119. $this->CI->noticeslog_model->save_notices_log($notices_log);
  120. }
  121. }
  122. /**
  123. * 签收工单
  124. * @param $workorder
  125. * @param $remark
  126. */
  127. public function sign_workorder($workorder,$remark){
  128. $receive_user = $this->CI->user_model->get_user_with_user_id($workorder['receive_user_id']);
  129. $admin_list = $this->CI->user_model->select_users("1");
  130. $sso_admin_list = $this->CI->user_model->set_collection_name("sso_users")->select_users("1");
  131. $mobiles = array();
  132. $emails = array();
  133. foreach ($admin_list as $key => $val){
  134. $mobiles[] = $val['mobile'];
  135. $emails[] = $val['email'];
  136. }
  137. foreach ($sso_admin_list as $key => $val){
  138. $mobiles[] = $val['mobile'];
  139. $emails[] = $val['email'];
  140. }
  141. if($this->setting['is_sms'] && in_array("10",$workorder['send_type'])){
  142. $sms_content = '工单ID:'.$workorder['workorder_id'].',工单名称:'.$workorder['workorder_name'].',类型:'.$workorder['type'].',已由责任人'.$receive_user['name'].'签收,备注:'.$remark['remark_content'];
  143. for($i = 0;$i<count($mobiles);$i++) {
  144. $notices_log = $this->CI->noticeslog_model->get_model();
  145. $notices_log['type'] = "sms";
  146. $notices_log['content'] = $sms_content;
  147. $notices_log['log_id'] = $this->create_id();
  148. $notices_log['mobile'] = $mobiles[$i];
  149. if($this->setting['sms_type'] == '10' ){
  150. if(send_by_modem($this->setting, $notices_log['mobile'], $sms_content)){
  151. $notices_log['status'] = "1";
  152. }else{
  153. $notices_log['status'] = "0";
  154. }
  155. }elseif($this->setting['sms_type'] == '20' ){
  156. $sms_content = array(
  157. "workorder_id"=>$workorder['workorder_id'],
  158. "workorder_name"=>$workorder['workorder_name'],
  159. "workorder_type"=>$workorder['type'],
  160. "receive_user_name"=>$receive_user['name'],
  161. "remark_content"=>$workorder['remark_list'][count($workorder['remark_list'])-1]['remark_content']
  162. );
  163. $resp = $this->Aliyunsms->sendSms($notices_log['mobile'],$this->setting['template_codes'][1],$sms_content);
  164. if($resp['Code'] == 'OK'){
  165. $notices_log['status'] = "1";
  166. }else{
  167. $notices_log['status'] = "0";
  168. }
  169. }
  170. $notices_log['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  171. $this->CI->noticeslog_model->save_notices_log($notices_log);
  172. }
  173. }
  174. if($this->setting['is_email'] && in_array("20",$workorder['send_type'])){
  175. $notices_log = $this->CI->noticeslog_model->get_model();
  176. $notices_log['log_id'] = $this->create_id();
  177. $notices_log['type'] = "email";
  178. $notices_log['subject'] = "工单ID:".$workorder['workorder_id']."已由责任人:".$receive_user['name']."签收";
  179. $email_content = '<div style="font-size:12px;">';
  180. $email_content .='<p style="white-space: normal; background-color: rgb(255, 255, 255);">系统管理员,您好!</p>';
  181. $email_content .='<p style="white-space: normal; background-color: rgb(255, 255, 255); text-indent: 2em;">以下工单已由责任人:'.$receive_user['name'].'签收:</p>';
  182. $email_content .='<table align="left" border="1" cellspacing="0" cellpadding="0" style="font-size:12px;"><thead>';
  183. $email_content .='<tr class="firstRow"><td valign="top" rowspan="1" colspan="5" style="word-break: break-all;">';
  184. $email_content .='<strong>工单ID:'.$workorder['workorder_id'].'</strong><strong>工单名称:'.$workorder['workorder_name'].'</strong>';
  185. $email_content .='</td></tr>';
  186. $email_content .='<tr>';
  187. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>工单名称</strong></th>';
  188. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>类型</strong></th>';
  189. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>等级</strong></th>';
  190. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>时间</strong></th>';
  191. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>告警详情</strong></th>';
  192. $email_content .='</tr></thead><tbody>';
  193. foreach($workorder['warning_list'] as $key=>$val) {
  194. $email_content .= '<tr>';
  195. $email_content .= '<td valign="top" colspan="1" rowspan="1">'.$val['warning_name'].'</td>';
  196. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.$this->warning_type[$val['type']].'</td>';
  197. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.$this->warning_level[$val['level']].'</td>';
  198. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.date("Y-m-d H:i:s",$val['create_time']->toDateTime()->getTimestamp()).'</td>';
  199. $email_content .= '<td valign="top" colspan="1" rowspan="1">'.$val['content'].'</td>';
  200. $email_content .= '</tr>';
  201. }
  202. $email_content .='<tr>';
  203. $email_content .='<td valign="top" rowspan="1" colspan="5" style="word-break: break-all;"><strong>备注:</strong>'.$remark['remark_content'].'</td>';
  204. $email_content .='</tr>';
  205. $email_content .='</tbody></table>';
  206. $email_content .='<p><br/>&nbsp;</p><p><br/>&nbsp;</p>';
  207. $email_content .='<p style="text-align: right;">责任人:'.$receive_user['name'].'&nbsp;<br>';
  208. $email_content .=date("Y年m月d日",time()).'</p>';
  209. $email_content .='</div>';
  210. $notices_log['recipient'] = implode(",",$emails);
  211. $notices_log['content'] = $email_content;
  212. for ($i=0;$i<count($emails);$i++) {
  213. $this->CI->mailer->add_recipient($emails[$i]);
  214. }
  215. if ($this->CI->mailer->send_email("", $notices_log['subject'], $notices_log['content'])) {
  216. $notices_log['status'] = "1";
  217. } else {
  218. $notices_log['status'] = "0";
  219. }
  220. $notices_log['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  221. $this->CI->noticeslog_model->save_notices_log($notices_log);
  222. }
  223. }
  224. /**
  225. * 核查工单未发现问题
  226. * @param $workorder
  227. * @param $remark
  228. */
  229. public function check_workorder($workorder,$remark){
  230. $receive_user = $this->CI->user_model->get_user_with_user_id($workorder['receive_user_id']);
  231. $admin_list = $this->CI->user_model->select_users("1");
  232. $sso_admin_list = $this->CI->user_model->set_collection_name("sso_users")->select_users("1");
  233. $mobiles = array();
  234. $emails = array();
  235. foreach ($admin_list as $key => $val){
  236. $mobiles[] = $val['mobile'];
  237. $emails[] = $val['email'];
  238. }
  239. foreach ($sso_admin_list as $key => $val){
  240. $mobiles[] = $val['mobile'];
  241. $emails[] = $val['email'];
  242. }
  243. if($this->setting['is_sms'] && in_array("10",$workorder['send_type'])){
  244. $sms_content = '工单ID:'.$workorder['workorder_id'].',工单名称:'.$workorder['workorder_name'].',类型:'.$workorder['type'].',已由责任人'.$receive_user['name'].'核查无问题,备注:'.$remark['remark_content'];
  245. for($i = 0;$i<count($mobiles);$i++) {
  246. $notices_log = $this->CI->noticeslog_model->get_model();
  247. $notices_log['type'] = "sms";
  248. $notices_log['content'] = $sms_content;
  249. $notices_log['log_id'] = $this->create_id();
  250. $notices_log['mobile'] = $mobiles[$i];
  251. if($this->setting['sms_type'] == '10' ){
  252. if(send_by_modem($this->setting, $notices_log['mobile'], $sms_content)){
  253. $notices_log['status'] = "1";
  254. }else{
  255. $notices_log['status'] = "0";
  256. }
  257. }elseif($this->setting['sms_type'] == '20' ){
  258. $sms_content = array(
  259. "workorder_id"=>$workorder['workorder_id'],
  260. "workorder_name"=>$workorder['workorder_name'],
  261. "workorder_type"=>$workorder['type'],
  262. "receive_user_name"=>$receive_user['name'],
  263. "remark_content"=>$workorder['remark_list'][count($workorder['remark_list'])-1]['remark_content']
  264. );
  265. $resp = $this->Aliyunsms->sendSms($notices_log['mobile'],$this->setting['template_codes'][2],$sms_content);
  266. if($resp['Code'] == 'OK'){
  267. $notices_log['status'] = "1";
  268. }else{
  269. $notices_log['status'] = "0";
  270. }
  271. }
  272. $notices_log['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  273. $this->CI->noticeslog_model->save_notices_log($notices_log);
  274. }
  275. }
  276. if($this->setting['is_email'] && in_array("20",$workorder['send_type'])){
  277. $notices_log = $this->CI->noticeslog_model->get_model();
  278. $notices_log['log_id'] = $this->create_id();
  279. $notices_log['type'] = "email";
  280. $notices_log['subject'] = "工单ID:".$workorder['workorder_id']."已由责任人:".$receive_user['name']."核查无问题";
  281. $email_content = '<div style="font-size:12px;">';
  282. $email_content .='<p style="white-space: normal; background-color: rgb(255, 255, 255);">系统管理员,您好!</p>';
  283. $email_content .='<p style="white-space: normal; background-color: rgb(255, 255, 255); text-indent: 2em;">以下工单已由责任人:'.$receive_user['name'].'核查无问题:</p>';
  284. $email_content .='<table align="left" border="1" cellspacing="0" cellpadding="0" style="font-size:12px;"><thead>';
  285. $email_content .='<tr class="firstRow"><td valign="top" rowspan="1" colspan="5" style="word-break: break-all;">';
  286. $email_content .='<strong>工单ID:'.$workorder['workorder_id'].'</strong><strong>工单名称:'.$workorder['workorder_name'].'</strong>';
  287. $email_content .='</td></tr>';
  288. $email_content .='<tr>';
  289. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>工单名称</strong></th>';
  290. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>类型</strong></th>';
  291. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>等级</strong></th>';
  292. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>时间</strong></th>';
  293. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>告警详情</strong></th>';
  294. $email_content .='</tr></thead><tbody>';
  295. foreach($workorder['warning_list'] as $key=>$val) {
  296. $email_content .= '<tr>';
  297. $email_content .= '<td valign="top" colspan="1" rowspan="1">'.$val['warning_name'].'</td>';
  298. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.$this->warning_type[$val['type']].'</td>';
  299. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.$this->warning_level[$val['level']].'</td>';
  300. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.date("Y-m-d H:i:s",$val['create_time']->toDateTime()->getTimestamp()).'</td>';
  301. $email_content .= '<td valign="top" colspan="1" rowspan="1">'.$val['content'].'</td>';
  302. $email_content .= '</tr>';
  303. }
  304. $email_content .='<tr>';
  305. $email_content .='<td valign="top" rowspan="1" colspan="5" style="word-break: break-all;"><strong>备注:</strong>'.$remark['remark_content'] .'</td>';
  306. $email_content .='</tr>';
  307. $email_content .='</tbody></table>';
  308. $email_content .='<p><br/>&nbsp;</p><p><br/>&nbsp;</p>';
  309. $email_content .='<p style="text-align: right;">责任人:'.$receive_user['name'].'&nbsp;<br>';
  310. $email_content .=date("Y年m月d日",time()).'</p>';
  311. $email_content .='</div>';
  312. $notices_log['recipient'] = implode(",",$emails);
  313. $notices_log['content'] = $email_content;
  314. for ($i=0;$i<count($emails);$i++) {
  315. $this->CI->mailer->add_recipient($emails[$i]);
  316. }
  317. if($remark['remark_file']){
  318. $attachments = getcwd().'/static/upload'.$remark['remark_file'];
  319. }else{
  320. $attachments = null;
  321. }
  322. if ($this->CI->mailer->send_email("", $notices_log['subject'], $notices_log['content'],$attachments)) {
  323. $notices_log['status'] = "1";
  324. } else {
  325. $notices_log['status'] = "0";
  326. }
  327. $notices_log['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  328. $this->CI->noticeslog_model->save_notices_log($notices_log);
  329. }
  330. }
  331. /**
  332. * 工单已处理
  333. * @param $workorder
  334. * @param $remark
  335. */
  336. public function doit_workorder($workorder,$remark){
  337. $receive_user = $this->CI->user_model->get_user_with_user_id($workorder['receive_user_id']);
  338. $admin_list = $this->CI->user_model->select_users("1");
  339. $sso_admin_list = $this->CI->user_model->set_collection_name("sso_users")->select_users("1");
  340. $mobiles = array();
  341. $emails = array();
  342. foreach ($admin_list as $key => $val){
  343. $mobiles[] = $val['mobile'];
  344. $emails[] = $val['email'];
  345. }
  346. foreach ($sso_admin_list as $key => $val){
  347. $mobiles[] = $val['mobile'];
  348. $emails[] = $val['email'];
  349. }
  350. if($this->setting['is_sms'] && in_array("10",$workorder['send_type'])){
  351. $sms_content = '工单ID:'.$workorder['workorder_id'].',工单名称:'.$workorder['workorder_name'].',类型:'.$workorder['type'].',已由责任人'.$receive_user['name'].'处理完成,备注:'.$remark['remark_content'];
  352. for($i = 0;$i<count($mobiles);$i++) {
  353. $notices_log = $this->CI->noticeslog_model->get_model();
  354. $notices_log['type'] = "sms";
  355. $notices_log['content'] = $sms_content;
  356. $notices_log['log_id'] = $this->create_id();
  357. $notices_log['mobile'] = $mobiles[$i];
  358. if($this->setting['sms_type'] == '10' ){
  359. if(send_by_modem($this->setting, $notices_log['mobile'], $sms_content)){
  360. $notices_log['status'] = "1";
  361. }else{
  362. $notices_log['status'] = "0";
  363. }
  364. }elseif($this->setting['sms_type'] == '20' ){
  365. $sms_content = array(
  366. "workorder_id"=>$workorder['workorder_id'],
  367. "workorder_name"=>$workorder['workorder_name'],
  368. "workorder_type"=>$workorder['type'],
  369. "receive_user_name"=>$receive_user['name'],
  370. "remark_content"=>$workorder['remark_list'][count($workorder['remark_list'])-1]['remark_content']
  371. );
  372. $resp = $this->Aliyunsms->sendSms($notices_log['mobile'],$this->setting['template_codes'][3],$sms_content);
  373. if($resp['Code'] == 'OK'){
  374. $notices_log['status'] = "1";
  375. }else{
  376. $notices_log['status'] = "0";
  377. }
  378. }
  379. $notices_log['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  380. $this->CI->noticeslog_model->save_notices_log($notices_log);
  381. }
  382. }
  383. if($this->setting['is_email'] && in_array("20",$workorder['send_type'])){
  384. $notices_log = $this->CI->noticeslog_model->get_model();
  385. $notices_log['log_id'] = $this->create_id();
  386. $notices_log['type'] = "email";
  387. $notices_log['subject'] = "工单ID:".$workorder['workorder_id']."已由责任人:".$receive_user['name']."处理完成";
  388. $email_content = '<div style="font-size:12px;">';
  389. $email_content .='<p style="white-space: normal; background-color: rgb(255, 255, 255);">系统管理员,您好!</p>';
  390. $email_content .='<p style="white-space: normal; background-color: rgb(255, 255, 255); text-indent: 2em;">以下工单已由责任人:'.$receive_user['name'].'处理完成:</p>';
  391. $email_content .='<table align="left" border="1" cellspacing="0" cellpadding="0" style="font-size:12px;"><thead>';
  392. $email_content .='<tr class="firstRow"><td valign="top" rowspan="1" colspan="5" style="word-break: break-all;">';
  393. $email_content .='<strong>工单ID:'.$workorder['workorder_id'].'</strong><strong>工单名称:'.$workorder['workorder_name'].'</strong>';
  394. $email_content .='</td></tr>';
  395. $email_content .='<tr>';
  396. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>工单名称</strong></th>';
  397. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>类型</strong></th>';
  398. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>等级</strong></th>';
  399. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>时间</strong></th>';
  400. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>告警详情</strong></th>';
  401. $email_content .='</tr></thead><tbody>';
  402. foreach($workorder['warning_list'] as $key=>$val) {
  403. $email_content .= '<tr>';
  404. $email_content .= '<td valign="top" colspan="1" rowspan="1">'.$val['warning_name'].'</td>';
  405. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.$this->warning_type[$val['type']].'</td>';
  406. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.$this->warning_level[$val['level']].'</td>';
  407. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.date("Y-m-d H:i:s",$val['create_time']->toDateTime()->getTimestamp()).'</td>';
  408. $email_content .= '<td valign="top" colspan="1" rowspan="1">'.$val['content'].'</td>';
  409. $email_content .= '</tr>';
  410. }
  411. $email_content .='<tr>';
  412. $email_content .='<td valign="top" rowspan="1" colspan="5" style="word-break: break-all;"><strong>备注:</strong>'.$remark['remark_content'] .'</td>';
  413. $email_content .='</tr>';
  414. $email_content .='</tbody></table>';
  415. $email_content .='<p><br/>&nbsp;</p><p><br/>&nbsp;</p>';
  416. $email_content .='<p style="text-align: right;">责任人:'.$receive_user['name'].'&nbsp;<br>';
  417. $email_content .=date("Y年m月d日",time()).'</p>';
  418. $email_content .='</div>';
  419. $notices_log['recipient'] = implode(",",$emails);
  420. $notices_log['content'] = $email_content;
  421. for ($i=0;$i<count($emails);$i++) {
  422. $this->CI->mailer->add_recipient($emails[$i]);
  423. }
  424. if($remark['remark_file']){
  425. $attachments = getcwd().'/static/upload'.$remark['remark_file'];
  426. }else{
  427. $attachments = null;
  428. }
  429. if ($this->CI->mailer->send_email("", $notices_log['subject'], $notices_log['content'],$attachments)) {
  430. $notices_log['status'] = "1";
  431. } else {
  432. $notices_log['status'] = "0";
  433. }
  434. $notices_log['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  435. $this->CI->noticeslog_model->save_notices_log($notices_log);
  436. }
  437. }
  438. /**
  439. * 驳回工单
  440. * @param $workorder
  441. * @param $remark
  442. */
  443. public function reject_workorder($workorder,$remark){
  444. $receive_user = $this->CI->user_model->get_user_with_user_id($workorder['receive_user_id']);
  445. if($this->setting['is_sms'] && in_array("10",$workorder['send_type'])){
  446. $sms_content = '你的工单已由管理员驳回,请重新处理。工单ID:'.$workorder['workorder_id'].',工单名称:'.$workorder['workorder_name'].',类型:'.$workorder['type'].',备注:'.$remark['remark_content'];
  447. $notices_log = $this->CI->noticeslog_model->get_model();
  448. $notices_log['log_id'] = $this->create_id();
  449. $notices_log['type'] = "sms";
  450. $notices_log['mobile'] = $receive_user['mobile'];
  451. $notices_log['content'] = $sms_content;
  452. if($this->setting['sms_type'] == '10' ){
  453. if(send_by_modem($this->setting, $receive_user['mobile'], $sms_content)){
  454. $notices_log['status'] = "1";
  455. }else{
  456. $notices_log['status'] = "0";
  457. }
  458. }elseif($this->setting['sms_type'] == '20' ){
  459. $sms_content = array(
  460. "workorder_id"=>$workorder['workorder_id'],
  461. "workorder_name"=>$workorder['workorder_name'],
  462. "workorder_type"=>$workorder['type'],
  463. "remark_content"=>$workorder['remark_list'][count($workorder['remark_list'])-1]['remark_content']
  464. );
  465. $resp = $this->Aliyunsms->sendSms($receive_user['mobile'],$this->setting['template_codes'][4],$sms_content);
  466. if($resp['Code'] == 'OK'){
  467. $notices_log['status'] = "1";
  468. }else{
  469. $notices_log['status'] = "0";
  470. }
  471. }
  472. $notices_log['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  473. $this->CI->noticeslog_model->save_notices_log($notices_log);
  474. }
  475. if($this->setting['is_email'] && in_array("20",$workorder['send_type'])){
  476. $notices_log = $this->CI->noticeslog_model->get_model();
  477. $notices_log['log_id'] = $this->create_id();
  478. $notices_log['type'] = "email";
  479. $notices_log['recipient'] = $receive_user['email'];
  480. $notices_log['subject'] = "你的工单已由管理员驳回,请重新处理,工单ID:".$workorder['workorder_id'];
  481. $email_content = '<div style="font-size:12px;">';
  482. $email_content .='<p style="white-space: normal; background-color: rgb(255, 255, 255);">'.$receive_user['name'].',您好!</p>';
  483. $email_content .='<p style="white-space: normal; background-color: rgb(255, 255, 255); text-indent: 2em;">以下工单已由管理员驳回,请重新处理:</p>';
  484. $email_content .='<table align="left" border="1" cellspacing="0" cellpadding="0" style="font-size:12px;"><thead>';
  485. $email_content .='<tr class="firstRow"><td valign="top" rowspan="1" colspan="5" style="word-break: break-all;">';
  486. $email_content .='<strong>工单ID:'.$workorder['workorder_id'].'</strong><strong>工单名称:'.$workorder['workorder_name'].'</strong>';
  487. $email_content .='</td></tr>';
  488. $email_content .='<tr>';
  489. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>工单名称</strong></th>';
  490. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>类型</strong></th>';
  491. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>等级</strong></th>';
  492. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>时间</strong></th>';
  493. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>告警详情</strong></th>';
  494. $email_content .='</tr></thead><tbody>';
  495. foreach($workorder['warning_list'] as $key=>$val) {
  496. $email_content .= '<tr>';
  497. $email_content .= '<td valign="top" colspan="1" rowspan="1">'.$val['warning_name'].'</td>';
  498. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.$this->warning_type[$val['type']].'</td>';
  499. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.$this->warning_level[$val['level']].'</td>';
  500. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.date("Y-m-d H:i:s",$val['create_time']->toDateTime()->getTimestamp()).'</td>';
  501. $email_content .= '<td valign="top" colspan="1" rowspan="1">'.$val['content'].'</td>';
  502. $email_content .= '</tr>';
  503. }
  504. $email_content .='<tr>';
  505. $email_content .='<td valign="top" rowspan="1" colspan="5" style="word-break: break-all;"><strong>备注:</strong>'.$remark['remark_content'] .'</td>';
  506. $email_content .='</tr>';
  507. $email_content .='</tbody></table>';
  508. $email_content .='<p><br/>&nbsp;</p><p><br/>&nbsp;</p>';
  509. $email_content .='<p style="text-align: right;">系统管理员&nbsp;&nbsp;<br>';
  510. $email_content .=date("Y年m月d日",time()).'</p>';
  511. $email_content .='</div>';
  512. $notices_log['content'] = $email_content;
  513. if($this->CI->mailer->send_email($receive_user['email'],$notices_log['subject'],$notices_log['content'])){
  514. $notices_log['status'] = "1";
  515. }else{
  516. $notices_log['status'] = "0";
  517. }
  518. $notices_log['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  519. $this->CI->noticeslog_model->save_notices_log($notices_log);
  520. }
  521. }
  522. /**
  523. * 完成工单
  524. * @param $workorder
  525. */
  526. public function finish_workorder($workorder){
  527. $receive_user = $this->CI->user_model->get_user_with_user_id($workorder['receive_user_id']);
  528. if($this->setting['is_sms'] && in_array("10",$workorder['send_type'])){
  529. $sms_content = '你的工单已由管理员结束,工单ID:'.$workorder['workorder_id'].',工单名称:'.$workorder['workorder_name'].',类型:'.$workorder['type'];
  530. $notices_log = $this->CI->noticeslog_model->get_model();
  531. $notices_log['log_id'] = $this->create_id();
  532. $notices_log['type'] = "sms";
  533. $notices_log['mobile'] = $receive_user['mobile'];
  534. $notices_log['content'] = $sms_content;
  535. if($this->setting['sms_type'] == '10' ){
  536. if(send_by_modem($this->setting, $receive_user['mobile'], $sms_content)){
  537. $notices_log['status'] = "1";
  538. }else{
  539. $notices_log['status'] = "0";
  540. }
  541. }elseif($this->setting['sms_type'] == '20' ){
  542. $sms_content = array(
  543. "workorder_id"=>$workorder['workorder_id'],
  544. "workorder_name"=>$workorder['workorder_name'],
  545. "workorder_type"=>$workorder['type']
  546. );
  547. $resp = $this->Aliyunsms->sendSms($receive_user['mobile'],$this->setting['template_codes'][4],$sms_content);
  548. if($resp['Code'] == 'OK'){
  549. $notices_log['status'] = "1";
  550. }else{
  551. $notices_log['status'] = "0";
  552. }
  553. }
  554. $notices_log['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  555. $this->CI->noticeslog_model->save_notices_log($notices_log);
  556. }
  557. if($this->setting['is_email'] && in_array("20",$workorder['send_type'])){
  558. $notices_log = $this->CI->noticeslog_model->get_model();
  559. $notices_log['log_id'] = $this->create_id();
  560. $notices_log['type'] = "email";
  561. $notices_log['recipient'] = $receive_user['email'];
  562. $notices_log['subject'] = "你的工单已由管理员结束,工单ID:".$workorder['workorder_id'];
  563. $email_content = '<div style="font-size:12px;">';
  564. $email_content .='<p style="white-space: normal; background-color: rgb(255, 255, 255);">'.$receive_user['name'].',您好!</p>';
  565. $email_content .='<p style="white-space: normal; background-color: rgb(255, 255, 255); text-indent: 2em;">以下工单已由管理员确认结束:</p>';
  566. $email_content .='<table align="left" border="1" cellspacing="0" cellpadding="0" style="font-size:12px;"><thead>';
  567. $email_content .='<tr class="firstRow"><td valign="top" rowspan="1" colspan="5" style="word-break: break-all;">';
  568. $email_content .='<strong>工单ID:'.$workorder['workorder_id'].'</strong><strong>工单名称:'.$workorder['workorder_name'].'</strong>';
  569. $email_content .='</td></tr>';
  570. $email_content .='<tr>';
  571. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>工单名称</strong></th>';
  572. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>类型</strong></th>';
  573. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>等级</strong></th>';
  574. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>时间</strong></th>';
  575. $email_content .='<th width="147" valign="middle" style="word-break: break-all;" align="center"><strong>告警详情</strong></th>';
  576. $email_content .='</tr></thead><tbody>';
  577. foreach($workorder['warning_list'] as $key=>$val) {
  578. $email_content .= '<tr>';
  579. $email_content .= '<td valign="top" colspan="1" rowspan="1">'.$val['warning_name'].'</td>';
  580. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.$this->warning_type[$val['type']].'</td>';
  581. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.$this->warning_level[$val['level']].'</td>';
  582. $email_content .= '<td valign="middle" colspan="1" rowspan="1" align="center">'.date("Y-m-d H:i:s",$val['create_time']->toDateTime()->getTimestamp()).'</td>';
  583. $email_content .= '<td valign="top" colspan="1" rowspan="1">'.$val['content'].'</td>';
  584. $email_content .= '</tr>';
  585. }
  586. $email_content .='</tbody></table>';
  587. $email_content .='<p><br/>&nbsp;</p><p><br/>&nbsp;</p>';
  588. $email_content .='<p style="text-align: right;">系统管理员&nbsp;&nbsp;<br>';
  589. $email_content .=date("Y年m月d日",time()).'</p>';
  590. $email_content .='</div>';
  591. $notices_log['content'] = $email_content;
  592. if($this->CI->mailer->send_email($receive_user['email'],$notices_log['subject'],$notices_log['content'])){
  593. $notices_log['status'] = "1";
  594. }else{
  595. $notices_log['status'] = "0";
  596. }
  597. $notices_log['create_time'] = new MongoDB\BSON\UTCDateTime(time()*1000);
  598. $this->CI->noticeslog_model->save_notices_log($notices_log);
  599. }
  600. }
  601. /**
  602. * 生成ID
  603. * @return string
  604. */
  605. public function create_id()
  606. {
  607. return date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
  608. }
  609. }