|
@@ -67,7 +67,7 @@ class User extends Model{
|
|
|
* @param int $id
|
|
|
*/
|
|
|
public function getUserById($id){
|
|
|
- return $this->db()->where(['id'=>$id])->find()->toArray();
|
|
|
+ return $this->db()->where(['id'=>$id])->find();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -76,7 +76,7 @@ class User extends Model{
|
|
|
* @return array
|
|
|
*/
|
|
|
public function getUserByCode($code){
|
|
|
- return $this->db()->where(['short'=>$code])->find()->toArray();
|
|
|
+ return $this->db()->where(['short'=>$code])->find();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -112,20 +112,9 @@ class User extends Model{
|
|
|
* 随机出非个人的短码
|
|
|
* @param int $id
|
|
|
*/
|
|
|
- public function randOtherCode($id){
|
|
|
- $info = $this->db()->field('short')->where("id", "<>", $id)->select();
|
|
|
- return $this->getUserJsonFile($info, 'short');
|
|
|
- }
|
|
|
-
|
|
|
- private function getUserJsonFile($info, $field){
|
|
|
- $r = rand(0, count($info)-1);
|
|
|
- $filename = $info[$r][$field];
|
|
|
- $path = "load/$filename.txt";
|
|
|
- if(!file_exists($path)){
|
|
|
- unset($info[$r]);
|
|
|
- $short = $this->getUserJsonFile(array_values($info), $field);
|
|
|
- }
|
|
|
- return $filename;
|
|
|
+ public function randOtherInfoByShort($short){
|
|
|
+ $info = $this->db()->field('id, short')->where("short", "<>", $short)->select();
|
|
|
+ return $this->getUserJsonFile($info);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -133,9 +122,34 @@ class User extends Model{
|
|
|
* @param int $id
|
|
|
* @return int
|
|
|
*/
|
|
|
- public function randOtherId($id){
|
|
|
- $info = $this->db()->field('id')->where("id", "<>", $id)->select();
|
|
|
- return $this->getUserJsonFile($info, 'id');
|
|
|
+ public function randOtherInfoById($id){
|
|
|
+ $info = $this->db()->field('id, short')->where("id", "<>", $id)->select();
|
|
|
+ return $this->getUserJsonFile($info);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 找到文件路径
|
|
|
+ * @param unknown $info
|
|
|
+ * @param string $id
|
|
|
+ * @param string $short
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ private function getUserJsonFile($info, $id = 'id', $short = 'short'){
|
|
|
+ $r = rand(0, count($info)-1);
|
|
|
+ $file_id = $info[$r][$id];
|
|
|
+ $file_short = $info[$r][$short];
|
|
|
+
|
|
|
+ $path_id = "load/$file_id.txt";
|
|
|
+ $path_short = "load/$file_short.txt";
|
|
|
+
|
|
|
+ if(is_file($path_id)){
|
|
|
+ return $file_id;
|
|
|
+ } elseif (is_file($path_short)){
|
|
|
+ return $file_short;
|
|
|
+ } else {
|
|
|
+ unset($info[$r]);
|
|
|
+ return $this->getUserJsonFile(array_values($info));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|