BuddhistPagesService.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 = ['p.bid'=> $bid,'p.mark'=> 1,'p.status'=> 1];
  83. if($id){
  84. $where['p.id'] = $id;
  85. }
  86. $info = $this->model::from('buddhist_pages as p')
  87. ->leftJoin('buddhists as b','b.id','=','p.bid')
  88. ->leftJoin('buddhist_cates as bc','bc.id','=','b.cate_id')
  89. ->where($where)
  90. ->select(['p.id','p.title','p.content','bc.name as cate_name','p.create_time'])
  91. ->orderBy('p.sort','asc')
  92. ->orderBy('p.create_time','asc')
  93. ->first();
  94. $info = $info? $info->toArray() : [];
  95. if($info){
  96. $info['publish_at'] = $info['create_time']? datetime($info['create_time'],'Y-m-d H:i:s') : '';
  97. $info['last'] = $this->model::where(['bid'=> $bid,'mark'=> 1,'status'=> 1])
  98. ->where('id','<', $id)
  99. ->orderBy('sort','desc')
  100. ->orderBy('create_time','desc')
  101. ->first();
  102. $info['last'] = $info['last']? $info['last'] : ['id'=>0];
  103. $info['next'] = $this->model::where(['bid'=> $bid,'mark'=> 1,'status'=> 1])
  104. ->where('id','>', $id)
  105. ->orderBy('sort','asc')
  106. ->orderBy('create_time','asc')
  107. ->first();
  108. $info['next'] = $info['next']? $info['next'] : ['id'=>0];
  109. }
  110. return message(MESSAGE_OK, true, $info);
  111. }
  112. }