MemBaseModel.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * MemBaseModel.php UTF-8
  4. * 获取用户ID
  5. *
  6. * @date : 2018/4/24 20:13
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\model\member;
  13. use huo\model\common\CommonModel;
  14. class MemBaseModel extends CommonModel {
  15. protected $name = 'mem_base';
  16. public function genUsername($prefix = 't') {
  17. $_base_num = 10000;
  18. // 生成用户名
  19. $_min = $this->min('base');
  20. $_map['base'] = $_min;
  21. $_cnt = $this->where($_map)->count('id');
  22. $_limit = rand(0, $_cnt);
  23. $_sql_limit = "$_limit,1";
  24. $_mem_id = $this->where($_map)->limit($_sql_limit)->value('id');
  25. $_rs = $this->where('id', $_mem_id)->setInc('base');
  26. $_username = false;
  27. if (false != $_rs) {
  28. $_username = $_base_num * $_min + $_mem_id;
  29. $_username = $prefix.$_username.rand(100, 999);
  30. }
  31. return $_username;
  32. }
  33. }