| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 | <?php/** * Created by PhpStorm. * User: Administrator * Date: 2018/11/8 * Time: 10:03 */namespace App\Services\Content;use App\Repositories\NoticeRepository;class NoticeServer{    protected $noticeRepository;    /**     * NoticeServer constructor.     * @param $noticeRepository     */    public function __construct(NoticeRepository $noticeRepository)    {        $this->noticeRepository = $noticeRepository;    }    public function getLists($where, $page_num = '')    {        $lists = $this->noticeRepository->getNotices($where, $page_num);        if ($lists->toArray()) {            foreach ($lists as $k => $v) {                $lists[$k]->origin_title = $v->title;                $style_font = '';                $style_color ='';                if ($v->tit_b == 1) {                    $style_font = "font-weight:bold;";                }                if ($v->tit_color) {                    $style_color = 'color:'.$v->tit_color.';';                }                if ($style_font || $style_color) {                    $lists[$k]->title = "<span style=".$style_color.$style_font.">".$v->title."</span>";                }                if ($v->is_url) {                    $lists[$k]->url = $v->is_url;                } else {                    $lists[$k]->url = route('notice.show', array('id'=>$v->id));                }            }        }        return $lists;    }    public function getNotice($where)    {        $notice_info = $this->noticeRepository->getNotice($where);        if (!$notice_info) {            return null;        }        $notice_info->prev = 0;        $notice_info->next = 0;        $map[] = array('is_display','=','1');        //$map[] = array('type_id','=',$notice_info->type_id);        $lists = $this->getLists($map);        if ($lists->isNotEmpty()) {            $info_key = -1;            foreach ($lists as $k => $v) {                if ($v->id==$notice_info->id) {                    $info_key = $k;                }            }            $pre_info = array();            $nex_info = array();            if ($info_key>-1 && !empty($lists[$info_key-1])) {                $prev =  $lists[$info_key-1];                if ($prev) {                    $notice_info->prev = 1;                    $notice_info->prev_title = $prev->origin_title;                    $notice_info->prev_url = route('notice.show', ['id'=>$prev->id]);                }            }            if ($info_key>-1 && !empty($lists[$info_key+1])) {                $next = $lists[$info_key+1];                if ($next) {                    $notice_info->next = 1;                    $notice_info->next_title = $next->origin_title;                    $notice_info->next_url = route('notice.show', ['id'=>$next->id]);                }            }        }        return $notice_info;    }    public function incrementData($where, $num, $filed)    {        return $this->noticeRepository->incrementData($where, $num, $filed);    }    public function getNotices($params)    {        $where = array(            array('is_display','=',1)        );        if (array_has($params, 'type_id')) {            $where[] = array('type_id','=',$params['type_id']);        }        $limit = '';        if (array_has($params, 'size')) {            $limit = $params['size'];        }        $order = array('sort'=>'desc','created_at'=>'desc');        $rst = $this->noticeRepository->getLimitNotices($where, $order, $limit);        if ($rst->isNotEmpty() && array_has($params, 'titlelen')) {            $dot = '...';            if (array_has($params, 'dot')) {                $dot = $params['dot'];            }            foreach ($rst as $k => $v) {                $rst[$k]->dot_title = cut_str($v->title, $params['titlelen'], 0, $dot);            }        }        return $rst;    }}
 |