Contents.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\common\controller\Backend;
  5. use app\common\model\Notice;
  6. use app\common\model\Problem;
  7. use think\facade\Db;
  8. use think\facade\Request;
  9. use think\facade\View;
  10. class Contents extends Backend
  11. {
  12. // todo 内容管理
  13. //轮播图
  14. public function index()
  15. {
  16. if (Request::isPost()){
  17. $page=input("page")?:1;
  18. $limit=input("limit")?:10;
  19. $url="http://".$_SERVER['HTTP_HOST'];
  20. $list=Db::name("banner")->order("id desc")->paginate(['list_rows' => $limit, 'page' => $page])->each(function ($item) use (&$url){
  21. $item["url"]=$url;
  22. return $item;
  23. })->toArray();
  24. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data']?:[], 'count' => $list['total']?:0];
  25. }
  26. return View::fetch();
  27. }
  28. // 添加轮播图
  29. public function addbanner()
  30. {
  31. $name=input("text");
  32. $img=input("img")?:"";
  33. $text=input("text")?:"";
  34. $id=input("id");
  35. $add["text"]=$name;
  36. $add["image"]=$img;
  37. $add["text"]=$text;
  38. // $add["centos"]=$centos;
  39. if ($id){
  40. $where["id"]=$id;
  41. $res=Db::name("banner")->where($where)->update($add);
  42. }else{
  43. $res=Db::name("banner")->insert($add);
  44. }
  45. if ($res){
  46. json_result(1,"添加成功");
  47. }
  48. json_result(2,"添加失败");
  49. }
  50. public function add()
  51. {
  52. $id=input("id");
  53. $info=[];
  54. if ($id){
  55. $where["id"]=$id;
  56. $info=Db::name("banner")->where($where)->find();
  57. }else{
  58. $info["text"]='';
  59. $info["img"]='';
  60. }
  61. $view = [
  62. 'info' => $info,
  63. 'title' => lang('add'),
  64. ];
  65. View::assign($view);
  66. return View::fetch();
  67. }
  68. // 删除轮播图
  69. public function del_banner()
  70. {
  71. $id=input("id");
  72. $where["id"]=$id;
  73. Db::name("banner")->where($where)->delete();
  74. json_result(1,"删除成功");
  75. }
  76. //
  77. //关于我们
  78. public function about()
  79. {
  80. if (Request::isPost()){
  81. $centos=input("text");
  82. $add["text"]=$centos;
  83. $ehere["id"]=1;
  84. Db::name("about")->where($ehere)->update($add);
  85. json_result(1,"修改成功");
  86. }
  87. $data=Db::name("about")->where(["id"=>1])->value("text");
  88. $view = [
  89. 'info' => $data,
  90. 'title' => lang('add'),
  91. ];
  92. View::assign($view);
  93. return View::fetch();
  94. }
  95. //
  96. //意见反馈
  97. public function feedback()
  98. {
  99. if (Request::isPost()){
  100. $name=input("name");
  101. $page=input("page")?:1;
  102. $limit=input("limit")?:10;
  103. $where=[];
  104. // if ($name){
  105. // $where["name"]=["like","% $name %"];
  106. // }
  107. $list=Db::name("feedback")->order("id desc")->where($where)->paginate(["list_row"=>$limit,"page"=>$page])->each(function ($item){
  108. $user=\app\common\model\User::where(["id"=>$item["user_id"]])->field("name")->find();
  109. $item["name"]=$user->name;
  110. if ($item["image"]){
  111. $item["image"]=explode(",",$item["image"]);
  112. }else{
  113. $item["image"]="";
  114. }
  115. return $item;
  116. })->toArray();
  117. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data']?:[], 'count' => $list['total']?:0];
  118. }
  119. return View::fetch();
  120. }
  121. //
  122. public function hlep()
  123. {
  124. if (Request::isPost()){
  125. $name=input("name");
  126. $page=input("page")?:1;
  127. $limit=input("limit")?:10;
  128. $where=[];
  129. $list=Db::name("problem")->order("id desc")->where($where)->paginate(["list_row"=>$limit,"page"=>$page])->each(function ($item){
  130. return $item;
  131. })->toArray();
  132. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data']?:[], 'count' => $list['total']?:0];
  133. }
  134. return View::fetch();
  135. }
  136. // 删除常见问题
  137. public function del_hlep()
  138. {
  139. $id=input("id");
  140. Problem::where(["id"=>$id])->delete();
  141. json_result(200,"删除成功");
  142. }
  143. // 添加修改
  144. public function addhlep()
  145. {
  146. if (Request::isPost()){
  147. $id=input("id");
  148. $add["name"]=input("name");
  149. $add["text"]=input("text");
  150. if ($id){
  151. Problem::update($add,["id"=>$id]);
  152. }else{
  153. Problem::create($add);
  154. }
  155. json_result(200,"操作成功");
  156. }else{
  157. $id=input("id");
  158. if ($id){
  159. $da=Problem::where(["id"=>$id])->find();
  160. $info["name"]=$da->name;
  161. $info["text"]=$da->text;
  162. $info["id"]=$id;
  163. }else{
  164. $info["name"]="";
  165. $info["text"]="";
  166. $info["id"]=0;
  167. }
  168. $view = [
  169. 'info' => $info,
  170. 'title' => lang('add'),
  171. ];
  172. View::assign($view);
  173. return View::fetch();
  174. }
  175. }
  176. // 收款信息
  177. public function push()
  178. {
  179. if (Request::isPost()){
  180. $data = Request::post();
  181. foreach ($data as $k=>$v){
  182. $res = Db::name('system')->where('name',$k)->update(['value'=>$v]);
  183. }
  184. json_result(200,"修改成功",$data);
  185. }
  186. $list = Db::name('system')
  187. ->where(["type"=>"shouk"])
  188. ->field('name,value')
  189. ->column('value','name');
  190. View::assign('config',json_encode($list));
  191. $view = [
  192. 'info' => $list,
  193. 'title' => lang('add'),
  194. ];
  195. View::assign($view);
  196. return View::fetch();
  197. }
  198. //系统消息管理
  199. public function sysmsg()
  200. {
  201. if (Request::isPost()){
  202. $name=input("name");
  203. $page=input("page")?:1;
  204. $limit=input("limit")?:10;
  205. $where=[];
  206. $list=Db::name("notice")->order("id desc")->where($where)->paginate(["list_row"=>$limit,"page"=>$page])->each(function ($item){
  207. return $item;
  208. })->toArray();
  209. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data']?:[], 'count' => $list['total']?:0];
  210. }
  211. return View::fetch();
  212. }
  213. // 更新是否显示消息
  214. public function update_nocice_status()
  215. {
  216. $id=input("id");
  217. $status=input("status")?:0;
  218. Notice::update(["status"=>$status],["id"=>$id]);
  219. json_result(200,"操作成功");
  220. }
  221. public function del_msg()
  222. {
  223. $id=input("id");
  224. Notice::where(["id"=>$id])->delete();
  225. json_result(200,"删除成功");
  226. }
  227. // 添加消息
  228. public function addmsg()
  229. {
  230. if (Request::isPost()){
  231. $id=input("id");
  232. $add["name"]=input("name");
  233. $add["text"]=input("text");
  234. if ($id){
  235. Notice::update($add,["id"=>$id]);
  236. }else{
  237. Notice::create($add);
  238. }
  239. json_result(200,"操作成功");
  240. }else{
  241. $id=input("id");
  242. if ($id){
  243. $da=Problem::where(["id"=>$id])->find();
  244. $info["name"]=$da->name;
  245. $info["text"]=$da->text;
  246. $info["id"]=$id;
  247. }else{
  248. $info["name"]="";
  249. $info["text"]="";
  250. $info["id"]=0;
  251. }
  252. $view = [
  253. 'info' => $info,
  254. 'title' => lang('add'),
  255. ];
  256. View::assign($view);
  257. return View::fetch();
  258. }
  259. }
  260. }