|
@@ -0,0 +1,124 @@
|
|
|
+<?php
|
|
|
+namespace app\newhome\controller;
|
|
|
+
|
|
|
+use think\Controller;
|
|
|
+use app\user\model\UserSkill;
|
|
|
+
|
|
|
+class User extends Controller {
|
|
|
+
|
|
|
+ private $userModel, $skillModel;
|
|
|
+
|
|
|
+ public function _initialize(){
|
|
|
+ $this->skillModel = new UserSkill();
|
|
|
+ $this->userModel = new \app\user\model\User();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function login()
|
|
|
+ {
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $info = $this->userModel->loginByUid($data['u']);
|
|
|
+ $info['s'] = $this->skillModel->getUserSkill($info['i']);
|
|
|
+ $info['time'] = time();
|
|
|
+
|
|
|
+ return json($info);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getskill(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $info = $this->skillModel->getSkillByInfo($data['i']);
|
|
|
+ return json($info);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addskill(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $info = $this->skillModel->addUserSkill($data['u'], $data['s']);
|
|
|
+ return json($info);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function other(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $res = $this->userModel->getUserById($data['u']);
|
|
|
+ $path = "load/".$res['id'].'.txt';
|
|
|
+
|
|
|
+ $file = fopen($path, "r") or die(json(['error'=>1009]));
|
|
|
+ $info = fread($file, filesize($path));
|
|
|
+ fclose($file);
|
|
|
+
|
|
|
+ return json(['l'=>$info, 'p'=>$res['praise']]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function load(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+ $id = $data['u'];
|
|
|
+ $path = "load/$id.txt";
|
|
|
+
|
|
|
+ $res = $this->userModel->getUserById($id);
|
|
|
+
|
|
|
+ $file = fopen($path, "r") or die(json(['error'=>1009]));
|
|
|
+ $info = fread($file, filesize($path));
|
|
|
+ fclose($file);
|
|
|
+
|
|
|
+ return json(['l'=>$info, 'p'=>$res['praise']]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function save(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+ $id = $data['u'];
|
|
|
+ $path = "load/$id.txt";
|
|
|
+
|
|
|
+ $file = fopen($path, 'w') or die(json(['error'=>1009]));
|
|
|
+ fwrite($file, $data['l']);
|
|
|
+ fclose($file);
|
|
|
+
|
|
|
+ return json(['error'=>0]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function rand(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $id = $this->userModel->randOtherId($data['i']);
|
|
|
+ $res = $this->userModel->getUserById($id);
|
|
|
+
|
|
|
+ $path = "load/$id.txt";
|
|
|
+ $file = fopen($path, "r") or die(json(['error'=>1009]));
|
|
|
+ $info = fread($file, filesize($path));
|
|
|
+ fclose($file);
|
|
|
+
|
|
|
+ return json(['l'=>$info, 'p'=>$res['praise']]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function delete(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $id = $data['s'];
|
|
|
+
|
|
|
+ $path = "load/$id.txt";
|
|
|
+ $res = unlink($path);
|
|
|
+
|
|
|
+ return json(['r'=>(($res)?1:0)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function look(){
|
|
|
+ $res = $this->userModel->lookList();
|
|
|
+
|
|
|
+ return json(['l'=>$res]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function nickname(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $nickname = trim($data['n']);
|
|
|
+ $res = $this->userModel->findUserByName($nickname);
|
|
|
+ if($res) return json(['error'=>2020]);
|
|
|
+
|
|
|
+ $this->userModel->addAndSave(['id'=>$data['u'], 'nickname'=>$nickname]);
|
|
|
+
|
|
|
+ return json(['error'=>0]);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|