BoxSettingInitCommand.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Handlers\BikeControl;
  4. use App\Models\Bike;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\DB;
  7. use function Matrix\trace;
  8. class BoxSettingInitCommand extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'set:box-setting {--bike_no=0} {--box_no=0} {--area=0} {--min=0} {--max=0}';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '配置中控';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. const config = [
  32. 'weilaibike' => [
  33. // 心跳间隔时间(秒)
  34. 'PULSE' => 120,
  35. // 骑行定位包间隔(秒)
  36. 'FREQ' => 10,
  37. // 骑行时静止多少分钟报锁车(分)
  38. 'VIBFILTERREMINDT' => 30,
  39. // 配置服务器地址
  40. 'SERVER' => 'relay.weilaibike.com:8282',
  41. // 蓝牙秘钥
  42. // 'DFTBLEENCKEY' => 'TBIT_WA205-7HBLE',
  43. // // 蓝牙功能开关
  44. 'BLEKG' => 1,
  45. //车的最高速度
  46. 'MAXECUSPEED' => 3
  47. ],
  48. 'xiaobanma' => [
  49. // 心跳间隔时间(秒)
  50. 'PULSE' => 120,
  51. // 骑行定位包间隔(秒)
  52. 'FREQ' => 15,
  53. // 骑行时静止多少分钟报锁车(分)
  54. 'VIBFILTERREMINDT' => 30,
  55. // 配置服务器地址
  56. 'SERVER' => 'relay.xbm.weilaibike.com:8383',
  57. // 蓝牙秘钥
  58. // 'DFTBLEENCKEY' => 'TBIT_WA205-7HBLE',
  59. // 蓝牙功能开关
  60. 'BLEKG' => 1,
  61. //车的最高速度
  62. 'MAXECUSPEED' => 7
  63. ],
  64. 'demo' => [
  65. // 心跳间隔时间(秒)
  66. 'PULSE' => 120,
  67. // 骑行定位包间隔(秒)
  68. 'FREQ' => 10,
  69. // 骑行时静止多少分钟报锁车(分)
  70. 'VIBFILTERREMINDT' => 30,
  71. // 配置服务器地址
  72. 'SERVER' => 'relay.demo.weilaibike.com:8282',
  73. // 蓝牙秘钥
  74. // 'DFTBLEENCKEY' => 'TBIT_WA205-7HBLE',
  75. // 蓝牙功能开关
  76. // 'BLEKG' => 1,
  77. //车的最高速度
  78. 'MAXECUSPEED' => 7
  79. ]
  80. ];
  81. /**
  82. * Execute the console command.
  83. *
  84. * @return mixed
  85. */
  86. public function handle()
  87. {
  88. $bike_no = $this->option('bike_no');
  89. $box_no = $this->option('box_no');
  90. $area_id = $this->option('area');
  91. $min = $this->option('min');
  92. $max = $this->option('max');
  93. $bike = Bike::query();
  94. if ($area_id) {
  95. $bike->where('put_area_id', $area_id);
  96. }
  97. if ($bike_no) {
  98. $bike->where('bike_no', $bike_no);
  99. }
  100. if ($box_no) {
  101. $bike->where('box_no', $box_no);
  102. }
  103. if ($min) {
  104. $bike->where('bike_no', '>=', $min);
  105. }
  106. if ($max) {
  107. $bike->where('bike_no', '<=', $max);
  108. }
  109. $bikes = $bike->select(['bike_no', 'box_no', 'id', 'blu_key', 'put_area_id'])->get();
  110. if ($bikes->isEmpty()) {
  111. $this->line('没有找到要调整的车');
  112. return true;
  113. }
  114. $config_name = $this->choice('请选择配置文件?(weilaibike「闪现GO」和xiaobanma「小班马」)', ['no', 'weilaibike', 'xiaobanma', 'demo'], 'no');
  115. if ($config_name === 'no') {
  116. return false;
  117. }
  118. $MAXECUSPEED = $this->choice('请选择速度配置值?(1~7 值越大越快(70%~100%))', [7, 6, 5, 4, 3, 2, 1], 7);
  119. $num = count($bikes);
  120. $setting = [];
  121. foreach (self::config[$config_name] as $key => $item) {
  122. if ($key === 'MAXECUSPEED') {
  123. $item = $MAXECUSPEED;
  124. }
  125. $setting[] = "{$key}={$item}";
  126. }
  127. $this->line("配置文件为:" . implode(';', $setting));
  128. $results = [];
  129. if ($this->confirm("您确定要修改{$num}辆车?")) {
  130. foreach ($bikes as $bike) {
  131. if (in_array('DFTBLEENCKEY', array_keys(self::config[$config_name]))) {
  132. // 处理蓝牙模块
  133. }
  134. if ($bike['box_no']) {
  135. $result = BikeControl::setBoxSetting($bike['box_no'], $setting);
  136. $results[] = [
  137. 'bike_no' => $bike['bike_no'],
  138. 'box_no' => $bike['box_no'],
  139. 'status' => $result
  140. ];
  141. } else {
  142. $results[] = [
  143. 'bike_no' => $bike['bike_no'],
  144. 'box_no' => $bike['box_no'],
  145. 'status' => '没有绑定'
  146. ];
  147. }
  148. }
  149. $this->line('设置完成,结果见下表:');
  150. $this->table(array_keys($results[0]), $results);
  151. $this->line('------over------');
  152. return true;
  153. }
  154. $this->line('关闭修改');
  155. }
  156. }