receiver.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. class CoreModuleReceiver extends WeModuleReceiver {
  8. public function receive() {
  9. global $_W;
  10. if ('subscribe' == $this->message['event'] && !empty($this->message['ticket'])) {
  11. $sceneid = $this->message['scene'];
  12. $acid = $this->acid;
  13. $uniacid = $this->uniacid;
  14. $ticket = trim($this->message['ticket']);
  15. if (!empty($ticket)) {
  16. $qr = table('qrcode')
  17. ->select(array('id', 'keyword', 'name', 'acid'))
  18. ->where(array(
  19. 'uniacid' => $uniacid,
  20. 'ticket' => $ticket
  21. ))
  22. ->getall();
  23. if (!empty($qr)) {
  24. if (1 != count($qr)) {
  25. $qr = array();
  26. } else {
  27. $qr = $qr[0];
  28. }
  29. }
  30. }
  31. if (empty($qr)) {
  32. $sceneid = trim($this->message['scene']);
  33. $where = array(
  34. 'uniacid' => $_W['uniacid']
  35. );
  36. if (is_numeric($sceneid)) {
  37. $where['qrcid'] = $sceneid;
  38. } else {
  39. $where['scene_str'] = $sceneid;
  40. }
  41. $qr = table('qrcode')
  42. ->select(array('id', 'keyword', 'name', 'acid'))
  43. ->where($where)
  44. ->get();
  45. }
  46. $insert = array(
  47. 'uniacid' => $_W['uniacid'],
  48. 'acid' => $qr['acid'],
  49. 'qid' => $qr['id'],
  50. 'openid' => $this->message['from'],
  51. 'type' => 1,
  52. 'qrcid' => intval($sceneid),
  53. 'scene_str' => $sceneid,
  54. 'name' => $qr['name'],
  55. 'createtime' => TIMESTAMP,
  56. );
  57. table('qrcode_stat')->fill($insert)->save();
  58. } elseif ('SCAN' == $this->message['event']) {
  59. $sceneid = trim($this->message['scene']);
  60. $where = array('uniacid' => $_W['uniacid']);
  61. if (is_numeric($sceneid)) {
  62. $where['qrcid'] = $sceneid;
  63. } else {
  64. $where['scene_str'] = $sceneid;
  65. }
  66. $row = table('qrcode')
  67. ->select(array('id', 'keyword', 'name', 'acid'))
  68. ->where($where)
  69. ->get();
  70. $insert = array(
  71. 'uniacid' => $_W['uniacid'],
  72. 'acid' => $row['acid'],
  73. 'qid' => $row['id'],
  74. 'openid' => $this->message['from'],
  75. 'type' => 2,
  76. 'qrcid' => intval($sceneid),
  77. 'scene_str' => $sceneid,
  78. 'name' => $row['name'],
  79. 'createtime' => TIMESTAMP,
  80. );
  81. if ($_W['setting']['qr_status']['status'] == 1) {
  82. $qrLog = table('qrcode_stat')->where(array('uniacid' => $_W['uniacid'], 'qid' => $row['id'], 'openid' => $this->message['from']))->get();
  83. if (empty($qrLog)) table('qrcode_stat')->fill($insert)->save();
  84. } else {
  85. table('qrcode_stat')->fill($insert)->save();
  86. }
  87. } elseif ('user_get_card' == $this->message['event']) {
  88. $sceneid = $this->message['outerid'];
  89. $row = table('qrcode')->where(array('qrcid' => $sceneid))->get();
  90. if (!empty($row)) {
  91. $insert = array(
  92. 'uniacid' => $_W['uniacid'],
  93. 'acid' => $row['acid'],
  94. 'qid' => $row['id'],
  95. 'openid' => $this->message['from'],
  96. 'type' => 2,
  97. 'qrcid' => $sceneid,
  98. 'scene_str' => $sceneid,
  99. 'name' => $row['name'],
  100. 'createtime' => TIMESTAMP,
  101. );
  102. table('qrcode_stat')->fill($insert)->save();
  103. }
  104. }
  105. if ('subscribe' == $this->message['event'] && !empty($_W['account']) && ($_W['account']['level'] == ACCOUNT_SERVICE_VERIFY || $_W['account']['level'] == ACCOUNT_SUBSCRIPTION_VERIFY)) {
  106. $account_obj = WeAccount::createByUniacid();
  107. $userinfo = $account_obj->fansQueryInfo($this->message['from']);
  108. if (!is_error($userinfo) && !empty($userinfo) && !empty($userinfo['subscribe'])) {
  109. load()->model('mc');
  110. $fan = mc_fansinfo($this->message['from'], 0 , $_W['uniacid']);
  111. $userinfo['nickname'] = $fan['nickname'];
  112. $fans = array(
  113. 'unionid' => $userinfo['unionid'],
  114. );
  115. if (empty($fan['tag'])) {
  116. $fans['tag'] = base64_encode(iserializer($userinfo));
  117. }
  118. table('mc_mapping_fans')
  119. ->where(array('openid' => $this->message['from']))
  120. ->fill($fans)
  121. ->save();
  122. $mc_fans_tag_table = table('mc_fans_tag');
  123. $mc_fans_tag_fields = mc_fans_tag_fields();
  124. $fans_tag_update_info = array();
  125. foreach ($userinfo as $fans_field_key => $fans_field_info) {
  126. if (in_array($fans_field_key, array_keys($mc_fans_tag_fields))) {
  127. $fans_tag_update_info[$fans_field_key] = $fans_field_info;
  128. }
  129. }
  130. $fans_tag_update_info['tagid_list'] = iserializer($fans_tag_update_info['tagid_list']);
  131. $fans_tag_update_info['uniacid'] = $_W['uniacid'];
  132. $fans_tag_update_info['fanid'] = $fan['fanid'];
  133. $fans_tag_exists = $mc_fans_tag_table->getByOpenid($fans_tag_update_info['openid']);
  134. if (!empty($fans_tag_exists)) {
  135. unset($fans_tag_update_info['headimgurl']);
  136. table('mc_fans_tag')
  137. ->where(array('openid' => $fans_tag_update_info['openid']))
  138. ->fill($fans_tag_update_info)
  139. ->save();
  140. } else {
  141. table('mc_fans_tag')->fill($fans_tag_update_info)->save();
  142. }
  143. $uid = !empty($_W['member']['uid']) ? $_W['member']['uid'] : $this->message['from'];
  144. if (!empty($uid)) {
  145. $member = array();
  146. if (!empty($userinfo['nickname'])) {
  147. $member['nickname'] = $userinfo['nickname'];
  148. }
  149. mc_update($uid, $member);
  150. }
  151. }
  152. }
  153. }
  154. }