123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <?php
- namespace App\Console\Commands;
- use App\Handlers\BikeControl;
- use App\Models\Bike;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- use function Matrix\trace;
- class BoxSettingInitCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'set:box-setting {--bike_no=0} {--box_no=0} {--area=0} {--min=0} {--max=0}';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '配置中控';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- const config = [
- 'weilaibike' => [
- // 心跳间隔时间(秒)
- 'PULSE' => 120,
- // 骑行定位包间隔(秒)
- 'FREQ' => 10,
- // 骑行时静止多少分钟报锁车(分)
- 'VIBFILTERREMINDT' => 30,
- // 配置服务器地址
- 'SERVER' => 'relay.weilaibike.com:8282',
- // 蓝牙秘钥
- // 'DFTBLEENCKEY' => 'TBIT_WA205-7HBLE',
- // // 蓝牙功能开关
- 'BLEKG' => 1,
- //车的最高速度
- 'MAXECUSPEED' => 3
- ],
- 'xiaobanma' => [
- // 心跳间隔时间(秒)
- 'PULSE' => 120,
- // 骑行定位包间隔(秒)
- 'FREQ' => 15,
- // 骑行时静止多少分钟报锁车(分)
- 'VIBFILTERREMINDT' => 30,
- // 配置服务器地址
- 'SERVER' => 'relay.xbm.weilaibike.com:8383',
- // 蓝牙秘钥
- // 'DFTBLEENCKEY' => 'TBIT_WA205-7HBLE',
- // 蓝牙功能开关
- 'BLEKG' => 1,
- //车的最高速度
- 'MAXECUSPEED' => 7
- ],
- 'demo' => [
- // 心跳间隔时间(秒)
- 'PULSE' => 120,
- // 骑行定位包间隔(秒)
- 'FREQ' => 10,
- // 骑行时静止多少分钟报锁车(分)
- 'VIBFILTERREMINDT' => 30,
- // 配置服务器地址
- 'SERVER' => 'relay.demo.weilaibike.com:8282',
- // 蓝牙秘钥
- // 'DFTBLEENCKEY' => 'TBIT_WA205-7HBLE',
- // 蓝牙功能开关
- // 'BLEKG' => 1,
- //车的最高速度
- 'MAXECUSPEED' => 7
- ]
- ];
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $bike_no = $this->option('bike_no');
- $box_no = $this->option('box_no');
- $area_id = $this->option('area');
- $min = $this->option('min');
- $max = $this->option('max');
- $bike = Bike::query();
- if ($area_id) {
- $bike->where('put_area_id', $area_id);
- }
- if ($bike_no) {
- $bike->where('bike_no', $bike_no);
- }
- if ($box_no) {
- $bike->where('box_no', $box_no);
- }
- if ($min) {
- $bike->where('bike_no', '>=', $min);
- }
- if ($max) {
- $bike->where('bike_no', '<=', $max);
- }
- $bikes = $bike->select(['bike_no', 'box_no', 'id', 'blu_key', 'put_area_id'])->get();
- if ($bikes->isEmpty()) {
- $this->line('没有找到要调整的车');
- return true;
- }
- $config_name = $this->choice('请选择配置文件?(weilaibike「闪现GO」和xiaobanma「小班马」)', ['no', 'weilaibike', 'xiaobanma', 'demo'], 'no');
- if ($config_name === 'no') {
- return false;
- }
- $MAXECUSPEED = $this->choice('请选择速度配置值?(1~7 值越大越快(70%~100%))', [7, 6, 5, 4, 3, 2, 1], 7);
- $num = count($bikes);
- $setting = [];
- foreach (self::config[$config_name] as $key => $item) {
- if ($key === 'MAXECUSPEED') {
- $item = $MAXECUSPEED;
- }
- $setting[] = "{$key}={$item}";
- }
- $this->line("配置文件为:" . implode(';', $setting));
- $results = [];
- if ($this->confirm("您确定要修改{$num}辆车?")) {
- foreach ($bikes as $bike) {
- if (in_array('DFTBLEENCKEY', array_keys(self::config[$config_name]))) {
- // 处理蓝牙模块
- }
- if ($bike['box_no']) {
- $result = BikeControl::setBoxSetting($bike['box_no'], $setting);
- $results[] = [
- 'bike_no' => $bike['bike_no'],
- 'box_no' => $bike['box_no'],
- 'status' => $result
- ];
- } else {
- $results[] = [
- 'bike_no' => $bike['bike_no'],
- 'box_no' => $bike['box_no'],
- 'status' => '没有绑定'
- ];
- }
- }
- $this->line('设置完成,结果见下表:');
- $this->table(array_keys($results[0]), $results);
- $this->line('------over------');
- return true;
- }
- $this->line('关闭修改');
- }
- }
|