添加设备流程优化
This commit is contained in:
@@ -8,6 +8,7 @@ use app\common\model\User as UserModel;
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use library\ResponseHelper;
|
||||
use think\Db;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 设备控制器
|
||||
@@ -94,12 +95,14 @@ class GetAddResultedV1Controller extends BaseController
|
||||
*/
|
||||
protected function getCkbDeviceCount(): int
|
||||
{
|
||||
return DeviceModel::where(
|
||||
[
|
||||
'companyId' => $this->getUserInfo('companyId')
|
||||
]
|
||||
)
|
||||
->count('*');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
$cacheKey = 'deviceNum_'.$companyId;
|
||||
$deviceNum = Cache::get($cacheKey);
|
||||
if (empty($deviceNum)) {
|
||||
$deviceNum = DeviceModel::where(['companyId' => $companyId])->count('*');
|
||||
Cache::set($cacheKey,$deviceNum,120);
|
||||
}
|
||||
return $deviceNum;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,6 +113,7 @@ class GetAddResultedV1Controller extends BaseController
|
||||
*/
|
||||
protected function getAddResulted(int $accountId): bool
|
||||
{
|
||||
$deviceNum = $this->getCkbDeviceCount();
|
||||
$result = (new ApiDeviceController())->getlist(
|
||||
[
|
||||
'accountId' => $accountId,
|
||||
@@ -118,13 +122,22 @@ class GetAddResultedV1Controller extends BaseController
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
$result = json_decode($result, true);
|
||||
$result = $result['data']['results'] ?? false;
|
||||
|
||||
return $result ? (
|
||||
count($result) > $this->getCkbDeviceCount()
|
||||
) : false;
|
||||
if (empty($result)){
|
||||
return false;
|
||||
}else{
|
||||
if (count($result) > $deviceNum){
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
$cacheKey = 'deviceNum_'.$companyId;
|
||||
Cache::rm($cacheKey);
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user