将用户的订单信息展示出来,包括未付款未发货等等状态的订单,数据库可以用数字来实现订单实时订单状态。
新建一张表将订单信息的id都放进去,并把json数据写入到字段中,前台只需要把数据库json的数据转换成数组然后输出就可以实现对于订单商品的名称和信息了。
页面代码full_order.html:
~~~
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="__INDEXSS__/css/full_order.css">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div class="fullorder">
<footer class="ordertitle">
<a href="" class="ordera">返回</a><span class="orderspan">全部订单</span>
</footer>
<br />
<div class="orderbo">
<table>
{foreach $shopddan as $k=>$v}
<tr class="ordertra">
<td class="ordertda">{switch name="$v['ddzt']"}
{case value = "0"}<p>未付款</p>{/case}
{case value = "1"}<p>未发货</p>{/case}
{case value = "2"}<p>已发货</p>{/case}
{case value = "3"}<p>已收货</p>{/case}
{/switch}
</td>
</tr>
<tr>
<td>
<?php
$json = $v['goods'];
$array = json_decode($json,true);
echo $array['title'];
?>
</td>
<td><img src="__INDEXTP__/{$v['imga']}" width="200px" height="200px"/></td>
</tr>
{/foreach}
</table>
</div>
</div>
</body>
</html>
~~~
控制器类ddan.php:
~~~
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/7/1
* Time: 1:44
*/
namespace app\index\controller;
use app\index\model\Danshop;
use app\admin\model\Commodi;
use think\Controller;
use think\Db;
use think\Request;
class Ddan extends Controller{
/**
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException测试页面订单列表测试
*/
public function shopddan(){
$info = Db::name('ddanshop');
$request = Request::instance();
$ids = $request->session('ids');
// $ddds = $info->where('gerenid','=',$ids)->column('ddzt');
$shopad = Danshop::where('gerenid',$ids)->select();
// $shopad = Danshop::get($ids);
// $shopad = Commodi::where('id',$ddid)->select();
// $this->assign('shopddana',$shopa);
// $this->assign('shopddan',$shopa);
// echo($shopad['id']);
$shopbas = $this->shopxq();
$this->assign('shopddana',$shopbas);
$this->assign('shopddan',$shopad);
echo($shopbas);
//
return $this->fetch('test');
}
/**
* @return mixed
* @throws \think\exception\DbException获取商品的数据
*/
public function shopxq(){
$info = Db::name('ddanshop');
$request = Request::instance();
$ids = $request->session('ids');
$ddid = $info->where('gerenid','=',$ids)->column('ddanid');
foreach ($ddid as $key => $value) {
$shopa = Commodi::get($value);
$shopba[$key] = $shopa;
}
// $json = json_encode($shopba);
// $array = json_decode($json,TRUE);
// dump($array);
// echo $json;
return $shopba;
// foreach ($array as $k){
// echo $k['title'];
// }
}
/**
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException获取用户付款的订单数据
*/
public function fullorder()
{
if (!session('susername') || !session('spassword')) {
return $this->error('未登录', url('index/login/index'));
} else {
$info = Db::name('ddanshop');
$request = Request::instance();
$ids = $request->session('ids');
$shopad = Danshop::where('gerenid', $ids)->limit(5)->select();
$shopbas = $this->shopxq();
// $shopad[''] = $shopbas;
// dump($shopad);
$this->assign('shopddana', $shopbas);
$this->assign('shopddan', $shopad);
return $this->fetch('full_order');
}
}
/**
* @param int $id
* @throws \think\exception\DbException保存json数据测试
*/
public function testa($id = 40){
// $info = Db::name('ddanshop');
// $shopa = Danshop::where('gerenid', 1)->select();
$info = Danshop::get();
$shop = $info;
$json = json_decode($shop,true);
dump($json);
}
}
~~~
到这里就已经差不多完成这些功能了,还有一些样式的东西没改,但是可能最近一段时间都没有时间再去做这个网站了,因为公司那边有个项目快要完成了,其实我本来打算下一个章节写一下下拉刷新功能的,这对于js基础薄弱还是有一定帮助的。