ku_controller.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. use Workerman\Protocols\Http;
  3. class KuController extends AppController
  4. {
  5. protected function before_filter()
  6. {
  7. View::select(null, null);
  8. Http::header('Content-Type: application/json');
  9. }
  10. public function index()
  11. {
  12. KuRaw::$db->execute([mt_rand(1, 10000)]);
  13. echo json_encode(KuRaw::$db->fetch());
  14. }
  15. public function query($count = 1)
  16. {
  17. $count = min(max($count, 1), 500);
  18. while ($count--) {
  19. KuRaw::$db->execute([mt_rand(1, 10000)]);
  20. $worlds[] = KuRaw::$db->fetch();
  21. }
  22. echo json_encode($worlds);
  23. }
  24. public function update($count = 1)
  25. {
  26. $count = min(max($count, 1), 500);
  27. while ($count--) {
  28. $id = mt_rand(1, 10000);
  29. KuRaw::$random->execute([$id]);
  30. $row = ['id' => $id, 'randomNumber' => KuRaw::$random->fetchColumn()];
  31. $row['randomNumber'] = mt_rand(1, 10000);
  32. $worlds[] = $row;
  33. }
  34. KuRaw::update($worlds);
  35. echo json_encode($worlds);
  36. }
  37. }