superbee 7 سال پیش
والد
کامیت
1ee4fdd0ee
3فایلهای تغییر یافته به همراه40 افزوده شده و 1 حذف شده
  1. 23 0
      application/newhome/controller/Index.php
  2. 8 1
      application/newhome/controller/User.php
  3. 9 0
      application/user/model/User.php

+ 23 - 0
application/newhome/controller/Index.php

@@ -3,13 +3,36 @@ namespace app\newhome\controller;
 
 use think\Controller;
 use think\Db;
+use app\user\model\User;
 
 class Index extends Controller {
 	
+	private $userModel;
+	
+	public function _initialize(){
+		$this->userModel = new User();
+	}
+	
 	public function index()
 	{
 		$data = Db::name('config')->select();
 		return json(["l"=>$data]);
 	}
 	
+	public function robot(){
+		$data = decode($this->request->post());
+		
+		$this->userModel->addAndSave(['id'=>$data['u'], 'robot'=>1]);
+		
+		return json(['error'=>0]);
+	}
+	
+	public function number(){
+		$data = decode($this->request->post());
+		
+		$res = $this->userModel->getRobotId($data['n']);
+		
+		return json(['l'=>$res]);
+	}
+	
 }

+ 8 - 1
application/newhome/controller/User.php

@@ -54,7 +54,14 @@ class User extends Controller {
 	
 	public function load(){
 		$data = decode($this->request->post());
-		$res = $this->userModel->getUserById($data['u']);
+		
+		$id = $data['u'];
+		
+		if(strlen($id) > 10){
+			$res = $this->userModel->getUserById($id);
+		}else{
+			$res = $this->userModel->getUserByCode($id);
+		}
 		
 		if(empty($res)) return json(['error'=>1023]);
 		$path = "load/".$res['id'].".txt";

+ 9 - 0
application/user/model/User.php

@@ -226,4 +226,13 @@ class User extends Model{
 		return $this->db()->where(['nickname'=>$nickname])->find();
 	}
 	
+	/**
+	 * 获取近期注册机器人id
+	 * @param number $limit
+	 * @return \think\Collection|\think\db\false|PDOStatement|string
+	 */
+	public function getRobotId($limit = 1){
+		return $this->db()->field("id i")->where(['robot'=>1])->order('registertime DESC')->limit($limit)->select();
+	}
+	
 }