System.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\BaseController;
  5. use think\facade\Db;
  6. use think\facade\Validate;
  7. use think\Request;
  8. //系统设置
  9. class System extends BaseController
  10. {
  11. /**
  12. * 显示资源列表
  13. *
  14. * @return \think\Response
  15. */
  16. public function index()
  17. {
  18. $post =$this->request->post();
  19. $token = isset($post['token']) ? trim($post['token']) : "";
  20. if($token==""){
  21. return error_show(101,'token不能为空');
  22. }
  23. $effetc =VerifyTokens($token);
  24. if(!empty($effetc) && $effetc['code']!=0){
  25. return error_show($effetc['code'],$effetc['message']);
  26. }
  27. $condition = [];
  28. isset($post['startTime'])&& $post['startTime']!="" ? $condition[] = ["addtime",">=",$post["startTime"]]:"";
  29. isset($post['endTime'])&& $post['endTime']!="" ? $condition[] = ["addtime","<=",$post["endTime"]]:"";
  30. isset($post['event'])&& $post['event']!="" ? $condition[] = ["url","like","%".$post['event']."%"]:"";
  31. isset($post['name'])&& $post['name']!="" ? $condition[] = ["name","like","%".$post['name']."%"]:"";
  32. isset($post['action'])&& $post['action']!="" ? $condition[] = ["info","=",$post["action"]]:"";
  33. isset($post['role'])&& $post['role']!="" ? $condition[] = ["rolename","like","%".$post['role']."%"]:"";
  34. $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :0;
  35. $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10;
  36. $count = Db::name("system_log")->where($condition)->count();
  37. $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
  38. $page = $page>=$total?intval($total):$page;
  39. $list = Db::name("system_log")->where($condition)->page($page,$size)->order("addtime desc")->field("id,info,url,param,rolename,name,addtime")->select();
  40. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  41. }
  42. /**
  43. * 显示创建资源表单页.
  44. *
  45. * @return \think\Response
  46. */
  47. public function version()
  48. {
  49. $post =$this->request->post();
  50. $token = isset($post['token']) ? trim($post['token']) : "";
  51. if($token==""){
  52. return error_show(101,'token不能为空');
  53. }
  54. $effetc =VerifyTokens($token);
  55. if(!empty($effetc) && $effetc['code']!=0){
  56. return error_show($effetc['code'],$effetc['message']);
  57. }
  58. $condition = " 1=1 ";
  59. $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :0;
  60. $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10;
  61. $count = Db::name("system_version")->where($condition)->count();
  62. $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
  63. $page = $page>=$total?intval($total):$page;
  64. $list = Db::name("system_version")->where($condition)->page($page,$size)->order("addtime desc")->select();
  65. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  66. }
  67. /**
  68. * 保存新建的资源
  69. *
  70. * @param \think\Request $request
  71. * @return \think\Response
  72. */
  73. public function LastVersion()
  74. {
  75. $post =$this->request->post();
  76. $type = isset($post['type'])&& $post['type']!="" ? $post['type'] : "";
  77. if($type=="" || !in_array($type,["VER","MSG"])){
  78. $where="1=1";
  79. }else{
  80. $where="sys_type='{$type}'";
  81. }
  82. $version=Db::name("system_version")->where($where)->order("addtime desc")->find();
  83. if(!$version){
  84. return error_show(1004,'未找到数据');
  85. }
  86. return app_show(0,"获取成功",$version);
  87. }
  88. /**
  89. * 显示指定的资源
  90. *
  91. * @param int $id
  92. * @return \think\Response
  93. */
  94. public function upload()
  95. {
  96. // $post =$this->request->post();
  97. // $token = isset($post['token']) ? trim($post['token']) : "";
  98. // if($token==""){
  99. // return error_show(101,'token不能为空');
  100. // }
  101. // $effetc = VerifyTokens($token);
  102. // if(!empty($effetc) && $effetc['code']!=0){
  103. // return error_show($effetc['code'],$effetc['message']);
  104. // }
  105. $files = $this->request->file('image');
  106. $list = "";
  107. if ($files != "") $list = UploadImg($files);
  108. if (is_array($list) && !empty($list)) return json_show(0, "上传成功!", $list);
  109. else return json_show(1005, "上传失败!" . $list);
  110. }
  111. /**
  112. * 显示编辑资源表单页.
  113. *
  114. * @param int $id
  115. * @return \think\Response
  116. */
  117. public function upload_file()
  118. {
  119. $post =$this->request->post();
  120. $token = isset($post['token']) ? trim($post['token']) : "";
  121. if($token==""){
  122. return error_show(101,'token不能为空');
  123. }
  124. $effetc = VerifyTokens($token);
  125. if(!empty($effetc) && $effetc['code']!=0){
  126. return error_show($effetc['code'],$effetc['message']);
  127. }
  128. $files = $this->request->file('files');
  129. $list="";
  130. if($files!=""){
  131. $list=UploadFile($files);
  132. }
  133. if(is_array($list)&&!empty($list)){
  134. return app_show(0, "上传成功!",$list);
  135. }else{
  136. return error_show(1005, "上传失败!".$list);
  137. }
  138. }
  139. /**
  140. * 显示编辑资源表单页.
  141. *
  142. * @param int $id
  143. * @return \think\Response
  144. */
  145. public function upload_video()
  146. {
  147. $post =$this->request->post();
  148. // $token = isset($post['token']) ? trim($post['token']) : "";
  149. // if($token==""){
  150. // return error_show(101,'token不能为空');
  151. // }
  152. // $effetc = VerifyTokens($token);
  153. // if(!empty($effetc) && $effetc['code']!=0){
  154. // return error_show($effetc['code'],$effetc['message']);
  155. // }
  156. $files = $this->request->file('video');
  157. $list="";
  158. if($files!=""){
  159. $list=UploadVideo($files);
  160. }
  161. if(is_array($list)&&!empty($list)){
  162. return app_show(0, "上传成功!",$list);
  163. }else{
  164. return error_show(1005, "上传失败!".$list);
  165. }
  166. }
  167. /**
  168. * 保存更新的资源
  169. *
  170. * @param \think\Request $request
  171. * @param int $id
  172. * @return \think\Response
  173. */
  174. public function update(Request $request, $id)
  175. {
  176. //
  177. }
  178. /**
  179. * 删除指定资源
  180. *
  181. * @param int $id
  182. * @return \think\Response
  183. */
  184. public function delete($id)
  185. {
  186. //
  187. }
  188. //添加版本信息
  189. public function add()
  190. {
  191. $param = $this->request->only(['module', 'system', 'sys_type', 'version', 'addtime'], 'post');
  192. $val = Validate::rule([
  193. 'module' => 'require|max:255',
  194. 'system' => 'require',
  195. 'sys_type' => 'require|upper|in:MSG,VER',
  196. 'version' => 'require|max:255',
  197. 'addtime' => 'require|date',
  198. ]);
  199. if (!$val->check($param)) return error_show(1004, $val->getError());
  200. $rs = Db::name('system_version')
  201. ->insert($param);
  202. return $rs ? app_show(0, '添加版本信息成功') : error_show(1004, '添加版本信息失败');
  203. }
  204. }