You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.5 KiB
91 lines
2.5 KiB
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\api\model;
|
|
|
|
use app\Request;
|
|
use think\facade\Db;
|
|
use think\Model;
|
|
|
|
/**
|
|
* @mixin think\Model
|
|
*/
|
|
class Ad extends CmsCommon
|
|
{
|
|
|
|
protected $table = 'bmz_ad';
|
|
protected $_data_table = 'ad_data';
|
|
/**
|
|
* 管理员列表数据模型
|
|
* @return array|\think\Collection
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function index()
|
|
{
|
|
|
|
$this->search_arr = ['name'];
|
|
|
|
$type = $this->request->param('type', 0);
|
|
$_op = $this->field('*');
|
|
|
|
if($type){
|
|
$_op = $this->where('type',$type);
|
|
}
|
|
|
|
//执行通用查询
|
|
return parent::parentLists($_op);
|
|
}
|
|
|
|
|
|
/**
|
|
* 读取后
|
|
* @param Model $model
|
|
* @return bool|void
|
|
*/
|
|
public static function onAfterRead(Model $model)
|
|
{
|
|
if (in_array(request()->action(), ['edit', 'delete', 'status'])) {
|
|
return true;
|
|
}
|
|
$typeArr = config('dict.sqlfields.ad_type');
|
|
|
|
$model->setAttr('type_str',$typeArr[$model->getAttr('type')]);
|
|
}
|
|
|
|
/**
|
|
* 获取广告数据
|
|
* @return array|\think\Collection
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function AdData()
|
|
{
|
|
$adid = $this->request->param('ad_id', '');
|
|
|
|
$_op = Db::name($this->_data_table)->where('site_id', SITE_ID); //没有默认where查询 这个一定要 否则获取不到下面的getOptions查询条件值
|
|
if ($adid) {
|
|
$_op->whereLike('ad_id', $adid);
|
|
}
|
|
|
|
$_op->order('create_time DESC');
|
|
$data = parent::parentLists($_op);
|
|
$result = $data['data'];
|
|
|
|
// //查询广告位限制的图片宽度、高度
|
|
// $_ad = Db::name('ad')->field('width,height')->where('id',$adid)->find();
|
|
// array_walk($result, function (&$v) use ($_ad) {
|
|
// $v['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
|
|
// $v['start_time'] = date('Y-m-d H:i:s', $v['start_time']);
|
|
// $v['end_time'] = date('Y-m-d H:i:s', $v['end_time']);
|
|
// $v['thumb'] = config('dictionary.upload.cdn_img_host') . $v['thumb'];
|
|
// $v['crop_thumb'] = crop_thumb($v['thumb'], (int)$_ad['width'], (int)$_ad['height']);
|
|
// });
|
|
// $data['data'] = $result;
|
|
return $data;
|
|
}
|
|
|
|
|
|
}
|
|
|