receiver.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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($this->message['event'] == 'subscribe' && !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 = pdo_fetchall(
  17. "SELECT `id`, `keyword`, `name`, `acid` FROM " . tablename('qrcode') . " WHERE `uniacid` = :uniacid AND ticket = :ticket",
  18. array(':uniacid' => $uniacid, ':ticket' => $ticket)
  19. );
  20. if(!empty($qr)) {
  21. if(count($qr) != 1) {
  22. $qr = array();
  23. } else {
  24. $qr = $qr[0];
  25. }
  26. }
  27. }
  28. if(empty($qr)) {
  29. $sceneid = trim($this->message['scene']);
  30. if(is_numeric($sceneid)) {
  31. $scene_condition = " `qrcid` = :sceneid";
  32. } else {
  33. $scene_condition = " `scene_str` = :sceneid";
  34. }
  35. $condition = array(':sceneid' => $sceneid, ':uniacid' => $_W['uniacid']);
  36. $qr = pdo_fetch("SELECT `id`, `keyword`, `name`, `acid` FROM " . tablename('qrcode') . " WHERE `uniacid` = :uniacid AND {$scene_condition}", $condition);
  37. }
  38. $insert = array(
  39. 'uniacid' => $_W['uniacid'],
  40. 'acid' => $qr['acid'],
  41. 'qid' => $qr['id'],
  42. 'openid' => $this->message['from'],
  43. 'type' => 1,
  44. 'qrcid' => intval($sceneid),
  45. 'scene_str' => $sceneid,
  46. 'name' => $qr['name'],
  47. 'createtime' => TIMESTAMP,
  48. );
  49. pdo_insert('qrcode_stat', $insert);
  50. } elseif($this->message['event'] == 'SCAN') {
  51. $acid = $this->acid;
  52. $uniacid = $this->uniacid;
  53. $sceneid = trim($this->message['scene']);
  54. if(is_numeric($sceneid)) {
  55. $scene_condition = " `qrcid` = :sceneid";
  56. } else {
  57. $scene_condition = " `scene_str` = :sceneid";
  58. }
  59. $condition = array(':sceneid' => $sceneid, ':uniacid' => $_W['uniacid']);
  60. $row = pdo_fetch("SELECT `id`, `keyword`, `name`, `acid` FROM " . tablename('qrcode') . " WHERE `uniacid` = :uniacid AND {$scene_condition} AND `type` = 'scene'", $condition);
  61. $insert = array(
  62. 'uniacid' => $_W['uniacid'],
  63. 'acid' => $row['acid'],
  64. 'qid' => $row['id'],
  65. 'openid' => $this->message['from'],
  66. 'type' => 2,
  67. 'qrcid' => intval($sceneid),
  68. 'scene_str' => $sceneid,
  69. 'name' => $row['name'],
  70. 'createtime' => TIMESTAMP,
  71. );
  72. pdo_insert('qrcode_stat', $insert);
  73. } elseif ($this->message['event'] == 'user_get_card') {
  74. $sceneid = $this->message['outerid'];
  75. $acid = $this->acid;
  76. $uniacid = $this->uniacid;
  77. $row = pdo_get('qrcode', array('qrcid' => $sceneid));
  78. if (!empty($row)) {
  79. $insert = array(
  80. 'uniacid' => $_W['uniacid'],
  81. 'acid' => $row['acid'],
  82. 'qid' => $row['id'],
  83. 'openid' => $this->message['from'],
  84. 'type' => 2,
  85. 'qrcid' => $sceneid,
  86. 'scene_str' => $sceneid,
  87. 'name' => $row['name'],
  88. 'createtime' => TIMESTAMP,
  89. );
  90. pdo_insert('qrcode_stat', $insert);
  91. }
  92. }
  93. if ($this->message['event'] == 'subscribe' && !empty($_W['account']) && ($_W['account']['level'] == ACCOUNT_SERVICE_VERIFY || $_W['account']['level'] == ACCOUNT_SUBSCRIPTION_VERIFY)) {
  94. $account_obj = WeAccount::createByUniacid();
  95. $userinfo = $account_obj->fansQueryInfo($this->message['from']);
  96. if(!is_error($userinfo) && !empty($userinfo) && !empty($userinfo['subscribe'])) {
  97. $userinfo['nickname'] = stripcslashes($userinfo['nickname']);
  98. $userinfo['avatar'] = $userinfo['headimgurl'];
  99. $fans = array(
  100. 'unionid' => $userinfo['unionid'],
  101. 'nickname' => strip_emoji($userinfo['nickname']),
  102. 'tag' => base64_encode(iserializer($userinfo)),
  103. );
  104. pdo_update('mc_mapping_fans', $fans, array('openid' => $this->message['from']));
  105. $uid = !empty($_W['member']['uid']) ? $_W['member']['uid'] : $this->message['from'];
  106. if (!empty($uid)) {
  107. $member = array();
  108. if (!empty($userinfo['nickname'])) {
  109. $member['nickname'] = $fans['nickname'];
  110. }
  111. if (!empty($userinfo['headimgurl'])) {
  112. $member['avatar'] = $userinfo['headimgurl'];
  113. }
  114. load()->model('mc');
  115. mc_update($uid, $member);
  116. }
  117. }
  118. }
  119. }
  120. }