Index.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. }