QrcodeEventBehavior.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace behavior\wechat;
  12. use app\admin\model\wechat\WechatReply;
  13. use app\wap\model\user\PhoneUser;
  14. use app\wap\model\user\User;
  15. use app\wap\model\user\WechatUser;
  16. class QrcodeEventBehavior
  17. {
  18. public static function wechatQrcodeSpread($qrInfo, $message)
  19. {
  20. try {
  21. $spreadUid = $qrInfo['third_id'];
  22. $uid = WechatUser::openidToUid($message->FromUserName, true);
  23. if ($spreadUid == $uid) return '自己不能推荐自己';
  24. $userInfo = User::getUserInfo($uid);
  25. if ($userInfo['spread_uid']) return '已有推荐人!';
  26. if (User::setSpreadUid($userInfo['uid'], $spreadUid))
  27. return WechatReply::reply('subscribe');
  28. else
  29. return '绑定推荐人失败!';
  30. } catch (\Exception $e) {
  31. return $e->getMessage();
  32. }
  33. }
  34. public static function wechatQrcodeBinding($qrInfo, $message)
  35. {
  36. $bindingPhoneUid = $qrInfo['third_id'];
  37. $uid = WechatUser::openidToUid($message->FromUserName, true);
  38. $userInfo = User::getUserInfo($uid);
  39. if ($userInfo['phone']) return '您已绑定手机号码,需要更换手机号码去[个人中心]更换绑定手机号';
  40. $bindingPhone = PhoneUser::UidToPhone($bindingPhoneUid);
  41. if (!$bindingPhone) return '绑定失败,手机号码不存在';
  42. if (User::setUserRelationInfos($bindingPhone, $bindingPhoneUid, $uid, true, $qrInfo['id']))
  43. return '恭喜您,手机号码[' . $bindingPhone . ']绑定成功,';
  44. else
  45. return User::getErrorInfo();
  46. }
  47. }