|
@@ -5,12 +5,14 @@ namespace SixShop\AliyunWuliu\Entity;
|
|
|
|
|
|
|
|
use SixShop\AliyunWuliu\Facade\WuLiuClient;
|
|
use SixShop\AliyunWuliu\Facade\WuLiuClient;
|
|
|
use SixShop\Core\Entity\BaseEntity;
|
|
use SixShop\Core\Entity\BaseEntity;
|
|
|
|
|
+use think\facade\Cache;
|
|
|
use think\Model;
|
|
use think\Model;
|
|
|
|
|
+use function SixShop\Core\throw_logic_exception;
|
|
|
|
|
|
|
|
class ExtensionWuLiuEntity extends BaseEntity
|
|
class ExtensionWuLiuEntity extends BaseEntity
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
- public function getWuliuInfo(string $no, string $type = ''): array
|
|
|
|
|
|
|
+ public function getWuliuInfo(int $userID, string $no, string $type = ''): array
|
|
|
{
|
|
{
|
|
|
$entity = $this->where('number', $no)->when($type, function (Model $query, $type) {
|
|
$entity = $this->where('number', $no)->when($type, function (Model $query, $type) {
|
|
|
$query->where('type', $type);
|
|
$query->where('type', $type);
|
|
@@ -19,6 +21,13 @@ class ExtensionWuLiuEntity extends BaseEntity
|
|
|
// 已签收或一小时内更新过,直接返回
|
|
// 已签收或一小时内更新过,直接返回
|
|
|
return $entity->toArray();
|
|
return $entity->toArray();
|
|
|
}
|
|
}
|
|
|
|
|
+ // 一个人一天最多查询100次
|
|
|
|
|
+ $times = Cache::remember('wuliu_'.date('Ymd').'_' . $userID, function () {
|
|
|
|
|
+ return Cache::get('wuliu_'.date('Ymd').'_' . $userID, 0) + 1;
|
|
|
|
|
+ }, 86400);
|
|
|
|
|
+ if ($times > 100) {
|
|
|
|
|
+ throw_logic_exception('查询太过频繁,请明天再试');
|
|
|
|
|
+ }
|
|
|
$result = WuLiuClient::kdi($no, $type);
|
|
$result = WuLiuClient::kdi($no, $type);
|
|
|
$entity->number = $result->number;
|
|
$entity->number = $result->number;
|
|
|
$entity->type = $result->type;
|
|
$entity->type = $result->type;
|