|
|
@@ -0,0 +1,38 @@
|
|
|
+<?php
|
|
|
+declare(strict_types=1);
|
|
|
+
|
|
|
+namespace SixShop\AliyunWuliu\Entity;
|
|
|
+
|
|
|
+use SixShop\AliyunWuliu\Facade\WuLiuClient;
|
|
|
+use SixShop\Core\Entity\BaseEntity;
|
|
|
+use think\Model;
|
|
|
+
|
|
|
+class ExtensionWuLiuEntity extends BaseEntity
|
|
|
+{
|
|
|
+
|
|
|
+ public function getWuliuInfo(string $no, string $type = ''): array
|
|
|
+ {
|
|
|
+ $entity = $this->where('number', $no)->when($type, function (Model $query, $type) {
|
|
|
+ $query->where('type', $type);
|
|
|
+ })->findOrEmpty();
|
|
|
+ if (!$entity->isEmpty() && ($entity->is_sign == 1 || $entity->update_time > time() - 3600)) {
|
|
|
+ // 已签收或一小时内更新过,直接返回
|
|
|
+ return $entity->toArray();
|
|
|
+ }
|
|
|
+ $result = WuLiuClient::kdi($no, $type);
|
|
|
+ $entity->number = $result->number;
|
|
|
+ $entity->type = $result->type;
|
|
|
+ $entity->list = $result->list;
|
|
|
+ $entity->delivery_status = $result->deliverystatus;
|
|
|
+ $entity->is_sign = $result->issign;
|
|
|
+ $entity->exp_name = $result->expName;
|
|
|
+ $entity->exp_site = $result->expSite;
|
|
|
+ $entity->exp_phone = $result->expPhone;
|
|
|
+ $entity->courier = $result->courier;
|
|
|
+ $entity->courier_phone = $result->courierPhone;
|
|
|
+ $entity->take_time = $result->takeTime;
|
|
|
+ $entity->save();
|
|
|
+
|
|
|
+ return $entity->toArray();
|
|
|
+ }
|
|
|
+}
|