夺命雷公狗ThinkPHP项目之----商城6数据库设计和完成后台首页

废话步多说,我们开工,

数据库设计如下所示:

SQL语句如下:

#创建数据库
create database shopp charset utf8;

#选择数据库
use shopp;

/*------------------------------------商品模块---------------------------------------*/
#创建商品类别表
create table cz_category(
    cat_id smallint unsigned not null auto_increment primary key comment '商品类别ID',
    cat_name varchar(30) not null default '' comment '商品类别名称',
    parent_id smallint unsigned not null default 0 comment '商品类别父ID',
    cat_desc varchar(255) not null default '' comment '商品类别描述',
    sort_order tinyint not null default 50 comment '排序依据',
    unit varchar(15) not null default '' comment '单位',
    is_show tinyint not null default 1 comment '是否显示,默认显示',
    index pid(parent_id)
)engine=MyISAM charset=utf8;


#创建商品品牌表
create table cz_brand(
    brand_id smallint unsigned not null auto_increment primary key comment '商品品牌ID',
    brand_name varchar(30) not null default '' comment '商品品牌名称',
    brand_desc varchar(255) not null default '' comment '商品品牌描述',
    url varchar(100) not null default '' comment '商品品牌网址',
    logo varchar(50) not null default '' comment '品牌logo',
    sort_order tinyint unsigned not null default 50 comment '商品品牌排序依据',
    is_show tinyint not null default 1 comment '是否显示,默认显示'    
)engine=MyISAM charset=utf8;

#创建商品类型表
create table cz_goods_type(
    type_id smallint unsigned not null auto_increment primary key comment '商品类型ID',
    type_name varchar(50) not null default '' comment '商品类型名称'
)engine=MyISAM charset=utf8;


#创建商品属性表
create table cz_attribute(
    attr_id smallint unsigned not null auto_increment primary key comment '商品属性ID',
    attr_name varchar(50) not null default '' comment '商品属性名称',
    type_id smallint not null default 0 comment '商品属性所属类型ID',
    attr_type tinyint not null default 1 comment '属性是否可选 0 为唯一,1为单选,2为多选',
    attr_input_type tinyint not null default 1 comment '属性录入方式 0为手工录入,1为从列表中选择,2为文本域',
    attr_value text comment '属性的值',
    sort_order tinyint not null default 50 comment '属性排序依据',
    index type_id(type_id)
)engine=MyISAM charset=utf8;

#创建商品表
create table cz_goods(
    goods_id int unsigned not null auto_increment primary key comment '商品ID',
    goods_sn varchar(30) not null default '' comment '商品货号',
    goods_name varchar(100) not null default '' comment '商品名称',
    goods_brief varchar(255) not null default '' comment '商品简单描述',
    goods_desc text comment '商品详情',
    cat_id smallint unsigned not null default 0 comment '商品所属类别ID',
    brand_id smallint unsigned not null default 0 comment '商品所属品牌ID',
    market_price decimal(10,2) not null default 0 comment '市场价',
    shop_price decimal(10,2) not null default 0 comment '本店价格',
    promote_price decimal(10,2) not null default 0 comment '促销价格',
    promote_start_time int unsigned not null default 0 comment '促销起始时间',
    promote_end_time int unsigned not null default 0 comment '促销截止时间',
    goods_img varchar(50) not null default '' comment '商品图片',
    goods_thumb varchar(50) not null default '' comment '商品缩略图',
    goods_number smallint unsigned not null default 0 comment '商品库存',
    click_count int unsigned not null default 0 comment '点击次数',
    type_id smallint unsigned not null default 0 comment '商品类型ID',
    is_promote tinyint unsigned not null default 0 comment '是否促销,默认为0不促销',
    is_best tinyint unsigned not null default 0 comment '是否精品,默认为0',
    is_new tinyint unsigned not null default 0 comment '是否新品,默认为0',
    is_hot tinyint unsigned not null default 0 comment '是否热卖,默认为0',
    is_onsale tinyint unsigned not null default 1 comment '是否上架,默认为1',
    add_time int unsigned not null default 0 comment '添加时间',
    index cat_id(cat_id),
    index brand_id(brand_id),
    index type_id(type_id)
)engine=MyISAM charset=utf8;

#创建商品属性对应表
create table cz_goods_attr(
    goods_attr_id int unsigned not null auto_increment primary key comment '编号ID',
    goods_id int unsigned not null default 0 comment '商品ID',
    attr_id smallint unsigned not null default 0 comment '属性ID',
    attr_value varchar(255) not null default '' comment '属性值',
    attr_price decimal(10,2) not null default 0 comment '属性价格',
    index goods_id(goods_id),
    index attr_id(attr_id)
)engine=MyISAM charset=utf8;

