System.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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!=""){
  108. $list=UploadImg($files);
  109. }
  110. if(is_array($list)&&!empty($list)){
  111. return app_show(0, "上传成功!",$list);
  112. }else{
  113. return error_show(1005, "上传失败!".$list);
  114. }
  115. }
  116. /**
  117. * 显示编辑资源表单页.
  118. *
  119. * @param int $id
  120. * @return \think\Response
  121. */
  122. public function upload_file()
  123. {
  124. $post =$this->request->post();
  125. $token = isset($post['token']) ? trim($post['token']) : "";
  126. if($token==""){
  127. return error_show(101,'token不能为空');
  128. }
  129. $effetc = VerifyTokens($token);
  130. if(!empty($effetc) && $effetc['code']!=0){
  131. return error_show($effetc['code'],$effetc['message']);
  132. }
  133. $files = $this->request->file('files');
  134. $list="";
  135. if($files!=""){
  136. $list=UploadFile($files);
  137. }
  138. if(is_array($list)&&!empty($list)){
  139. return app_show(0, "上传成功!",$list);
  140. }else{
  141. return error_show(1005, "上传失败!".$list);
  142. }
  143. }
  144. /**
  145. * 显示编辑资源表单页.
  146. *
  147. * @param int $id
  148. * @return \think\Response
  149. */
  150. public function upload_video()
  151. {
  152. $post =$this->request->post();
  153. // $token = isset($post['token']) ? trim($post['token']) : "";
  154. // if($token==""){
  155. // return error_show(101,'token不能为空');
  156. // }
  157. // $effetc = VerifyTokens($token);
  158. // if(!empty($effetc) && $effetc['code']!=0){
  159. // return error_show($effetc['code'],$effetc['message']);
  160. // }
  161. $files = $this->request->file('video');
  162. $list="";
  163. if($files!=""){
  164. $list=UploadVideo($files);
  165. }
  166. if(is_array($list)&&!empty($list)){
  167. return app_show(0, "上传成功!",$list);
  168. }else{
  169. return error_show(1005, "上传失败!".$list);
  170. }
  171. }
  172. /**
  173. * 保存更新的资源
  174. *
  175. * @param \think\Request $request
  176. * @param int $id
  177. * @return \think\Response
  178. */
  179. public function update(Request $request, $id)
  180. {
  181. //
  182. }
  183. /**
  184. * 删除指定资源
  185. *
  186. * @param int $id
  187. * @return \think\Response
  188. */
  189. public function delete($id)
  190. {
  191. //
  192. }
  193. //添加版本信息
  194. public function add()
  195. {
  196. $param = $this->request->only(['module', 'system', 'sys_type', 'version', 'addtime'], 'post');
  197. $val = Validate::rule([
  198. 'module' => 'require|max:255',
  199. 'system' => 'require',
  200. 'sys_type' => 'require|upper|in:MSG,VER',
  201. 'version' => 'require|max:255',
  202. 'addtime' => 'require|date',
  203. ]);
  204. if (!$val->check($param)) return error_show(1004, $val->getError());
  205. $rs = Db::name('system_version')
  206. ->insert($param);
  207. return $rs ? app_show(0, '添加版本信息成功') : error_show(1004, '添加版本信息失败');
  208. }
  209. }