1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- declare (strict_types = 1);
- namespace library\utils;
- // +----------------------------------------------------------------------
- // | [ 广告位 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2018-2020 rights reserved.
- // +----------------------------------------------------------------------
- // | Author: TABLE ME
- // +----------------------------------------------------------------------
- // | Date: 2020-08-29 20:41
- // +----------------------------------------------------------------------
- use \app\model\system\Advert as AdvertModel;
- class AdvertUtils
- {
- private $sassid;
- /**
- * Advert constructor.
- * @param int $sassid 子站sassid 无默认为0
- */
- public function __construct($sassid = 0)
- {
- $this->sassid = $sassid;
- }
- public function getData($page_id,$pageCount = 0) {
- $adver = (new AdvertModel())
- ->where('page_id',$page_id)
- ->where('is_show',1)
- ->where('sassid', $this->sassid)
- ->order("sort","desc")
- ->when(!empty($pageCount),function ($query) use($pageCount){
- $query->limit(0,$pageCount);
- })
- ->select()
- ->toArray();
- if(empty($adver)) {
- $adver = (new AdvertModel())
- ->where('page_id',$page_id)
- ->where('is_show',1)
- ->where('sassid', 0)
- ->order("sort","desc")
- ->when(!empty($pageCount),function ($query) use($pageCount){
- $query->limit(0,$pageCount);
- })
- ->select()
- ->toArray();
- }
- $lData = [];
- foreach ($adver as $v) {
- $d['title'] = $v['title'];
- $d['text'] = $v['text'];
- $d['url'] = $v['url'];
- $d['img'] = $v['img'];
- $tAr = [];
- $jsonData = empty($v['data']) ? [] : json_decode($v['data'],true);
- foreach($jsonData as $v2) {
- $tAr[$v2['code']] = [
- 'name' => $v2['name'],
- 'type' => $v2['type'],
- 'value' => $v2[$v2['code']]
- ];
- }
- $d['data'] = $tAr;
- $lData[] = $d;
- }
- return $lData;
- }
- }
|