System.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use think\App;
  5. use think\facade\Validate;
  6. use think\facade\Db;
  7. class System extends Base
  8. {
  9. public function __construct(App $app) {
  10. parent::__construct($app);
  11. }
  12. /**
  13. * 显示资源列表
  14. *
  15. * @return \think\Response
  16. */
  17. public function list()
  18. {
  19. $param =$this->request->only(["module"=>"","system"=>"","sys_type"=>"","version"=>"","page"=>1,"size"=>15],
  20. "post","trim");
  21. $where=[];
  22. if($param['module']!='') $where[]=["module","like","%{$param['module']}%"];
  23. if($param['system']!='') $where[]=["system","like","%{$param['system']}%"];
  24. if($param['sys_type']!='') $where[]=["sys_type","=",$param['sys_type']];
  25. if($param['version']!='') $where[]=["version","like","%{$param['version']}%"];
  26. $count= Db::name("system_version")->where($where)->count();
  27. $total=ceil($count/$param['size']);
  28. $page = $total>=$param['page']? intval($param['page']): intval($total);
  29. $list = Db::name("system_version")->where($where)->page($page,intval($param['size']))->order("id desc")
  30. ->select();
  31. return app_show(0,"获取成功",["list"=>$list,'count'=>$count]);
  32. }
  33. /**
  34. * 显示创建资源表单页.
  35. *
  36. * @return \think\Response
  37. */
  38. public function create()
  39. {
  40. $param =$this->request->only(["module"=>"","system"=>"","sys_type"=>"","version"=>"",'addtime'],"post","trim");
  41. $valid= Validate::rule([
  42. "module|标题"=>"require|max:255|min:4",
  43. "system|内容"=>"require|min:4",
  44. "sys_type|数据类型"=>"require|in:VER,MSG",
  45. "version|版本号"=>"require|max:255|min:4",
  46. "addtime|时间"=>"require|date",
  47. ]);
  48. if($valid->check($param)==false) return error_show(1004,$valid->getError());
  49. $data=[
  50. "module"=>$param['module'],
  51. "system"=>$param['system'],
  52. "sys_type"=>$param['sys_type'],
  53. "version"=>$param['version'],
  54. "addtime"=>$param['addtime'],
  55. ];
  56. $ip= Db::name("system_version")->insert($data,true);
  57. return $ip?app_show(0,"新建成功",["id"=>$ip]):error_show(1004,"新建失败");
  58. }
  59. /**
  60. * 保存新建的资源
  61. *
  62. * @param \think\Request $request
  63. * @return \think\Response
  64. */
  65. public function save()
  66. {
  67. $param =$this->request->only(["id"=>'',"module"=>"","system"=>"","sys_type"=>"","version"=>"",'addtime'],"post","trim");
  68. $valid= Validate::rule([
  69. "module|标题"=>"require|max:255|min:4",
  70. "system|内容"=>"require|min:4",
  71. "sys_type|数据类型"=>"require|in:VER,MSG",
  72. "version|版本号"=>"require|max:255|min:4",
  73. "addtime|时间"=>"require|date",
  74. "id|数据ID"=>"require|number|gt:0",
  75. ]);
  76. if($valid->check($param)==false) return error_show(1004,$valid->getError());
  77. $info= Db::name("system_version")->where(["id"=>$param['id']])->findOrEmpty();
  78. if(empty($info)) return error_show(1004,'未获取到信息');
  79. $data=[
  80. "module"=>$param['module'],
  81. "system"=>$param['system'],
  82. "sys_type"=>$param['sys_type'],
  83. "version"=>$param['version'],
  84. "addtime"=>$param['addtime'],
  85. ];
  86. $ip= Db::name("system_version")->where($info)->update($data);
  87. return $ip?app_show(0,"编辑成功"):error_show(1004,"编辑失败");
  88. }
  89. /**
  90. * 显示指定的资源
  91. *
  92. * @param int $id
  93. * @return \think\Response
  94. */
  95. public function GetLast()
  96. {
  97. $param =$this->request->only(["sys_type"=>"VER"],"post","trim");
  98. $info= Db::name("system_version")->where(["sys_type"=>$param['sys_type']])->order("addtime desc,id desc")
  99. ->findOrEmpty();
  100. return app_show(0,"获取成功",$info);
  101. }
  102. public function GetRate()
  103. {
  104. $info= Db::name("order_rate")->where(["status"=>1])->select()->toArray();
  105. return app_show(0,"获取成功",$info);
  106. }
  107. }