OrderscourierController.php
5.6 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
namespace app\admin\controller;
use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use think\Db;
class OrderscourierController extends AdminBaseController{
/**
*平台订单列表
*/
public function order_list(){
$param = $this->request->param();
$where = [
"indent_type" => 1
];
if(!empty($param['start_time']) && !empty($param['end_time'])){
$start_time = strtotime($param['start_time']);
$end_time = strtotime($param['end_time']);
$where['create_time'] = [['>=',$start_time],['<=',$end_time]];
}
if(!empty($param['keyword'])){
$where['order_number'] = ['like','%'.trim($param['keyword']).'%'];
}
if(!empty($param['state'])){
$where['state'] = $param['state'];
}
$data = Db::name('indent')->where($where)->where("state = 2 or state = 3 or state = 5")->order('create_time','DESC')->paginate(12);
$data->appends($param);
$list = $data->items();
foreach ($list as $k=>$v) {
$indent_goods = Db::name('indent_goods')->alias('ig')
->field('g.book_name,ig.number')
->join('__GOODS__ g','ig.goods_id = g.id')
->where('ig.indent_id',$v['id'])
->select()->toArray();
$goods = [];
foreach ($indent_goods as $kg=>$vg) {
$goods[] = $vg['book_name'].'X'.$vg['number'];
}
$list[$k]['books'] = implode(',',$goods);
}
$this->assign('start_time',!empty($param['start_time']) ? $param['start_time'] : '');
$this->assign('end_time',!empty($param['end_time']) ? $param['end_time'] : '');
$this->assign('keyword',!empty($param['keyword']) ? trim($param['keyword']) : '');
$this->assign('state',!empty($param['state']) ? $param['state'] : '');
$this->assign('data',$list);
$this->assign('page',$data->render());
return $this->fetch();
}
/**
*平台订单查看
*/
public function plat_view(){
$id = $this -> request -> param();
$indent_id = $id['id'];
$data_goods = Db::name('indent_goods') -> where('indent_id',$indent_id) -> select();
$data_in = Db::name('indent') -> where('id',$indent_id) -> find();
$this -> assign('data_goods',$data_goods);
$this -> assign('data_in',$data_in);
//地址查询
$address = Db::name('address') -> where("id",$data_in['indent_address']) -> find();
if(!empty($address)){
$this -> assign('address',$address);
}else{
$this -> assign('address',null);
}
return $this -> fetch();
}
/**
* 查看物流信息
*/
public function logistics_information(){
$indent_id = $this -> request -> param();
$bird = new BirdController();
$logistics = $bird -> getOrder($indent_id['id']);
$this -> assign('logistics',$logistics['data']['traces']);
return $this -> fetch();
}
/**
* 发货
* @adminMenu(
* 'name' => '发货',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '发货',
* 'param' => ''
* )
*/
public function fahuo()
{
$id = $this->request->param('id', 0, 'intval');
if($this->request->isPost()) {
$param = $this->request->param();
$url = $param['url'];
unset($param['url']);
// 判断订单是否可发货
$info = Db::name('indent')->where('id',$param['id'])->find();
if (!$info) {
$this->error("订单不存在!");
}
if ($info['state'] != 2) {
$this->error("订单无法发货!");
}
// 修改发货状态
$param['state'] = 5;
$result = Db::name('indent')->update($param);
if ($result) {
$this->success("发货成功!",$url);
} else {
$this->error('发货失败!');
}
} else {
if ($id) {
$info = Db::name('indent')->where('id',$id)->find();
$this->assign('info',$info);
$this->assign('url',$_SERVER['HTTP_REFERER']);
return $this->fetch();
} else {
$this->error('数据传入失败!');
}
}
}
/**
* 完成
* @adminMenu(
* 'name' => '完成',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '完成',
* 'param' => ''
* )
*/
public function complete()
{
$param = $this->request->param();
// 判断订单是否可发货
$info = Db::name('indent')->where('id',$param['id'])->find();
if (!$info) {
$this->error("订单不存在!");
}
if ($info['state'] != 5) {
$this->error("订单无法完成!");
}
// 修改发货状态
$param['state'] = 3;
$result = Db::name('indent')->update($param);
if ($result) {
$this->success("操作成功!");
} else {
$this->error('操作失败!');
}
}
}