Index.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\api\controller\script;
  3. use app\admin\model\Device;
  4. use app\common\controller\Api;
  5. /**
  6. * 首页接口
  7. */
  8. class Index extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 首页
  14. *
  15. */
  16. public function index()
  17. {
  18. $this->success('请求成功');
  19. }
  20. // 保存编号
  21. public function saveNumber()
  22. {
  23. try {
  24. if ($this->request->isPost()) {
  25. $number = $this->request->post('number');
  26. $row = Device::where('number', $number)->find();
  27. if ($row) {
  28. $this->error('编号已存在');
  29. } else {
  30. $data['number'] = $number;
  31. $data['createtime'] = time();
  32. $data['updatetime'] = time();
  33. $res = Device::insertGetId($data);
  34. }
  35. if ($res) {
  36. $this->success('保存成功', ['id' => $res]);
  37. } else {
  38. $this->error('保存失败');
  39. }
  40. }
  41. } catch (ValidateException $e) {
  42. $this->error($e->getMessage());
  43. } catch (PDOException $e) {
  44. $this->error($e->getMessage());
  45. }
  46. }
  47. // 获取任务状态
  48. public function getTaskStatus()
  49. {
  50. try {
  51. $number = $this->request->post('number');
  52. if (!$number) $this->error('编号不能为空');
  53. $row = Device::where('number', $number)->find();
  54. if ($row) {
  55. $this->success('获取成功', ['status' => $row['status']]);
  56. }
  57. $this->error('获取失败');
  58. } catch (Exception $e) {
  59. $this->error($e->getMessage());
  60. }
  61. }
  62. }