Commit e721b0b7 authored by 龚双喜's avatar 龚双喜

更新首页广告功能

parent 897d2ad7
[app]
debug = true
trace = true
[database]
hostname = 127.0.0.1
database = fastadmin
username = root
password = root
hostport = 3306
prefix = fa_
......@@ -10,3 +10,4 @@ composer.lock
.svn
.vscode
.user.ini
/public/uploads
\ No newline at end of file
......@@ -9,13 +9,14 @@ use app\admin\model\shopro\decorate\Page;
use app\common\library\Sms as Smslib;
use app\admin\model\shopro\user\User as UserModel;
use addons\shopro\facade\Wechat;
use app\common\model\shopro\Ad;
use think\Hook;
class Index extends Common
{
use Util;
protected $noNeedLogin = ['init', 'pageSync', 'page', 'feedback', 'send', 'test'];
protected $noNeedLogin = ['init', 'pageSync', 'page', 'feedback', 'send', 'test', 'ad'];
protected $noNeedRight = ['*'];
public function init()
......@@ -214,4 +215,18 @@ class Index extends Common
'token' => $token
]);
}
/**
* 获取广告
*
* @return void
*/
public function ad()
{
$ad = Ad::where(['status' => 'normal'])->order('id', 'desc')->find();
$this->success('获取成功', [
'ad' => $ad
]);
}
}
<?php
namespace app\admin\controller\shopro\miniprogram;
use think\Db;
use app\common\controller\Backend;
use app\common\model\shopro\Ad as AdModel;
class Ad extends Backend
{
protected $model = null;
protected $searchFields = 'title';
public function _initialize()
{
parent::_initialize();
$this->model = new AdModel();
$this->view->assign("statusList", $this->model->getStatusList());
}
// 广告列表
public function index()
{
if ($this->request->isAjax()) {
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->where($where)
->order($sort, $order)
->paginate($limit);
$result = ['total' => $list->total(), 'rows' => $list->items()];
return json($result);
}
return $this->view->fetch();
}
// 删除广告
public function del($ids = null)
{
if (!$this->request->isPost()) {
$this->error('非法请求');
}
$ids = $this->request->post('ids');
if (empty($ids)) {
$this->error('参数错误');
}
$result = $this->model->destroy($ids);
if ($result) {
$this->success('删除成功');
} else {
$this->error('删除失败');
}
}
// 切换状态
public function toggle()
{
$id = $this->request->post('id');
$row = $this->model->find($id);
if (!$row) {
$this->error('广告不存在');
}
$row->status = $row->status == 1 ? 0 : 1;
$row->save();
$this->success('操作成功');
}
}
<?php
return [
'Id' => 'ID',
'Title' => '标题',
'Video' => '视频',
'Status' => '状态',
'Link' => '跳转链接',
'Skip_time' => '跳过等待秒数',
'Show_count' => '累计展示次数',
'Createtime' => '创建时间',
'Updatetime' => '更新时间',
];
\ No newline at end of file
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-title" class="form-control" name="row[title]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Video')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-video" data-rule="required" class="form-control" size="50" name="row[video]" type="text">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="faupload-video" class="btn btn-danger faupload" data-input-id="c-video" data-mimetype="mp4,flv,avi,wmv,mov" data-multiple="false" data-preview-id="p-video"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-video" class="btn btn-primary fachoose" data-input-id="c-video" data-mimetype="mp4,flv,avi,wmv,mov" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-video"></span>
</div>
<ul class="row list-inline faupload-preview" id="p-video"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Link')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-link" class="form-control" name="row[link]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Skip_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-skip_time" class="form-control" name="row[skip_time]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="statusList" item="vo"}
<label for="row[status]-{$key|htmlentities}"><input id="row[status]-{$key|htmlentities}" name="row[status]" type="radio" value="{$key|htmlentities}" {in name="key" value="normal"}checked{/in} /> {$vo|htmlentities}</label>
{/foreach}
</div>
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-title" class="form-control" name="row[title]" type="text" value="{$row.title|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Video')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-video" data-rule="required" class="form-control" size="50" name="row[video]" type="text" value="{$row.video|htmlentities}">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="faupload-video" class="btn btn-danger faupload" data-input-id="c-video" data-mimetype="mp4,flv,avi,wmv,mov" data-multiple="false" data-preview-id="p-video"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-video" class="btn btn-primary fachoose" data-input-id="c-video" data-mimetype="mp4,flv,avi,wmv,mov" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-video"></span>
</div>
<ul class="row list-inline faupload-preview" id="p-video"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Link')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-link" class="form-control" name="row[link]" type="text" value="{$row.link|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Skip_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-skip_time" class="form-control" name="row[skip_time]" type="text" value="{$row.skip_time|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="statusList" item="vo"}
<label for="row[status]-{$key|htmlentities}"><input id="row[status]-{$key|htmlentities}" name="row[status]" type="radio" value="{$key|htmlentities}" {in name="key" value="$row.status"}checked{/in} /> {$vo|htmlentities}</label>
{/foreach}
</div>
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
<div class="panel panel-default panel-intro">
<div class="panel-heading">
</div>
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('shopro/miniprogram/ad/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('shopro/miniprogram/ad/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('shopro/miniprogram/ad/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<div class="dropdown btn-group {:$auth->check('shopro/miniprogram/ad/multi')?'':'hide'}">
<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
<ul class="dropdown-menu text-left" role="menu">
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
</ul>
</div>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('shopro/miniprogram/ad/edit')}"
data-operate-del="{:$auth->check('shopro/miniprogram/ad/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
<?php
namespace app\common\model\shopro;
use think\Model;
class Ad extends Model
{
protected $name = 'shopro_ad';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 获取当前可展示的广告
public static function getActiveAd()
{
$time = time();
return self::where('status', 1)
->where(function ($query) use ($time) {
$query->where('start_time', 0)
->whereOr('start_time', '<=', $time);
})
->where(function ($query) use ($time) {
$query->where('end_time', 0)
->whereOr('end_time', '>=', $time);
})
->order('sort', 'desc')
->order('id', 'desc')
->find();
}
// 增加展示次数
public function incrementShowCount()
{
$this->show_count = $this->show_count + 1;
$this->save();
}
public function getStatusList()
{
return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
}
}
......@@ -5,7 +5,7 @@ return [
'default' => 'default', // 默认的队列名称
'host' => '127.0.0.1', // redis 主机ip
'port' => 6379, // redis 端口
'password' => '', // redis 密码
'password' => '123456', // redis 密码
'select' => 0, // 使用哪一个 db,默认为 db0
'timeout' => 0, // redis连接的超时时间
'persistent' => false,
......
<?php
return [
'host' => '127.0.0.1',
'password' => '123456',
'port' => '6379',
'select' => '1',
'timeout' => '0',
'persistent' => false,
];
\ No newline at end of file
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'shopro/miniprogram/ad/index',
add_url: 'shopro/miniprogram/ad/add',
edit_url: 'shopro/miniprogram/ad/edit',
del_url: 'shopro/miniprogram/ad/del',
multi_url: 'shopro/miniprogram/ad/multi',
table: 'shopro_ad',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
fixedColumns: true,
fixedRightNumber: 1,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'title', title: __('Title'), operate: 'LIKE'},
{field: 'video', title: __('Video'), operate: false, formatter: function (val, data) {
if (!val) return '';
// 返回一个 video 标签,限制宽高以适应表格
return '<video style="width: 250px; height: 120px;" src="' + val + '" controls="controls"></video>';
}
},
{field: 'link', title: __('Link'), operate: false},
{field: 'skip_time', title: __('Skip_time'), operate: false},
{field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
\ No newline at end of file
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment