Version.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\Admin\controller;
  3. use think\Db;
  4. class Version extends Base
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. }
  10. public function list(){
  11. $page = isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) : 1;
  12. $size = isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :10;
  13. $count= Db::name("version")->count();
  14. $total = ceil($count/$size);
  15. $page = $page>=$total? $total:$page;
  16. $list = Db::name("version")->page($page,$size)->order("addtime desc")->select();
  17. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  18. }
  19. public function create(){
  20. $title = isset($this->post['title'])&&$this->post['title']!="" ? $this->post['title']:"";
  21. if($title==""){
  22. return error_show(1004,"参数title 不能为空");
  23. }
  24. $content = isset($this->post['content'])&&$this->post['content']!="" ? $this->post['content']:"";
  25. if($content==""){
  26. return error_show(1004,"参数content 不能为空");
  27. }
  28. $version = isset($this->post['version'])&&$this->post['version']!="" ? $this->post['version']:"";
  29. if($version==""){
  30. return error_show(1004,"参数version 不能为空");
  31. }
  32. $data=[
  33. "title"=>$title,
  34. "content"=>$content,
  35. "version"=>$version,
  36. "addtime"=>date("Y-m-d H:i:s")
  37. ];
  38. $inert= Db::name("version")->insert($data);
  39. if($inert){
  40. write_log("版本{$version}新建成功",$this->userinfo,"version","add");
  41. return app_show(0,"版本信息新建成功");
  42. }else{
  43. return app_show(0,"版本信息新建失败");
  44. }
  45. }
  46. }