You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.7 KiB
57 lines
1.7 KiB
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use think\Db;
|
|
use think\exception\ValidateException;
|
|
use think\Loader;
|
|
use think\Request;
|
|
use think\db\exception\DataNotFoundException;
|
|
use think\db\exception\ModelNotFoundException;
|
|
use think\exception\DbException;
|
|
|
|
class Information extends Base
|
|
{
|
|
|
|
/**
|
|
* 接收Wing推送数据
|
|
* @param Request $request
|
|
* @return false|string
|
|
* @throws DataNotFoundException
|
|
* @throws ModelNotFoundException
|
|
* @throws DbException
|
|
*/
|
|
public function receivingInformation(Request $request)
|
|
{
|
|
|
|
$param = $request->param();
|
|
|
|
try {
|
|
|
|
$InformationValidate = Loader::validate('InformationValidate');
|
|
if(!$InformationValidate->check($param)){
|
|
throw new ValidateException($InformationValidate->getError());
|
|
}
|
|
|
|
$insertArr = [
|
|
'tenant_id' => $param['tenantId'],
|
|
'task_id' => $param['taskId'],
|
|
'protocol' => $param['protocol'],
|
|
'product_id' => $param['productId'],
|
|
'device_id' => $param['deviceId'],
|
|
'timestamp' => $param['timestamp']
|
|
];
|
|
|
|
$query = Db::table('bs_device_receiving_information')->where($insertArr)->field('id')->find();
|
|
if ($query) throw new ValidateException('数据已存在,请勿重复发送');
|
|
|
|
$insertArr['create_time'] = date("Y-m-d H:i:s");
|
|
Db::table('bs_device_receiving_information')->insert($insertArr);
|
|
|
|
return $this->jsonSuccess();
|
|
} catch (ValidateException $exception) {
|
|
return $this->jsonError($exception->getMessage());
|
|
}
|
|
}
|
|
|
|
}
|