Setting.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. $resp = $this->mailer->send_email($setting['tester'], "邮件发送测试!", "邮件发送测试!如果收到这封邮件说明的邮箱配置已经成功!");
  79. if ($resp['code'] == "OK") {
  80. $msg .= "邮件发送成功!";
  81. } else {
  82. $msg .= "邮件发送失败!请检查配置!";
  83. }
  84. } else {
  85. $msg .= "未启用邮件发送!";
  86. }
  87. if ($setting['is_sms']) {
  88. if($setting['sms_type']=='10'){
  89. if(send_by_modem($setting, $setting['test_phone'], "短息发送成!收到该短信说明短信发送已经配置成功!")) {
  90. $msg .= "短信发送成功!如未收到短信请检查配置!";
  91. }else{
  92. $msg .= "短信发送失败!端口被占用或者配置错误!";
  93. }
  94. }elseif($setting['sms_type']=='20'){
  95. $sms_content = array("sys_name"=> $this->config->item('sys_name'));
  96. $resp = $this->aliyunsms->sendSms($setting['test_phone'],$setting['template_codes'][6],$sms_content);
  97. if($resp['Code'] == 'OK'){
  98. $msg .= "短信发送成功!如未收到短信请检查配置!";
  99. }else{
  100. $msg .= "短信发送失败!".$resp['Message'] ;
  101. }
  102. }
  103. } else {
  104. $msg .= "未启用短信发送!";
  105. }
  106. $this->response(array("icon" => 1, "msg" => $msg));
  107. } else {
  108. $this->response(array("icon" => 2, "msg" => "未配置短信和邮箱不能测试发送!"));
  109. }
  110. }
  111. /**
  112. * 配置向导
  113. */
  114. public function step(){
  115. $setting= $this->cache->get('setting');
  116. if (!$setting) {
  117. $setting = $this->setting_model->get_model();
  118. }
  119. $this->assign("setting", $setting);
  120. $this->display("setting/step.html");
  121. }
  122. /**
  123. * 设置已完成工单保存时间
  124. */
  125. public function savetime(){
  126. if ($this->input->post()) {
  127. $save_time= $this->input->post("save_time", true);
  128. $setting = $this->setting_model->get_setting();
  129. $setting['save_time'] = $save_time;
  130. $this->setting_model->update_setting($setting);
  131. $this->update_cahce();
  132. $this->response(array("code" => 1, "icon" => 1, "msg" => "已完成工单保存时间修改成功!"));
  133. }else{
  134. $this->response(array("code" => 2, "icon" => 2, "msg" => "请勿非法提交数据!"));
  135. }
  136. }
  137. /**
  138. * 清除缓存
  139. */
  140. public function clearcache(){
  141. if($this->cache->clean()) {
  142. $this->ci_smarty->clearAllCache();
  143. $this->response(array("code" => 1, "icon" => 1, "msg" => "缓存清除成功!"));
  144. }else{
  145. $this->response(array("code" => 2, "icon" => 2, "msg" => "缓存清除失败!请检查application/cache目录是否有写权限!"));
  146. }
  147. }
  148. }