Browse Source

绑定和service添加

master
Mike 5 years ago
parent
commit
f8f90aa0bf
  1. 3
      app/Controller/AbstractController.php
  2. 26
      app/Controller/DeviceController.php
  3. 29
      app/Service/DeviceServiceImp.php
  4. 2
      app/Service/DeviceServiceInterFace.php
  5. 1
      config/autoload/dependencies.php

3
app/Controller/AbstractController.php

@ -15,6 +15,7 @@ use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Psr\Container\ContainerInterface;
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
use App\Commons\Log;
abstract class AbstractController
@ -45,7 +46,7 @@ abstract class AbstractController
protected $response;
/**
* @Inject()
* @Inject
* @var ValidatorFactoryInterface
*/
protected $validationFactory;

26
app/Controller/DeviceController.php

@ -5,21 +5,34 @@ namespace App\Controller;
use Hyperf\Di\Annotation\Inject;
use App\Constants\ErrorCode;
use App\Exception\BusinessException;
use App\Service\DeviceServiceInterFace;
class DeviceController extends BaseController
{
/**
* @Inject
* @var DeviceServiceInterFace
*/
protected $deviceService;
public function bind()
{
$validator = $this->validationFactory->make(
$request->all(),
$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' => '参数不正确',
]
);
@ -29,9 +42,14 @@ class DeviceController extends BaseController
$this->result(200,[],$errorMessage);
}
$store_id = $this->request->input('store_id');
$device_name = $this->request->input('device_name');
$sd = $this->deviceService->bindByStoreId($device_name,$store_id);
return $this->result(0,[$sd],'绑定成功');
}
public function list()

29
app/Service/DeviceServiceImp.php

@ -0,0 +1,29 @@
<?php
namespace App\Service;
use App\Model\SpeakerDevic;
class DeviceServiceImp implements DeviceServiceInterFace
{
public function getListByStoreId($store_id){
}
public function bindByStoreId($dev_name,$store_id){
$sd = null;
try{
$sd = new SpeakerDevic;
$sd->store_id = $store_id;
$sd->device_name = $dev_name;
$sd->market_id = 1;
$sd->bind_time = time();
$sd->saveOrFail();
}catch(Exception $e){
//var_dump($e);
}
return $sd;
}
public function pubMsgByStoreIdAndDevName($dev_name,$store_id,$msg){
}
}

2
app/Service/DeviceServiceInterFace.php

@ -1,9 +1,7 @@
<?php
namespace App\Service;
interface DeviceServiceInterFace
{
public function getListByStoreId($store_id);

1
config/autoload/dependencies.php

@ -13,5 +13,6 @@ return [
\App\Service\ServiceEvaluateServiceInterface::class => \App\Service\ServiceEvaluateService::class,
\App\Service\AttachmentServiceInterface::class => \App\Service\AttachmentService::class,
\App\Service\ParamsTokenServiceInterface::class => \App\Service\ParamsTokenSsdbService::class,
\App\Service\DeviceServiceInterFace::class =>\App\Service\DeviceServiceImp::class,
\App\Commons\Log::class => \App\Commons\Log::class,
];
Loading…
Cancel
Save