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

35 篇文章 1 订阅
31 篇文章 1 订阅

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

②友情链接编辑

③友情链接添加

二.网站基础设置
①后台网站基础设置页面

②网站基础设置效果

三.部署流程

  • 部署流程

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

  • 前端采用Layui前端UI框架

    HTML 友情链接代码块

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>友情链接</title>
    <link rel="stylesheet" href="/static/layui-v2.6.8/layui/css/layui.css" />
    <script src="/static/layui-v2.6.8/layui/layui.js"></script>
    
</head>
<body style="padding: 10px;min-width:1000px;">
    <div class="layui-item"style="height:36px;border-bottom: 3px solid  009688;" >
        <span style="color: 777;font-size:20px;height:30px;line-height:30px">首页/</span>
        <span style="color: ccc">友情链接</span>
        <button class="layui-btn layui-btn-sm" style="float:right;margin:5px" onclick="add()">添加</button>
    </div>
    <table class="layui-table" >
        <thead>
            <tr>
                <th>ID</th>
                <th>友链名称</th>
                <th>友链地址</th>
                <th>友链图标</th>
                <th>友链描述</th>
                <th>添加时间</th>
                <th>状态</th>
                <th>编辑</th>
            </tr>
        </thead>
        <tbody>
            {foreach $friend as $v}
                <tr>
                    <td>{$v['id']}</td>
                    <td>{$v['title']}</td>
                    <td><a href="">{$v['url']}</a></td>
                    <td style="text-align: center;"><img src="{$v['url_img']}" style="width: 80px;"></td>
                    <td >{$v['description']}</td>
                    <td>{:date('Y-m-d H:i:s',$v['add_time'])}</td>
                    <td>{$v['status']==0?'<span style="color: green;">显示</span>':'<span style="color: red;">关闭</span>'}</td>
                    <td>
                    <button class="layui-btn layui-btn-sm" onclick="edit({$v['id']})">编辑</button>
                    <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="dle({$v['id']})">删除</button>
                    </td>
                </tr>
            {/foreach}
        </tbody>
    </table>
</body>
<script>
            $ = layui.jquery;
            //修改友情链接
            function edit(id) {
                
                layer.open({
                type:2,
                title: '修改信息',
                shadeClose: true,
                shade: 0.8,
                area: ['450px', '450px'],
                content: '/admin/Setting/edit_friend_link?id='+id
                }); 
            }
            //删除
            function dle(id) {
                layer.confirm('确定删除吗?', {
                btn: ['确定','取消'],
                },
                function(){
                  let date = {};
                  $.post('/admin/Setting/dle_friend_link?id='+id,date,function(res){
                    if (res.id == 1) {
                        layer.alert(res.msg,{icon:1});
                        setTimeout(() => {
                            window.location.reload();
                        }, 1000);
                    }else{
                        layer.alert(res.msg,{icon:2});
                    }
                  },'json')
                });
            }
            //添加友情链接
            function add()
            {
                 
                 layer.open({
                type:2,
                title: '添加信息',
                shadeClose: true,
                shade: 0.8,
                area: ['500px', '500px'],
                content: '/admin/Setting/save_friend_link'
                }); 
            }
</script>
</html>
HTML 网站设置代码块
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员账号列表</title>
    <link rel="stylesheet" href="/static/layui-v2.6.8/layui/css/layui.css" />
    <script src="/static/layui-v2.6.8/layui/layui.js"></script>
    
</head>
<body style="padding: 10px;min-width:737px">
    <div class="layui-item" style="height:36px;border-bottom: 3px solid  009688;" >
        <span style="color: 777;font-size:20px;height:30px;line-height:30px">首页/</span>
        <span style="color: ccc">基础设置</span>
    </div>
    <form class="layui-form">
        <div class="layui-box" style="padding: 10px;width:600px"> 
            <div class="layui-form-item">
                <label for="" class="layui-form-label">网站名称</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="title" value="{$find['vals']['title']}" placeholder="请输入" >
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">网站域名</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="url" value="{$find['vals']['url']}"" placeholder="请输入" >
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">Keywords</label>
                <div class="layui-input-block">
                    <textarea name="Keywords" required lay-verify="required" placeholder="请输入" class="layui-textarea">{$find['vals']['Keywords']}</textarea>
                    
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">description</label>
                <div class="layui-input-block">
                    <textarea name="description" required lay-verify="required" placeholder="请输入" class="layui-textarea">{$find['vals']['description']}</textarea>
                    
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">客服QQ</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="qq" value="{$find['vals']['qq']}" placeholder="请输入" >
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">客服电话</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="contact" value="{$find['vals']['contact']}" placeholder="请输入" >
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">版权信息</label>
                <div class="layui-input-block">
                    <textarea name="copyright" required lay-verify="required" placeholder="请输入" class="layui-textarea">{$find['vals']['copyright']}</textarea>
                    
                </div>
            </div>

            <div class="layui-form-item">
                <label for="" class="layui-form-label">备案号</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="record" value="{$find['vals']['record']}" placeholder="请输入" >
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                <button class="layui-btn" type="button" οnclick="save()">保存</button>
                </div>
                
            </div>
        </div>
 
    </form>
