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); } } } /** * 获取上几代推荐人 * @param string $ids 上级id * @param int $max 代数 * @return false|\PDOStatement|string|\think\Collection */ 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; } }