Message.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com.cn
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\admin\controller;
  13. use app\model\message\Email as EmailModel;
  14. use app\model\message\Message as MessageModel;
  15. use app\model\message\Sms;
  16. /**
  17. * 消息管理 控制器
  18. */
  19. class Message extends BaseAdmin
  20. {
  21. /**
  22. * 消息管理 列表
  23. */
  24. public function lists(){
  25. $message_model = new MessageModel();
  26. //买家消息
  27. $member_message_list_result = $message_model->getMessageList([["message_type", "=", 1]]);
  28. $member_message_list = $member_message_list_result["data"];
  29. $this->assign("member_message_list", $member_message_list);
  30. //卖家通知
  31. $shop_message_list_result = $message_model->getMessageList([["message_type", "=", 2]]);
  32. $shop_message_list = $shop_message_list_result["data"];
  33. $this->assign("shop_message_list", $shop_message_list);
  34. return $this->fetch("message/lists");
  35. }
  36. /**
  37. * 编辑短信模板(跳转)
  38. */
  39. public function editSmsMessage(){
  40. $keywords = input("keywords", '');
  41. $sms_model = new Sms();
  42. $edit_data_result = $sms_model->doEditSmsMessage();
  43. if(empty($edit_data_result["data"][0]))
  44. $this->error("没有开启的短信方式!");
  45. $edit_data = $edit_data_result["data"][0];
  46. $edit_url = $edit_data["edit_url"];
  47. $this->redirect(addon_url($edit_url, ["keywords" => $keywords]));
  48. }
  49. /**
  50. * 短信列表
  51. */
  52. public function sms(){
  53. if(request()->isAjax()){
  54. $sms_model = new Sms();
  55. $list = $sms_model->getSmsType();
  56. return $list;
  57. }else{
  58. $this->forthMenu();
  59. return $this->fetch("message/sms");
  60. }
  61. }
  62. /**
  63. * 短信记录
  64. */
  65. public function smsRecords(){
  66. if(request()->isAjax()){
  67. $sms_model = new Sms();
  68. $page = input('page', 1);
  69. $page_size = input('page_size', PAGE_LIST_ROWS);
  70. $search_text = input('search_text', '');
  71. $status = input('status', 'all');
  72. $condition = [];
  73. if(!empty($search_text)){
  74. $condition[] = ["keywords_name", "like", "%".$search_text."%"];
  75. }
  76. if (!empty($status) && $status != 'all') {
  77. if ($status == -1) {
  78. $condition[] = ['status', 'not in', [0, 1, '']];
  79. } else {
  80. $condition[] = ['status', '=', $status-1];
  81. }
  82. }
  83. $list = $sms_model->getSmsRecordsPageList($condition, $page, $page_size);
  84. return $list;
  85. }else{
  86. $this->forthMenu();
  87. return $this->fetch("message/smsrecords");
  88. }
  89. }
  90. /**
  91. * 删除短信记录
  92. */
  93. public function deleteSmsRecords(){
  94. if(request()->isAjax()) {
  95. $ids = input("ids", "");
  96. $sms_model = new Sms();
  97. $condition = array(
  98. ["id", "in", $ids]
  99. );
  100. $result = $sms_model->deleteSmsRecords($condition);
  101. return $result;
  102. }
  103. }
  104. /**
  105. * 邮箱配置
  106. */
  107. public function email(){
  108. $email_model = new EmailModel();
  109. if(request()->isAjax()) {
  110. $host = input("host", '');//SMTP服务器
  111. $port = input("port", '');//SMTP端口
  112. $from = input("from", '');//发信人邮件地址
  113. $username = input("username", '');//SMTP身份验证用户名
  114. $password = input("password", '');//SMTP身份验证码
  115. $is_auth = input("is_auth", 0);//是否使用安全链接
  116. $is_use = input("is_use", 0);//是否开启
  117. $data = array(
  118. "host" => $host,
  119. "port" => $port,
  120. "from" => $from,
  121. "username" => $username,
  122. "password" => $password,
  123. "is_auth" => $is_auth,
  124. );
  125. $result = $email_model->setEmailConfig($data, $is_use);
  126. return $result;
  127. }else{
  128. $this->forthMenu();
  129. $config_info = $email_model->getEmailConfig();
  130. $this->assign('config_info', $config_info["data"]["value"]);
  131. $this->assign('is_use', $config_info['data']['is_use']);
  132. return $this->fetch("message/email");
  133. }
  134. }
  135. /**
  136. * 测试发送邮箱
  137. */
  138. public function testSendEmail(){
  139. $email_model = new EmailModel();
  140. if(request()->isAjax()) {
  141. $test_address = input("test_address", '');//测试邮箱地址
  142. if(empty($test_address))
  143. return error(-1, "测试邮箱地址不可为空!");
  144. $subject = "测试发送";
  145. $body = "测试发送";
  146. $data = array(
  147. "host" => input("host", ""),
  148. "username" => input("username", ""),
  149. "password" => input("password", ""),
  150. "port" => input("port", ""),
  151. "from" => input("from", ""),
  152. "from_name" => input("from", ""),
  153. "address" => $test_address,
  154. "subject" => $subject,
  155. "body" => $body,
  156. "is_auth" => input("is_auth", ""),
  157. "attachment" => input("attachment", ""),
  158. "attachment_name" => input("attachment_name", ""),
  159. );
  160. $res = $email_model->send($data);
  161. return $res;
  162. }
  163. }
  164. /**
  165. * 邮箱记录
  166. */
  167. public function emailRecords(){
  168. if(request()->isAjax()){
  169. $email_model = new EmailModel();
  170. $page = input('page', 1);
  171. $page_size = input('page_size', PAGE_LIST_ROWS);
  172. $search_text = input('search_text', '');
  173. $status = input('status', 'all');
  174. $condition = [];
  175. if(!empty($search_text)){
  176. $condition[] = ["title", "like", "%".$search_text."%"];
  177. }
  178. if (!empty($status) && $status != 'all') {
  179. if ($status == -1) {
  180. $condition[] = ['status', 'not in', [0, 1, '']];
  181. } else {
  182. $condition[] = ['status', '=', $status-1];
  183. }
  184. }
  185. $list = $email_model->getEmailRecordsPageList($condition, $page, $page_size);
  186. return $list;
  187. }else{
  188. $this->forthMenu();
  189. return $this->fetch("message/emailrecords");
  190. }
  191. }
  192. /**
  193. * 删除邮件记录
  194. */
  195. public function deleteEmailRecords(){
  196. if(request()->isAjax()) {
  197. $ids = input("ids", "");
  198. $email_model = new EmailModel();
  199. $condition = array(
  200. ["id", "in", $ids]
  201. );
  202. $result = $email_model->deleteEmailRecords($condition);
  203. return $result;
  204. }
  205. }
  206. /**
  207. * 编辑短信模板(跳转)
  208. */
  209. public function editEmailMessage(){
  210. $message_model = new MessageModel();
  211. $keywords = input("keywords", "");
  212. $info_result = $message_model->getMessageInfo([["keywords", "=",$keywords ]]);
  213. $info = $info_result["data"];
  214. if (request()->isAjax()) {
  215. if(empty($info))
  216. return error(-1, "不存在的模板信息!");
  217. $email_title = input("email_title", '');//邮件标题
  218. $email_content = input("email_content", '');//邮件内容
  219. $email_is_open = input("email_is_open", 0);//邮件开关
  220. $data = array(
  221. 'email_title' => $email_title,
  222. 'email_content' => $email_content,
  223. "email_is_open" => $email_is_open,
  224. );
  225. $condition = array(
  226. ["keywords", "=", $keywords]
  227. );
  228. $this->addLog("编辑邮箱模板:".$keywords);
  229. $res = $message_model->editMessage($data, $condition);
  230. return $res;
  231. } else {
  232. if(empty($info))
  233. $this->error("不存在的模板信息!");
  234. $email_title = $info["email_title"];//邮件标题
  235. $email_content = $info["email_content"];//邮件内容
  236. $email_is_open = $info["email_is_open"];//邮件开关
  237. $this->assign("email_title", $email_title);
  238. $this->assign("email_content", $email_content);
  239. $this->assign("email_is_open", $email_is_open);
  240. $this->assign("keywords", $keywords);
  241. //模板变量
  242. $message_variable_list = $info["message_json_array"];
  243. $this->assign("message_variable_list", $message_variable_list);
  244. return $this->fetch("message/edit_email_message");
  245. }
  246. }
  247. }