NovelData.php 710 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace app\model;
  3. class NovelData extends \think\Model
  4. {
  5. protected $pk = 'id';
  6. public static function getNextPrev($id, $nid = null)
  7. {
  8. $whereP = [];
  9. $whereN = [];
  10. // $whereP[] = ['status', '=', 1];
  11. // $whereN[] = ['status', '=', 1];
  12. if ($nid) {
  13. $whereP[] = ['n_id', '=', $nid];
  14. $whereN[] = ['n_id', '=', $nid];
  15. }
  16. $whereP[] = ['id', "<", $id];
  17. $whereN[] = ['id', ">", $id];
  18. $data_P = self::where($whereP)->order("id asc")->limit(1)->find();
  19. $data_N = self::where($whereN)->order("id asc")->limit(1)->find();
  20. return ['prev' => $data_P, 'next' => $data_N];
  21. }
  22. }