Index.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\newhome\controller;
  3. use think\Controller;
  4. use think\Db;
  5. use app\user\model\User;
  6. class Index extends Controller {
  7. private $userModel;
  8. public function _initialize(){
  9. $this->userModel = new User();
  10. }
  11. public function index()
  12. {
  13. $data = Db::name('config')->select();
  14. return json(["l"=>$data]);
  15. }
  16. public function gift(){
  17. $data = Db::name('gift')->field("id, packid, pack p, diamond d, coin g, flower f, dress c, pit s, elf a, starttime, endtime")->select();
  18. return json(['l'=>$data]);
  19. }
  20. public function robot(){
  21. $data = decode($this->request->post());
  22. $this->userModel->addAndSave(['id'=>$data['u'], 'robot'=>1]);
  23. return json(['error'=>0]);
  24. }
  25. public function number(){
  26. $data = decode($this->request->post());
  27. $res = $this->userModel->getRobotId($data['n']);
  28. return json(['l'=>$res]);
  29. }
  30. public function loadFile(){
  31. $data = decode($this->request->post());
  32. $filename = $data['f'];
  33. $path = "gameconfig/$filename.txt";
  34. if(!is_file($path)) return json(['error'=>1016]);
  35. $file = fopen($path, "r") or die(json(['error'=>1009]));
  36. $info = fread($file, filesize($path));
  37. fclose($file);
  38. return json(['l'=>$info]);
  39. }
  40. }