Order.php
22.3 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
<?php
defined('IN_IA') or exit('Access Denied');
require_once IA_ROOT . '/addons/zh_cjdianc/inc/func/Http.php';
require_once IA_ROOT . '/addons/zh_cjdianc/inc/config.php';
require_once IA_ROOT . '/addons/zh_cjdianc/inc/func/WxPay.php';
require_once IA_ROOT . '/addons/zh_cjdianc/inc/class/Commission.php';
require_once IA_ROOT . '/addons/zh_cjdianc/inc/class/Finance.php';
class Order
{
const ORDER_STATUS_WAIT_PAY = 1; //.待付款
const ORDER_STATUS_FINISHING = 2; //.等待接单 WAIT_PICK
const ORDER_STATUS_DELIVERING = 3;//.等待送达
const ORDER_STATUS_FINISHED = 4;//.完成
const ORDER_STATUS_COMMENT = 5;//.已评价
const ORDER_STATUS_CANCEL = 6;//.取消
const ORDER_STATUS_REJECT = 7;//.拒绝
const ORDER_STATUS_REFUNDING = 8;//.退款中
const ORDER_STATUS_REFUNDED = 9;//.已退款
const ORDER_STATUS_REJECT_FAIL = 10;//.退款失败
const PAY_TYPE_WX = 1; //.微信支付
const PAY_TYPE_BALANCE = 2; //.余额支付
const PAY_TYPE_POINTS = 3; //.积分支付
const PAY_TYPE_CASH = 4; //.货到付款
const TYPE_TAKE_OUT = 1; //.外卖
const TYPE_IN_STORE = 2; //2.店内
const TYPE_BOOKING = 3; //3.预定
const TYPE_DANG_MIAN = 4; //4.当面付
const TYPE_GROUP = 5; //5.拼团外卖订单, 不做核销的直接下单
/**
* @param string $state
* @return array|null
*/
static function getStatusLabel($state = '')
{
$arr = [
self::ORDER_STATUS_WAIT_PAY => '待付款',
self::ORDER_STATUS_FINISHING => '等待接单',
self::ORDER_STATUS_DELIVERING => '等待送达',
self::ORDER_STATUS_FINISHED => '完成',
self::ORDER_STATUS_COMMENT => '已评价',
self::ORDER_STATUS_CANCEL => '已取消',
self::ORDER_STATUS_REJECT => '已拒绝',
self::ORDER_STATUS_REFUNDING => '退款中',
self::ORDER_STATUS_REFUNDED => '退款成功',
self::ORDER_STATUS_REJECT_FAIL => '退款失败'
];
if ('' === $state) {
return $arr ;
}
if (isset($arr[$state])) {
return $arr[$state];
} else {
return null;
}
}
/*
* 支付用的code
*/
static function payCode($userId)
{
return 'N'.time() . rand(1000, 9999) . $userId;
}
/**
* @param $order
* @param $postData
*/
static function afterOrderPay($out_trade_no, $postData)
{
$order = pdo_get('cjdc_order', array('code' => $out_trade_no));
if (empty($order)) {
return false;
}
// checkPostData 校验数据是否正确 sign
//
$tt = time();
$orderId = $order['id'];
$sign = Config::genSign(['i' => $order['uniacid'], 'id' => $orderId, 'timeStamp' => $tt]);
$signStr = "&sign={$sign}&timeStamp={$tt}";
$callBackHeadURL = "https://{$_SERVER['HTTP_HOST']}/app/index.php?i={$order['uniacid']}&c=entry&a=wxapp&m=zh_cjdianc{$signStr}";
if (self::TYPE_TAKE_OUT == $order['type'] and (self::ORDER_STATUS_WAIT_PAY == $order['state'] || self::ORDER_STATUS_CANCEL == $order['state'])) {//外卖
Http::httpGet("{$callBackHeadURL}&do=NewOrderMessage&order_id=".$orderId); //模板消息
Http::httpGet("{$callBackHeadURL}&do=WeChatMsg&id=".$orderId); //模板消息
$store = pdo_get('cjdc_storeset', array('store_id' => $order['store_id']));
$sys = pdo_get('cjdc_system', array('uniacid' => $order['uniacid']), 'ps_name');
$ps_name = empty($sys['ps_name']) ? '超级跑腿' : $sys['ps_name'];
if ($store['is_jd'] == 1) {
$wmorder['state'] = 3;
$wmorder['pay_time'] = date('Y-m-d H:i:s');
$wmorder['jd_time'] = date('Y-m-d H:i:s');
$res = pdo_update('cjdc_order', $wmorder, array('id' => $orderId));
Http::httpGet("{$callBackHeadURL}&do=jdnotice&order_id=" . $orderId);//达达
} else {
$wmorder['state'] = 2;
$wmorder['pay_time'] = date('Y-m-d H:i:s');
$res = pdo_update('cjdc_order', $wmorder, array('id' => $orderId));
}
if ($store['is_jd'] == 1 && $order['order_type'] == 1) {//自动接单
if ($store['ps_mode'] == '达达配送') {
Http::httpGet("{$callBackHeadURL}&do=TestDada&order_id=" . $orderId); //达达
}
if ($store['ps_mode'] == '快服务配送') {
$res = Http::httpGet("{$callBackHeadURL}&do=kfw&order_id=" . $orderId); //快服务
$kfw['ship_id'] = $res;
pdo_update('cjdc_order', $kfw, array('id' => $orderId));
}
if ($store['ps_mode'] == $ps_name) {
Http::httpGet("{$callBackHeadURL}&do=cjpt&order_id=" . $orderId); //跑腿
}
}
pdo_update('cjdc_store', array('score +=' => 1), array('id' => $order['store_id']));
$good = pdo_getall('cjdc_order_goods', array('order_id' => $orderId));
for ($i = 0; $i < count($good); $i++) {
pdo_update('cjdc_goods', array('inventory -=' => $good[$i]['number']), array('id' => $good[$i]['dishes_id']));
pdo_update('cjdc_goods', array('sales +=' => $good[$i]['number']), array('id' => $good[$i]['dishes_id']));
}
//Http::httpGet("https://".$_SERVER['HTTP_HOST'] . "/app/index.php?i=".$order['uniacid']."&c=entry&a=wxapp&do=payorder&order_id=".$orderId);
$sms = Http::httpGet("{$callBackHeadURL}&do=Message&order_id=".$orderId);
//模板消息
Http::httpGet("{$callBackHeadURL}&do=QtPrint&order_id=".$orderId);//打印机
Http::httpGet("{$callBackHeadURL}&do=HcPrint&order_id=".$orderId);//打印机
Http::httpGet("{$callBackHeadURL}&do=sms&type=1&store_id=".$order['store_id']);//短信
//分销佣金
Http::httpGet("{$callBackHeadURL}&do=JsCommission&order_id=".$orderId);
}
if (self::TYPE_IN_STORE == $order['type'] and 1 == $order['dn_state']) {//店内
$dnorder['dn_state'] = 2;
$dnorder['pay_time'] = date('Y-m-d H:i:s');
$res = pdo_update('cjdc_order', $dnorder, array('id' => $orderId));
pdo_update('cjdc_store', array('score +=' => 1), array('id' => $order['store_id']));
$good = pdo_getall('cjdc_order_goods', array('order_id' => $orderId));
for ($i = 0; $i < count($good); $i++) {
pdo_update('cjdc_goods', array('inventory -=' => $good[$i]['number']), array('id' => $good[$i]['dishes_id']));
pdo_update('cjdc_goods', array('sales +=' => $good[$i]['number']), array('id' => $good[$i]['dishes_id']));
}
//Http::httpGet("{$callBackHeadURL}&do=payorder&order_id=".$orderId);
Http::httpGet("{$callBackHeadURL}&do=sms&type=2&store_id=".$order['store_id']);//短信
Http::httpGet("{$callBackHeadURL}&do=QtPrint&order_id=".$orderId);//打印机
Http::httpGet("{$callBackHeadURL}&do=HcPrint&order_id=".$orderId);//打印机
Http::httpGet("{$callBackHeadURL}&do=addintegral&type=2&order_id=".$orderId);//短信
//分销佣金
Http::httpGet("{$callBackHeadURL}&do=JsCommission&order_id=".$orderId);
}
if (self::TYPE_BOOKING == $order['type'] and 1 == $order['yy_state']) {//预约
pdo_update('cjdc_order',array('yy_state'=>2),array('code'=>$out_trade_no));
Http::httpGet("{$callBackHeadURL}&do=sms&type=3&store_id=".$order['store_id']);//短信
//分销佣金
Http::httpGet("{$callBackHeadURL}&do=JsCommission&order_id=".$orderId);
Http::httpGet("{$callBackHeadURL}&do=storeYyOrderMessage&order_id=".$orderId);//模板消息
Http::httpGet("{$callBackHeadURL}&do=QtPrint&order_id=".$orderId);//
}
if (self::TYPE_DANG_MIAN == $order['type'] and 1 == $order['dm_state']) {//当面付
Http::httpGet("{$callBackHeadURL}&do=NewDmOrderMessage&order_id=".$orderId);//模板消息
$res = pdo_update('cjdc_order',array('dm_state'=>2),array('id'=>$orderId));
Http::httpGet("{$callBackHeadURL}&do=sms&type=2&store_id=".$order['store_id']);//短信
Http::httpGet("{$callBackHeadURL}&do=QtPrint&order_id=".$orderId);//打印机
Http::httpGet("{$callBackHeadURL}&do=addintegral&type=5&order_id=".$orderId);//短信
//分销佣金
Http::httpGet("{$callBackHeadURL}&do=JsCommission&order_id=".$orderId);
}
$store = pdo_get('cjdc_store',array('code'=>$out_trade_no));
if($store['zf_state']==1) {
$res = pdo_update('cjdc_store',array('zf_state'=>2),array('id'=>$store['id']));
Http::httpGet("{$callBackHeadURL}&do=SaveRzLog&store_id=".$store['id']."&money=".$store['money']);
}
return true;
}
/**
* 店家订单列表
*/
static function storeAdminOrderPageList($_W, $_GPC, $storeid)
{
$pageindex = max(1, intval($_GPC['page']));
$pagesize = 8;
$type = isset($_GPC['type']) ? $_GPC['type'] : 'now';
$type2 = isset($_GPC['type2']) ? $_GPC['type2'] : 'today';
$orderType = self::TYPE_GROUP;
$where = " where a.uniacid=:uniacid and a.type={$orderType} and a.store_id=" . $storeid;
$data[':uniacid'] = $_W['uniacid'];
if (isset($_GPC['keywords'])) {
$where .= " and (a.name LIKE concat('%', :name,'%') || a.order_num LIKE concat('%', :name,'%') || b.name LIKE concat('%', :name,'%'))";
$data[':name'] = $_GPC['keywords'];
$type = 'all';
}
if ($_GPC['time']) {
$start = $_GPC['time']['start'];
$end = $_GPC['time']['end'];
$where .= " and a.time >='{$start}' and a.time<='{$end}'";
$type = 'all';
} else {
if ($type == 'wait') {
$where .= " and a.state=1";
}
if ($type == 'now') {
$where .= " and a.state=2";
}
if ($type == 'cancel') {
$where .= " and a.state in (6,7,8,9,10)";
}
if ($type == 'complete') {
$where .= " and a.state=4";
}
if ($type == 'delivery') {
$where .= " and a.state=3";
}
if ($type == 'zt') {
$where .= " and a.order_type=2";
}
if ($type == 'dd') {
$where .= " and a.order_type=3";
}
if ($type2 == 'today') {
$time = date("Y-m-d", time());
$where .= " and a.time LIKE '%{$time}%' ";
}
if ($type2 == 'yesterday') {
$time = date("Y-m-d", strtotime("-1 day"));
$where .= " and a.time LIKE '%{$time}%' ";
}
if ($type2 == 'week') {
$time = strtotime(date("Y-m-d", strtotime("-7 day")));
$where .= " and UNIX_TIMESTAMP(a.time) >" . $time;
}
if ($type2 == 'month') {
$time = date("Y-m");
$where .= " and a.time LIKE '%{$time}%' ";
}
}
$userOrderCountSql = "(select count(*) ".
" from ". tablename("cjdc_order") ." as uo ".
" WHERE uo.store_id={$storeid} and uo.user_id=a.user_id and uo.id<=a.id and uo.state!=1) as order_count";
$sql = "SELECT {selectFields} " .
" FROM ". tablename('cjdc_order') . " a " .
" left join " . tablename("cjdc_store") . " b on a.store_id=b.id " .
" left join " . tablename("cjdc_storetype") . " c on b.md_type=c.id " .
" left join " . tablename("cjdc_storeset") . " d on b.id=d.store_id " .
" left join " . tablename("cjdc_user") . " u on u.id=a.user_id " .
$where . " ORDER BY a.id DESC";
$countSql = str_replace("{selectFields}", "count(*)", $sql);
$total = pdo_fetchcolumn($countSql, $data);
$fields = "a.*,b.name as md_name,c.poundage as md_poundage,d.poundage,d.is_poundage,d.ps_mode,b.ps_poundage,u.name as userName, {$userOrderCountSql}";
$pageSql = str_replace("{selectFields}", $fields, $sql);
$select_sql = $pageSql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
echo $select_sql;
$list = pdo_fetchall($select_sql, $data);
$pageData = array();
foreach($list as $k => $order ) {
$orderGoods = array();
$goodsArr = pdo_getall('cjdc_order_goods', array('order_id' => $order['id']));
foreach($goodsArr as $kk => $goods ) {
if ($order['id'] == $goods['order_id']) {
$orderGoods[] = array(
'name' => $goods['name'],
'num' => $goods['number'],
'img' => $goods['img'],
'money' => $goods['money'],
'spec' => $goods['spec'],
'dishes_id' => $goods['dishes_id'],
);
}
}
$pageData[] = array(
'order' => $order,
'goods' => $orderGoods,
);
}
$pager = pagination($total, $pageindex, $pagesize);
return ['pageData' => $pageData, 'pager' => $pager];
}
/**
* 删除订单
* @param $orderId
* @return bool
*/
static function storeAdminOrderDelete($orderId)
{
$res = pdo_delete('cjdc_order', array('id' => $orderId));
return $res;
}
/**
* 取消订单,同时退款拼团订单
* @param $uniacid
* @param $orderId
* @return array
*/
static function storeAdminOrderCancel($uniacid, $orderId)
{
$order = pdo_get('cjdc_order', array('id' => $orderId));
$result = null ;
$tkres = null;
if (self::ORDER_STATUS_DELIVERING == $order['state']) {
if (self::PAY_TYPE_WX == $order['pay_type']) {
//微信退款
$result = WxPay::orderRefund($orderId, self::TYPE_GROUP);
}
if (self::PAY_TYPE_BALANCE == $order['pay_type']) {
//余额退款
pdo_update('cjdc_user', array('wallet +=' => $order['money']), array('id' => $order['user_id']));
$tk['money'] = $order['money'];
$tk['user_id'] = $order['user_id'];
$tk['type'] = 1;
$tk['note'] = '取消订单';
$tk['time'] = date('Y-m-d H:i:s');
$tkres = pdo_insert('cjdc_qbmx', $tk);
}
}
if ((!empty($result) && $result['result_code'] == 'SUCCESS') || $tkres) {
//退款成功
if ($order['coupon_id']) {
pdo_update('cjdc_usercoupons', array('state' => 2), array('id' => $order['coupon_id']));
}
if ($order['coupon_id2']) {
pdo_update('cjdc_usercoupons', array('state' => 2), array('id' => $order['coupon_id2']));
}
$updateResult = pdo_update('cjdc_order', array('state' => self::ORDER_STATUS_CANCEL), array('id' => $orderId));
// 冻结佣金,暂时作废
Commission::invalidOrderFee($orderId);
// 更新退款记录
Finance::updateOrderPriceStat($order['store_id'], $orderId, $order['money']);
$set = pdo_get('cjdc_storeset', array('store_id' => $order['store_id']), 'ps_mode');
$sys = pdo_get('cjdc_system', array('uniacid' => $uniacid), 'ps_name');
$ps_name = empty($sys['ps_name']) ? '超级跑腿' : $sys['ps_name'];
if ($updateResult) {
return ['success' => true, 'storeSet' => $set, 'delivery' => $ps_name, 'order' => $order];
} else {
return ['success' => false];
}
} else {
// 如果$result 返回前不够应该通知平台管理员
return ['success' => false, 'refundResult' => $result];
}
}
/**
* 店家接订单
* @param $uniacid
* @param $orderId
* @return array
*/
static function storeOwnerPickOrder($uniacid, $orderId)
{
$updateData['state'] = self::ORDER_STATUS_DELIVERING;
$updateData['jd_time'] = date('Y-m-d H:i:s');
$orderInfo = pdo_get('cjdc_order', array('id' => $orderId));
$store = pdo_get('cjdc_storeset', array('store_id' => $orderInfo['store_id']));
$sys = pdo_get('cjdc_system', array('uniacid' => $uniacid), 'ps_name');
$ps_name = empty($sys['ps_name']) ? '超级跑腿' : $sys['ps_name'];
$updateRes = pdo_update('cjdc_order', $updateData, array('id' => $orderId));
if ($updateRes) {
$orderInfo['state'] = $updateData['state'];
return ['storeSet' => $store, 'delivery' => $ps_name, "order" => $orderInfo];
} else {
return [];
}
}
/**
* 拒接接单
* @param $orderId
*/
static function storeOwnerRejectOrder($uniacId, $orderId)
{
$data2['state'] = self::ORDER_STATUS_REJECT;
$order = pdo_get('cjdc_order', array('id' => $orderId));
$result = null ;
$tkres = null;
if ((self::PAY_TYPE_WX == $order['pay_type'] || self::PAY_TYPE_BALANCE == $order['pay_type']) and $order['money'] > 0 and self::ORDER_STATUS_FINISHING == $order['state']) {
if (self::PAY_TYPE_WX == $order['pay_type']) {
//微信退款
$result = WxPay::orderRefund($orderId, self::TYPE_GROUP);
}
if (self::PAY_TYPE_BALANCE == $order['pay_type']) {
//余额退款
pdo_update('cjdc_user', array('wallet +=' => $order['money']), array('id' => $order['user_id']));
$tk['money'] = $order['money'];
$tk['user_id'] = $order['user_id'];
$tk['type'] = 1;
$tk['note'] = '订单拒绝';
$tk['time'] = date('Y-m-d H:i:s');
$tkres = pdo_insert('cjdc_qbmx', $tk);
}
if ((!empty($result) && $result['result_code'] == 'SUCCESS') || $tkres) {
//退款成功
//更改订单操作
pdo_update('cjdc_order', array('state' => self::ORDER_STATUS_REJECT), array('id' => $orderId));
if ($order['coupon_id']) {
pdo_update('cjdc_usercoupons', array('state' => 2), array('id' => $order['coupon_id']));
}
if ($order['coupon_id2']) {
pdo_update('cjdc_usercoupons', array('state' => 2), array('id' => $order['coupon_id2']));
}
Commission::invalidOrderFee($order['id']);
Finance::updateOrderPriceStat($order['store_id'], $orderId, $order['money']);
pdo_delete('cjdc_formid', array('time <=' => time() - 60 * 60 * 24 * 7));
return ['success' => true, 'order' => $order];
} else {
// 钱不够应该返回通知管理员
return ['success' => false, 'refundResult' => $result];
}
} else {
return ['success' => false, 'message' => '订单状态不对无法拒接'];
$updateResult = pdo_update('cjdc_order', array('state' => self::ORDER_STATUS_REJECT), array('id' => $orderId));
if ($updateResult) {
if ($order['coupon_id']) {
pdo_update('cjdc_usercoupons', array('state' => 2), array('id' => $order['coupon_id']));
}
if ($order['coupon_id2']) {
pdo_update('cjdc_usercoupons', array('state' => 2), array('id' => $order['coupon_id2']));
}
return ['success' => false, 'message' => '订单状态不对无法拒接'];
} else {
return ['success' => false, 'message' => '订单状态不对无法拒接'];
}
}
}
/**
* @param $uniacid
* @param $orderId
* @return bool
*/
static function storeOwnerFinishOrder($uniacid, $orderId)
{
$data2['state'] = self::ORDER_STATUS_FINISHED;
$res = pdo_update('cjdc_order', $data2, array('id' => $orderId));
Commission::availableOrderFee($orderId);
return $res;
}
/**
* 直接退款操作和取消有点不同
* @param $uniacid
* @param $orderId
*/
static function storeOwnerOrderRefundOp($uniacid, $orderId)
{
$order = pdo_get('cjdc_order', array('id' => $orderId));
$result = null;
$tkres = null;
if (self::ORDER_STATUS_REFUNDING == $order['state']) {
if (self::PAY_TYPE_WX == $order['pay_type']) {
//微信退款
$result = WxPay::orderRefund($orderId, self::TYPE_GROUP);
}
if (self::PAY_TYPE_BALANCE == $order['pay_type']) {
//余额退款
$rst = pdo_get('cjdc_qbmx', array('user_id' => $order['user_id'], 'order_id' => $orderId));
if (!$rst) {
$tk['money'] = $order['money'];
$tk['order_id'] = $order['id'];
$tk['user_id'] = $order['user_id'];
$tk['type'] = 1;
$tk['note'] = '订单退款';
$tk['time'] = date('Y-m-d H:i:s');
$tkres = pdo_insert('cjdc_qbmx', $tk);
pdo_update('cjdc_user', array('wallet +=' => $order['money']), array('id' => $order['user_id']));
}
}
}
if ($result['result_code'] == 'SUCCESS' || $tkres) {
//退款成功
//更改订单操作
$updateResult = pdo_update('cjdc_order', array('state' => self::ORDER_STATUS_REFUNDED), array('id' => $orderId));
Commission::invalidOrderFee($orderId);
Finance::updateOrderPriceStat($order['store_id'], $orderId, $order['money']);
pdo_delete('cjdc_formid', array('time <=' => time() - 60 * 60 * 24 * 7));
$set = pdo_get('cjdc_storeset', array('store_id' => $order['store_id']), 'ps_mode');
$sys = pdo_get('cjdc_system', array('uniacid' => $uniacid), 'ps_name');
$ps_name = empty($sys['ps_name']) ? '超级跑腿' : $sys['ps_name'];
if ($updateResult) {
return ['success' => true, 'storeSet' => $set, 'delivery' => $ps_name, 'order' => $order];
} else {
return ['success' => false];
}
} else {
// 如果$result 返回前不够应该通知平台管理员
return ['success' => false, 'refundResult' => $result];
}
}
/**
* 拒绝顾客退款
* @param $orderId
*/
static function storeOwnerRejectRefund($orderId)
{
$order = pdo_get('cjdc_order', array('id' => $orderId));
if (self::ORDER_STATUS_REFUNDING != $order['state']) {
return false;
}
$rst = pdo_update('cjdc_order', array('state' => self::ORDER_STATUS_REJECT_FAIL), array('id' => $orderId));
Commission::invalidOrderFee($orderId);
return $rst;
}
/**
* 导出订单
* @param $_GPC
* @param $storeId
* @return string
*/
static function exportOrderData($_GPC, $storeId)
{
$start = $_GPC['time']['start'];
$end = $_GPC['time']['end'];
$count = pdo_fetchcolumn("SELECT COUNT(*) FROM" . tablename("cjdc_order") . " WHERE type=1 and store_id={$storeId} and time >='{$start}' and time<='{$end}'");
$pagesize = ceil($count / 5000);
$header = array(
'item' => '序号',
'md_name' => '门店名称',
'order_num' => '订单号',
'name' => '联系人',
'tel' => '联系电话',
'address' => '联系地址',
'time' => '下单时间',
'money' => '金额',
'state' => '外卖状态',
'pay_type' => '支付方式',
'order_type' => '订单类型',
'goods' => '商品',
'box_money' => '餐盒费',
);
$keys = array_keys($header);
$html = "\xEF\xBB\xBF";
foreach ($header as $li) {
$html .= $li . "\t ,";
}
$html .= "\n";
for ($j = 1; $j <= $pagesize; $j++) {
$sql = "select a.*,b.name as md_name ".
" from ". tablename("cjdc_order") . " a" .
" inner join " . tablename("cjdc_store") . " b on a.store_id=b.id ".
" WHERE a.type=1 and a. time >='{$start}' and a.time<='{$end}' and a.store_id={$storeId} ".
" limit " . ($j - 1) * 5000 . ",5000 ";
$list = pdo_fetchall($sql);
}
if (!empty($list)) {
$size = ceil(count($list) / 500);
for ($i = 0; $i < $size; $i++) {
$buffer = array_slice($list, $i * 500, 500);
$user = array();
foreach ($buffer as $k => $row) {
$row['item'] = $k + 1;
$row['state'] = self::getStatusLabel($row['state']);
if (self::PAY_TYPE_WX == $row['pay_type']) {
$row['pay_type'] = '微信支付';
} elseif (self::PAY_TYPE_BALANCE == $row['pay_type']) {
$row['pay_type'] = '余额支付';
} elseif (self::PAY_TYPE_POINTS == $row['pay_type']) {
$row['pay_type'] = '积分支付';
} elseif (self::PAY_TYPE_CASH == $row['pay_type']) {
$row['pay_type'] = '货到付款';
}
if ($row['order_type'] == 1) {
$row['order_type'] = '外卖配送';
} elseif ($row['order_type'] == 2) {
$row['order_type'] = '到店自提';
}
$good = pdo_getall('cjdc_order_goods', array('order_id' => $row['id']));
$date6 = array();
for ($i = 0; $i < count($good); $i++) {
if ($good[$i]['spec']) {
$date6[$i] .= $good[$i]['name'] . '(' . $good[$i]['spec'] . ')*' . $good[$i]['number'] . " ";
} else {
$date6[$i] .= $good[$i]['name'] . '*' . $good[$i]['number'] . " ";
}
}
$goodsInfo = implode(" ", $date6);
$goodsInfo = str_replace(",", ",", $goodsInfo);
$row['goods'] = $goodsInfo;
foreach ($keys as $key) {
$data5[] = $row[$key];
}
$user[] = implode("\t ,", $data5) . "\t ,";
unset($data5);
}
$html .= implode("\n", $user) . "\n";
}
}
return $html;
}
}