فهرست منبع

commit user info

superbee 7 سال پیش
والد
کامیت
ae069b5467
2فایلهای تغییر یافته به همراه25 افزوده شده و 12 حذف شده
  1. 4 9
      application/newhome/controller/User.php
  2. 21 3
      application/user/model/User.php

+ 4 - 9
application/newhome/controller/User.php

@@ -54,17 +54,12 @@ class User extends Controller {
 	
 	public function load(){
 		$data = decode($this->request->post());
-		$id = $data['u'];
-		
-		$path = "load/$id.txt";
+		$res = $this->userModel->getUserById($data['u']);
 		
-		if(!is_file($path)) return json(['error'=>1005]); 
+		if(empty($res)) return json(['error'=>1023]);
+		$path = "load/".$res['id'].".txt";
 		
-		if(strlen($id) > 10){
-			$res = $this->userModel->getUserById($id);
-		}else{
-			$res = $this->userModel->getUserByCode($id);
-		}		
+		if(!is_file($path)) $path = "load/".$res['short'].".txt";
 		
 		$file = fopen($path, "r") or die(json(['error'=>1009]));
 		$info = fread($file, filesize($path));

+ 21 - 3
application/user/model/User.php

@@ -113,7 +113,11 @@ class User extends Model{
 	 * @param int $id
 	 */
 	public function randOtherInfoByShort($short){
-		$info = $this->db()->field('id, short')->where("short", "<>", $short)->select();
+		$info = $this->db()->field('id, short')
+		->where("short", "<>", $short)
+		->whereTime('last_login', 'between', $this->getNearMonth())
+		->select();
+		
 		return $this->getUserJsonFile($info);
 	}
 	
@@ -123,13 +127,27 @@ class User extends Model{
 	 * @return int
 	 */
 	public function randOtherInfoById($id){
-		$info = $this->db()->field('id, short')->where("id", "<>", $id)->select();
+		$info = $this->db()->field('id, short')
+		->where("id", "<>", $id)
+		->whereTime('last_login', 'between', $this->getNearMonth())
+		->select();
+		
 		return $this->getUserJsonFile($info);
 	}
 	
 	/**
+	 * 得到最近30天日期
+	 * @return array
+	 */
+	private function getNearMonth(){
+		$back = date('Y-m-d H:i:s');
+		$front = date('Y-m-d H:i:s',strtotime("-30 day"));
+		return [$front, $back];
+	}
+	
+	/**
 	 * 找到文件路径
-	 * @param unknown $info
+	 * @param array $info
 	 * @param string $id
 	 * @param string $short
 	 * @return string