人人商城

chats.ctrl.php 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. load()->model('mc');
  8. load()->classs('wesession');
  9. load()->classs('account');
  10. load()->model('material');
  11. $dos = array('chats', 'send', 'endchats');
  12. $do = in_array($do , $dos) ? $do : 'chats';
  13. permission_check_account_user('mc_fans');
  14. if ($do == 'chats') {
  15. $account_api = WeAccount::createByUniacid();
  16. $supports = $account_api->getMaterialSupport();
  17. $show_chast_content = $supports['chats'];
  18. $_W['page']['title'] = '粉丝聊天';
  19. $openid = addslashes($_GPC['openid']);
  20. $fans_info = mc_fansinfo($openid);
  21. if (!empty($fans_info['uid'])) {
  22. $fans_info['member_info'] = mc_fetch($fans_info['uid']);
  23. }
  24. $chat_record = pdo_getslice('mc_chats_record', array('uniacid' => $_W['uniacid'], 'openid' => $openid), array('1', 20), $total, array(), '', 'createtime desc');
  25. $chat_record = mc_fans_chats_record_formate($chat_record);
  26. }
  27. if ($do == 'send') {
  28. $content_formate = mc_send_content_formate($_GPC);
  29. $send = $content_formate['send'];
  30. $content = $content_formate['content'];
  31. $account_api = WeAccount::createByUniacid();
  32. $result = $account_api->sendCustomNotice($send);
  33. if (is_error($result)) {
  34. iajax(-1, $result['message']);
  35. } else {
  36. $account = account_fetch($_W['acid']);
  37. $message['from'] = $_W['openid'] = $send['touser'];
  38. $message['to'] = $account['original'];
  39. if(!empty($message['to'])) {
  40. $sessionid = md5($message['from'] . $message['to'] . $_W['uniacid']);
  41. session_id($sessionid);
  42. WeSession::start($_W['uniacid'], $_W['openid'], 300);
  43. $processor = WeUtility::createModuleProcessor('chats');
  44. $processor->begin(300);
  45. }
  46. if($send['msgtype'] == 'mpnews') {
  47. $material = pdo_getcolumn('wechat_attachment', array('uniacid' => $_W['uniacid'], 'media_id' => $content['mediaid']), 'id');
  48. $content = $content['thumb'];
  49. }
  50. pdo_insert('mc_chats_record',array(
  51. 'uniacid' => $_W['uniacid'],
  52. 'acid' => $acid,
  53. 'flag' => 1,
  54. 'openid' => $send['touser'],
  55. 'msgtype' => $send['msgtype'],
  56. 'content' => iserializer($send[$send['msgtype']]),
  57. 'createtime' => TIMESTAMP,
  58. ));
  59. iajax(0, array('createtime' => date('Y-m-d H:i:s', time()), 'content' => $content, 'msgtype' => $send['msgtype']), '');
  60. }
  61. }
  62. if ($do == 'endchats') {
  63. $openid = trim($_GPC['openid']);
  64. if (empty($openid)) {
  65. iajax(1, '粉丝openid不合法', '');
  66. }
  67. $fans_info = mc_fansinfo($openid);
  68. $account = account_fetch($fans_info['acid']);
  69. $message['from'] = $_W['openid'] = $openid['openid'];
  70. $message['to'] = $account['original'];
  71. if(!empty($message['to'])) {
  72. $sessionid = md5($message['from'] . $message['to'] . $_W['uniacid']);
  73. session_id($sessionid);
  74. WeSession::start($_W['uniacid'], $_W['openid'], 300);
  75. $processor = WeUtility::createModuleProcessor('chats');
  76. $processor->end();
  77. }
  78. if (is_error($result)) {
  79. iajax(1, $result);
  80. }
  81. }
  82. template('mc/chats');