System.php 3.8 KB

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