StockChange.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Carbon;
  5. use Illuminate\Support\Facades\DB;
  6. class StockChange extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'stock_change';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command description';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. // 过滤试玩场
  37. $blacklist = [32, 33, 39];
  38. $list = DB::table('QPPlatformDB.dbo.GameRoomInfo')
  39. ->whereNotIn('ServerID', $blacklist)
  40. ->get();
  41. $stock = [];
  42. foreach ($list as $value) {
  43. $RoomStock = $value->RoomStock;
  44. $RoomStock = $RoomStock ? explode(':', explode(';', $RoomStock)[0])[1] : 0;
  45. $stock[] = ['stock' => (int)$RoomStock, 'serverID' => $value->ServerID, 'type' => 1, 'mydate' => date('Y-m-d H:i:s')];
  46. }
  47. // 首先把标识符取掉
  48. DB::table('agent.dbo.stock_change')->whereDate('mydate', date('Y-m-d'))->update(['identifier' => 0]);
  49. // 插入数据
  50. DB::table('agent.dbo.stock_change')->insert($stock);
  51. }
  52. }