Blogger Information
Blog 42
fans 2
comment 0
visits 53934
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
CMS后台管理商城系统(三) 商品分类管理 商品管理 用户列表 订单列表
小明的博客
Original
3112 people have browsed it

今天完成了商品分类管理、商品管理、用户管理、订单列表功能

一、商品分类管理
商品分类主要功能是新建商品一级分类列表,有添加、编辑、删除功能,还有二级分类列表。添加编辑,更具传入的id值确定,然后将id传给add方法,然后查到数据,展示给前台,然后保存;删除根据传入的id来删除;二级列表通过url方法,将传入的id值get到二级分类列表方法,然后查询该id下的所有记录。
  1. //分类一级
  2. public function cat_index() {
  3. $list = $this->db->table('shop_cat')->where(array('cat_fid'=>0))->order('sort DESC')->lists();
  4. $this->assign('list', $list);
  5. return $this->fetch();
  6. }
  7. //添加编辑商品分类
  8. public function cat_add() {
  9. $id = (int)input('get.id');
  10. $fid = (int)input('get.fid');
  11. //查询出id的商品分类记录
  12. $data = $this->db->table('shop_cat')->where(array('cat_id'=>$id))->item();
  13. $this->assign('data', $data);
  14. $this->assign('fid', $fid);
  15. return $this->fetch();
  16. }
  17. //保存商品分类
  18. public function cat_save() {
  19. //将传过来的数据整理在一起
  20. $id = (int)input('post.cat_id');
  21. $data['cat_name'] = trim(input('post.cat_name'));
  22. $data['sort'] = (int)input('post.sort');
  23. $data['status'] = (int)input('post.status');
  24. //判断 如果id存在那么就是修改执行更新操作
  25. if ($id) {
  26. $res = $this->db->table('shop_cat')->where(array('cat_id'=>$id))->update($data);
  27. } else {
  28. //如果id不存在 那么就是新增需要把level fid 和data插入
  29. $data['cat_fid'] = (int)input('post.fid');
  30. $res = $this->db->table('shop_cat')->insert($data);
  31. }
  32. if ($res) {
  33. exit(json_encode(array('code'=>0, 'msg'=>'保存成功')));
  34. } else {
  35. exit(json_encode(array('code'=>1, 'msg'=>'保存失败')));
  36. }
  37. }
  38. //删除分类
  39. public function cat_del() {
  40. $id = (int)input('post.id');
  41. //16 执行删除操作
  42. $res = $this->db->table('shop_cat')->where(array('cat_id'=>$id))->delete();
  43. if (!$res) {
  44. exit(json_encode(array('code'=>1, 'msg'=>'删除失败')));
  45. }
  46. exit(json_encode(array('code'=>0, 'msg'=>'删除成功')));
  47. }
  48. //二级分类列表
  49. public function cat_two_index() {
  50. $fid = (int)input('get.fid');
  51. //查找出一级分类记录
  52. $item = $this->db->table('shop_cat')->where(array('cat_id'=>$fid))->item();
  53. $list = $this->db->table('shop_cat')->where(array('cat_fid'=>$fid))->lists();
  54. $this->assign('list', $list);
  55. $this->assign('item', $item);
  56. $this->assign('fid', $fid);
  57. return $this->fetch();
  58. }
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <link rel="stylesheet" type="text/css" href="/static/plugins/layui/css/layui.css">
  6. <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
  7. <style type="text/css">
  8. .header span{background: #009688;margin-left: 30px;padding: 10px;color:#ffffff;}
  9. .header div{border-bottom: solid 2px #009688;margin-top: 8px;}
  10. .header button{float: right;margin-top: -5px;}
  11. </style>
  12. </head>
  13. <body style="padding: 10px;">
  14. <div class="header">
  15. <span>商品一级分类</span>
  16. <button class="layui-btn layui-btn-sm" onclick="add()">添加</button>
  17. <div></div>
  18. </div>
  19. <table class="layui-table">
  20. <thead>
  21. <tr>
  22. <th>排序</th>
  23. <th>ID</th>
  24. <th>分类名</th>
  25. <th>状态</th>
  26. <th>二级列表</th>
  27. <th>操作</th>
  28. </tr>
  29. </thead>
  30. <tbody>
  31. <!-- 循环出所有广告分类 -->
  32. {volist name="list" id="vo"}
  33. <tr>
  34. <td>{$vo.sort}</td>
  35. <td>{$vo.cat_id}</td>
  36. <td>{$vo.cat_name}</td>
  37. <td>{if condition="$vo.status == 1"}<span style="color: green;">开启</span>{else/}<span style="color: red;">关闭</span>{/if}</td>
  38. <td>
  39. <button class="layui-btn layui-btn-xs" onclick="url({$vo.cat_id})">进入二级分类列表</button>
  40. </td>
  41. <td>
  42. <button class="layui-btn layui-btn-xs" onclick="add({$vo.cat_id})">编辑</button>
  43. <button class="layui-btn layui-btn-danger layui-btn-xs" onclick="del({$vo.cat_id})">删除</button>
  44. </td>
  45. </tr>
  46. {/volist}
  47. </tbody>
  48. </table>
  49. <script type="text/javascript">
  50. layui.use(['layer'],function(){
  51. layer = layui.layer;
  52. $ = layui.jquery;
  53. });
  54. // 添加编辑
  55. function add(id) {
  56. layer.open({
  57. type: 2,
  58. title: id>0 ? '编辑分类' : '添加分类',
  59. shade: 0.3,
  60. area: ['480px', '420px'],
  61. content: '/index.php/admins/Shop/cat_add?id='+id
  62. });
  63. }
  64. //分类下的广告列表
  65. function url(id) {
  66. window.location.href = "/index.php/admins/Shop/cat_two_index?fid="+id;
  67. }
  68. // 删除
  69. function del(id) {
  70. layer.confirm('确定要删除吗?', {
  71. icon: 3,
  72. btn: ['确定', '取消']
  73. }, function () {
  74. $.post('/index.php/admins/Shop/cat_del', {'id':id}, function (res) {
  75. if (res.code > 0) {
  76. layer.alert(res.msg, {icon:2});
  77. } else {
  78. layer.msg(res.msg);
  79. setTimeout(function () {
  80. window.location.reload();
  81. }, 1000)
  82. }
  83. }, 'json');
  84. });
  85. }
  86. </script>
  87. </body>
  88. </html>
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <link rel="stylesheet" type="text/css" href="/static/plugins/layui/css/layui.css">
  6. <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
  7. </head>
  8. <body style="padding: 10px;">
  9. <form class="layui-form">
  10. <!-- hidden 是把input框隐藏,它的作用是把一些隐藏信息传值到接口中 -->
  11. <input type="hidden" name="cat_id" value="{$data.cat_id}">
  12. <input type="hidden" name="fid" value="{$fid}">
  13. <div class="layui-form-item">
  14. <label class="layui-form-label">名称</label>
  15. <div class="layui-input-inline">
  16. <input type="text" class="layui-input" name="cat_name" value="{$data.cat_name}">
  17. </div>
  18. </div>
  19. <div class="layui-form-item">
  20. <label class="layui-form-label">排序</label>
  21. <div class="layui-input-inline">
  22. <input type="text" class="layui-input" name="sort" value="{$data.sort}">
  23. </div>
  24. </div>
  25. <div class="layui-form-item">
  26. <label class="layui-form-label">状态</label>
  27. <div class="layui-input-inline">
  28. <input type="checkbox" name="status" lay-skin="primary" title="开启" value="1" {$data.status==1 || !$data ?'checked':''}>
  29. </div>
  30. </div>
  31. </form>
  32. <div class="layui-form-item">
  33. <div class="layui-input-block">
  34. <button class="layui-btn" onclick="save()">保存</button>
  35. </div>
  36. </div>
  37. <script type="text/javascript">
  38. layui.use(['layer','form'],function(){
  39. form = layui.form;
  40. layer = layui.layer;
  41. $ = layui.jquery;
  42. });
  43. // 保存管理员
  44. function save(){
  45. // 用js 获取省名称 首字母
  46. var cat_name = $.trim($('input[name="cat_name"]').val());
  47. if(cat_name==''){
  48. layer.alert('请输入名称',{icon:2});
  49. return;
  50. }
  51. // 请求保存接口,把数据传值到接口中。
  52. $.post('/index.php/admins/Shop/cat_save',$('form').serialize(),function(res){
  53. if(res.code>0){
  54. layer.alert(res.msg,{icon:2});
  55. }else{
  56. layer.msg(res.msg);
  57. setTimeout(function(){parent.window.location.reload();},1000);
  58. }
  59. },'json');
  60. }
  61. </script>
  62. </body>
  63. </html>
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <link rel="stylesheet" type="text/css" href="/static/plugins/layui/css/layui.css">
  6. <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
  7. <style type="text/css">
  8. .header span{background: #009688;margin-left: 30px;padding: 10px;color:#ffffff;}
  9. .header div{border-bottom: solid 2px #009688;margin-top: 8px;}
  10. .header button{float: right;margin-top: -5px;}
  11. </style>
  12. </head>
  13. <body style="padding: 10px;">
  14. <div class="header">
  15. <span style="background-color:#999;"><a href="/index.php/admins/Shop/cat_index" style="color:#fff;">商品分类一级列表</a></span>
  16. <span>{$item.cat_name}的二级列表</span>
  17. <button class="layui-btn layui-btn-sm" onclick="add()">添加</button>
  18. <div></div>
  19. </div>
  20. <table class="layui-table">
  21. <thead>
  22. <tr>
  23. <th>排序</th>
  24. <th>ID</th>
  25. <th>分类名</th>
  26. <th>状态</th>
  27. <th>操作</th>
  28. </tr>
  29. </thead>
  30. <tbody>
  31. <!-- 循环出二级分类 -->
  32. {volist name="list" id="vo"}
  33. <tr>
  34. <td>{$vo.sort}</td>
  35. <td>{$vo.cat_id}</td>
  36. <td>{$vo.cat_name}</td>
  37. <td>{if condition="$vo.status == 1"}<span style="color: green;">开启</span>{else/}<span style="color: red;">关闭</span>{/if}</td>
  38. <td>
  39. <button class="layui-btn layui-btn-xs" onclick="add({$vo.cat_id})">编辑</button>
  40. <button class="layui-btn layui-btn-danger layui-btn-xs" onclick="del({$vo.cat_id})">删除</button>
  41. </td>
  42. </tr>
  43. {/volist}
  44. </tbody>
  45. </table>
  46. <script type="text/javascript">
  47. layui.use(['layer'],function(){
  48. layer = layui.layer;
  49. $ = layui.jquery;
  50. });
  51. var fid = '{$fid}';
  52. // 添加编辑
  53. function add(id) {
  54. layer.open({
  55. type: 2,
  56. title: id>0 ? '编辑分类' : '添加分类',
  57. shade: 0.3,
  58. area: ['480px', '420px'],
  59. content: '/index.php/admins/Shop/cat_add?id='+id+'&fid='+fid
  60. });
  61. }
  62. // 删除
  63. function del(id) {
  64. layer.confirm('确定要删除吗?', {
  65. icon: 3,
  66. btn: ['确定', '取消']
  67. }, function () {
  68. $.post('/index.php/admins/Shop/cat_del', {'id':id}, function (res) {
  69. if (res.code > 0) {
  70. layer.alert(res.msg, {icon:2});
  71. } else {
  72. layer.msg(res.msg);
  73. setTimeout(function () {
  74. window.location.reload();
  75. }, 1000)
  76. }
  77. }, 'json');
  78. });
  79. }
  80. </script>
  81. </body>
  82. </html>
二、商品管理

道理和之前的一样,查询所有商品在前端展示出来,可以添加编辑删除,重点在添加编辑功能,有图片上传功能和一二级分类选择(下一节在完善)。

  1. //商品列表
  2. public function shop_index() {
  3. //查询出商品列表中的所有商品
  4. $list = $this->db->table('shop_goods')->order('sort DESC,id DESC')->lists();
  5. //查找出该商品的分类,将分类名赋给list
  6. if ($list) {
  7. foreach ($list as &$v) {
  8. $cat = $this->db->table('shop_cat')->where(array('cat_id'=>$v['cat_id']))->item();
  9. $v['cat_name'] = $cat['cat_name'];
  10. }
  11. }
  12. $this->assign('list', $list);
  13. return $this->fetch();
  14. }
  15. //添加编辑商品
  16. public function shop_add() {
  17. $id = (int)input('get.id');
  18. //查找出id对应下的单条商品记录
  19. $data = $this->db->table('shop_goods')->where(array('id'=>$id))->item();
  20. $this->assign('data', $data);
  21. // 查询出所有的一级分类
  22. $cat = $this->db->table('shop_cat')->where(array('status'=>1, 'cat_fid'=>0))->lists();
  23. $this->assign('cat', $cat);
  24. return $this->fetch();
  25. }
  26. //保存商品信息
  27. public function shop_save(){
  28. $id = (int)input('post.id');
  29. $data['cat_id'] = (int)input('post.cat_id'); // 分类ID
  30. $data['title'] = trim(input('post.title')); // 标题
  31. $data['price'] = trim(input('post.price')); // 价格
  32. $data['o_price'] = trim(input('post.o_price')); // 原价
  33. $data['img'] = input('post.img'); // 图片
  34. $data['info'] = trim(input('post.info')); // 商品介绍
  35. $data['sort'] = (int)input('post.sort'); // 排序
  36. $data['status'] = (int)input('post.status'); // 状态
  37. if($id){
  38. $add = $this->db->table('shop_goods')->where(array('id'=>$id))->update($data);
  39. }else{
  40. $add = $this->db->table('shop_goods')->insert($data);
  41. }
  42. if($add > 0){
  43. exit(json_encode(array('code'=>0,'msg'=>'数据保存成功')));
  44. }else{
  45. exit(json_encode(array('code'=>1,'msg'=>'数据保存失败')));
  46. }
  47. }
  48. # 商品删除
  49. public function shop_del(){
  50. $id = (int)input('post.id');
  51. $del = $this->db->table('shop_goods')->where(array('id'=>$id))->delete();
  52. if($del){
  53. exit(json_encode(array('code'=>0,'msg'=>'删除成功')));
  54. }else{
  55. exit(json_encode(array('code'=>1,'msg'=>'删除失败')));
  56. }
  57. }
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <link rel="stylesheet" type="text/css" href="/static/plugins/layui/css/layui.css">
  6. <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
  7. <style type="text/css">
  8. .header span{background: #009688;margin-left: 30px;padding: 10px;color:#ffffff;}
  9. .header div{border-bottom: solid 2px #009688;margin-top: 8px;}
  10. .header button{float: right;margin-top: -5px;}
  11. </style>
  12. </head>
  13. <body style="padding: 10px;">
  14. <div class="header">
  15. <span>商品列表</span>
  16. <button class="layui-btn layui-btn-sm" onclick="add()">添加</button>
  17. <div></div>
  18. </div>
  19. <table class="layui-table">
  20. <thead>
  21. <tr>
  22. <th>排序</th>
  23. <th>ID</th>
  24. <th>分类</th>
  25. <th>标题</th>
  26. <th>价格</th>
  27. <th>原价</th>
  28. <th>图片</th>
  29. <th>状态</th>
  30. <th>操作</th>
  31. </tr>
  32. </thead>
  33. <tbody>
  34. <!-- 循环出所有商品 -->
  35. {volist name="list" id="vo"}
  36. <tr>
  37. <td>{$vo.sort}</td>
  38. <td>{$vo.id}</td>
  39. <td>{$vo.cat_id}</td>
  40. <td>{$vo.title}</td>
  41. <td>{$vo.price}</td>
  42. <td>{$vo.o_price}</td>
  43. <td><img src="{$vo.img}" alt=""></td>
  44. <td>{if condition="$vo.status == 1"}<span style="color: green;">开启</span>{else/}<span style="color: red;">关闭</span>{/if}</td>
  45. <td>
  46. <button class="layui-btn layui-btn-xs" onclick="add({$vo.id})">编辑</button>
  47. <button class="layui-btn layui-btn-danger layui-btn-xs" onclick="del({$vo.id})">删除</button>
  48. </td>
  49. </tr>
  50. {/volist}
  51. </tbody>
  52. </table>
  53. <script type="text/javascript">
  54. layui.use(['layer'],function(){
  55. layer = layui.layer;
  56. $ = layui.jquery;
  57. });
  58. // 添加编辑
  59. function add(id) {
  60. layer.open({
  61. type: 2,
  62. title: id>0 ? '编辑分类' : '添加分类',
  63. shade: 0.3,
  64. area: ['1080px', '600px'],
  65. content: '/index.php/admins/Shop/shop_add?id='+id
  66. });
  67. }
  68. // 删除
  69. function del(id) {
  70. layer.confirm('确定要删除吗?', {
  71. icon: 3,
  72. btn: ['确定', '取消']
  73. }, function () {
  74. $.post('/index.php/admins/Shop/shop_del', {'id':id}, function (res) {
  75. if (res.code > 0) {
  76. layer.alert(res.msg, {icon:2});
  77. } else {
  78. layer.msg(res.msg);
  79. setTimeout(function () {
  80. window.location.reload();
  81. }, 1000)
  82. }
  83. }, 'json');
  84. });
  85. }
  86. </script>
  87. </body>
  88. </html>
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/html">
  3. <head>
  4. <title></title>
  5. <link rel="stylesheet" type="text/css" href="/static/plugins/layui/css/layui.css">
  6. <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
  7. </head>
  8. <body style="padding: 10px;">
  9. <form class="layui-form">
  10. <!-- hidden 是把input框隐藏,它的作用是把一些隐藏信息传值到接口中 -->
  11. <input type="hidden" name="id" value="{$data.id}">
  12. <div class="layui-form-item">
  13. <label class="layui-form-label">标题</label>
  14. <div class="layui-input-inline">
  15. <input type="text" class="layui-input" name="title" value="{$data.title}">
  16. </div>
  17. </div>
  18. <div class="layui-form-item">
  19. <label class="layui-form-label">一级分类</label>
  20. <div class="layui-input-inline">
  21. <select name="cat_fid" id="cat_id">
  22. <option value="0">请选择</option>
  23. {volist name="cat" id="cat_vo"}
  24. <option value="{$cat_vo['cat_id']}">{$cat_vo.cat_name}</option>
  25. {/volist}
  26. </select>
  27. </div>
  28. </div>
  29. <div class="layui-form-item">
  30. <label class="layui-form-label">二级分类</label>
  31. <div class="layui-input-inline">
  32. <select name="cat_id">
  33. <option value=0>请选择</option>
  34. </select>
  35. </div>
  36. </div>
  37. <div class="layui-form-item">
  38. <label class="layui-form-label">原价</label>
  39. <div class="layui-input-inline">
  40. <input type="text" class="layui-input" name="price" value="{$data.price}">
  41. </div>
  42. </div>
  43. <div class="layui-form-item">
  44. <label class="layui-form-label">现价</label>
  45. <div class="layui-input-inline">
  46. <input type="text" class="layui-input" name="o_price" value="{$data.o_price}">
  47. </div>
  48. </div>
  49. <div class="layui-form-item">
  50. <label class="layui-form-label">图片上传</label>
  51. <div class="layui-upload">
  52. <button type="button" class="layui-btn" id="test1">上传图片</button>
  53. </div>
  54. </div>
  55. <div class="layui-form-item">
  56. <label class="layui-form-label">图片预览</label>
  57. <div class="layui-upload-list">
  58. <img class="layui-upload-img" id="demo1" style="width: 200px;" src="{$data.img}">
  59. <p id="demoText"></p>
  60. <input type="hidden" name="img" value="">
  61. </div>
  62. </div>
  63. <div class="layui-form-item">
  64. <label class="layui-form-label">排序</label>
  65. <div class="layui-input-inline">
  66. <input type="text" class="layui-input" name="sort" value="{$data.sort}">
  67. </div>
  68. </div>
  69. <div class="layui-form-item">
  70. <label class="layui-form-label">状态</label>
  71. <div class="layui-input-inline">
  72. <input type="checkbox" name="status" lay-skin="primary" title="开启" value="1" {$data.status==1 || !$data ?'checked':''}>
  73. </div>
  74. </div>
  75. <div class="layui-form-item">
  76. <label class="layui-form-label">商品介绍</label>
  77. <div class="layui-input-inline" id="editor" style="width: 80%;">
  78. </div>
  79. </div>
  80. </form>
  81. <div class="layui-form-item">
  82. <div class="layui-input-block">
  83. <button class="layui-btn" onclick="save()">保存</button>
  84. </div>
  85. </div>
  86. <script type="text/javascript" src="/static/wangEditor/release/wangEditor.js"></script>
  87. <script type="text/javascript">
  88. var E = window.wangEditor;
  89. var editor = new E('#editor');
  90. // 或者 var editor = new E( document.getElementById('editor') )
  91. editor.create();
  92. editor.txt.html('<?php echo htmlspecialchars_decode($data['info']); ?>');
  93. layui.use(['layer','form', 'upload'],function(){
  94. form = layui.form;
  95. layer = layui.layer;
  96. $ = layui.jquery;
  97. upload = layui.upload;
  98. var uploadInst = upload.render({
  99. elem: '#test1'
  100. ,url: '/index.php/admins/Home/up_img'
  101. ,before: function(obj){
  102. //预读本地文件示例,不支持ie8
  103. obj.preview(function(index, file, result){
  104. $('#demo1').attr('src', result); //图片链接(base64)
  105. });
  106. }
  107. ,done: function(res){
  108. //如果上传失败
  109. if(res.code > 0){
  110. return layer.msg('上传失败');
  111. }else{
  112. $('#demo1').attr('src', res.data); //图片链接(base64)
  113. $('input[name="img"]').val(res.data); //图片链接(base64)
  114. }
  115. //上传成功
  116. }
  117. ,error: function(){
  118. //演示失败状态,并实现重传
  119. var demoText = $('#demoText');
  120. demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
  121. demoText.find('.demo-reload').on('click', function(){
  122. uploadInst.upload();
  123. });
  124. }
  125. });
  126. });
  127. // 保存管理员
  128. function save(){
  129. // 用js 获取省名称 首字母
  130. var title = $.trim($('input[name="title"]').val());
  131. if(title==''){
  132. layer.alert('请输入标题',{icon:2});
  133. return;
  134. }
  135. var data = new Object();
  136. data.id = $('input[name="id"]').val();
  137. data.title = $('input[name="title"]').val();
  138. data.price = $('input[name="pirce"]').val();
  139. data.o_price = $('input[name="o_price"]').val();
  140. data.img = $('input[name="img"]').val();
  141. data.info = editor.txt.html();
  142. data.sort = $('input[name="sort"]').val();
  143. data.status = $('input[name="status"]').val();
  144. // 请求保存接口,把数据传值到接口中。
  145. $.post('/index.php/admins/Shop/shop_save',data,function(res){
  146. if(res.code>0){
  147. layer.alert(res.msg,{icon:2});
  148. }else{
  149. layer.msg(res.msg);
  150. setTimeout(function(){parent.window.location.reload();},1000);
  151. }
  152. },'json');
  153. }
  154. </script>
  155. </body>
  156. </html>
三、用户管理

这里只需要查询到所有的用户 然后展示出来就可以

  1. //用户列表
  2. public function index() {
  3. //查找所有用户按照uid降序
  4. $list = $this->db->table('shop_user')->order('uid DESC')->lists();
  5. $this->assign('list', $list);
  6. $address = $this->db->table('shop_city')->where(array('status'=>1))->cates('id');
  7. $this->assign('address', $address);
  8. return $this->fetch();
  9. }
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <link rel="stylesheet" type="text/css" href="/static/plugins/layui/css/layui.css">
  6. <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
  7. <style type="text/css">
  8. .header span{background: #009688;margin-left: 30px;padding: 10px;color:#ffffff;}
  9. .header div{border-bottom: solid 2px #009688;margin-top: 8px;}
  10. .header button{float: right;margin-top: -5px;}
  11. </style>
  12. </head>
  13. <body style="padding: 10px;">
  14. <div class="header">
  15. <span>用户列表</span>
  16. <div></div>
  17. </div>
  18. <table class="layui-table">
  19. <thead>
  20. <tr>
  21. <th>ID</th>
  22. <th>昵称</th>
  23. <th>电话</th>
  24. <th>性别</th>
  25. <th>省市区</th>
  26. <th>状态</th>
  27. </tr>
  28. </thead>
  29. <tbody>
  30. <!-- 循环出所有用户 -->
  31. {volist name="list" id="vo"}
  32. <tr>
  33. <td>{$vo.uid}</td>
  34. <td>{$vo.nickname}</td>
  35. <td>{$vo.phone}</td>
  36. <td>
  37. {if condition="$vo.sex == 1"}<span style="color: green;"></span>
  38. {elseif condition="$vo.sex == 2" /}<span style="color: red;"></span>
  39. {else/}未知
  40. {/if}
  41. </td>
  42. <td>{$address[$vo.province]['name']}{$address[$vo.city]['name']}{$address[$vo.area]['name']}</td>
  43. <td>{if condition="$vo.status == 1"}<span style="color: green;">开启</span>{else/}<span style="color: red;">关闭</span>{/if}</td>
  44. </tr>
  45. {/volist}
  46. </tbody>
  47. </table>
  48. </body>
  49. </html>
四、订单管理

查询出所有总订单列表展示出来,可以查看子订单,可以发货。这里主要是数据库的数据需要转化成相应的文字,产看子订单就是根据order_id在子订单表理查询出来,发货是弹出新页面,选择快递、单号,然后发送给保存方法,同时还有order_id,发货时间、发货状态,然后修改数据库数据

  1. //订单列表
  2. public function order() {
  3. //按照添加时间降序查询出所有订单信息
  4. $list = $this->db->table('shop_order')->order('add_time DESC')->lists();
  5. $this->assign('list', $list);
  6. return $this->fetch();
  7. }
  8. //子订单页面
  9. public function order_two() {
  10. $id = (int)input('get.id');
  11. $list = $this->db->table('shop_order_son')->where(array('order_id'=>$id))->lists();
  12. $this->assign('list', $list);
  13. $user = $this->db->table('shop_order')->where(array('order_id'=>$id))->item();
  14. $uid = $user['uid'];
  15. $people = $this->db->table('shop_user')->where(array('uid'=>$uid))->item();
  16. $nickname = $people['nickname'];
  17. $this->assign('nickname', $nickname);
  18. return $this->fetch();
  19. }
  20. //发货
  21. public function send_goods() {
  22. $order_id = (int)input('get.id');
  23. $this->assign('order_id', $order_id);
  24. return $this->fetch();
  25. }
  26. //发货保存
  27. public function order_save() {
  28. $id = (int)input('post.id');
  29. $data['express'] = trim(input('post.express'));
  30. $data['express_id'] = trim(input('post.express_id'));
  31. $data['deliver_time'] = time();
  32. $data['status'] = 3;
  33. //修改
  34. $add = $this->db->table('shop_order')->where(array('order_id'=>$id))->update($data);
  35. if($add > 0){
  36. exit(json_encode(array('code'=>0,'msg'=>'发货成功')));
  37. }else{
  38. exit(json_encode(array('code'=>1,'msg'=>'发货失败')));
  39. }
  40. }
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <link rel="stylesheet" type="text/css" href="/static/plugins/layui/css/layui.css">
  6. <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
  7. <style type="text/css">
  8. .header span{background: #009688;margin-left: 30px;padding: 10px;color:#ffffff;}
  9. .header div{border-bottom: solid 2px #009688;margin-top: 8px;}
  10. .header button{float: right;margin-top: -5px;}
  11. </style>
  12. </head>
  13. <body style="padding: 10px;">
  14. <div class="header">
  15. <span>订单列表</span>
  16. <div></div>
  17. </div>
  18. <table class="layui-table">
  19. <thead>
  20. <tr>
  21. <th>ID</th>
  22. <th>第三方ID</th>
  23. <th>支付方式</th>
  24. <th>总价</th>
  25. <th>支付价格</th>
  26. <th>用户id</th>
  27. <th>地址</th>
  28. <th>手机</th>
  29. <th>快递</th>
  30. <th>时间</th>
  31. <th>状态</th>
  32. <th>操作</th>
  33. </tr>
  34. </thead>
  35. <tbody>
  36. <!-- 循环出所有用户 -->
  37. {volist name="list" id="vo"}
  38. <tr>
  39. <td>{$vo.order_id}</td>
  40. <td>{$vo.orders_id}</td>
  41. <td>
  42. {if condition="$vo.pay_mode == 1"}支付宝{/if}
  43. {if condition="$vo.pay_mode == 2"}微信{/if}
  44. {if condition="$vo.pay_mode == 3"}PayPal{/if}
  45. {if condition="$vo.pay_mode == 4"}线下支付{/if}
  46. </td>
  47. <td>{$vo.price}</td>
  48. <td>{$vo.pay_price}</td>
  49. <td>{$vo.uid}</td>
  50. <td>{$vo.address}</td>
  51. <td>{$vo.phone}</td>
  52. <td>
  53. {if condition="$vo.express == 1"}顺丰:{$vo.express_id}{/if}
  54. {if condition="$vo.express == 2"}韵达:{$vo.express_id}{/if}
  55. {if condition="$vo.express == 3"}中通:{$vo.express_id}{/if}
  56. </td>
  57. <td>
  58. 支付时间:{$vo.pay_time|date="Y-m-d H:i:s"}<br/>
  59. 发货时间:{$vo.deliver_time|date="Y-m-d H:i:s"}<br/>
  60. 收货时间:{$vo.receiv_time|date="Y-m-d H:i:s"}<br/>
  61. </td>
  62. <td>
  63. {if condition="$vo.status == 1"}<span style="color: red;">未支付</span>{/if}
  64. {if condition="$vo.status == 2"}<span style="color: red;">已支付 未发货</span>{/if}
  65. {if condition="$vo.status == 3"}<span style="color: red;">已发货 未收货</span>{/if}
  66. {if condition="$vo.status == 4"}<span style="color: red;">已收货 未评论</span>{/if}
  67. {if condition="$vo.status == 5"}<span style="color: red;">已退货</span>{/if}
  68. {if condition="$vo.status == 10"}<span style="color: red;">已关闭</span>{/if}
  69. </td>
  70. <td>
  71. <button class="layui-btn layui-btn-xs" onclick="add({$vo.order_id})">子订单</button>
  72. <button class="layui-btn layui-btn-danger layui-btn-xs" onclick="del({$vo.order_id})">发货</button>
  73. </td>
  74. {/volist}
  75. </tbody>
  76. </table>
  77. <script type="text/javascript">
  78. layui.use(['layer'],function(){
  79. layer = layui.layer;
  80. $ = layui.jquery;
  81. });
  82. //跳转到子订单
  83. function add(id) {
  84. window.location.href = '/index.php/admins/User/order_two?id='+id;
  85. }
  86. //弹出发货页面
  87. function del(id) {
  88. layer.open({
  89. type: 2,
  90. title: '发货',
  91. shade: 0.3,
  92. area: ['1080px', '600px'],
  93. content: '/index.php/admins/User/send_goods?id=' + id
  94. });
  95. }
  96. </script>
  97. </body>
  98. </html>
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <link rel="stylesheet" type="text/css" href="/static/plugins/layui/css/layui.css">
  6. <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
  7. <style type="text/css">
  8. .header span{background: #009688;margin-left: 30px;padding: 10px;color:#ffffff;}
  9. .header div{border-bottom: solid 2px #009688;margin-top: 8px;}
  10. .header button{float: right;margin-top: -5px;}
  11. </style>
  12. </head>
  13. <body style="padding: 10px;">
  14. <div class="header">
  15. <span style="background-color:#999;"><a href="/index.php/admins/User/order" style="color:#fff;">总订单</a></span>
  16. <span>{$nickname}的子订单</span>
  17. <div></div>
  18. </div>
  19. <table class="layui-table">
  20. <thead>
  21. <tr>
  22. <th>ID</th>
  23. <th>总订单ID</th>
  24. <th>商品ID</th>
  25. <th>价格</th>
  26. <th>数量</th>
  27. </tr>
  28. </thead>
  29. <tbody>
  30. <!-- 循环出所有用户 -->
  31. {volist name="list" id="vo"}
  32. <tr>
  33. <td>{$vo.id}</td>
  34. <td>{$vo.order_id}</td>
  35. <td>{$vo.goods_id}</td>
  36. <td>{$vo.price}</td>
  37. <td>{$vo.number}</td>
  38. {/volist}
  39. </tbody>
  40. </table>
  41. </body>
  42. </html>
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <link rel="stylesheet" type="text/css" href="/static/plugins/layui/css/layui.css">
  6. <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
  7. </head>
  8. <body style="padding: 10px;">
  9. <form class="layui-form">
  10. <input type="hidden" name="id" value="{$order_id}">
  11. <div class="layui-form-item">
  12. <label class="layui-form-label">快递</label>
  13. <div class="layui-input-inline">
  14. <select name="express">
  15. <option value="1">顺丰</option>
  16. <option value="2">韵达</option>
  17. <option value="3">中通</option>
  18. </select>
  19. </div>
  20. </div>
  21. <div class="layui-form-item">
  22. <label class="layui-form-label">快递单号</label>
  23. <div class="layui-input-inline">
  24. <input type="text" class="layui-input" name="express_id">
  25. </div>
  26. </div>
  27. </form>
  28. <div class="layui-form-item">
  29. <div class="layui-input-block">
  30. <button class="layui-btn" onclick="save()">保存</button>
  31. </div>
  32. </div>
  33. <script type="text/javascript">
  34. layui.use(['layer','form'],function(){
  35. form = layui.form;
  36. layer = layui.layer;
  37. $ = layui.jquery;
  38. });
  39. // 保存管理员
  40. function save(){
  41. var express_id = $.trim($('input[name="express_id"]').val());
  42. if(express_id==''){
  43. layer.alert('请输入快递单号',{icon:2});
  44. return;
  45. }
  46. // 请求保存接口,把数据传值到接口中。
  47. $.post('/index.php/admins/User/order_save',$('form').serialize(),function(res){
  48. if(res.code>0){
  49. layer.alert(res.msg,{icon:2});
  50. }else{
  51. layer.msg(res.msg);
  52. setTimeout(function(){parent.window.location.reload();},1000);
  53. }
  54. },'json');
  55. }
  56. </script>
  57. </body>
  58. </html>
Correction status:Uncorrected

Teacher's comments:
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