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.
114 lines
3.1 KiB
114 lines
3.1 KiB
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use App\Exception\BusinessException;
|
|
use App\Service\DeviceServiceInterFace;
|
|
use Hyperf\Validation\ValidationException;
|
|
|
|
class DeviceController extends BaseController
|
|
{
|
|
|
|
/**
|
|
* @Inject
|
|
* @var DeviceServiceInterFace
|
|
*/
|
|
protected $deviceService;
|
|
|
|
|
|
public function bind()
|
|
{
|
|
$validator = $this->validationFactory->make(
|
|
$this->request->all(),
|
|
[
|
|
'store_id' => 'required|nonempty|integer',
|
|
'device_name' => 'required|nonempty|alpha_num',
|
|
],
|
|
[
|
|
'store_id.required' => '参数不正确',
|
|
'store_id.nonempty' => '参数不正确',
|
|
'store_id.integer' => '参数不正确',
|
|
'device_name.required' => '参数不正确',
|
|
'device_name.nonempty' => '参数不正确',
|
|
'device_name.alpha_num' => '参数不正确',
|
|
]
|
|
);
|
|
|
|
if ($validator->fails()) {
|
|
// Handle exception
|
|
throw new ValidationException($validator);
|
|
return;
|
|
}
|
|
|
|
$store_id = $this->request->input('store_id');
|
|
$device_name = $this->request->input('device_name');
|
|
|
|
$sd = $this->deviceService->bindByStoreId($device_name, $store_id);
|
|
|
|
if (is_null($sd)) {
|
|
return $this->result(100, '', '绑定失败: 设备号已经被绑定或不存在');
|
|
}
|
|
|
|
return $this->success($sd, '绑定成功');
|
|
|
|
}
|
|
|
|
public function list()
|
|
{
|
|
$validator = $this->validationFactory->make(
|
|
$this->request->all(),
|
|
[
|
|
'store_id' => 'required|nonempty|integer',
|
|
],
|
|
[
|
|
'store_id.required' => '参数不正确',
|
|
'store_id.nonempty' => '参数不正确',
|
|
'store_id.integer' => '参数不正确',
|
|
]
|
|
);
|
|
|
|
if ($validator->fails()) {
|
|
// Handle exception
|
|
throw new ValidationException($validator);
|
|
return;
|
|
}
|
|
|
|
$store_id = $this->request->input('store_id');
|
|
|
|
$devices = $this->deviceService->getListByStoreId($store_id);
|
|
|
|
return $this->success($devices);
|
|
}
|
|
|
|
public function unbind()
|
|
{
|
|
$validator = $this->validationFactory->make(
|
|
$this->request->all(),
|
|
[
|
|
'bind_id' => 'required|nonempty|integer',
|
|
],
|
|
[
|
|
'bind_id.required' => '参数不正确',
|
|
'bind_id.nonempty' => '参数不正确',
|
|
'bind_id.integer' => '参数不正确',
|
|
]
|
|
);
|
|
|
|
if ($validator->fails()) {
|
|
// Handle exception
|
|
throw new ValidationException($validator);
|
|
return;
|
|
}
|
|
|
|
$bind_id = $this->request->input('bind_id');
|
|
|
|
$unbind_num = $this->deviceService->unbindById($bind_id);
|
|
|
|
if ($unbind_num == 0) {
|
|
return $this->result(100, '', '解绑失败: 设备已经解绑或不存在');
|
|
}
|
|
|
|
return $this->success(['unbind' => $unbind_num]);
|
|
}
|
|
}
|