Blogger Information
Blog 70
fans 4
comment 5
visits 105104
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP:【商城后台管理系统】部署友情链接,网站基础设置
JiaJieChen
Original
1819 people have browsed it

PHP:【商城后台管理系统】部署友情链接,网站基础设置

一.友情链接

①友情链接页面

②友情链接编辑

③友情链接添加

二.网站基础设置

①后台网站基础设置页面

②网站基础设置效果

三.部署流程

  • 部署流程
    • 后端采用thinkphp6.0,首先是网站基础设置,网站基础在数据库中可以建立一个单独的表,但是这个单独的表存放的信息很特殊,表里可以存商品规格,或者别的数据,因为这个网站设置就是设置网站的tdk,表字段的名称是这样的,id,names,values,就只有这两个字段,names的字段可以存tdk,或者商品名称,第二个values,可以存放tdk的信息,还有商品规格信息,我们将这些数据转换成json存入表中,需要的时候再json_decode取出渲染到前端页面。友情链接就比较简单了,可以新建一个友情链接的表,存放链接数据到表中。
    • 前端采用Layui前端UI框架

HTML 友情链接代码块

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>友情链接</title>
  8. <link rel="stylesheet" href="/static/layui-v2.6.8/layui/css/layui.css" />
  9. <script src="/static/layui-v2.6.8/layui/layui.js"></script>
  10. </head>
  11. <body style="padding: 10px;min-width:1000px;">
  12. <div class="layui-item"style="height:36px;border-bottom: 3px solid #009688;" >
  13. <span style="color:#777;font-size:20px;height:30px;line-height:30px">首页/</span>
  14. <span style="color:#ccc">友情链接</span>
  15. <button class="layui-btn layui-btn-sm" style="float:right;margin:5px" onclick="add()">添加</button>
  16. </div>
  17. <table class="layui-table" >
  18. <thead>
  19. <tr>
  20. <th>ID</th>
  21. <th>友链名称</th>
  22. <th>友链地址</th>
  23. <th>友链图标</th>
  24. <th>友链描述</th>
  25. <th>添加时间</th>
  26. <th>状态</th>
  27. <th>编辑</th>
  28. </tr>
  29. </thead>
  30. <tbody>
  31. {foreach $friend as $v}
  32. <tr>
  33. <td>{$v['id']}</td>
  34. <td>{$v['title']}</td>
  35. <td><a href="">{$v['url']}</a></td>
  36. <td style="text-align: center;"><img src="{$v['url_img']}" style="width: 80px;"></td>
  37. <td >{$v['description']}</td>
  38. <td>{:date('Y-m-d H:i:s',$v['add_time'])}</td>
  39. <td>{$v['status']==0?'<span style="color: green;">显示</span>':'<span style="color: red;">关闭</span>'}</td>
  40. <td>
  41. <button class="layui-btn layui-btn-sm" onclick="edit({$v['id']})">编辑</button>
  42. <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="dle({$v['id']})">删除</button>
  43. </td>
  44. </tr>
  45. {/foreach}
  46. </tbody>
  47. </table>
  48. </body>
  49. <script>
  50. $ = layui.jquery;
  51. //修改友情链接
  52. function edit(id) {
  53. layer.open({
  54. type:2,
  55. title: '修改信息',
  56. shadeClose: true,
  57. shade: 0.8,
  58. area: ['450px', '450px'],
  59. content: '/admin/Setting/edit_friend_link?id='+id
  60. });
  61. }
  62. //删除
  63. function dle(id) {
  64. layer.confirm('确定删除吗?', {
  65. btn: ['确定','取消'],
  66. },
  67. function(){
  68. let date = {};
  69. $.post('/admin/Setting/dle_friend_link?id='+id,date,function(res){
  70. if (res.id == 1) {
  71. layer.alert(res.msg,{icon:1});
  72. setTimeout(() => {
  73. window.location.reload();
  74. }, 1000);
  75. }else{
  76. layer.alert(res.msg,{icon:2});
  77. }
  78. },'json')
  79. });
  80. }
  81. //添加友情链接
  82. function add()
  83. {
  84. layer.open({
  85. type:2,
  86. title: '添加信息',
  87. shadeClose: true,
  88. shade: 0.8,
  89. area: ['500px', '500px'],
  90. content: '/admin/Setting/save_friend_link'
  91. });
  92. }
  93. </script>
  94. </html>

