Contents.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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. use app\common\model\User;
  11. class Contents extends Backend
  12. {
  13. // todo 内容管理
  14. //轮播图
  15. public function index()
  16. {
  17. if (Request::isPost()){
  18. $page=input("page")?:1;
  19. $limit=input("limit")?:10;
  20. $url="http://".$_SERVER['HTTP_HOST'];
  21. $list=Db::name("banner")->order("id desc")->paginate(['list_rows' => $limit, 'page' => $page])->each(function ($item) use (&$url){
  22. $item["url"]=$url;
  23. return $item;
  24. })->toArray();
  25. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data']?:[], 'count' => $list['total']?:0];
  26. }
  27. return View::fetch();
  28. }
  29. // 添加轮播图
  30. public function addbanner()
  31. {
  32. $name=input("text");
  33. $img=input("img")?:"";
  34. $text=input("text")?:"";
  35. $id=input("id");
  36. $add["text"]=$name;
  37. $add["image"]=$img;
  38. $add["text"]=$text;
  39. // $add["centos"]=$centos;
  40. if ($id){
  41. $where["id"]=$id;
  42. $res=Db::name("banner")->where($where)->update($add);
  43. }else{
  44. $res=Db::name("banner")->insert($add);
  45. }
  46. if ($res){
  47. json_result(1,"添加成功");
  48. }
  49. json_result(2,"添加失败");
  50. }
  51. public function add()
  52. {
  53. $id=input("id");
  54. $info=[];
  55. if ($id){
  56. $where["id"]=$id;
  57. $info=Db::name("banner")->where($where)->find();
  58. }else{
  59. $info["text"]='';
  60. $info["img"]='';
  61. }
  62. $view = [
  63. 'info' => $info,
  64. 'title' => lang('add'),
  65. ];
  66. View::assign($view);
  67. return View::fetch();
  68. }
  69. // 删除轮播图
  70. public function del_banner()
  71. {
  72. $id=input("id");
  73. $where["id"]=$id;
  74. Db::name("banner")->where($where)->delete();
  75. json_result(1,"删除成功");
  76. }
  77. //
  78. //关于我们
  79. public function about()
  80. {
  81. if (Request::isPost()){
  82. $centos=input("text");
  83. $add["text"]=$centos;
  84. $ehere["id"]=1;
  85. Db::name("about")->where($ehere)->update($add);
  86. json_result(1,"修改成功");
  87. }
  88. $data=Db::name("about")->where(["id"=>1])->value("text");
  89. $view = [
  90. 'info' => $data,
  91. 'title' => lang('add'),
  92. ];
  93. View::assign($view);
  94. return View::fetch();
  95. }
  96. //
  97. //意见反馈
  98. public function feedback()
  99. {
  100. if (Request::isPost()){
  101. $name=input("name");
  102. $page=input("page")?:1;
  103. $limit=input("limit")?:10;
  104. $where=[];
  105. // if ($name){
  106. // $where["name"]=["like","% $name %"];
  107. // }
  108. $list=Db::name("feedback")->order("id desc")->where($where)->paginate(["list_row"=>$limit,"page"=>$page])->each(function ($item){
  109. $user=\app\common\model\User::where(["id"=>$item["user_id"]])->field("name")->find();
  110. $item["name"]=$user->name;
  111. if ($item["image"]){
  112. $item["image"]=explode(",",$item["image"]);
  113. }else{
  114. $item["image"]="";
  115. }
  116. return $item;
  117. })->toArray();
  118. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data']?:[], 'count' => $list['total']?:0];
  119. }
  120. return View::fetch();
  121. }
  122. //
  123. public function hlep()
  124. {
  125. if (Request::isPost()){
  126. $name=input("name");
  127. $page=input("page")?:1;
  128. $limit=input("limit")?:10;
  129. $where=[];
  130. $list=Db::name("problem")->order("id desc")->where($where)->paginate(["list_row"=>$limit,"page"=>$page])->each(function ($item){
  131. return $item;
  132. })->toArray();
  133. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data']?:[], 'count' => $list['total']?:0];
  134. }
  135. return View::fetch();
  136. }
  137. // 删除常见问题
  138. public function del_hlep()
  139. {
  140. $id=input("id");
  141. Problem::where(["id"=>$id])->delete();
  142. json_result(200,"删除成功");
  143. }
  144. // 添加修改
  145. public function addhlep()
  146. {
  147. if (Request::isPost()){
  148. $id=input("id");
  149. $add["name"]=input("name");
  150. $add["text"]=input("text");
  151. if ($id){
  152. Problem::update($add,["id"=>$id]);
  153. }else{
  154. Problem::create($add);
  155. }
  156. json_result(200,"操作成功");
  157. }else{
  158. $id=input("id");
  159. if ($id){
  160. $da=Problem::where(["id"=>$id])->find();
  161. $info["name"]=$da->name;
  162. $info["text"]=$da->text;
  163. $info["id"]=$id;
  164. }else{
  165. $info["name"]="";
  166. $info["text"]="";
  167. $info["id"]=0;
  168. }
  169. $view = [
  170. 'info' => $info,
  171. 'title' => lang('add'),
  172. ];
  173. View::assign($view);
  174. return View::fetch();
  175. }
  176. }
  177. // 收款信息
  178. public function push()
  179. {
  180. if (Request::isPost()){
  181. $data = Request::post();
  182. foreach ($data as $k=>$v){
  183. $res = Db::name('system')->where('name',$k)->update(['value'=>$v]);
  184. }
  185. json_result(200,"修改成功",$data);
  186. }
  187. $list = Db::name('system')
  188. ->where(["type"=>"shouk"])
  189. ->field('name,value')
  190. ->column('value','name');
  191. View::assign('config',json_encode($list));
  192. $view = [
  193. 'info' => $list,
  194. 'title' => lang('add'),
  195. ];
  196. View::assign($view);
  197. return View::fetch();
  198. }
  199. //系统消息管理
  200. public function sysmsg()
  201. {
  202. if (Request::isPost()){
  203. $name=input("name");
  204. $page=input("page")?:1;
  205. $limit=input("limit")?:10;
  206. $where=[];
  207. $list=Db::name("notice")->order("id desc")->where($where)->paginate(["list_row"=>$limit,"page"=>$page])->each(function ($item){
  208. return $item;
  209. })->toArray();
  210. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data']?:[], 'count' => $list['total']?:0];
  211. }
  212. return View::fetch();
  213. }
  214. // 更新是否显示消息
  215. public function update_nocice_status()
  216. {
  217. $id=input("id");
  218. $status=input("status")?:0;
  219. Notice::update(["status"=>$status],["id"=>$id]);
  220. json_result(200,"操作成功");
  221. }
  222. public function del_msg()
  223. {
  224. $id=input("id");
  225. Notice::where(["id"=>$id])->delete();
  226. json_result(200,"删除成功");
  227. }
  228. // 添加消息
  229. public function addmsg()
  230. {
  231. if (Request::isPost()){
  232. $id=input("id");
  233. $add["name"]=input("name");
  234. $add["text"]=input("text");
  235. if ($id){
  236. Notice::update($add,["id"=>$id]);
  237. }else{
  238. Notice::create($add);
  239. }
  240. json_result(200,"操作成功");
  241. }else{
  242. $id=input("id");
  243. if ($id){
  244. $da=Problem::where(["id"=>$id])->find();
  245. $info["name"]=$da->name;
  246. $info["text"]=$da->text;
  247. $info["id"]=$id;
  248. }else{
  249. $info["name"]="";
  250. $info["text"]="";
  251. $info["id"]=0;
  252. }
  253. $view = [
  254. 'info' => $info,
  255. 'title' => lang('add'),
  256. ];
  257. View::assign($view);
  258. return View::fetch();
  259. }
  260. }
  261. // 开盘设置
  262. public function opens()
  263. {
  264. if (Request::isPost()){
  265. $data = Request::post();
  266. if (isset($data["open"])){
  267. $data["open"]=1;
  268. }else{
  269. $data["open"]="";
  270. }
  271. foreach ($data as $k=>$v){
  272. $res = Db::name('system')->where('name',$k)->update(['value'=>$v]);
  273. }
  274. json_result(200,"修改成功",$data);
  275. }
  276. $list = Db::name('system')
  277. ->where(["type"=>"open"])
  278. ->field('name,value')
  279. ->column('value','name');
  280. // var_dump($list["open"]);die();
  281. View::assign('config',json_encode($list));
  282. $view = [
  283. 'info' => $list,
  284. 'title' => lang('add'),
  285. ];
  286. View::assign($view);
  287. return View::fetch();
  288. }
  289. // 后台收款账号
  290. public function adminuser()
  291. {
  292. if (Request::isPost()){
  293. $page=input("page")?:1;
  294. $limit=input("limit")?:10;
  295. $name=input("name");
  296. $where=[];
  297. if ($name){
  298. $where[]=["name","like","%".$name."%"];
  299. }
  300. $where[]=["admin","=",1];
  301. $list=User::where($where)->order("id desc")->paginate(['list_rows' => $limit, 'page' => $page])->each(function ($item) {
  302. return $item;
  303. })->toArray();
  304. return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data']?:[], 'count' => $list['total']?:0];
  305. }
  306. return View::fetch();
  307. }
  308. // 修改信息
  309. public function update_user_admin()
  310. {
  311. $id=input("id");
  312. $field=input("field");
  313. $value=input("value");
  314. $where["id"]=$id;
  315. $update[$field]=$value;
  316. User::update($update,$where);
  317. json_result(200,"操作成功");
  318. }
  319. // 收款信息
  320. public function showuser()
  321. {
  322. if (Request::isPost()) {
  323. $data = Request::post();
  324. $adminid=input("user_id");
  325. $where["user_id"]=$adminid;
  326. \app\common\model\UserMessage::update($data,$where);
  327. json_result(200, "修改成功", $data);
  328. }
  329. $adminid=input("user_id");
  330. $where["user_id"]=$adminid;
  331. $code=\app\common\model\UserMessage::where($where)->find();
  332. if (!$code){
  333. \app\common\model\UserMessage::create($where);
  334. $code=\app\common\model\UserMessage::where($where)->find();
  335. }
  336. View::assign("user",$code);
  337. return View::fetch();
  338. }
  339. // 封号
  340. public function fenhao()
  341. {
  342. $id=input("id");
  343. $user=\app\common\model\User::where(["id"=>$id])->field("status")->find();
  344. if ($user->status==1){
  345. $update["status"]=0;
  346. }else{
  347. $update["status"]=1;
  348. }
  349. \app\common\model\User::update($update,["id"=>$id]);
  350. json_result(200,"操作成功");
  351. }
  352. // 密码重置
  353. public function update_pwd()
  354. {
  355. $id=input("id");
  356. $pwd=input("pwd");
  357. $data["pwd"] = password_hash($pwd, PASSWORD_DEFAULT);;
  358. User::update($data,["id"=>$id]);
  359. json_result(200,"重置成功");
  360. }
  361. // 删除账号
  362. public function delete_user()
  363. {
  364. $id=input("id");
  365. User::where(["id"=>$id])->delete();
  366. json_result(200,"删除成功");
  367. }
  368. // 添加后台账号
  369. public function add_admin_user()
  370. {
  371. $name=input("name");
  372. $add["name"]=$name;
  373. $add["admin"]=1;
  374. $add["add_time"]=time();
  375. $add["update_time"]=time();
  376. User::create($add);
  377. json_result(200,"添加成功");
  378. }
  379. }