2 changed files with 117 additions and 3 deletions
@ -0,0 +1,114 @@ |
|||
<?php |
|||
|
|||
namespace App\Controller\v3; |
|||
|
|||
use App\Controller\BaseController; |
|||
use App\Service\v3\Interfaces\DeviceServiceInterface; |
|||
use Hyperf\Di\Annotation\Inject; |
|||
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]); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue