BeaconController.php
2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/1/30
* Time: 10:52
*/
namespace App\Http\Controllers\Backend\Beacon;
use App\Exceptions\GeneralException;
use EasyWeChat\Factory;
use App\Http\Controllers\Controller;
use App\Modules\Models\Beacon\Beacon;
use App\Repositories\Backend\Beacon\BeaconRepository;
use App\Http\Requests\Backend\Beacon\UpdatBeaconRequest;
use App\Http\Requests\Backend\Beacon\DevicedRequest;
class BeaconController extends Controller
{
private $beacon;
public function __construct(BeaconRepository $beacon)
{
$this->beacon = $beacon;
}
public function index()
{
return view('backend.beacon.index');
}
public function edit(Beacon $beacon)
{
$spot=$this->spot();
return view('backend.beacon.edit', ['info' => $spot])->withBeacon($beacon);
}
public function update(Beacon $beacon, UpdatBeaconRequest $request)
{
$this->beacon->update($beacon,
$request->only(
'rssi',
'sd',
'explain_id'
));
return redirect()->route('admin.beacon.index')->withFlashSuccess(trans('alerts.backend.beacon.updated'));
}
public function mark(Beacon $beacon, $status)
{
$this->beacon->mark($beacon, $status);
return redirect()->route($status == 0 ? 'admin.beacon.index' : 'admin.beacon.deactivated')->withFlashSuccess(trans('alerts.backend.beacon.updated'));
}
public function getDeactivated()
{
return view('backend.beacon.deactivated');
}
public function binding()
{
return view('backend.beacon.binding');
}
public function deviced(DevicedRequest $request)
{
$data =$request->only('deviced_id');
$deviced_id = explode(',',$data['deviced_id']);
foreach ($deviced_id as $key=> $d){
$da[]['device_id']= (int)$d;
}
$wx_config = config('wechat.official_account.default');
$app = Factory::officialAccount($wx_config);
$shakearound = $app->shake_around;
//添加设备到分组,每个分组能够持有的设备上限为10000,并且每次添加操作的添加上限为1000。
$result = $shakearound->group->addDevices(3274117, $da);
//如果失败就是超过1000次要换一个组,
;
if($result['errcode']!=0){
throw new GeneralException(trans('alerts.backend.beacon.binding_error'));
die();
}
return redirect()->route('admin.beacon.index')->withFlashSuccess(trans('alerts.backend.beacon.binding_success'));
}
}