</body>
    <script>
            $ = layui.jquery;
            //页面刷新时聚焦焦点
            $('input[name = "title"]').focus();

            //保存
            function save()
            {
                if ($('input[name = "title"]').val() == '') {
                    layer.alert('网站名称不能为空',{icon:2});
                    return;
                }

                if ($('textarea[name = "Keywords"]').val() == '') {
                    layer.alert('Keywords不能为空',{icon:2});
                    return;
                }

                if ($('textarea[name = "description"]').val() == '') {
                    layer.alert('description不能为空',{icon:2});
                    return;
                }

                if ($('input[name = "qq"]').val() == '') {
                    layer.alert('客服qq不能为空',{icon:2});
                    return;
                }

                $.post('/admin/Setting/basesetting',$('form').serialize(),function (res) {
                        if (res.id == 1) {
                            layer.alert(res.msg,{icon:1});
                            setTimeout(() => {
                            parent.window.location.reload();
                            
                        }, 1000);
                        }else{
                           layer.alert(res.msg,{icon:2});
                       }
                },'json')
            }
    </script>
</html>
PHP 友情链接/网站设置代码块
<?php
namespace app\admin\controller;
use app\admin\controller\Base;
use think\facade\Request;
use think\facade\Db;
use think\facade\View;
use think\facade\Session;
/**
 * 网站管理
 */
class Setting extends Base
{   //友情链接
    public function friend_link()
    {   
        $friend_link = Db::table('friend_link')->select()->toArray();
        View::assign([
            'friend' => $friend_link
        ]);
        return View('/setting/friend_link');
    }

    //添加友情链接
    public function save_friend_link()
    {   
        if (Request::isPost()) {
            $data['title'] = Request::post('title');
            $data['url'] = Request::post('url');
            $data['url_img'] = Request::post('url_img');
            $data['description'] = Request::post('description');
            $data['add_time'] = time();
            $data['status'] = Request::post('status');

            if (empty($data['title'])) {
                exit(json_encode(['id'=>0,'msg'=>'友链名称不能为空']));
            }

            if (empty($data['url'])) {
                exit(json_encode(['id'=>0,'msg'=>'友链地址不能为空']));
            }

            $insert = Db::table('friend_link')->insert($data);
            if (!empty($insert)) {
                echo json_encode(['id'=>1,'msg'=>'保存成功']);
            }else {
                echo json_encode(['id'=>0,'msg'=>'保存失败']);
            }
        }else {
            return View('/setting/save_friend_link');
        }
        
    }

    //修改友情链接
    public function edit_friend_link()
    {   
        if (Request::isPost()) {
            $id = Request::post('id');
            $data['title'] = Request::post('title');
            $data['url'] = Request::post('url');
            $data['url_img'] = Request::post('url_img');
            $data['description'] = Request::post('description');
            $data['add_time'] = time();
            $data['status'] = Request::post('status');

            if (empty($data['title'])) {
                exit(json_encode(['id'=>0,'msg'=>'友链名称不能为空']));
            }

            if (empty($data['url'])) {
                exit(json_encode(['id'=>0,'msg'=>'友链地址不能为空']));
            }

            $update = Db::table('friend_link')->where('id',$id)->update($data);
            if (!empty($update)) {
                echo json_encode(['id'=>1,'msg'=>'保存成功']);
            }else {
                echo json_encode(['id'=>0,'msg'=>'保存失败']);
            }
        }else {
            $id = Request::get('id');
            $data = Db::table('friend_link')->where('id',$id)->find();
            View::assign([
                'id' => $id,
                'data' => $data
            ]);
            return View('/setting/edit_friend_link');
        }
        
    }

    //删除友情链接
    public function dle_friend_link()
    {
        $id = Request::get('id');
        
        $delete = Db::table('friend_link')->where('id',$id)->delete();
        if (!empty($delete)) {
            echo json_encode(['id'=>1,'msg'=>'删除成功']);
        }else {
            echo json_encode(['id'=>0,'msg'=>'删除失败']);
        }
    }
    //基础设置
    public function basesetting()
    {   
        if (Request::isPost()) {
            $names = 'tdk';
            $data['title'] = Request::post('title');
            $data['Keywords'] = Request::post('Keywords');
            $data['url'] = Request::post('url');
            $data['contact'] = Request::post('contact');
            $data['copyright'] = Request::post('copyright');
            $data['record'] = Request::post('record');
            $data['description'] = Request::post('description');
            $data['qq'] = Request::post('qq');

        

            if (empty($data['title'])) {
                exit(json_encode(['id'=>0,'msg'=>'网站名称不能为空']));
            }
            if (empty($data['Keywords'])) {
                exit(json_encode(['id'=>0,'msg'=>'Keywords不能为空']));
            }
            if (empty($data['description'])) {
                exit(json_encode(['id'=>0,'msg'=>'description不能为空']));
            }
            if (empty($data['qq'])) {
                exit(json_encode(['id'=>0,'msg'=>'客服qq不能为空']));
            }

            $find = Db::table('setting')->where('names',$names)->find();
            if (!empty($find)) {
               $update = Db::table('setting')->where('names',$names)->update(['names' => $names,'vals' => json_encode($data)]);
            }else {
                $insert = Db::table('setting')->insert(['names' => $names,'vals' => json_encode($data)]);
            }
           

            if (!empty($insert) || isset($update)) {
                echo json_encode(['id' => 1 , 'msg' => '保存成功']);
            }else {
                echo json_encode(['id' => 0 , 'msg' => '保存失败']);
            }


        }else {
            $names = 'tdk';
            $find = Db::table('setting')->where('names',$names)->find();
            $find['vals'] = json_decode($find['vals'],true);

            View::assign([
                'find' => $find
            ]);
            return View('/setting/basesetting');
        }
        
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值