SettingsController.class.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?php
  2. /**
  3. * 小梦科技资源nanodreamtech.com
  4. *
  5. * ==========================================================================
  6. * @link https://www.nanodreamtech.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license https://www.nanodreamtech.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Admin\Controller;
  15. class SettingsController extends CommonController{
  16. protected function _initialize(){
  17. parent::_initialize();
  18. $this->breadcrumb1='系统';
  19. }
  20. function other(){
  21. $this->breadcrumb2='其他选项';
  22. $this->other=$this->get_config_by_group('other');
  23. $this->display();
  24. }
  25. function image(){
  26. $this->breadcrumb2='图片尺寸';
  27. $this->image=$this->get_config_by_group('image');
  28. $this->display();
  29. }
  30. function general(){
  31. $this->breadcrumb2='基本信息';
  32. $this->site=$this->get_config_by_group('site');
  33. $this->display();
  34. }
  35. function wxprogram()
  36. {
  37. $this->breadcrumb2='微信小程序配置';
  38. $this->site=$this->get_config_by_group('weixin');
  39. $this->type = 1;
  40. $this->display();
  41. }
  42. function wxprogram_template()
  43. {
  44. $this->breadcrumb2='微信小程序配置';
  45. $this->site=$this->get_config_by_group('weixin');
  46. $this->type = 2;
  47. $this->display();
  48. }
  49. function wxtempmsg()
  50. {
  51. $this->breadcrumb2='微信模板消息';
  52. $this->site=$this->get_config_by_group('weixin');
  53. $this->type = 1;
  54. $this->display();
  55. }
  56. function sendallwxmsg()
  57. {
  58. $this->breadcrumb2='微信模板消息';
  59. $this->type = 2;
  60. $this->display();
  61. }
  62. function sendallcuswxmsg()
  63. {
  64. $this->breadcrumb3='微信客服消息';
  65. $this->type = 3;
  66. $this->display();
  67. }
  68. function clearuserqrcode()
  69. {
  70. $result = array('code' =>1);
  71. $sql = "update ".C('DB_PREFIX')."member_common set qrcode_img ='' where member_id>0 ";
  72. M()->execute($sql);
  73. echo json_encode($result);
  74. die();
  75. }
  76. function sendallcuswxmsg_save()
  77. {
  78. $data = I('post.');
  79. @set_time_limit(0);
  80. $template_data = array();
  81. if( empty($data['title']) )
  82. {
  83. $this->error('请填写标题');
  84. }
  85. if( empty($data['image']) )
  86. {
  87. $this->error('请上传封面图片');
  88. }
  89. if( empty($data['url_link']) )
  90. {
  91. $this->error('请填写链接');
  92. }
  93. $data['image'] = C('SITE_URL').'/Uploads/image/'.$data['image'];
  94. $template_data['title'] = $data['title'];
  95. $template_data['image'] = $data['image'];
  96. $template_data['descript'] = $data['descript'];
  97. $user_list = M('member')->select();
  98. foreach($user_list as $user)
  99. {
  100. if(empty($user['openid']))
  101. {
  102. continue;
  103. }
  104. $msg_order = array();
  105. $msg_order['template_data'] = serialize($template_data);
  106. $msg_order['url'] = $data['url_link'];
  107. $msg_order['type'] = 1;
  108. $msg_order['open_id'] = $user['openid'];
  109. $msg_order['template_id'] = 8888;
  110. $msg_order['state'] = 0;
  111. $msg_order['addtime'] = time();
  112. M('template_msg_order')->add($msg_order);
  113. }
  114. $this->success('保存成功,客服消息将会陆续发出!');
  115. }
  116. /**
  117. 群发自定义模板消息
  118. **/
  119. function sendallmodifywxmsg()
  120. {
  121. $this->type =4;
  122. $this->display();
  123. }
  124. /**
  125. 分析模板消息模板
  126. **/
  127. function sendallmodifywxmsg_analys()
  128. {
  129. $this->type =4;
  130. $moban = I('post.moban');
  131. $str = str_replace(array("\r\n", "\r", "\n"), "", $moban);
  132. preg_match_all('/{{(.*?)}}/',$str,$contain_arr);
  133. $data = $contain_arr[1];
  134. if(empty($data))
  135. {
  136. $this->error('模板格式错误');
  137. }
  138. $this->moban = $moban;
  139. $this->data = $data;
  140. $this->display();
  141. }
  142. /**
  143. 自定义模板消息保存
  144. **/
  145. public function sendallmodifywxmsg_save()
  146. {
  147. @set_time_limit(0);
  148. $data = I('post.');
  149. $url_link = $data['url_link'];
  150. $moban_id = $data['moban_id'];
  151. unset($data['url_link']);
  152. unset($data['moban_id']);
  153. $template_data = array();
  154. $page = empty($data['page']) ? 1: intval($data['page']);
  155. unset($data['page']);
  156. $per_count = 100;
  157. $offset = ($page-1)*$per_count;
  158. $total_count = M('member')->count();
  159. foreach($data as $key => $val)
  160. {
  161. if( strpos($key,'_color') === false )
  162. {
  163. $real_key = explode('_',$key);
  164. $tp_key = $real_key[0];
  165. $tp_color = empty($data[$key.'_color']) ? '#173177': trim($data[$key.'_color']);
  166. $template_data[$tp_key] = array('value' => ($val), 'color' => $tp_color);
  167. }
  168. }
  169. $template_id = $moban_id;
  170. $has_next = ( $total_count > ($offset+$per_count) ) ? 1:0;
  171. $del_count = $total_count - ($offset+$per_count);
  172. $user_list = M('member')->order('member_id asc')->limit($offset,$per_count)->select();
  173. foreach($user_list as $user)
  174. {
  175. if(empty($user['openid']))
  176. {
  177. continue;
  178. }
  179. $msg_order = array();
  180. $msg_order['template_data'] = serialize($template_data);
  181. $msg_order['url'] = $url_link;
  182. $msg_order['open_id'] = $user['openid'];
  183. $msg_order['template_id'] = $template_id;
  184. $msg_order['state'] = 0;
  185. $msg_order['addtime'] = time();
  186. M('template_msg_order')->add($msg_order);
  187. }
  188. $result = array();
  189. $result['code'] = 1;
  190. $result['has_next'] = $has_next;
  191. $result['del_count'] = $del_count;
  192. $result['offset'] = $offset;
  193. $result['per_count'] = $per_count;
  194. echo json_encode($result);
  195. die();
  196. //$this->success('保存成功,消息将会陆续发出!','/Settings/sendallmodifywxmsg');
  197. }
  198. function sendallwxmsg_save()
  199. {
  200. $data = I('post.');
  201. @set_time_limit(0);
  202. $title_color = empty($data['title_color']) ? '#173177':trim($data['title_color']);
  203. $goods_name_color = empty($data['goods_name_color']) ? '#173177':trim($data['goods_name_color']);
  204. $lian_man_color = empty($data['lian_man_color']) ? '#173177':trim($data['lian_man_color']);
  205. $lian_mobile_color = empty($data['lian_mobile_color']) ? '#173177':trim($data['lian_mobile_color']);
  206. $qv_address_color = empty($data['qv_address_color']) ? '#173177':trim($data['qv_address_color']);
  207. $description_color = empty($data['description_color']) ? '#173177':trim($data['description_color']);
  208. $template_data = array();
  209. $template_data['first'] = array('value' => ($data['title']), 'color' => $title_color);
  210. $template_data['keyword1'] = array('value' => ($data['goods_name']), 'color' => $goods_name_color);
  211. $template_data['keyword2'] = array('value' => ($data['lian_man']), 'color' => $lian_man_color);
  212. $template_data['keyword3'] = array('value' => ($data['lian_mobile']), 'color' => $lian_mobile_color);
  213. $template_data['keyword4'] = array('value' => ($data['qv_address']), 'color' => $qv_address_color);
  214. $template_data['remark'] = array('value' => ($data['description']), 'color' => $description_color);
  215. $url = $data['url_link'];
  216. $config = M('config')->where( array('name' => 'GoodsOnNoticeId') )->find();
  217. $template_id = $config['value'];
  218. $user_list = M('member')->select();
  219. foreach($user_list as $user)
  220. {
  221. if(empty($user['openid']))
  222. {
  223. continue;
  224. }
  225. $msg_order = array();
  226. $msg_order['template_data'] = serialize($template_data);
  227. $msg_order['url'] = $url;
  228. $msg_order['open_id'] = $user['openid'];
  229. $msg_order['template_id'] = $template_id;
  230. $msg_order['state'] = 0;
  231. $msg_order['addtime'] = time();
  232. M('template_msg_order')->add($msg_order);
  233. }
  234. $this->success('保存成功,消息将会陆续发出!');
  235. }
  236. function smtp_mail(){
  237. $this->breadcrumb2='邮件配置';
  238. $this->smtp=$this->get_config_by_group('smtp');
  239. $this->display();
  240. }
  241. function get_config_by_group($group){
  242. $list=M('config')->where(array('config_group'=>$group))->select();
  243. if(isset($list)){
  244. foreach ($list as $k => $v) {
  245. $config[$v['name']]=$v;
  246. }
  247. }
  248. return $config;
  249. }
  250. function save(){
  251. if(IS_POST){
  252. $config=I('post.');
  253. if($config && is_array($config)){
  254. $c=M('Config');
  255. foreach ($config as $name => $value) {
  256. $map = array('name' => $name);
  257. $c->where($map)->setField('value', $value);
  258. }
  259. }
  260. S('DB_CONFIG_DATA',null);
  261. $this->success('保存成功!');
  262. }
  263. }
  264. }
  265. ?>