Index.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\controller\apps\poetry;
  3. use app\model\CardModel;
  4. use app\PluginsBase;
  5. class Index extends PluginsBase
  6. {
  7. function poetryList(): \think\response\Json
  8. {
  9. $admin = $this->getAdmin();
  10. $foodListArr = include "content.php";
  11. $list = CardModel::config("poetry", "poetryList");
  12. if (!$list) {
  13. $list = $foodListArr;
  14. }
  15. return $this->success("ok", $list);
  16. }
  17. function reset(): \think\response\Json
  18. {
  19. $admin = $this->getAdmin();
  20. CardModel::saveConfig('poetry', 'poetryList', []);
  21. return $this->success('ok');
  22. }
  23. function poetryOne(): \think\response\Json
  24. {
  25. $foodListArr = include 'content.php';
  26. $list = CardModel::config('poetry', 'poetryList');
  27. if (!$list) {
  28. $list = $foodListArr;
  29. }
  30. //随机取一个数组中的内容
  31. $one = $list[array_rand($list)];
  32. return $this->success('ok', $one);
  33. }
  34. function poetryListSave(): \think\response\Json
  35. {
  36. $admin = $this->getAdmin();
  37. $list = $this->request->post("list", []);
  38. //php取300条,如果少于300条全部取上
  39. $list = array_slice($list, 0, 300);
  40. CardModel::saveConfig("poetry", "poetryList", $list);
  41. if (count($list) > 300) {
  42. return $this->success('最多只能保存300条,超出部分将被忽略');
  43. }
  44. return $this->success('保存成功');
  45. }
  46. }