RegNum.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 统计直接人数 Table<ai_fastshop_regnum>
  7. */
  8. namespace app\fastshop\model;
  9. use think\Model;
  10. use app\common\model\SystemUserLevel;
  11. class RegNum extends Model{
  12. protected $pk = 'id';
  13. protected $table = 'ai_fastshop_regnum';
  14. protected $createTime = false;
  15. //用户
  16. public function user(){
  17. return $this->hasOne('app\common\model\SystemUser','id','uid');
  18. }
  19. /**
  20. * 统计人数
  21. */
  22. public static function countMum(int $appid,int $uid){
  23. $people_num = SystemUserLevel::where(['parent_id' => $uid,'level' => 1])->count();
  24. $allnum = SystemUserLevel::where(['parent_id' => $uid])->count();
  25. $info = self::where(['uid' => $uid])->find();
  26. if(empty($info)){
  27. $data['member_miniapp_id'] = $appid;
  28. $data['uid'] = $uid;
  29. $data['num'] = $people_num;
  30. $data['allnum'] = $allnum;
  31. return self::insert($data);
  32. }else{
  33. $info->num = $people_num;
  34. $info->allnum = $allnum;
  35. return $info->save();
  36. }
  37. }
  38. }