12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace app\common\model;
- use think\Db;
- use think\Model;
- class Intro extends Model
- {
- protected $table = 'user';
-
- public function addIntroNum($intro_id, $num, $team)
- {
-
- if($num < 0) {
- $this->where(['id' => $intro_id])->setDec('intro_num', abs($num));
- } else {
- $this->where(['id' => $intro_id])->setInc('intro_num', $num);
- }
-
- $rstjr = $this->where(['id' => $intro_id])->field('id,intro_ids')->find();
- if($rstjr) {
- $tjstr = $rstjr['intro_ids'] . "," . $rstjr['id'];
- $tjstr = trim($tjstr, ',');
- $arr_intro = explode(',', $tjstr);
- if($team < 0) {
- $this->where(['id' => ['in', $arr_intro]])->setDec('intro_num_all', abs($team));
- } else {
- $this->where(['id' => ['in', $arr_intro]])->setInc('intro_num_all', $team);
- }
- }
- }
-
- public function getUp($ids = '', $max = 1)
- {
- if($ids) {
- $intro_arr = explode(',', $ids);
- $intro_arr = array_filter($intro_arr);
- $intro_arr = array_slice($intro_arr, -$max);
- $info = Db::name('user')
- ->where(['id' => ['in', $intro_arr]])
- ->field('id,username,nickname,logo,mobile,email,rank')
- ->order('intro_level desc')
- ->limit($max)
- ->select();
- }
- return $info ?? '';
- }
-
- function getUpComplex($username, $min = 1, $max = 1, $str = '', $step = 0)
- {
- if($max >= $step) {
- $user = Db::name('user')->where(['username' => $username])->field("username,intro")->find();
- if($user['username']) {
- if($step >= $min) {
- $str .= ",".$user["username"];
- }
- if($user['intro']) {
- return $this->getUpComplex($user['intro'], $min, $max, $str, $step + 1);
- }
- }
- }
- return $str;
- }
- }
|