HTML 网站设置代码块

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>管理员账号列表</title>
  8. <link rel="stylesheet" href="/static/layui-v2.6.8/layui/css/layui.css" />
  9. <script src="/static/layui-v2.6.8/layui/layui.js"></script>
  10. </head>
  11. <body style="padding: 10px;min-width:737px">
  12. <div class="layui-item" style="height:36px;border-bottom: 3px solid #009688;" >
  13. <span style="color:#777;font-size:20px;height:30px;line-height:30px">首页/</span>
  14. <span style="color:#ccc">基础设置</span>
  15. </div>
  16. <form class="layui-form">
  17. <div class="layui-box" style="padding: 10px;width:600px">
  18. <div class="layui-form-item">
  19. <label for="" class="layui-form-label">网站名称</label>
  20. <div class="layui-input-block">
  21. <input type="text" class="layui-input" name="title" value="{$find['vals']['title']}" placeholder="请输入" >
  22. </div>
  23. </div>
  24. <div class="layui-form-item">
  25. <label for="" class="layui-form-label">网站域名</label>
  26. <div class="layui-input-block">
  27. <input type="text" class="layui-input" name="url" value="{$find['vals']['url']}"" placeholder="请输入" >
  28. </div>
  29. </div>
  30. <div class="layui-form-item">
  31. <label for="" class="layui-form-label">Keywords</label>
  32. <div class="layui-input-block">
  33. <textarea name="Keywords" required lay-verify="required" placeholder="请输入" class="layui-textarea">{$find['vals']['Keywords']}</textarea>
  34. </div>
  35. </div>
  36. <div class="layui-form-item">
  37. <label for="" class="layui-form-label">description</label>
  38. <div class="layui-input-block">
  39. <textarea name="description" required lay-verify="required" placeholder="请输入" class="layui-textarea">{$find['vals']['description']}</textarea>
  40. </div>
  41. </div>
  42. <div class="layui-form-item">
  43. <label for="" class="layui-form-label">客服QQ</label>
  44. <div class="layui-input-block">
  45. <input type="text" class="layui-input" name="qq" value="{$find['vals']['qq']}" placeholder="请输入" >
  46. </div>
  47. </div>
  48. <div class="layui-form-item">
  49. <label for="" class="layui-form-label">客服电话</label>
  50. <div class="layui-input-block">
  51. <input type="text" class="layui-input" name="contact" value="{$find['vals']['contact']}" placeholder="请输入" >
  52. </div>
  53. </div>
  54. <div class="layui-form-item">
  55. <label for="" class="layui-form-label">版权信息</label>
  56. <div class="layui-input-block">
  57. <textarea name="copyright" required lay-verify="required" placeholder="请输入" class="layui-textarea">{$find['vals']['copyright']}</textarea>
  58. </div>
  59. </div>
  60. <div class="layui-form-item">
  61. <label for="" class="layui-form-label">备案号</label>
  62. <div class="layui-input-block">
  63. <input type="text" class="layui-input" name="record" value="{$find['vals']['record']}" placeholder="请输入" >
  64. </div>
  65. </div>
  66. <div class="layui-form-item">
  67. <div class="layui-input-block">
  68. <button class="layui-btn" type="button" onclick="save()">保存</button>
  69. </div>
  70. </div>
  71. </div>
  72. </form>
  73. </body>
  74. <script>
  75. $ = layui.jquery;
  76. //页面刷新时聚焦焦点
  77. $('input[name = "title"]').focus();
  78. //保存
  79. function save()
  80. {
  81. if ($('input[name = "title"]').val() == '') {
  82. layer.alert('网站名称不能为空',{icon:2});
  83. return;
  84. }
  85. if ($('textarea[name = "Keywords"]').val() == '') {
  86. layer.alert('Keywords不能为空',{icon:2});
  87. return;
  88. }
  89. if ($('textarea[name = "description"]').val() == '') {
  90. layer.alert('description不能为空',{icon:2});
  91. return;
  92. }
  93. if ($('input[name = "qq"]').val() == '') {
  94. layer.alert('客服qq不能为空',{icon:2});
  95. return;
  96. }
  97. $.post('/admin/Setting/basesetting',$('form').serialize(),function (res) {
  98. if (res.id == 1) {
  99. layer.alert(res.msg,{icon:1});
  100. setTimeout(() => {
  101. parent.window.location.reload();
  102. }, 1000);
  103. }else{
  104. layer.alert(res.msg,{icon:2});
  105. }
  106. },'json')
  107. }
  108. </script>
  109. </html>

