BuddhistPagesService.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Laravel框架 [ Laravel ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 Laravel研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: wesmiler <12345678@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services;
  12. use App\Models\BuddhistModel;
  13. use App\Models\BuddhistPagesModel;
  14. /**
  15. * 佛经章节管理-服务类
  16. * @author wesmiler
  17. * @since 2020/11/11
  18. * Class BuddhistPagesService
  19. * @package App\Services
  20. */
  21. class BuddhistPagesService extends BaseService
  22. {
  23. protected static $instance = null;
  24. /**
  25. * 构造函数
  26. * @author wesmiler
  27. * @since 2020/11/11
  28. * BuddhistPagesService constructor.
  29. */
  30. public function __construct()
  31. {
  32. $this->model = new BuddhistPagesModel();
  33. }
  34. /**
  35. * 静态入口
  36. * @return BuddhistPagesService|null
  37. */
  38. public static function make(){
  39. if(!self::$instance){
  40. self::$instance = new BuddhistPagesService();
  41. }
  42. return self::$instance;
  43. }
  44. /**
  45. * 获取列表
  46. * @return array
  47. * @since 2020/11/11
  48. * @author wesmiler
  49. */
  50. public function getList()
  51. {
  52. $params = request()->all();
  53. return parent::getList();
  54. }
  55. /**
  56. * 添加或编辑
  57. * @return array
  58. * @since 2020/11/11
  59. * @author wesmiler
  60. */
  61. public function edit()
  62. {
  63. $data = request()->all();
  64. $data['update_time'] = time();
  65. return parent::edit($data); // TODO: Change the autogenerated stub
  66. }
  67. /**
  68. * 获取章节数量
  69. * @param $id
  70. * @return mixed
  71. */
  72. public function getCount($id){
  73. return $this->model::where(['bid'=> $id,'status'=> 1])->count('id');
  74. }
  75. /**
  76. * 获取详情
  77. * @param $bid
  78. * @param int $id
  79. * @return array
  80. */
  81. public function getDetail($bid, $id=0){
  82. $where = ['bid'=> $bid,'mark'=> 1,'status'=> 1];
  83. if($id){
  84. $where['id'] = $id;
  85. }
  86. $info = $this->model::where($where)
  87. ->select(['id','title','description','content','create_time'])
  88. ->orderBy('sort','asc')
  89. ->orderBy('create_time','asc')
  90. ->first();
  91. $info = $info? $info->toArray() : [];
  92. if($info){
  93. $info['last'] = $this->model::where(['bid'=> $bid,'mark'=> 1,'status'=> 1])
  94. ->where('id','<', $id)
  95. ->orderBy('sort','desc')
  96. ->orderBy('create_time','desc')
  97. ->first();
  98. $info['next'] = $this->model::where(['bid'=> $bid,'mark'=> 1,'status'=> 1])
  99. ->where('id','>', $id)
  100. ->orderBy('sort','desc')
  101. ->orderBy('create_time','desc')
  102. ->first();
  103. }
  104. return message(MESSAGE_OK, true, $info);
  105. }
  106. }