#创建商品相册表
create table cz_galary(
    img_id int unsigned not null auto_increment primary key comment '图片编号',
    goods_id int unsigned not null default 0 comment '商品ID',
    img_url varchar(50) not null default '' comment '图片URL',
    thumb_url varchar(50) not null default '' comment '缩略图URL',
    img_desc varchar(50) not null default '' comment '图片描述',
    index goods_id(goods_id)
)engine=MyISAM charset=utf8;

/*------------------------------------商品模块 end-----------------------------------*/


/*------------------------------------用户模块---------------------------------------*/
#创建用户表
create table cz_user(
    user_id int unsigned not null auto_increment primary key comment '用户编号',
    user_name varchar(50) not null default '' comment '用户名',
    email varchar(50) not null default '' comment '电子邮箱',
    password char(32) not null default '' comment '用户密码,md5加密',
    reg_time int unsigned not null default 0 comment '用户注册时间'
)engine=MyISAM charset=utf8;

#创建用户收货地址表
create table cz_address(
    address_id int unsigned not null auto_increment primary key comment '地址编号',
    user_id int unsigned not null default 0 comment '地址所属用户ID',
    consignee varchar(60) not null default '' comment '收货人姓名',
    province smallint unsigned not null default 0 comment '省份,保存是ID',
    city smallint unsigned not null default 0 comment '',
    district smallint unsigned not null default 0 comment '',
    street varchar(100) not null default '' comment '街道地址',
    zipcode varchar(10) not null default '' comment '邮政编码',
    telephone varchar(20) not null default '' comment '电话',
    mobile varchar(20) not null default '' comment '移动电话',
    index user_id(user_id)
)engine=MyISAM charset=utf8;

#创建地区表,包括省市区三级
create table cz_region(
    region_id smallint unsigned not null auto_increment primary key comment '地区ID',
    parent_id smallint unsigned not null default 0 comment '父ID',
    region_name varchar(30) not null default '' comment '地区名称',
    region_type tinyint unsigned not null default 1 comment '地区类型 1 省份 2 市 3 区(县)'
)engine=MyISAM charset=utf8;

#创建购物车表
create table cz_cart(
    cart_id int unsigned not null auto_increment primary key comment '购物车ID',
    user_id int unsigned not null default 0 comment '用户ID',
    goods_id int unsigned not null default 0 comment '商品ID',
    goods_name varchar(100) not null default '' comment '商品名称',
    goods_img varchar(50) not null default '' comment '商品图片',
    goods_attr varchar(255) not null default '' comment '商品属性',
    goods_number smallint unsigned not null default 1 comment '商品数量',
    market_price decimal(10,2) not null default 0 comment '市场价格',
    goods_price decimal(10,2) not null default 0 comment '成交价格',
    subtotal decimal(10,2) not null default 0 comment '小计'
)engine=MyISAM charset=utf8;
/*------------------------------------用户模块 end-----------------------------------*/




/*------------------------------------订单模块---------------------------------------*/
#创建送货方式表
create table cz_shipping(
    shipping_id tinyint unsigned not null auto_increment primary key comment '编号',
    shipping_name varchar(30) not null default '' comment '送货方式名称',
    shipping_desc varchar(255) not null default '' comment '送货方式描述',
    shipping_fee decimal(10,2) not null default 0 comment '送货费用',
    enabled tinyint unsigned not null default 1 comment '是否启用,默认启用'
)engine=MyISAM charset=utf8;


#创建支付方式表
create table cz_payment(
    pay_id tinyint unsigned not null auto_increment primary key comment '支付方式ID',
    pay_name varchar(30) not null default '' comment '支付方式名称',
    pay_desc varchar(255) not null default '' comment '支付方式描述',
    enabled tinyint unsigned not null default 1 comment '是否启用,默认启用'
)engine=MyISAM charset=utf8;


