Notices.php 39 KB

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