OrderModel.php
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* Created by PhpStorm.
* User: yhbr
* Date: 2018/9/29
* Time: 13:42
*/
namespace app\order\model;
use think\Model;
use think\Db;
class OrderModel extends Model
{
//订单列表的全部、待支付、代发货、待收货、已完成订单
public function getAllOrders()
{
$all = Db::name('zj_order')
->field('id,order_num,step,is_evaluate,create_time')
->where(['uid' => session('user.id')])
->order('create_time DESC')
->select()
->toArray();
$unpaid = [];
$undelivered = [];
$unreceived = [];
$completed = [];
$a = 0;
$b = 0;
$c = 0;
$d = 0;
foreach ($all as $key => $item) {
$item['detail'] = Db::name('zj_order_goods')->alias('o')
->field('o.*,g.name,g.intro,o.price,g.thumb')
->join('zj_goods g', 'g.id=o.gid')
->where(['oid' => $item['id']])->select()->toArray();
foreach ($item['detail'] as $k => $v) {
$item['detail'][$k]['thumb'] = cmf_get_image_url($v['thumb']);
}
$all[$key] = $item;
if ($item['step'] == 1) {
$unpaid[$a] = $item;
$a++;
} elseif ($item['step'] == 2) {
$undelivered[$b] = $item;
$b++;
} elseif ($item['step'] == 3) {
$unreceived[$c] = $item;
$c++;
} elseif ($item['step'] >= 5 && $item['step'] <= 9) {
$completed[$d] = $item;
$d++;
} else {
continue;
}
}
$data = [
'all' => $all,
'unpaid' => $unpaid,
'undelivered' => $undelivered,
'unreceived' => $unreceived,
'completed' => $completed
];
return $data;
}
}