// +---------------------------------------------------------------------- namespace App\Services\Common; use App\Models\ActionLogModel; use App\Models\ArticleModel; use App\Services\BaseService; /** * 文章管理-服务类 * @author laravel开发员 * @since 2020/11/11 * Class ArticleService * @package App\Services\Common */ class ArticleService extends BaseService { /** * 构造函数 * @author laravel开发员 * @since 2020/11/11 * ArticleService constructor. */ public function __construct() { $this->model = new ArticleModel(); } /** * 静态入口 * @return static|null */ public static function make() { if (!self::$instance) { self::$instance = (new static()); } return self::$instance; } /** * @param $params * @param int $pageSize * @return array */ public function getDataList($params, $pageSize = 15) { $where = ['a.mark' => 1]; $status = isset($params['status'])? $params['status'] : 0; $type = isset($params['type'])? $params['type'] : 0; $showType = isset($params['show_type'])? $params['show_type'] : 0; if($status>0){ $where['a.status'] = $status; } if($showType==1){ $type = [1,2,3,4,5,6,7,8]; }else if($showType == 2){ $type = [9,10,11,99]; } $list = $this->model->from('article as a') ->where($where) ->where(function($query) use($type){ if($type && is_array($type)){ $query->whereIn('a.type',$type); }else if($type){ $query->where('a.type',$type); } }) ->where(function ($query) use($params){ $keyword = isset($params['keyword'])? $params['keyword'] : ''; if($keyword){ $query->where('a.title','like',"%{$keyword}%")->orWhere('a.tags','like',"%{$keyword}%"); } }) ->select(['a.*']) ->orderBy('a.create_time','desc') ->paginate($pageSize > 0 ? $pageSize : 9999999); $list = $list? $list->toArray() :[]; if($list){ $typrArr = ['','普通文章','诚意金说明','关于我们','司机等级升级说明','用户注册协议','隐私政策','申请司机说明','邀请有奖活动规则','常见问题','账号登录','商家合作']; foreach($list['data'] as &$item){ $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : ''; $item['cover'] = $item['cover']? get_image_url($item['cover']) : ''; $item['content'] = $item['content']? get_format_content($item['content']) : ''; $item['type_name'] = isset($typrArr[$item['type']])? $typrArr[$item['type']] : '其他'; } } return [ 'pageSize'=> $pageSize, 'total'=>isset($list['total'])? $list['total'] : 0, 'list'=> isset($list['data'])? $list['data'] : [] ]; } /** * 添加或编辑 * @return array * @since 2020/11/11 * @author laravel开发员 */ public function edit() { $data = request()->all(); $content = isset($data['content'])? $data['content'] : ''; if($content){ $data['content'] = set_format_content($content); } // 设置日志标题 ActionLogModel::setTitle("发布文章或客服咨询信息"); ActionLogModel::record(); return parent::edit($data); // TODO: Change the autogenerated stub } }