| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- 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'] : 1; // 1:协议 2:公告
- if ($status > 0) {
- $where['a.status'] = $status;
- }
- $list = $this->model->from('article as a')
- ->where($where)
- ->where(function ($query) use ($type, $showType) {
- // 根据show_type区分协议和公告
- if ($showType == 1) {
- // 协议类型:1-5
- $query->whereIn('a.type', [1, 2, 3, 4, 5]);
- } else if ($showType == 2) {
- // 公告类型:固定为6
- $query->where('a.type', 6);
- }
- // 如果指定了具体类型,则进一步筛选(仅用于协议)
- if ($showType == 1 && $type && is_array($type)) {
- $query->whereIn('a.type', $type);
- } else if ($showType == 1 && $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);
- } else {
- // 确保content字段存在(即使为空字符串)
- $data['content'] = '';
- }
- // 设置日志标题
- ActionLogModel::setTitle("发布文章或客服咨询信息");
- ActionLogModel::record();
- return parent::edit($data); // TODO: Change the autogenerated stub
- }
- /**
- * 删除
- * @return array
- */
- public function delete()
- {
- $id = request()->post('id');
- if (!$id) {
- return ['code' => 1, 'msg' => '参数错误'];
- }
- // 支持批量删除
- if (is_array($id)) {
- $result = $this->model->whereIn('id', $id)->update(['mark' => 0]);
- } else {
- $result = $this->model->where('id', $id)->update(['mark' => 0]);
- }
- if ($result) {
- // 设置日志标题
- ActionLogModel::setTitle("删除协议内容");
- ActionLogModel::record();
- return ['code' => 0, 'msg' => '删除成功'];
- }
- return ['code' => 1, 'msg' => '删除失败'];
- }
- }
|