|
|
@@ -25,15 +25,15 @@ class OrderPackageReceivedSyncService
|
|
|
* 2 如果当前时间小于等于初始化时间,执行初始化脚本,将数据库中全部小于等于初始化时间的数据更新
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public function syncLogisticRoute($is_to_init=false)
|
|
|
+ public function syncLogisticRoute($is_to_init = false)
|
|
|
{
|
|
|
ini_set('max_execution_time', 2 * 60 * 60);
|
|
|
ini_set('memory_limit', '1024M');
|
|
|
// LogService::log(OrderPackageReceivedSyncService::class, "同步快递信息定时方法", '');
|
|
|
$query = OrderPackage::query()
|
|
|
- ->select(['logistic_number', 'order_id','id'])
|
|
|
+ ->select(['logistic_number', 'order_id', 'id'])
|
|
|
->with(['order' => function ($query) {
|
|
|
- return $query->select(['id','logistic_id'])->with('logistic:id,name,code');
|
|
|
+ return $query->select(['id', 'logistic_id'])->with('logistic:id,name,code');
|
|
|
}]);
|
|
|
if ($is_to_init) {//当前时间小于等于初始化时间
|
|
|
$initDate = Carbon::parse(config('api_logistic.init_date'));
|
|
|
@@ -79,7 +79,7 @@ class OrderPackageReceivedSyncService
|
|
|
$YTOLogisticNumbers = $logisticNumbers['YTO'];
|
|
|
// LogService::log(OrderPackageReceivedSyncService::class, "同步快递信息定时方法-YTO", json_encode($YTOLogisticNumbers));
|
|
|
foreach ($YTOLogisticNumbers as $logistic_number) {
|
|
|
- if ($logistic_number)LogisticYTOSync::dispatch($logistic_number);
|
|
|
+ if ($logistic_number) LogisticYTOSync::dispatch($logistic_number);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -89,10 +89,10 @@ class OrderPackageReceivedSyncService
|
|
|
{
|
|
|
ini_set('max_execution_time', 2 * 60 * 60);
|
|
|
$query = OrderPackage::query()
|
|
|
- ->select(['logistic_number', 'order_id','id'])
|
|
|
- ->whereIn('order_id',function ($query){
|
|
|
- $query->from('orders')->selectRaw('id')->whereIn('logistic_id',function ($builder){
|
|
|
- $builder->from('logistics')->selectRaw('id')->where('type','=','快递')->whereNotIn('belong_company',['顺丰','中通','韵达','圆通','京东']);
|
|
|
+ ->select(['logistic_number', 'order_id', 'id'])
|
|
|
+ ->whereIn('order_id', function ($query) {
|
|
|
+ $query->from('orders')->selectRaw('id')->whereIn('logistic_id', function ($builder) {
|
|
|
+ $builder->from('logistics')->selectRaw('id')->where('type', '=', '快递')->whereNotIn('belong_company', ['顺丰', '中通', '韵达', '圆通', '京东']);
|
|
|
});
|
|
|
});
|
|
|
$query = $query->where('sent_at', '>=', now()->subDays(config('api_logistic.querying_days')))
|
|
|
@@ -100,31 +100,34 @@ class OrderPackageReceivedSyncService
|
|
|
|
|
|
$query->chunkById(200, function ($orderPackages) {
|
|
|
// LogService::log(OrderPackageReceivedSyncService::class, "同步快递信息定时方法-阿里公用接口", json_encode($orderPackages));
|
|
|
- foreach ($orderPackages as $orderPackage){
|
|
|
- if ($orderPackage && $orderPackage->logistic_number)LogisticAliJiSuSync::dispatch($orderPackage->logistic_number);
|
|
|
+ foreach ($orderPackages as $orderPackage) {
|
|
|
+ if ($orderPackage && $orderPackage->logistic_number) LogisticAliJiSuSync::dispatch($orderPackage->logistic_number);
|
|
|
}
|
|
|
});
|
|
|
//TODO 暂时不同步京东
|
|
|
// $this->syncLogisticRouteJD();
|
|
|
}
|
|
|
- public function syncLogisticRouteJD(){
|
|
|
+
|
|
|
+ public function syncLogisticRouteJD()
|
|
|
+ {
|
|
|
ini_set('max_execution_time', 60);
|
|
|
$query = OrderPackage::query()
|
|
|
- ->select(['logistic_number', 'order_id','id'])
|
|
|
- ->whereIn('order_id',function ($query){
|
|
|
- $query->from('orders')->selectRaw('id')->whereIn('logistic_id',function ($builder){
|
|
|
- $builder->from('logistics')->selectRaw('id')->where('type','!=','物流')->where('belong_company','京东');
|
|
|
+ ->select(['logistic_number', 'order_id', 'id'])
|
|
|
+ ->whereIn('order_id', function ($query) {
|
|
|
+ $query->from('orders')->selectRaw('id')->whereIn('logistic_id', function ($builder) {
|
|
|
+ $builder->from('logistics')->selectRaw('id')->where('type', '!=', '物流')->where('belong_company', '京东');
|
|
|
});
|
|
|
});
|
|
|
$query = $query->where('created_at', '>=', now()->subDays(config('api_logistic.querying_days')))
|
|
|
- ->whereNull('received_at')->where('logistic_number','like','JD%');
|
|
|
+ ->whereNull('received_at')->where('logistic_number', 'like', 'JD%');
|
|
|
$query->chunkById(200, function ($orderPackages) {
|
|
|
// LogService::log(OrderPackageReceivedSyncService::class, "同步快递信息定时方法-JD", json_encode($orderPackages));
|
|
|
- foreach ($orderPackages as $orderPackage){
|
|
|
- if ($orderPackage && $orderPackage->logistic_number)LogisticAliJiSuSync::dispatch($orderPackage->logistic_number);
|
|
|
+ foreach ($orderPackages as $orderPackage) {
|
|
|
+ if ($orderPackage && $orderPackage->logistic_number) LogisticAliJiSuSync::dispatch($orderPackage->logistic_number);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 根据传递的承运商与快递单号更新快递信息
|
|
|
* @param array $logisticNumbers 快递单号
|
|
|
@@ -181,7 +184,7 @@ class OrderPackageReceivedSyncService
|
|
|
if (empty($logisticResponse)) continue;
|
|
|
$orderPackage = OrderPackage::query()->where('logistic_number', $logisticResponse['logistic_number'])->first();
|
|
|
//如果已经收货,状态改为已签收
|
|
|
- if ($logisticResponse['received_at']??false) {
|
|
|
+ if ($logisticResponse['received_at'] ?? false) {
|
|
|
$logisticResponse['status'] = '已签收';
|
|
|
}
|
|
|
//未查询到路由信息改为 揽件异常
|
|
|
@@ -191,6 +194,8 @@ class OrderPackageReceivedSyncService
|
|
|
if (empty($orderPackage->weighed_at)) {
|
|
|
$logisticResponse['status'] = '疑似库内丢件';
|
|
|
}
|
|
|
+ } else if (count($logisticResponse['transfer_status'])<=3) {//快递记录不为空但是小于3条
|
|
|
+ $logisticResponse['status'] = '揽件异常';
|
|
|
}
|
|
|
//标记为手动更新的 status不更新
|
|
|
if ($orderPackage->is_manual_update) {
|