| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- // +----------------------------------------------------------------------
- // | Laravel框架 [ Laravel ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 Laravel研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: wesmiler <12345678@qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services;
- use App\Models\BuddhistModel;
- use App\Models\BuddhistPagesModel;
- /**
- * 佛经章节管理-服务类
- * @author wesmiler
- * @since 2020/11/11
- * Class BuddhistPagesService
- * @package App\Services
- */
- class BuddhistPagesService extends BaseService
- {
- protected static $instance = null;
- /**
- * 构造函数
- * @author wesmiler
- * @since 2020/11/11
- * BuddhistPagesService constructor.
- */
- public function __construct()
- {
- $this->model = new BuddhistPagesModel();
- }
- /**
- * 静态入口
- * @return BuddhistPagesService|null
- */
- public static function make(){
- if(!self::$instance){
- self::$instance = new BuddhistPagesService();
- }
- return self::$instance;
- }
- /**
- * 获取列表
- * @return array
- * @since 2020/11/11
- * @author wesmiler
- */
- public function getList()
- {
- $params = request()->all();
- return parent::getList();
- }
- /**
- * 添加或编辑
- * @return array
- * @since 2020/11/11
- * @author wesmiler
- */
- public function edit()
- {
- $data = request()->all();
-
- $data['update_time'] = time();
- return parent::edit($data); // TODO: Change the autogenerated stub
- }
- /**
- * 获取章节数量
- * @param $id
- * @return mixed
- */
- public function getCount($id){
- return $this->model::where(['bid'=> $id,'status'=> 1])->count('id');
- }
- /**
- * 获取详情
- * @param $bid
- * @param int $id
- * @return array
- */
- public function getDetail($bid, $id=0){
- $where = ['p.bid'=> $bid,'p.mark'=> 1,'p.status'=> 1];
- if($id){
- $where['p.id'] = $id;
- }
- $info = $this->model::from('buddhist_pages as p')
- ->leftJoin('buddhists as b','b.id','=','p.bid')
- ->leftJoin('buddhist_cates as bc','bc.id','=','b.cate_id')
- ->where($where)
- ->select(['p.id','p.title','p.content','bc.name as cate_name','p.create_time'])
- ->orderBy('p.sort','asc')
- ->orderBy('p.create_time','asc')
- ->first();
- $info = $info? $info->toArray() : [];
- if($info){
- $info['publish_at'] = $info['create_time']? datetime($info['create_time'],'Y-m-d H:i:s') : '';
- $info['last'] = $this->model::where(['bid'=> $bid,'mark'=> 1,'status'=> 1])
- ->where('id','<', $id)
- ->orderBy('sort','desc')
- ->orderBy('create_time','desc')
- ->first();
- $info['last'] = $info['last']? $info['last'] : ['id'=>0];
- $info['next'] = $this->model::where(['bid'=> $bid,'mark'=> 1,'status'=> 1])
- ->where('id','>', $id)
- ->orderBy('sort','asc')
- ->orderBy('create_time','asc')
- ->first();
- $info['next'] = $info['next']? $info['next'] : ['id'=>0];
- }
- return message(MESSAGE_OK, true, $info);
- }
- }
|