Setting.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /**
  4. * Class 设置类
  5. */
  6. class Setting extends MY_controller
  7. {
  8. function __construct()
  9. {
  10. parent::__construct();
  11. $this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
  12. $this->load->helper(array('form', 'url', 'date', 'sms'));
  13. $this->load->model("setting_model");
  14. $this->load->library('aliyunsms');
  15. $this->assign("setting", $this->cache->get('setting'));
  16. }
  17. /**
  18. * 设置短信和邮件
  19. */
  20. public function setting()
  21. {
  22. if ($this->input->post()) {
  23. $data['setting_id'] = $this->input->post("setting_id", true);
  24. $data['is_sms'] = $this->input->post("is_sms", true);
  25. $data['sms_type'] = $this->input->post("sms_type", true);
  26. $data['serial_port'] = $this->input->post("serial_port", true);
  27. $data['baud_rate'] = $this->input->post("baud_rate", true);
  28. $data['sms_cneter_num'] = $this->input->post("sms_cneter_num", true);
  29. $data['test_phone'] = $this->input->post("test_phone", true);
  30. $data['product'] = $this->input->post("product", true);
  31. $data['access_key_id'] = $this->input->post("access_key_id", true);
  32. $data['access_key_secret'] = $this->input->post("access_key_secret", true);
  33. $data['sign_name'] = $this->input->post("sign_name", true);
  34. $data['template_codes'] = $this->input->post("template_codes", true);
  35. $data['is_email'] = $this->input->post("is_email", true);
  36. $data['server'] = $this->input->post("server", true);
  37. $data['smtp_secure'] = $this->input->post("smtp_secure", true);
  38. $data['port'] = $this->input->post("port", true);
  39. $data['sender'] = $this->input->post("sender", true);
  40. $data['secret_key'] = $this->input->post("secret_key", true);
  41. $data['tester'] = $this->input->post("tester", true);
  42. if ($data['setting_id']) {
  43. $this->setting_model->update_setting($data);
  44. } elseif($data['is_sms'] != null && $data['is_email'] != null) {
  45. $data['setting_id'] = $this->create_id();
  46. $data['save_time'] = "180";
  47. $this->setting_model->save_setting($data);
  48. }
  49. $this->update_cahce();
  50. $this->response(array("code" => 1, "icon" => 1, "msg" => "配置信息保存成功!"));
  51. } else {
  52. $setting= $this->cache->get('setting');
  53. if (!$setting) {
  54. $setting = $this->setting_model->get_model();
  55. }
  56. $this->assign("setting", $setting);
  57. $this->display("setting/setting.html");
  58. }
  59. }
  60. /**
  61. * 更新设置缓存
  62. */
  63. private function update_cahce(){
  64. $setting = $this->setting_model->get_setting();
  65. $this->cache->save('setting', $setting, 30000);
  66. }
  67. /**
  68. * 测试发送
  69. */
  70. public function test()
  71. {
  72. $setting = $this->setting_model->get_setting();
  73. if ($setting) {
  74. $msg = "";
  75. if ($setting['is_email']) {
  76. $this->load->library('mailer');
  77. $this->mailer->set_config($setting);
  78. if ($this->mailer->send_email($setting['tester'], "邮件发送测试!", "邮件发送测试!如果收到这封邮件说明的邮箱配置已经成功!")) {
  79. $msg .= "邮件发送成功!";
  80. } else {
  81. $msg .= "邮件发送失败!请检查配置!";
  82. }
  83. } else {
  84. $msg .= "未启用邮件发送!";
  85. }
  86. if ($setting['is_sms']) {
  87. if($setting['sms_type']=='10'){
  88. if(send_by_modem($setting, $setting['test_phone'], "短息发送成!收到该短信说明短信发送已经配置成功!")) {
  89. $msg .= "短信发送成功!如未收到短信请检查配置!";
  90. }else{
  91. $msg .= "短信发送失败!端口被占用或者配置错误!";
  92. }
  93. }elseif($setting['sms_type']=='20'){
  94. $sms_content = array("sys_name"=> $this->config->item('sys_name'));
  95. $resp = $this->aliyunsms->sendSms($setting['test_phone'],$setting['template_codes'][6],$sms_content);
  96. if($resp['Code'] == 'OK'){
  97. $msg .= "短信发送成功!如未收到短信请检查配置!";
  98. }else{
  99. $msg .= "短信发送失败!".$resp['Code'] ;
  100. }
  101. }
  102. } else {
  103. $msg .= "未启用短信发送!";
  104. }
  105. $this->response(array("icon" => 1, "msg" => $msg));
  106. } else {
  107. $this->response(array("icon" => 2, "msg" => "未配置短信和邮箱不能测试发送!"));
  108. }
  109. }
  110. /**
  111. * 配置向导
  112. */
  113. public function step(){
  114. $setting= $this->cache->get('setting');
  115. if (!$setting) {
  116. $setting = $this->setting_model->get_model();
  117. }
  118. $this->assign("setting", $setting);
  119. $this->display("setting/step.html");
  120. }
  121. /**
  122. * 设置已完成工单保存时间
  123. */
  124. public function savetime(){
  125. if ($this->input->post()) {
  126. $save_time= $this->input->post("save_time", true);
  127. $setting = $this->setting_model->get_setting();
  128. $setting['save_time'] = $save_time;
  129. $this->setting_model->update_setting($setting);
  130. $this->update_cahce();
  131. $this->response(array("code" => 1, "icon" => 1, "msg" => "已完成工单保存时间修改成功!"));
  132. }else{
  133. $this->response(array("code" => 2, "icon" => 2, "msg" => "请勿非法提交数据!"));
  134. }
  135. }
  136. /**
  137. * 清除缓存
  138. */
  139. public function clearcache(){
  140. if($this->cache->clean()) {
  141. $this->ci_smarty->clearAllCache();
  142. $this->response(array("code" => 1, "icon" => 1, "msg" => "缓存清除成功!"));
  143. }else{
  144. $this->response(array("code" => 2, "icon" => 2, "msg" => "缓存清除失败!请检查application/cache目录是否有写权限!"));
  145. }
  146. }
  147. }