123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace app\home\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());
-
- $info = $this->userModel->getUserById($data['u']);
- $path = "load/".$info['short'].'.txt';
-
- $file = fopen($path, "r") or die(json(['error'=>1009]));
- $info = fread($file, filesize($path));
- fclose($file);
-
- return json(['l'=>$info]);
- }
-
- public function load(){
- $data = decode($this->request->post());
- $id = $data['u'];
- $path = "load/$id.txt";
-
- $file = fopen($path, "r") or die(json(['error'=>1009]));
- $info = fread($file, filesize($path));
- fclose($file);
-
- return json(['l'=>$info]);
- }
-
- 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());
-
- $short = $this->userModel->randOtherCode($data['i']);
-
- $path = "load/$short.txt";
- $file = fopen($path, "r") or die(json(['error'=>1009]));
- $info = fread($file, filesize($path));
- fclose($file);
-
- return json(['l'=>$info]);
- }
-
- public function delete(){
- $data = decode($this->request->post());
-
- $short = $data['s'];
-
- $path = "load/$short.txt";
- $res = unlink($path);
-
- return json(['r'=>(($res)?1:0)]);
- }
-
- }
|