|
|
|
1
|
+<?php
|
|
|
|
2
|
+
|
|
|
|
3
|
+namespace app\admin\controller;
|
|
|
|
4
|
+
|
|
|
|
5
|
+use app\admin\model\User;
|
|
|
|
6
|
+use app\api\controller\v1\WxxcxPush;
|
|
|
|
7
|
+use app\common\controller\Backend;
|
|
|
|
8
|
+use think\Db;
|
|
|
|
9
|
+use app\api\controller\Index;
|
|
|
|
10
|
+use think\exception\DbException;
|
|
|
|
11
|
+use think\exception\PDOException;
|
|
|
|
12
|
+use think\exception\ValidateException;
|
|
|
|
13
|
+
|
|
|
|
14
|
+/**
|
|
|
|
15
|
+ * 订单管理
|
|
|
|
16
|
+ *
|
|
|
|
17
|
+ * @icon fa fa-circle-o
|
|
|
|
18
|
+ */
|
|
|
|
19
|
+class Dispatch extends Backend
|
|
|
|
20
|
+{
|
|
|
|
21
|
+
|
|
|
|
22
|
+ /**
|
|
|
|
23
|
+ * Order模型对象
|
|
|
|
24
|
+ * @var \app\admin\model\Order
|
|
|
|
25
|
+ */
|
|
|
|
26
|
+ protected $model = null;
|
|
|
|
27
|
+
|
|
|
|
28
|
+ public function _initialize()
|
|
|
|
29
|
+ {
|
|
|
|
30
|
+ parent::_initialize();
|
|
|
|
31
|
+ $this->model = new \app\admin\model\Order;
|
|
|
|
32
|
+ $this->view->assign("isPayList", $this->model->getIsPayList());
|
|
|
|
33
|
+ $this->view->assign("typeList", $this->model->gettypeList());
|
|
|
|
34
|
+ }
|
|
|
|
35
|
+
|
|
|
|
36
|
+
|
|
|
|
37
|
+
|
|
|
|
38
|
+ /**
|
|
|
|
39
|
+ * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
|
|
|
40
|
+ * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
|
|
|
41
|
+ * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
|
|
|
42
|
+ */
|
|
|
|
43
|
+
|
|
|
|
44
|
+
|
|
|
|
45
|
+ /**
|
|
|
|
46
|
+ * 查看
|
|
|
|
47
|
+ */
|
|
|
|
48
|
+ public function index()
|
|
|
|
49
|
+ {
|
|
|
|
50
|
+ //当前是否为关联查询
|
|
|
|
51
|
+ $this->relationSearch = true;
|
|
|
|
52
|
+ //设置过滤方法
|
|
|
|
53
|
+ $this->request->filter(['strip_tags', 'trim']);
|
|
|
|
54
|
+ if ($this->request->isAjax()) {
|
|
|
|
55
|
+ //如果发送的来源是Selectpage,则转发到Selectpage
|
|
|
|
56
|
+ if ($this->request->request('keyField')) {
|
|
|
|
57
|
+ return $this->selectpage();
|
|
|
|
58
|
+ }
|
|
|
|
59
|
+ list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
|
60
|
+
|
|
|
|
61
|
+ $list = $this->model
|
|
|
|
62
|
+ ->with(['driver', 'car', 'user'])
|
|
|
|
63
|
+ ->where($where)
|
|
|
|
64
|
+ ->where("order.driver_id",null)
|
|
|
|
65
|
+ ->where("order.is_pay",1)
|
|
|
|
66
|
+ ->order($sort, $order)
|
|
|
|
67
|
+ ->paginate($limit);
|
|
|
|
68
|
+ $res=$this->model->where("id",">",0)->update(["is_check"=>1]);
|
|
|
|
69
|
+ foreach ($list as $row) {
|
|
|
|
70
|
+ $row->visible(['id', 'order_no','phone', 'type','intended_driver_id', 'pay_type', 'price', 'is_pay', 'user_name', 'driver_name', 'pay_time', 'refund_time','reservation_time', 'create_time']);
|
|
|
|
71
|
+ if(!$row['driver_name']){
|
|
|
|
72
|
+ $row['driver_name']="未选择司机";
|
|
|
|
73
|
+ }
|
|
|
|
74
|
+ $row->visible(['driver']);
|
|
|
|
75
|
+ $row->getRelation('driver')->visible(['name']);
|
|
|
|
76
|
+ $row->visible(['car']);
|
|
|
|
77
|
+ $row->getRelation('car')->visible(['license_plate']);
|
|
|
|
78
|
+ $row->visible(['user']);
|
|
|
|
79
|
+ $row->getRelation('user')->visible(['username']);
|
|
|
|
80
|
+ }
|
|
|
|
81
|
+
|
|
|
|
82
|
+ $result = array("total" => $list->total(), "rows" => $list->items());
|
|
|
|
83
|
+
|
|
|
|
84
|
+ return json($result);
|
|
|
|
85
|
+ }
|
|
|
|
86
|
+ return $this->view->fetch();
|
|
|
|
87
|
+ }
|
|
|
|
88
|
+
|
|
|
|
89
|
+ /**
|
|
|
|
90
|
+ * 查看
|
|
|
|
91
|
+ */
|
|
|
|
92
|
+ public function dispatch()
|
|
|
|
93
|
+ {
|
|
|
|
94
|
+ //当前是否为关联查询
|
|
|
|
95
|
+ $this->relationSearch = true;
|
|
|
|
96
|
+ //设置过滤方法
|
|
|
|
97
|
+ $this->request->filter(['strip_tags', 'trim']);
|
|
|
|
98
|
+ if ($this->request->isAjax()) {
|
|
|
|
99
|
+ //如果发送的来源是Selectpage,则转发到Selectpage
|
|
|
|
100
|
+ if ($this->request->request('keyField')) {
|
|
|
|
101
|
+ return $this->selectpage();
|
|
|
|
102
|
+ }
|
|
|
|
103
|
+ list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
|
104
|
+
|
|
|
|
105
|
+ $list = $this->model
|
|
|
|
106
|
+ ->with(['driver', 'car', 'user'])
|
|
|
|
107
|
+ ->where($where)
|
|
|
|
108
|
+ ->order($sort, $order)
|
|
|
|
109
|
+ ->paginate($limit);
|
|
|
|
110
|
+ $res=$this->model->where("id",">",0)->update(["is_check"=>1]);
|
|
|
|
111
|
+ foreach ($list as $row) {
|
|
|
|
112
|
+ $row->visible(['id', 'order_no','phone', 'type','intended_driver_id', 'pay_type', 'price', 'is_pay', 'user_name', 'driver_name', 'pay_time', 'refund_time','reservation_time', 'create_time']);
|
|
|
|
113
|
+ if(!$row['driver_name']){
|
|
|
|
114
|
+ $row['driver_name']="未选择司机";
|
|
|
|
115
|
+ }
|
|
|
|
116
|
+ $row->visible(['driver']);
|
|
|
|
117
|
+ $row->getRelation('driver')->visible(['name']);
|
|
|
|
118
|
+ $row->visible(['car']);
|
|
|
|
119
|
+ $row->getRelation('car')->visible(['license_plate']);
|
|
|
|
120
|
+ $row->visible(['user']);
|
|
|
|
121
|
+ $row->getRelation('user')->visible(['username']);
|
|
|
|
122
|
+ }
|
|
|
|
123
|
+
|
|
|
|
124
|
+ $result = array("total" => $list->total(), "rows" => $list->items());
|
|
|
|
125
|
+
|
|
|
|
126
|
+ return json($result);
|
|
|
|
127
|
+ }
|
|
|
|
128
|
+ return $this->view->fetch('order/dispatch');
|
|
|
|
129
|
+ }
|
|
|
|
130
|
+
|
|
|
|
131
|
+ public function refund($id)
|
|
|
|
132
|
+ {
|
|
|
|
133
|
+
|
|
|
|
134
|
+ //查询订单
|
|
|
|
135
|
+ $order = Db::name("order")->where("id", $id)->find();
|
|
|
|
136
|
+ if ($order['is_pay'] != 1) {
|
|
|
|
137
|
+ $this->error("该订单无法退款");
|
|
|
|
138
|
+ }
|
|
|
|
139
|
+ if($order['pay_type']=="offlinepay" || $order['pay_type']=="background"){
|
|
|
|
140
|
+ $relogs['update_time'] = time();
|
|
|
|
141
|
+ $relogs['is_pay'] = 3;
|
|
|
|
142
|
+ $relogs['refund_time'] = time();
|
|
|
|
143
|
+ $rs2 = Db::name('order')
|
|
|
|
144
|
+ ->where(['id' => $order['id']])
|
|
|
|
145
|
+ ->update($relogs);
|
|
|
|
146
|
+ if($order['pay_type']="offlinepay"){
|
|
|
|
147
|
+ $index=new Index();
|
|
|
|
148
|
+ $index->refundToDriverUser($order['id']);
|
|
|
|
149
|
+ $this->refundSendMessage($id);//发送订阅消息
|
|
|
|
150
|
+ }
|
|
|
|
151
|
+ $this->success("退款成功");
|
|
|
|
152
|
+ }
|
|
|
|
153
|
+
|
|
|
|
154
|
+ //拼接退款参数
|
|
|
|
155
|
+ $pay_fee = $order['price'];
|
|
|
|
156
|
+ $refund_fee = $pay_fee;
|
|
|
|
157
|
+ $order_sn = $order['order_no'];
|
|
|
|
158
|
+ $pay_type = 'wechat';
|
|
|
|
159
|
+ $reason = '订单退款';
|
|
|
|
160
|
+ $notifyurl = 'https://wyc.tenyes.cn/api/index/refundNotifyx';//退款回调地址
|
|
|
|
161
|
+ //直接调用退款方法传参即可
|
|
|
|
162
|
+ $response = \addons\epay\library\Service::submitRefund($pay_fee, $refund_fee, $order_sn, getRefundSn($order['user_id']), $pay_type, $reason, $notifyurl, '', 'miniapp');
|
|
|
|
163
|
+ $response = json_encode($response);
|
|
|
|
164
|
+ $response = json_decode($response, true);
|
|
|
|
165
|
+ file_put_contents("pcl_repay_v2.log", date("Y-m-d H:i:s") . "::" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
|
|
|
|
166
|
+ if (!empty($response['return_code'] == 'SUCCESS')) {
|
|
|
|
167
|
+ //退款成功,更新退款记录
|
|
|
|
168
|
+ $relogs['update_time'] = time();
|
|
|
|
169
|
+ $relogs['is_pay'] = 3;
|
|
|
|
170
|
+ $relogs['out_refund_no'] = $response['out_refund_no'];
|
|
|
|
171
|
+ $relogs['refund_time'] = time();
|
|
|
|
172
|
+ $rs2 = Db::name('order')
|
|
|
|
173
|
+ ->where(['id' => $order['id']])
|
|
|
|
174
|
+ ->update($relogs);
|
|
|
|
175
|
+ } else {
|
|
|
|
176
|
+ $this->error('退款失败');
|
|
|
|
177
|
+ }
|
|
|
|
178
|
+ $index=new Index();
|
|
|
|
179
|
+ $index->refundToDriverUser($id);
|
|
|
|
180
|
+ $this->refundSendMessage($id);//发送订阅消息
|
|
|
|
181
|
+
|
|
|
|
182
|
+ $this->success("退款成功");
|
|
|
|
183
|
+ }
|
|
|
|
184
|
+
|
|
|
|
185
|
+
|
|
|
|
186
|
+ /**
|
|
|
|
187
|
+ * 编辑
|
|
|
|
188
|
+ *
|
|
|
|
189
|
+ * @param $ids
|
|
|
|
190
|
+ * @return string
|
|
|
|
191
|
+ * @throws DbException
|
|
|
|
192
|
+ * @throws \think\Exception
|
|
|
|
193
|
+ */
|
|
|
|
194
|
+ public function edit($ids = null)
|
|
|
|
195
|
+ {
|
|
|
|
196
|
+ $row = $this->model->get($ids);
|
|
|
|
197
|
+ if (!$row) {
|
|
|
|
198
|
+ $this->error(__('No Results were found'));
|
|
|
|
199
|
+ }
|
|
|
|
200
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
|
201
|
+ if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
|
|
|
|
202
|
+ $this->error(__('You have no permission'));
|
|
|
|
203
|
+ }
|
|
|
|
204
|
+ if (false === $this->request->isPost()) {
|
|
|
|
205
|
+ $car=Db::name("car")
|
|
|
|
206
|
+ ->alias("a")
|
|
|
|
207
|
+ ->join("driver b","a.driver_id=b.id")
|
|
|
|
208
|
+ ->where("a.route_id",$row['route_id'])
|
|
|
|
209
|
+ ->field("b.id,car_model,name,license_plate")
|
|
|
|
210
|
+ ->select();
|
|
|
|
211
|
+ $this->view->assign('row', $car);
|
|
|
|
212
|
+ return $this->view->fetch();
|
|
|
|
213
|
+ }
|
|
|
|
214
|
+ $params = $this->request->post('row/a');
|
|
|
|
215
|
+ if (empty($params)) {
|
|
|
|
216
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
|
217
|
+ }
|
|
|
|
218
|
+ $params = $this->preExcludeFields($params);
|
|
|
|
219
|
+ $result = false;
|
|
|
|
220
|
+ Db::startTrans();
|
|
|
|
221
|
+ try {
|
|
|
|
222
|
+ //是否采用模型验证
|
|
|
|
223
|
+ if ($this->modelValidate) {
|
|
|
|
224
|
+ $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
|
225
|
+ $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
|
|
|
|
226
|
+ $row->validateFailException()->validate($validate);
|
|
|
|
227
|
+ }
|
|
|
|
228
|
+ $driver = Db::name("driver")->where("id", $ids)->find();
|
|
|
|
229
|
+ $car = Db::name("car")->where("driver_id", $driver['id'])->find();
|
|
|
|
230
|
+ $carmodel = Db::name("carmodel")->where("id", $car['carmodel_id'])->find();
|
|
|
|
231
|
+ $route = Db::name("route")->where("id", $car['route_id'])->find();
|
|
|
|
232
|
+//判断总表
|
|
|
|
233
|
+ $time = strtotime(date("Y-m-d", time()));
|
|
|
|
234
|
+ $order_review = Db::name("order_review")
|
|
|
|
235
|
+ ->where("car_id", $car["id"])
|
|
|
|
236
|
+ ->where("route_id", $route['id'])
|
|
|
|
237
|
+ ->where("driver_id", $driver['id'])
|
|
|
|
238
|
+ ->where("createtime", ">", $time)
|
|
|
|
239
|
+ ->find();
|
|
|
|
240
|
+
|
|
|
|
241
|
+ if (!$order_review) {
|
|
|
|
242
|
+ $order_review_id = Db::name("order_review")
|
|
|
|
243
|
+ ->insertGetId([
|
|
|
|
244
|
+ "car_id" => $car["id"],
|
|
|
|
245
|
+ "route_id" => $route['id'],
|
|
|
|
246
|
+ "driver_id" => $driver['id'],
|
|
|
|
247
|
+ "type" => 2,
|
|
|
|
248
|
+ "order_status" => 3,
|
|
|
|
249
|
+ "createtime" => time()
|
|
|
|
250
|
+ ]);
|
|
|
|
251
|
+ } else {
|
|
|
|
252
|
+ $order_review_id = $order_review['id'];
|
|
|
|
253
|
+ }
|
|
|
|
254
|
+ $params["order_review_id"]=$order_review_id;
|
|
|
|
255
|
+ $result = $row->allowField(true)->save($params);
|
|
|
|
256
|
+ Db::commit();
|
|
|
|
257
|
+ } catch (ValidateException|PDOException|Exception $e) {
|
|
|
|
258
|
+ Db::rollback();
|
|
|
|
259
|
+ $this->error($e->getMessage());
|
|
|
|
260
|
+ }
|
|
|
|
261
|
+ if (false === $result) {
|
|
|
|
262
|
+ $this->error(__('No rows were updated'));
|
|
|
|
263
|
+ }
|
|
|
|
264
|
+ $this->success();
|
|
|
|
265
|
+ }
|
|
|
|
266
|
+
|
|
|
|
267
|
+ public function orderinfo($ids){
|
|
|
|
268
|
+ $row = Db::name("order")->field("id,passengers,driver_id,starting_point,end_point,order_no,pay_type,price,route_id,is_pay,phone,type")->find(['id' => $ids]);
|
|
|
|
269
|
+ $res=Db::name("passenger")->where("id","in",$row['passengers'])->select();
|
|
|
|
270
|
+ $row['passenger']="";
|
|
|
|
271
|
+ foreach ($res as $k=>$v) {
|
|
|
|
272
|
+ $row['passenger']=$row['passenger']."姓名:".$res[$k]['name']." 身份证:".$res[$k]['IDcard']." 手机号:".$res[$k]['phone'];
|
|
|
|
273
|
+ }
|
|
|
|
274
|
+ unset($row['passengers']);
|
|
|
|
275
|
+ if($row['is_pay']==1){
|
|
|
|
276
|
+ $row['is_pay']="已支付";
|
|
|
|
277
|
+ }elseif($row['is_pay']==2){
|
|
|
|
278
|
+ $row['is_pay']="未支付";
|
|
|
|
279
|
+ }elseif($row['is_pay']==3){
|
|
|
|
280
|
+ $row['is_pay']="已退款";
|
|
|
|
281
|
+ }elseif($row['is_pay']==4){
|
|
|
|
282
|
+ $row['is_pay']="已取消";
|
|
|
|
283
|
+ }
|
|
|
|
284
|
+ if($row['type']==1){
|
|
|
|
285
|
+ $row['type']="计票";
|
|
|
|
286
|
+ }elseif($row['type']==2){
|
|
|
|
287
|
+ $row['type']="城际";
|
|
|
|
288
|
+ }elseif($row['type']==3){
|
|
|
|
289
|
+ $row['type']="包车";
|
|
|
|
290
|
+ }
|
|
|
|
291
|
+ if($row['pay_type']=="wxpay"){
|
|
|
|
292
|
+ $row['pay_type']="微信";
|
|
|
|
293
|
+ }elseif($row['pay_type']=="offlinepay"){
|
|
|
|
294
|
+ $row['pay_type']="线下";
|
|
|
|
295
|
+ }elseif($row['pay_type']=="background"){
|
|
|
|
296
|
+ $row['pay_type']="后台下单";
|
|
|
|
297
|
+ }
|
|
|
|
298
|
+ $driver=Db::name("driver")->find($row['driver_id']);
|
|
|
|
299
|
+ $car=Db::name("car")->where("driver_id",$row['driver_id'])->find();
|
|
|
|
300
|
+ $row['license_plate']=$car['license_plate'];
|
|
|
|
301
|
+ $row['driver_name']=$driver['name'];
|
|
|
|
302
|
+ $route=Db::name("route")->find($row['route_id']);
|
|
|
|
303
|
+ $row['route_name']=$route['name'];
|
|
|
|
304
|
+ unset($row['driver_id']);
|
|
|
|
305
|
+ unset($row['route_id']);
|
|
|
|
306
|
+ if (!$row) {
|
|
|
|
307
|
+ $this->error(__('No Results were found'));
|
|
|
|
308
|
+ }
|
|
|
|
309
|
+ $this->view->assign("row", $row);
|
|
|
|
310
|
+ return $this->view->fetch();
|
|
|
|
311
|
+ }
|
|
|
|
312
|
+ public function chackorder(){
|
|
|
|
313
|
+ $newadditionorder= \app\admin\model\Order::where("is_check",0)->count();
|
|
|
|
314
|
+ return $newadditionorder;
|
|
|
|
315
|
+ }
|
|
|
|
316
|
+ public function notselectedorder(){
|
|
|
|
317
|
+ $newadditionorder= \app\admin\model\Order::where("driver_id",null)->count();
|
|
|
|
318
|
+ return $newadditionorder;
|
|
|
|
319
|
+ }
|
|
|
|
320
|
+ /**
|
|
|
|
321
|
+ * 发送模板消息
|
|
|
|
322
|
+ * @return void
|
|
|
|
323
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
324
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
325
|
+ * @throws \think\exception\DbException
|
|
|
|
326
|
+ */
|
|
|
|
327
|
+ function refundSendMessage($order_id){
|
|
|
|
328
|
+ $order=\think\Db::name("order")->find($order_id);
|
|
|
|
329
|
+ $wxxcxpush=new WxxcxPush();
|
|
|
|
330
|
+ $user=new User();
|
|
|
|
331
|
+ $user=$user->find($order['user_id']);
|
|
|
|
332
|
+ $res=$wxxcxpush->refundMessage($user['wx_xcx_openid'],$order_id);
|
|
|
|
333
|
+ if ($res !== false) {
|
|
|
|
334
|
+ return $res;
|
|
|
|
335
|
+ }
|
|
|
|
336
|
+ }
|
|
|
|
337
|
+
|
|
|
|
338
|
+ /**
|
|
|
|
339
|
+ * 检查是否有新订单
|
|
|
|
340
|
+ * @return void
|
|
|
|
341
|
+ */
|
|
|
|
342
|
+ public function chackordershow(){
|
|
|
|
343
|
+ $res=Db::name("order")->where("is_pay",1)->where("driver_id",null)->count();
|
|
|
|
344
|
+ return $res;
|
|
|
|
345
|
+ }
|
|
|
|
346
|
+ /**
|
|
|
|
347
|
+ * 添加
|
|
|
|
348
|
+ *
|
|
|
|
349
|
+ * @return string
|
|
|
|
350
|
+ * @throws \think\Exception
|
|
|
|
351
|
+ */
|
|
|
|
352
|
+ public function add()
|
|
|
|
353
|
+ {
|
|
|
|
354
|
+ if (false === $this->request->isPost()) {
|
|
|
|
355
|
+ return $this->view->fetch();
|
|
|
|
356
|
+ }
|
|
|
|
357
|
+ $params = $this->request->post('row/a');
|
|
|
|
358
|
+ if (empty($params)) {
|
|
|
|
359
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
|
360
|
+ }
|
|
|
|
361
|
+ $params = $this->preExcludeFields($params);
|
|
|
|
362
|
+ $params['pay_type']="background";
|
|
|
|
363
|
+ $params['is_pay']=1;
|
|
|
|
364
|
+ $driver=Db::name("driver")->where("id",$params['driver_id'])->find();
|
|
|
|
365
|
+ $params['driver_name']=$driver['name'];
|
|
|
|
366
|
+ $params['order_no']=$this->getOrderSn();
|
|
|
|
367
|
+ if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
|
|
|
368
|
+ $params[$this->dataLimitField] = $this->auth->id;
|
|
|
|
369
|
+ }
|
|
|
|
370
|
+ $result = false;
|
|
|
|
371
|
+ Db::startTrans();
|
|
|
|
372
|
+ try {
|
|
|
|
373
|
+ //是否采用模型验证
|
|
|
|
374
|
+ if ($this->modelValidate) {
|
|
|
|
375
|
+ $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
|
376
|
+ $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
|
|
|
|
377
|
+ $this->model->validateFailException()->validate($validate);
|
|
|
|
378
|
+ }
|
|
|
|
379
|
+
|
|
|
|
380
|
+ $passenger=Db::name("passenger")->insertGetId(['name'=>$params['user_name'],'IDcard'=>$params['IDcard'],'phone'=>$params['phone']]);
|
|
|
|
381
|
+ $params['passengers']=$passenger;
|
|
|
|
382
|
+ //判断总表
|
|
|
|
383
|
+ $time = strtotime(date("Y-m-d", time()));
|
|
|
|
384
|
+ $order_review = Db::name("order_review")
|
|
|
|
385
|
+ ->where("car_id", $params['car_id'])
|
|
|
|
386
|
+ ->where("route_id", $params['route_id'])
|
|
|
|
387
|
+ ->where("driver_id", $params['driver_id'])
|
|
|
|
388
|
+ ->where("createtime", ">", $time)
|
|
|
|
389
|
+ ->find();
|
|
|
|
390
|
+
|
|
|
|
391
|
+ if (!$order_review) {
|
|
|
|
392
|
+ $order_review_id = Db::name("order_review")
|
|
|
|
393
|
+ ->insertGetId([
|
|
|
|
394
|
+ "car_id" => $params['car_id'],
|
|
|
|
395
|
+ "route_id" => $params['route_id'],
|
|
|
|
396
|
+ "driver_id" => $params['driver_id'],
|
|
|
|
397
|
+ "type" => 1,
|
|
|
|
398
|
+ "order_status" => 1,
|
|
|
|
399
|
+ "createtime" => time()
|
|
|
|
400
|
+ ]);
|
|
|
|
401
|
+ } else {
|
|
|
|
402
|
+ $order_review_id = $order_review['id'];
|
|
|
|
403
|
+ }
|
|
|
|
404
|
+ $params['order_review_id']=$order_review_id;
|
|
|
|
405
|
+ $result = $this->model->allowField(true)->save($params);
|
|
|
|
406
|
+ Db::commit();
|
|
|
|
407
|
+ } catch (ValidateException|PDOException|Exception $e) {
|
|
|
|
408
|
+ Db::rollback();
|
|
|
|
409
|
+ $this->error($e->getMessage());
|
|
|
|
410
|
+ }
|
|
|
|
411
|
+ if ($result === false) {
|
|
|
|
412
|
+ $this->error(__('No rows were inserted'));
|
|
|
|
413
|
+ }
|
|
|
|
414
|
+ $this->success();
|
|
|
|
415
|
+ }
|
|
|
|
416
|
+ function getOrderSn()
|
|
|
|
417
|
+ {
|
|
|
|
418
|
+ $orderid = date("YmdHis") . mt_rand(1000, 999999);
|
|
|
|
419
|
+ $odcks = \think\Db::name('order')
|
|
|
|
420
|
+ ->where(['order_no' => $orderid])
|
|
|
|
421
|
+ ->find();
|
|
|
|
422
|
+ while (!empty($odcks)) {
|
|
|
|
423
|
+ $orderid = date("YmdHis") . mt_rand(1000, 999999);
|
|
|
|
424
|
+ }
|
|
|
|
425
|
+ return $orderid;
|
|
|
|
426
|
+ }
|
|
|
|
427
|
+} |