Commit dc454a86 authored by ZhuChunYang's avatar ZhuChunYang

update

parent ee630520
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/12/18
* Time: 16:24
*/
namespace backend\controllers;
use common\models\psources\CoinApplicateRecommend;
use common\models\psources\CoinApplication;
use common\models\psources\CoinApplicationCategory;
use common\models\psources\CoinBannerItem;
use common\models\psources\CoinImage;
use Yii;
class CoinBannerController extends BaseController
{
public function actionAdd()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$image_url = $request->post('image_url', '');
$banner_url = $request->post('banner_url','');
if($image_url && $banner_url){
$banner_item = new CoinBannerItem();
$banner_item->banner_url = $banner_url;
$banner_item->image_url = $image_url;
$banner_item->save();
return ['code' => 0,'msg' => 'banner添加成功'];
}else{
return ['code' => 1,'msg' => 'banner添加加失败'];
}
}
}
public function actionDelete()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$id = $request->get('id', '');
if($id){
$banner = CoinBannerItem::getBanner($id);
if(!$banner){
return ['code' => 1,'msg' =>'banner不存在,不能删除'];
}
$banner->delete();
return ['code' => 0,'msg' => 'banner删除成功'];
}else{
return ['code' => 1 ,'msg' => 'banner删除失败'];
}
}
}
/**
* banner列表
*/
public function actionIndex()
{
if(Yii::$app->request->isAjax){
Yii::$app->response->format = 'json';
$data = CoinBannerItem::getItems();
return [ 'data' =>$data, 'code' => 0];
}
return $this->render('index');
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/17
* Time: 10:55
*/
?>
<style>
.layui-form-label {
width: 100px;
}
</style>
<h4>banner管理列表</h4>
<div class="layui-row">
<div class="layui-col-md1">
<button class="layui-btn layui-btn-default" id="add">添加banner图</button>
</div>
</div>
<div class="layui-col-md9">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
<div class="layui-row add" style="display: none;padding: 5px;" id="_form">
<div class="layui-col-xs6 layui-col-sm6 layui-col-md11">
<form class="layui-form" action="javascript:void(0)" id="form1" method="post" lay-filter="form1">
<input type="hidden" name="_csrf" value="<?= Yii::$app->request->getCsrfToken() ?>">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">图片</label>
<div class="layui-input-block">
<img src="" style="margin-top: 11px; max-width: 32px; max-height: 32px"
id="icon1">
</div>
<input type="hidden" name="image_url" value="">
</div>
<div class="layui-inline" style="margin-left: 50px;">
<button type="button" class="layui-btn" id="upload1" style="">
<i class="layui-icon">&#xe67c;</i>上传新图片
</button>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">跳转地址</label>
<div class="layui-input-block">
<input type="text" class="layui-input" name="banner_url" value="">
</div>
</div>
</form>
</div>
</div>
<script type="text/html" id="operationTpl">
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/javascript">
var table = layui.table;
table.render({
elem: '#table1',
url: '/admin/coin-banner/index',
cols: [[
{
field: 'id',
title: '编号'
},
{
field: 'banner_url',
title: 'banner跳转地址',
templet: function(d){
return "<a href='"+d.banner_url+"' target='_blank'>"+d.banner_url+"</a>";
}
},
{
field: 'image_url',
title: '图片跳转地址',
templet: function(d){
return "<a href='"+d.image_url+"' target='_blank'>"+d.image_url+"</a>";
},
width: 600
},
{
title: '操作',
templet: '#operationTpl',
width: 200
}
]],
});
var form = layui.form;
form.render();
table.on('tool(table1)', function(obj) {
var event = obj.event;
var data = obj.data;
if (event === 'del') {
var index = layer.confirm("确认删除?", {icon: 3, title: '删除'}, function () {
$.get('/admin/coin-banner/delete', {id: data.id}, function (rev) {
layer.msg(rev.msg);
if (0==rev.code) {
table.reload('table1');
}
});
});
}
});
$('#add').click(function () {
var index = layer.open({
title: '添加banner',
area: '800px',
type: 1,
content: $("#_form"),
btn: ['保存', '取消'],
success: function() {
clearForm();
},
btn1: function() {
$.post('/admin/coin-banner/add', $("#form1").serialize(), function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
layer.close(index);
$("#_form").css('display', 'none');
clearForm();
table.reload('table1');
}
});
},
btn2: function() {
layer.close(index);
$("#_form").css('display', 'none');
},
cancel: function() {
layer.close(index);
$("#_form").css('display', 'none');
}
});
})
function clearForm(){
form.val("form1", {
image_url: '',
banner_url: ''
});
$("#icon1").attr('src', '');
}
//图片上传
var uploader = layui.upload;
$_csrf = $("input[name='_csrf']").val();
uploader.render({
elem: "#upload1",
url: '/admin/image/upload',
data: {_csrf: $_csrf,image_type:2},
done: function (res) {
if(res.code == 0){
$("input[name='image_url']").val(res.data.image_src);
$("#icon1").attr('src', res.data.image_src);
}
},
error: function (res) {
}
});
</script>
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/12/18
* Time: 16:56
*/
namespace common\models\psources;
use common\core\BaseActiveRecord;
use Yii;
class CoinBannerItem extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{coin_banner_item}}';
}
public static function getItems()
{
return self::find()->asArray()->all();
}
public static function getBanner($id)
{
return self::find()->where(['id' => $id])->one();
}
}
\ 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