User.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\home\controller;
  3. use think\Controller;
  4. use app\user\model\UserSkill;
  5. class User extends Controller {
  6. private $userModel, $skillModel;
  7. public function _initialize(){
  8. $this->skillModel = new UserSkill();
  9. $this->userModel = new \app\user\model\User();
  10. }
  11. public function login()
  12. {
  13. $data = decode($this->request->post());
  14. $info = $this->userModel->loginByUid($data['u']);
  15. $info['s'] = $this->skillModel->getUserSkill($info['i']);
  16. $info['time'] = time();
  17. return json($info);
  18. }
  19. public function getskill(){
  20. $data = decode($this->request->post());
  21. $info = $this->skillModel->getSkillByInfo($data['i']);
  22. return json($info);
  23. }
  24. public function addskill(){
  25. $data = decode($this->request->post());
  26. $info = $this->skillModel->addUserSkill($data['u'], $data['s']);
  27. return json($info);
  28. }
  29. public function other(){
  30. $data = decode($this->request->post());
  31. $info = $this->userModel->getUserById($data['u']);
  32. $path = "load/".$info['short'].'.txt';
  33. $file = fopen($path, "r") or die(json(['error'=>1009]));
  34. $info = fread($file, filesize($path));
  35. fclose($file);
  36. return json(['l'=>$info]);
  37. }
  38. public function load(){
  39. $data = decode($this->request->post());
  40. $id = $data['u'];
  41. $path = "load/$id.txt";
  42. $file = fopen($path, "r") or die(json(['error'=>1009]));
  43. $info = fread($file, filesize($path));
  44. fclose($file);
  45. return json(['l'=>$info]);
  46. }
  47. public function save(){
  48. $data = decode($this->request->post());
  49. $id = $data['u'];
  50. $path = "load/$id.txt";
  51. $file = fopen($path, 'w') or die(json(['error'=>1009]));
  52. fwrite($file, $data['l']);
  53. fclose($file);
  54. return json(['error'=>0]);
  55. }
  56. public function rand(){
  57. $data = decode($this->request->post());
  58. $short = $this->userModel->randOtherCode($data['i']);
  59. $path = "load/$short.txt";
  60. $file = fopen($path, "r") or die(json(['error'=>1009]));
  61. $info = fread($file, filesize($path));
  62. fclose($file);
  63. return json(['l'=>$info]);
  64. }
  65. public function delete(){
  66. $data = decode($this->request->post());
  67. $short = $data['s'];
  68. $path = "load/$short.txt";
  69. $res = unlink($path);
  70. return json(['r'=>(($res)?1:0)]);
  71. }
  72. }