#创建订单表
create table cz_order(
    order_id int unsigned not null auto_increment primary key comment '订单ID',
    order_sn varchar(30) not null default '' comment '订单号',
    user_id int unsigned not null default 0 comment '用户ID',
    address_id int unsigned not null default 0 comment '收货地址id',
    order_status tinyint unsigned not null default 0 comment '订单状态 1 待付款 2 待发货 3 已发货 4 已完成',
    postscripts varchar(255) not null default '' comment '订单附言',
    shipping_id tinyint not null default 0 comment '送货方式ID',
    pay_id tinyint not null default 0 comment '支付方式ID',
    goods_amount decimal(10,2) not null default 0 comment '商品总金额',
    order_amount decimal(10,2) not null default 0 comment '订单总金额',
    order_time int unsigned not null default 0 comment '下单时间',
    index user_id(user_id),
    index address_id(address_id),
    index pay_id(pay_id),
    index shipping_id(shipping_id)
)engine=MyISAM charset=utf8;


#创建订单明细表,即商品订单关系表(多对多)
create table cz_order_goods(
    rec_id int unsigned not null auto_increment primary key comment '编号',
    order_id int unsigned not null default 0 comment '订单ID',
    goods_id int unsigned not null default 0 comment '商品ID',
    goods_name varchar(100) not null default '' comment '商品名称',
    goods_img varchar(50) not null default '' comment '商品图片',
    shop_price decimal(10,2) not null default 0 comment '商品价格',
    goods_price decimal(10,2) not null default 0 comment '成交价格',
    goods_number smallint unsigned not null default 1 comment '购买数量',
    goods_attr varchar(255) not null default '' comment '商品属性',
    subtotal decimal(10,2) not null default 0 comment '商品小计'
)engine=MyISAM charset=utf8;

/*------------------------------------订单模块 end-----------------------------------*/



#创建后台管理员表
create table cz_admin(
    admin_id smallint unsigned not null auto_increment primary key comment '管理员编号',
    admin_name varchar(30) not null default '' comment '管理员名称',
    password char(32) not null default '' comment '管理员密码',
    email varchar(50) not null default '' comment '管理员邮箱',
    add_time int unsigned not null default 0 comment '添加时间'
)engine=MyISAM charset=utf8;

#插入一条记录作为管理员 用户名和密码均为admin
insert into cz_admin(admin_name,password,email) values('admin','21232f297a57a5a743894a0e4a801fc3','admin@itcast.cn');

首先我们将thinkphp文件都解压到环境目录下的shop文件夹下

然后将里面多余的东西都干掉,留下public文件夹和thinkphp文件夹,即可,别的东西干掉,

然后我们新建一个名字叫index.php的文件,里面的配置文件可以按以下方法进行自定义:

<?php
    // 定义项目目录
    define("APP_PATH",'./Shop/');
    // 开启调试
    define("APP_DEBUG",true);
    // 引入ThinkPHP入口文件
    require "./ThinkPHP/Thinkphp.php";

我们打开shop目录下发现了Common和Home以及Runtime这三个文件夹

那么我们第一个目标是完成网站后台的首页吧,那么我们就直接将Home的文件夹复制一份出来,并且改名为Admin这样就可以分出前后台目录文件了

下一步是在shoppshopCommonConfconfig.php配置文件上设置下后台的配置文件和数据库的链接方式了,而且里面也可以一块开启session到时候不用那么麻烦,一个个的去打开了,如下所示:

<?php
return array(
    //'配置项'=>'配置值'
    //系统中允许访问的模块(前后台)
    'MODULE_ALLOW_LIST'      =>  array('Home','Admin'),
    //配置默认进入模块Home
    'DEFAULT_MODULE'         =>     'Home',//默认模块
    
        //禁止在模版中使用php代码  默认为false
        //'TMPL_DENY_PHP'=>false;
        
        //数据库配置
        'DB_TYPE'               =>  'mysql',     // 数据库类型
        'DB_HOST'               =>  'localhost', // 服务器地址
        'DB_NAME'               =>  'shopp',          // 数据库名
        'DB_USER'               =>  'root',      // 用户名
        'DB_PWD'                =>  '',          // 密码
        'DB_PORT'               =>  '3306',        // 端口
        'DB_PREFIX'             =>  'cz_',    // 数据库表前缀
        
        /*开启SESSION开关 */
        'SESSION_AUTO_START'    =>  true,    // 是否自动开启Session

);

然后在Admin目录下找到IndexController的控制器,将里面的

namespace HomeController;

改成namespace AdminController;

然后用浏览器进行访问下http://localhost/shopp/index.php/admin,看下是否能正常见到笑脸,如果能正常看到,那么恭喜您,您成成功配置成功Thinkphp的环境了

下一步我们就是在Admin---View---目录下创建Index的文件夹,然后将网站模版放进去,

