將用戶的訂單信息展示出來,包括未付款未發貨等等狀態的訂單,數據庫可以用數字來實現訂單實時訂單狀態。
新建一張表將訂單信息的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基礎薄弱還是有一定幫助的。