这一章主要讲的是商品的购买功能还有实现商品的列表功能
我先把几个页面的代码放上来吧
支付页面shopddan.html:
~~~
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="__INDEXSS__/css/shopddan.css">
<title></title>
</head>
<body>
<div class="shopddan">
<footer class="footer"><a href="{:url('playshop?id=' . $shopdid->getData('id'))}" class="footergoum"><span class="shopspan">支付订单¥{$shopjiag.jiage}</span></a></footer>
</div>
</body>
</html>
~~~
商品列表shoppta.html:
~~~
<!--平台商品页面-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>平台自营</title>
<link rel="stylesheet" href="__INDEXSS__/css/shoppta.css">
<link rel="stylesheet" href="__ADMINS__/css/xadmin.css">
<script src="__ADMINS__/lib/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<div class="shophea">
<div class="shoptitle">
<img src="" />
</div>
<div class="shopsou">
<button class="fanhui" type="submit">返回</button><input class="sousuo" type="text" name="" /><button type="submit" class="soubut">搜索</button>
</div>
<div class="filtrate_term">
<ul class="seul">
<!--<tr>-->
<li class="onea"><a href="" name="list_sort_index">默认</a></li><li class="oneb"><a href="" name="list_sort_sales">销量</a></li><li class="onec"><a href="" name="list_sort_price">价格</a></li><li class="oned"><a href="" name="list_sort_date">最新</a></li>
<!--</tr>-->
</ul>
</div>
<div class="jianxi">
</div>
<div class="shoplie">
<table class="clearfixp_right">
{volist name="shopcx" id="shopzs" key="key"}
<tr class="shopad">
<th>
<div><a href="{:url('ptaishop?id=' . $shopzs->getData('id'))}" name="product_item" dd_name="商品">
<p class="img"><img class="imashop" src="__INDEXTP__/{$shopzs.imga}" alt="{$shopzs.title}" ></p>
<p class="name" style="margin: 8px ;font-size: 18px;"><img width="80px" height="25px" src="__INDEXTP__/{$shopzs.paitaitb}">{$shopzs.title}</p></a><p class="price"><span class="reda" style="float: left;font-size: 15px;">¥{$shopzs.jiage}</span></p>
</div>
</th>
</tr>
{/volist}
</table>
</div>
<div class="layui-card-body ">
<div class="page">
<div>
{$page}
</div>
</div>
</div>
<!--底部固定菜单栏-->
<!--<footer class="footer">底部固定菜单</footer>-->
</div>
</body>
</html>
~~~
商品详情ptaishop.html:
~~~
<!--平台商品详情-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>商品详情</title>
<link rel="stylesheet" href="__INDEXSS__/css/ptaishop.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.3/css/swiper.min.css">
</head>
<body>
<div class="shophea">
<div class="xqimage">
<div class="swiper-wrapper">
<img class="swiper-slide" src="__INDEXTP__/{$shopzs.imga}" />
<img class="swiper-slide" src="__INDEXTP__/{$shopzs.imgb}" />
<img class="swiper-slide" src="__INDEXTP__/{$shopzs.imgc}" />
</div>
</div>
<div class="shoptitle">
<p style="font-size: 30px; margin:0px 0 0 0 ;"><img style="margin: 0px 0 0 0;" align="top" width="120px" height="40px" src="__INDEXTP__/{$shopzs.paitaitb}">{$shopzs.title}</p>
</div>
<div class="shopxxi">
<span style="color: #00FFFF;">商品销量:{$shopzs.volume} 商品库存:{$shopzs.stock}</span>
</div>
<div class="shoppjia">
<span><img style="margin: 0px 0 0 0;" align="top" width="100%" height="100%" src="__INDEXTP__/{$shopzs.paitaitb}"></span>
</div>
<div class="shopxiaq">
<span>商品详情</span>
</div>
<div class="jiange">
<span style="width: 100%;height: 100%;">{$shopzs.xiangqwz}</span>
{volist name="shopimg" id="shopxqimg" key="key"}
<img width="100%" height="100%" src="__INDEXTP__/{$shopxqimg.xqimage}" />
{/volist}
</br>
<p>-----到底了-----</p>
</br>
</br>
</br>
</br>
</div>
<div>
</div>
<footer class="footer"><a href="{:url('dindan?id=' . $shopzs->getData('id'))}" class="footergoum" style="font-size: 50px;">立即购买</a></footer>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.3.3/js/swiper.min.js"></script>
<script type="text/javascript">
var mySwiper = new Swiper('.xqimage',{
// direction: 'vertical', //上下滑动
//
// loop设置为true。会在原本slide前后复制若干个slide(默认一个)并在合适的时候切换,让Swiper看起来是循环的。
loop:true,
// 使用分页导航
pagination:{
el:'.daohanfy',
clickable :true,
},
//
});
</script>
</html>
~~~
上面这几个页面也没有什么新的技术涉及到的,也就一个footer标签吧,主要是用在固定菜单栏上的
下面我把控制器类代码放上来吧还有模型代码
控制器shopgou.php:
~~~
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/6/23
* Time: 18:54
*/
namespace app\index\controller;
use app\index\model\Shopxian;
use think\Controller;
use app\admin\model\Commodi;
use think\Db;
use app\index\model\Namex;
use think\Request;
use app\index\model\Danshop;
use think\Session;
class Shopgou extends Controller{
/**
* @return mixed
* @throws \think\exception\DbException商品列表页面,加载6个数据
*/
public function shoppta(){
$shopcx = Commodi::paginate(6);
// 分页变量
$page = $shopcx->render();
$this->assign('shopcx',$shopcx);
$this->assign('page',$page);
return $this->fetch('shoppta');
}
/**
* @param string $id
* @return mixed
* @throws \think\exception\DbException商品详情页面数据加载
*/
public function ptaishop($id = ''){
$shopzs = Commodi::get($id);
$time = $shopzs['addtime'];
// 获取详情图片
$shopimg = Db::name('shangpp')->where('shopid','=',$id)->where('atime','=',$time)->select();
$this->assign('shopzs',$shopzs);
$this->assign('shopimg',$shopimg);
return $this->fetch('ptaishop');
}
/**
* @param string $id
* @return mixed|void
* @throws \think\exception\DbException订单支付页面
*/
public function dindan($id = ''){
if (!session('susername') || !session('spassword')){
return $this->error('未登录',url('index/login/index'));
}else {
$ddinfo = Db::name('ddanshop');
$request = Request::instance();
$ids = $request->session('ids');
$info = Commodi::get($id);
$shopid['ddanid'] = $id;
$shopid['gerenid'] = $ids;
//订单状态
$shopid['ddzt'] = 0;
$shopid['shoptime'] = $info['addtime'];
$shopxx = Db::name('shopsp')->where('id','=',$id)->find();
$shopxa = Db::name('shopsp')->where('id','=',$id)->value('imga');
$shopid['imga'] = $shopxa;
$json = json_encode($shopxx);
$shopid['goods'] = $json;
$ddangr = $ddinfo->insert($shopid);
$ddid = $ddinfo->getLastInsID();
$ddshop = Danshop::get($ddid);
$this->assign('shopdid',$ddshop);
$this->assign('shopjiag', $info);
return $this->fetch('shopddan');
}
}
/**
* @param string $id
* @throws \think\exception\DbException订单支付功能
*/
public function playshop($id = ''){
if (!session('susername') || !session('spassword')){
return $this->error('未登录',url('index/login/index'));
}else {
$ztinfo = Db::name('ddanshop');
$ddanid = $ztinfo->where('id','=',$id)->value('ddanid');
$info = Commodi::get($ddanid);
$request = Request::instance();
$ids = $request->session('ids');
$geren = Namex::get($ids);
$shopjg = $info['jiage'];
$gerenjg = $geren['balance'];
// dump ($id);
if ($shopjg > $gerenjg) {
$this->error('余额不足请充值');
} else {
$gryue = $gerenjg - $shopjg;
$grye['balance'] = $gryue;
$ddzt['ddzt'] = 1;
$shopid = $ztinfo->where('id','=',$id)->where('gerenid','=',$ids)->where('ddanid','=',$ddanid)->update($ddzt);
$upye = Db::name('name')->where('id', '=', $ids)->update($grye);
}
if ($upye) {
$this->redirect(url('index/index/index'));
} else {
$this->error($upye->getError());
}
}
}
}
~~~
模型类ddanshop.php:
~~~
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/6/29
* Time: 16:12
*/
namespace app\index\model;
use think\Model;
class Danshop extends Model{
protected $name = 'ddanshop';
}
~~~
其他也是差不多的,并没有太多改变;