按正常来说,我们访问http://localhost/shopp/index.php/admin应该可以看到一些东西才是对的,但是我打开发现报了一大堆的错,不过没关系,这都是小问题,还没全部加载进来,因为我们框架是由分针技术实现的,而且框架上的路径还没成功引入,那么我们就打开index.html让他们进行引入

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>myshop管理中心</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<frameset rows="51,*" framespacing="0" border="0">
  <frame src="__MODULE__/Index/top" id="header-frame" name="header-frame" frameborder="no" scrolling="no">
  <frameset cols="180, 10, *" framespacing="0" border="0" id="frame-body">
    <frame src="__MODULE__/Index/menu" id="menu-frame" name="menu-frame" frameborder="no" scrolling="yes">
    <frame src="__MODULE__/Index/drag" id="drag-frame" name="drag-frame" frameborder="no" scrolling="no">
    <frame src="__MODULE__/Index/main" id="main-frame" name="main-frame" frameborder="no" scrolling="yes">
  </frameset>
</frameset>
  <frameset rows="0, 0" framespacing="0" border="0">
  <frame src="http://api.ecshop.com/record.php?mod=login&url={$shop_url}" id="hidd-frame" name="hidd-frame" frameborder="no" scrolling="no">
  </frameset>
</head>
</html>

上面的__MODULE__他目前的指向是当前admin文件夹下,Index是控制器,top之类的是方法,那么我们就打开IndexController.class.php控制器设置以下方法让他进行输出

<?php
namespace AdminController;
use ThinkController;
class IndexController extends Controller {
    public function index(){
       $this -> display();
      }

      public function top(){
          $this -> display();
      }
      
      public function menu(){
          $this -> display();
      }

      public function drag(){
          $this -> display();
      }

      public function main(){
          $this -> display();
      }
}

这样设置好了,但是打开http://localhost/shopp/index.php/admin/  后还是发现不能正常显示,原因也很简单,就是因为他的css和js之类的没引入进来,那么我们的解决方法是在项目的更目录下新建一个Public的目录然后在public里面建立一个叫Admin的目录,如下图所示:

然后在shoppShopCommonConfconfig.php里面进行自定义目录,目的是为了更加的方便引入各种样式和图片,代码如下所示:

<?php
return array(
    //'配置项'=>'配置值'
    //系统中允许访问的模块(前后台)
    'MODULE_ALLOW_LIST'      =>  array('Home','Admin'),
    //配置默认进入模块Home
    'DEFAULT_MODULE'         =>     'Home',//默认模块
        
        //数据库配置
        'DB_TYPE'               =>  'mysql',     // 数据库类型
        'DB_HOST'               =>  'localhost', // 服务器地址
        'DB_NAME'               =>  'shopp',          // 数据库名
        'DB_USER'               =>  'root',      // 用户名
        'DB_PWD'                =>  '',          // 密码
        'DB_PORT'               =>  '3306',        // 端口
'DB_PREFIX'             =>  'cz_',    // 数据库表前缀
/*开启SESSION开关 */ 'SESSION_AUTO_START' => true, // 是否自动开启Session //自定义目录,方便样式的引入 'TMPL_PARSE_STRING' => array( //后台的 '__ADMIN__'=>'/Public/Admin', ), );

路径测试了,那么下一步就是来对wamp进行一个配置,

打开后进入里面拉到最低下加上

Include "D:/wamp/alias/*"
<VirtualHost *:80>
    DocumentRoot "D:wampwwwshopp"
    ServerName www.shop.com
</VirtualHost>

这段代码,因为我的wamp是放在D盘下的,所以我的DocumentRoot路径就指向那,大家可以看情况而定,

然后修改下host文件C:WindowsSystem32driversetchosts文件夹拉到最底部加上

127.0.0.1        www.shop.com

这段代码即可模拟出服务器端的环境了

对了别忘了从其apache噢,嘻嘻

然后对这下面的几个文件涉及到图片和样式的都该下即可,

如:

<link href="__ADMIN__/styles/general.css" rel="stylesheet" type="text/css" />
<img src="__ADMIN__/images/ecshop_logo.gif" alt="ECSHOP - power for e-commerce" />
<script type="text/javascript" src="__ADMIN__/js/transport.js"></script>

改成这样即可。

替换成功后首页即会变成这样

看上去没那么磕碜啦,嘻嘻..

不过我们在实际的情况下都是用到批量替换的噢,别手动一个个去换,有写模版太多图片之类的了,会改到发晕的噢..

原文地址:https://www.cnblogs.com/leigood/p/4943311.html