74 lines
3.0 KiB
PHP
74 lines
3.0 KiB
PHP
<?php
|
|
/**
|
|
* SaaSMall商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2019-2029 成都SAAS云科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.gobuysaas.com
|
|
* =========================================================
|
|
*/
|
|
namespace addon\alilife\event;
|
|
use addon\aliapp\model\MinCode;
|
|
class AutoPushOrderDelivery
|
|
{
|
|
public function handle()
|
|
{
|
|
$join = [
|
|
['member m', 'o.member_id=m.member_id', 'inner']
|
|
];
|
|
$field = 'o.site_id,o.order_id,o.out_trade_no,o.pay_type,m.ali_openid,m.wx_openid';
|
|
$orderInfo = model('order')->getList([
|
|
['is_video_number', '=', 1],
|
|
['is_sync_order', 'in', [0, 2]],
|
|
['order_status', '=', 3],
|
|
], $field, '', 'o', $join, '', 30);
|
|
if ($orderInfo) {
|
|
foreach ($orderInfo as $item) {
|
|
if (in_array($item['pay_type'], ['alipay', 'zmgopay', 'zmxxpay', 'huabie'])) {
|
|
$this->pushOrder($item);
|
|
}
|
|
}
|
|
}
|
|
return success();
|
|
}
|
|
|
|
/***
|
|
* 推送订单
|
|
* @param $item
|
|
* @return void
|
|
*/
|
|
public function pushOrder($item)
|
|
{
|
|
$temp = [
|
|
'TRADE_CREATED' => '订单创建',
|
|
'WAIT_PAY' => '等待支付',
|
|
'PAID' => '支付成功',
|
|
'INIT' => '冻结',
|
|
'PARTIAL_DELIVERED' => '部分发货',
|
|
'DELIVERED' => '全部发货',
|
|
'RECEIVED_CONFIRM' => '确认收货',
|
|
'TIMEOUT_CLOSED' => '超时取消',
|
|
'REFUND_CLOSED' => '全部退款'
|
|
];
|
|
$apiApp = new MinCode($item['site_id']);
|
|
$info = $apiApp->miniOrderQuery($item['out_trade_no'], $item['ali_openid']);
|
|
if ($info && $info['code'] == 10000 && $info['status'] == 'DELIVERED') { //已发货同步
|
|
model('order')->update(['is_sync_order' => 1, 'sync_msg' => ''], ['order_id' => $item['order_id']]);
|
|
} else if ($info['code'] == 10000 && $info['status'] == 'PAID') {
|
|
$res = event('OrderDelivery', ['order_id' => $item['order_id']]);//设置发货同步
|
|
if ($res[0]['code'] == 0) {
|
|
model('order')->update(['is_sync_order' => 1], ['order_id' => $item['order_id']]);
|
|
} else {
|
|
model('order')->update(['is_sync_order' => 2, 'sync_msg' => $res[0]['message']], ['order_id' => $item['order_id']]);
|
|
}
|
|
} else if ($info['code'] != 10000) {
|
|
model('order')->update(['is_sync_order' => 3, 'sync_msg' => $info['sub_msg']], ['order_id' => $item['order_id']]);
|
|
} else if ($info['code'] == 10000) {
|
|
$is_sync_order = 2;
|
|
if (in_array($info['status'], ['RECEIVED_CONFIRM', 'REFUND_CLOSED', 'TIMEOUT_CLOSED'])) {
|
|
$is_sync_order = 1;
|
|
}
|
|
model('order')->update(['is_sync_order' => $is_sync_order, 'sync_msg' => $temp[$info['status']]], ['order_id' => $item['order_id']]);
|
|
}
|
|
}
|
|
} |