人人商城

receiver.php 4.0KB

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