1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace Invite\Lib;
- use Dever;
- use Dever\Helper\Str;
- class Code
- {
- # 获取邀请码
- public function get($uid)
- {
- $info = Dever::db('code', 'invite')->find(array('uid' => $uid));
- if ($info) {
- return $info['value'];
- } else {
- //$code = Dever::uid($uid);
- $code = Str::rand(5, 0);
- return $this->createCode($uid, $code);
- }
- }
- private function createCode($uid, $code)
- {
- $info = Dever::db('code', 'invite')->find(array('value' => $code));
- if ($info) {
- $code = Str::rand(5, 0);
- return $this->createCode($uid, $code);
- } else {
- Dever::db('code', 'invite')->insert(array('value' => $code, 'uid' => $uid));
- return $code;
- }
- }
- # 根据邀请码获取邀请人uid
- public function getUid($code)
- {
- $info = Dever::db('code', 'invite')->find(array('value' => $code));
- if ($info) {
- return $info['uid'];
- }
- return false;
- }
- }
|