人人商城

special.ctrl.php 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. uni_user_permission_check('platform_special');
  8. $dos = array('display', 'set', 'cancel', 'message', 'search_key');
  9. $do = !empty($_GPC['do']) && in_array($do, $dos) ? $do : 'display';
  10. load()->model('reply');
  11. load()->model('account');
  12. $_W['account']['modules'] = uni_modules();
  13. if($_W['isajax']) {
  14. if($do == 'search_key') {
  15. $condition = '';
  16. $key_word = trim($_GPC['key_word']);
  17. if(!empty($key_word)) {
  18. $condition = " AND content LIKE '%{$key_word}%' ";
  19. }
  20. $data = pdo_fetchall('SELECT content FROM ' . tablename('rule_keyword') . " WHERE (uniacid = 0 OR uniacid = :uniacid) AND status != 0 " . $condition . ' ORDER BY uniacid DESC,displayorder DESC LIMIT 100', array(':uniacid' => $_W['uniacid']));
  21. $exit_da = array();
  22. if(!empty($data)) {
  23. foreach($data as $da) {
  24. $exit_da[] = $da['content'];
  25. }
  26. }
  27. exit(json_encode($exit_da));
  28. }
  29. exit('error');
  30. }
  31. if($do == 'display') {
  32. $_W['page']['title'] = '系统回复 - 特殊回复 - 高级功能';
  33. if (checksubmit('submit')) {
  34. $settings = array(
  35. 'default' => trim($_GPC['default']),
  36. 'welcome' => trim($_GPC['welcome']),
  37. );
  38. $item = pdo_fetch('SELECT uniacid FROM '.tablename('uni_settings')." WHERE uniacid=:uniacid", array(':uniacid' => $_W['uniacid']));
  39. if(!empty($item)){
  40. pdo_update('uni_settings', $settings, array('uniacid' => $_W['uniacid']));
  41. }else{
  42. $settings['uniacid'] = $_W['uniacid'];
  43. pdo_insert('uni_settings', $settings);
  44. }
  45. cache_delete("unisetting:{$_W['uniacid']}");
  46. message('系统回复更新成功!', url('platform/special/display'));
  47. }
  48. $setting = uni_setting($_W['uniacid'], array('default', 'welcome'));
  49. template('platform/special-display');
  50. exit;
  51. }
  52. if($do == 'message') {
  53. $_W['page']['title'] = '特殊消息类型处理 - 特殊回复 - 高级功能';
  54. $mtypes = array();
  55. $mtypes['image'] = '图片消息';
  56. $mtypes['voice'] = '语音消息';
  57. $mtypes['video'] = '视频消息';
  58. $mtypes['shortvideo'] = '小视频消息';
  59. $mtypes['location'] = '位置消息';
  60. $mtypes['trace'] = '上报地理位置';
  61. $mtypes['link'] = '链接消息';
  62. $mtypes['merchant_order'] = '微小店消息';
  63. $mtypes['ShakearoundUserShake'] = '摇一摇:开始摇一摇消息';
  64. $mtypes['ShakearoundLotteryBind'] = '摇一摇:摇到了红包消息';
  65. $mtypes['WifiConnected'] = 'Wifi连接成功消息';
  66. if(checksubmit()) {
  67. $ms = array();
  68. foreach($_W['account']['modules'] as $m) {
  69. $ms[] = $m['name'];
  70. }
  71. $setting = $_GPC['setting'];
  72. foreach($setting as $modulename => &$message_handler) {
  73. if (empty($message_handler['module']) && empty($message_handler['keyword'])) {
  74. unset($setting[$modulename]);
  75. }
  76. if(!empty($message_handler['module']) && $message_handler['type'] == 'module' && !in_array($message_handler['module'], $ms)) {
  77. message($message_handler['module'] . "选择的处理模块无效. ");
  78. }
  79. }
  80. if(uni_setting_save('default_message', $setting)) {
  81. message('保存特殊类型消息处理成功.', 'refresh');
  82. } else {
  83. message('保存失败, 请稍后重试. ');
  84. }
  85. }
  86. $setting = uni_setting_load('default_message', $_W['uniacid']);
  87. $setting = $setting['default_message'];
  88. if (!empty($setting)) {
  89. foreach ($setting as $modulename => $row) {
  90. if (!is_array($row)) {
  91. $setting[$modulename] = array(
  92. 'type' => 'module',
  93. 'module' => $row,
  94. );
  95. }
  96. }
  97. } else {
  98. $setting = array();
  99. }
  100. $ds = array();
  101. foreach($mtypes as $k => $v) {
  102. $row = array();
  103. $row['type'] = $k;
  104. $row['title'] = $v;
  105. $row['handles'] = array();
  106. foreach($_W['account']['modules'] as $m) {
  107. if(is_array($_W['account']['modules'][$m['name']]['handles']) && in_array($k, $_W['account']['modules'][$m['name']]['handles'])) {
  108. $row['handles'][] = array('name' => $m['name'], 'title' => $_W['account']['modules'][$m['name']]['title']);
  109. }
  110. }
  111. $ds[] = $row;
  112. }
  113. template('platform/special-message');
  114. }
  115. if($do == 'set') {
  116. $rid = intval($_GPC['id']);
  117. $rule = pdo_fetch("SELECT id, module FROM ".tablename('rule')." WHERE id = :id", array(':id' => $rid));
  118. if (empty($rule)) {
  119. message('抱歉,要设置的规则不存在或是已经被删除!', '', 'error');
  120. }
  121. $value = iserializer(array(
  122. 'module' => $rule['module'],
  123. 'id' => $rid,
  124. ));
  125. if ($_GPC['type'] == 'default') {
  126. $data = array(
  127. 'default' => $value,
  128. );
  129. } elseif ($_GPC['type'] == 'welcome') {
  130. $data = array(
  131. 'welcome' => $value,
  132. );
  133. }
  134. pdo_update('uni_settings', $data, array('uniacid' => $_W['uniacid']));
  135. cache_delete("unisetting:{$_W['uniacid']}");
  136. message('设置系统回复更新成功!', referer(), 'success');
  137. }
  138. if($do == 'cancel') {
  139. if ($_GPC['type'] == 'default') {
  140. $data = array(
  141. 'default' => '',
  142. );
  143. } elseif ($_GPC['type'] == 'welcome') {
  144. $data = array(
  145. 'welcome' => '',
  146. );
  147. }
  148. pdo_update('uni_settings', $data, array('uniacid' => $_W['uniacid']));
  149. cache_delete("unisetting:{$_W['uniacid']}");
  150. message('取消系统回复成功!', referer(), 'success');
  151. }