Contents.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\common\controller\Backend;
  5. use think\facade\Db;
  6. use think\facade\Request;
  7. use think\facade\View;
  8. class Contents extends Backend
  9. {
  10. // todo 内容管理
  11. //轮播图
  12. public function index()
  13. {
  14. if (Request::isPost()){
  15. $page=input("page")?:1;
  16. $limit=input("limit")?:10;
  17. $url="http://".$_SERVER['HTTP_HOST'];
  18. $list=Db::name("banner")->order("id desc")->paginate(['list_rows' => $limit, 'page' => $page])->each(function ($item) use (&$url){
  19. $item["url"]=$url;
  20. return $item;
  21. })->toArray();
  22. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data']?:[], 'count' => $list['total']?:0];
  23. }
  24. return View::fetch();
  25. }
  26. // 添加轮播图
  27. public function addbanner()
  28. {
  29. $name=input("text");
  30. $img=input("img")?:"";
  31. $id=input("id");
  32. $add["text"]=$name;
  33. $add["img"]=$img;
  34. // $add["centos"]=$centos;
  35. if ($id){
  36. $where["id"]=$id;
  37. $res=Db::name("banner")->where($where)->update($add);
  38. }else{
  39. $res=Db::name("banner")->insert($add);
  40. }
  41. if ($res){
  42. json_result(1,"添加成功");
  43. }
  44. json_result(2,"添加失败");
  45. }
  46. public function add()
  47. {
  48. $id=input("id");
  49. $info=[];
  50. if ($id){
  51. $where["id"]=$id;
  52. $info=Db::name("banner")->where($where)->find();
  53. }else{
  54. $info["text"]='';
  55. $info["img"]='';
  56. }
  57. $view = [
  58. 'info' => $info,
  59. 'title' => lang('add'),
  60. ];
  61. View::assign($view);
  62. return View::fetch();
  63. }
  64. // 删除轮播图
  65. public function del_banner()
  66. {
  67. $id=input("id");
  68. $where["id"]=$id;
  69. Db::name("banner")->where($where)->delete();
  70. json_result(1,"删除成功");
  71. }
  72. //
  73. //关于我们
  74. public function about()
  75. {
  76. if (Request::isPost()){
  77. $centos=input("text");
  78. $add["text"]=$centos;
  79. $ehere["id"]=1;
  80. Db::name("about")->where($ehere)->update($add);
  81. json_result(1,"修改成功");
  82. }
  83. $data=Db::name("about")->where(["id"=>1])->value("text");
  84. // var_dump(date("Y-m-d",time()));
  85. $view = [
  86. 'info' => $data,
  87. 'title' => lang('add'),
  88. ];
  89. View::assign($view);
  90. return View::fetch();
  91. }
  92. //
  93. //意见反馈
  94. public function feedback()
  95. {
  96. if (Request::isPost()){
  97. $name=input("name");
  98. $page=input("page")?:1;
  99. $limit=input("limit")?:10;
  100. $where=[];
  101. if ($name){
  102. $where["name"]=["like","% $name %"];
  103. }
  104. $list=Db::name("feedback")->order("id desc")->where($where)->paginate(["list_row"=>$limit,"page"=>$page])->each(function ($item){
  105. if ($item["create_time"]){
  106. // var_dump($item["create_time"]);
  107. // $date=date('Y-m-s h:i:s',$item["create_time"]);
  108. // $item["create_time"]=$date;
  109. }
  110. return $item;
  111. })->toArray();
  112. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data']?:[], 'count' => $list['total']?:0];
  113. }
  114. return View::fetch();
  115. }
  116. }