12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace huo\model\member;
- use huo\model\common\CommonModel;
- class MemBaseModel extends CommonModel {
- protected $name = 'mem_base';
- public function genUsername($prefix = 't') {
- $_base_num = 10000;
-
- $_min = $this->min('base');
- $_map['base'] = $_min;
- $_cnt = $this->where($_map)->count('id');
- $_limit = rand(0, $_cnt);
- $_sql_limit = "$_limit,1";
- $_mem_id = $this->where($_map)->limit($_sql_limit)->value('id');
- $_rs = $this->where('id', $_mem_id)->setInc('base');
- $_username = false;
- if (false != $_rs) {
- $_username = $_base_num * $_min + $_mem_id;
- $_username = $prefix.$_username.rand(100, 999);
- }
- return $_username;
- }
- }
|