PHP 友情链接/网站设置代码块

  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\controller\Base;
  4. use think\facade\Request;
  5. use think\facade\Db;
  6. use think\facade\View;
  7. use think\facade\Session;
  8. /**
  9. * 网站管理
  10. */
  11. class Setting extends Base
  12. { //友情链接
  13. public function friend_link()
  14. {
  15. $friend_link = Db::table('friend_link')->select()->toArray();
  16. View::assign([
  17. 'friend' => $friend_link
  18. ]);
  19. return View('/setting/friend_link');
  20. }
  21. //添加友情链接
  22. public function save_friend_link()
  23. {
  24. if (Request::isPost()) {
  25. $data['title'] = Request::post('title');
  26. $data['url'] = Request::post('url');
  27. $data['url_img'] = Request::post('url_img');
  28. $data['description'] = Request::post('description');
  29. $data['add_time'] = time();
  30. $data['status'] = Request::post('status');
  31. if (empty($data['title'])) {
  32. exit(json_encode(['id'=>0,'msg'=>'友链名称不能为空']));
  33. }
  34. if (empty($data['url'])) {
  35. exit(json_encode(['id'=>0,'msg'=>'友链地址不能为空']));
  36. }
  37. $insert = Db::table('friend_link')->insert($data);
  38. if (!empty($insert)) {
  39. echo json_encode(['id'=>1,'msg'=>'保存成功']);
  40. }else {
  41. echo json_encode(['id'=>0,'msg'=>'保存失败']);
  42. }
  43. }else {
  44. return View('/setting/save_friend_link');
  45. }
  46. }
  47. //修改友情链接
  48. public function edit_friend_link()
  49. {
  50. if (Request::isPost()) {
  51. $id = Request::post('id');
  52. $data['title'] = Request::post('title');
  53. $data['url'] = Request::post('url');
  54. $data['url_img'] = Request::post('url_img');
  55. $data['description'] = Request::post('description');
  56. $data['add_time'] = time();
  57. $data['status'] = Request::post('status');
  58. if (empty($data['title'])) {
  59. exit(json_encode(['id'=>0,'msg'=>'友链名称不能为空']));
  60. }
  61. if (empty($data['url'])) {
  62. exit(json_encode(['id'=>0,'msg'=>'友链地址不能为空']));
  63. }
  64. $update = Db::table('friend_link')->where('id',$id)->update($data);
  65. if (!empty($update)) {
  66. echo json_encode(['id'=>1,'msg'=>'保存成功']);
  67. }else {
  68. echo json_encode(['id'=>0,'msg'=>'保存失败']);
  69. }
  70. }else {
  71. $id = Request::get('id');
  72. $data = Db::table('friend_link')->where('id',$id)->find();
  73. View::assign([
  74. 'id' => $id,
  75. 'data' => $data
  76. ]);
  77. return View('/setting/edit_friend_link');
  78. }
  79. }
  80. //删除友情链接
  81. public function dle_friend_link()
  82. {
  83. $id = Request::get('id');
  84. $delete = Db::table('friend_link')->where('id',$id)->delete();
  85. if (!empty($delete)) {
  86. echo json_encode(['id'=>1,'msg'=>'删除成功']);
  87. }else {
  88. echo json_encode(['id'=>0,'msg'=>'删除失败']);
  89. }
  90. }
  91. //基础设置
  92. public function basesetting()
  93. {
  94. if (Request::isPost()) {
  95. $names = 'tdk';
  96. $data['title'] = Request::post('title');
  97. $data['Keywords'] = Request::post('Keywords');
  98. $data['url'] = Request::post('url');
  99. $data['contact'] = Request::post('contact');
  100. $data['copyright'] = Request::post('copyright');
  101. $data['record'] = Request::post('record');
  102. $data['description'] = Request::post('description');
  103. $data['qq'] = Request::post('qq');
  104. if (empty($data['title'])) {
  105. exit(json_encode(['id'=>0,'msg'=>'网站名称不能为空']));
  106. }
  107. if (empty($data['Keywords'])) {
  108. exit(json_encode(['id'=>0,'msg'=>'Keywords不能为空']));
  109. }
  110. if (empty($data['description'])) {
  111. exit(json_encode(['id'=>0,'msg'=>'description不能为空']));
  112. }
  113. if (empty($data['qq'])) {
  114. exit(json_encode(['id'=>0,'msg'=>'客服qq不能为空']));
  115. }
  116. $find = Db::table('setting')->where('names',$names)->find();
  117. if (!empty($find)) {
  118. $update = Db::table('setting')->where('names',$names)->update(['names' => $names,'vals' => json_encode($data)]);
  119. }else {
  120. $insert = Db::table('setting')->insert(['names' => $names,'vals' => json_encode($data)]);
  121. }
  122. if (!empty($insert) || isset($update)) {
  123. echo json_encode(['id' => 1 , 'msg' => '保存成功']);
  124. }else {
  125. echo json_encode(['id' => 0 , 'msg' => '保存失败']);
  126. }
  127. }else {
  128. $names = 'tdk';
  129. $find = Db::table('setting')->where('names',$names)->find();
  130. $find['vals'] = json_decode($find['vals'],true);
  131. View::assign([
  132. 'find' => $find
  133. ]);
  134. return View('/setting/basesetting');
  135. }
  136. }
  137. }
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post