|
|
@@ -27,25 +27,35 @@ class OrderPackageReceivedSyncService
|
|
|
* 2 如果当前时间小于等于初始化时间,执行初始化脚本,将数据库中全部小于等于初始化时间的数据更新
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public function syncLogisticRoute($is_to_init = false)
|
|
|
+ public function syncLogisticRoute($is_to_init = false,$logistic_numbers = [])
|
|
|
{
|
|
|
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'])
|
|
|
- ->with(['order' => function ($query) {
|
|
|
- return $query->select(['id', 'logistic_id'])->with('logistic:id,name,code');
|
|
|
- }]);
|
|
|
- if ($is_to_init) {//当前时间小于等于初始化时间
|
|
|
- $initDate = Carbon::parse(config('api_logistic.init_date'));
|
|
|
- //初始化查询一个月的数据,exception为否
|
|
|
- $query = $query->where('created_at', '>=', $initDate)
|
|
|
- ->whereNull('received_at');
|
|
|
- } else {//查询20天以内的数据
|
|
|
- $query = $query->where('created_at', '>=', now()->subDays(config('api_logistic.querying_days'))->startOfDay())
|
|
|
- ->whereNull('received_at');
|
|
|
+ if (empty($logistic_numbers)) {
|
|
|
+ $query = OrderPackage::query()
|
|
|
+ ->select(['logistic_number', 'order_id', 'id'])
|
|
|
+ ->with(['order' => function ($query) {
|
|
|
+ return $query->select(['id', 'logistic_id'])->with('logistic:id,name,code');
|
|
|
+ }]);
|
|
|
+ if ($is_to_init) {//当前时间小于等于初始化时间
|
|
|
+ $initDate = Carbon::parse(config('api_logistic.init_date'));
|
|
|
+ //初始化查询一个月的数据,exception为否
|
|
|
+ $query = $query->where('created_at', '>=', $initDate)
|
|
|
+ ->whereNull('received_at');
|
|
|
+ } else {//查询20天以内的数据
|
|
|
+ $query = $query->where('created_at', '>=', now()->subDays(config('api_logistic.querying_days'))->startOfDay())
|
|
|
+ ->whereNull('received_at');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $query = OrderPackage::query()
|
|
|
+ ->select(['logistic_number', 'order_id', 'id'])
|
|
|
+ ->with(['order' => function ($query) {
|
|
|
+ return $query->select(['id', 'logistic_id'])->with('logistic:id,name,code');
|
|
|
+ }])
|
|
|
+ ->whereIn('logistic_number', $logistic_numbers);
|
|
|
}
|
|
|
+
|
|
|
$query->chunkById(1000, function ($orderPackages) {
|
|
|
// LogService::log(OrderPackageReceivedSyncService::class, "同步快递信息定时方法", json_encode(data_get($orderPackages,'*.logistic_number')));
|
|
|
$logisticNumbers = $this->buildData($orderPackages);
|