作者 景龙
1 个管道 的构建 通过 耗费 1 秒

增加商城banner图

<?php
namespace app\admin\controller;
use app\common\controller\Backend;
/**
* 商城banner图标
*
* @icon fa fa-circle-o
*/
class Gbanner extends Backend
{
/**
* Gbanner模型对象
* @var \app\admin\model\Gbanner
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\Gbanner;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
}
... ...
<?php
return [
'Id' => 'ID',
'Image' => '图片',
'Createtime' => '创建时间',
];
... ...
<?php
namespace app\admin\model;
use think\Model;
class Gbanner extends Model
{
// 表名
protected $name = 'gbanner';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'deletetime_text'
];
public function getDeletetimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['deletetime']) ? $data['deletetime'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setDeletetimeAttr($value)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}
}
... ...
<?php
namespace app\admin\validate;
use think\Validate;
class Gbanner extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}
... ...
<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">{:__('Image')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-image" data-rule="required" class="form-control" size="50" name="row[image]" type="text" value="">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="plupload-image" class="btn btn-danger plupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-image"></span>
</div>
<ul class="row list-inline plupload-preview" id="p-image"></ul>
</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-success 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">{:__('Image')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-image" data-rule="required" class="form-control" size="50" name="row[image]" type="text" value="{$row.image}">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="plupload-image" class="btn btn-danger plupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-image"></span>
</div>
<ul class="row list-inline plupload-preview" id="p-image"></ul>
</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-success 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">
{:build_heading()}
<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('gbanner/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('gbanner/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('gbanner/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<!--<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('gbanner/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>-->
<div class="dropdown btn-group {:$auth->check('gbanner/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('gbanner/edit')}"
data-operate-del="{:$auth->check('gbanner/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -53,8 +53,8 @@ class Index extends Api
}
/**
* @ApiTitle (获取banner图)
* @ApiSummary (获取banner图)
* @ApiTitle (获取首页banner图)
* @ApiSummary (获取首页banner图)
* @ApiMethod (GET)
* @ApiRoute (/api/index/getBanner)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
... ... @@ -84,4 +84,37 @@ class Index extends Api
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (获取商城banner图)
* @ApiSummary (获取商城banner图)
* @ApiMethod (GET)
* @ApiRoute (/api/index/getGoodsBanner)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1553831004",
"data": [
{
"id": 1,
"image": "http://feipin.w.brotop.cn/uploads/20190319/4a4c015ca04593f70a4836da45f2dea4.jpg"//banner图
},
{
"id": 2,
"image": "http://feipin.w.brotop.cn/uploads/20190319/4d82786ab0f7866110519f221cbf29a6.jpg"
},
]
})
*/
public function getGoodsBanner(){
if($this->request->isGet()){
$data = Db::table('gc_gbanner')
->field('id,image')
->select();
$this->success('成功', $data);
}else{
$this->error('请求方式错误');
}
}
}
... ...
... ... @@ -45,6 +45,7 @@ class Person extends Api
"license_num": "",//公司编码
"license_img": ""//公司营业执照
"money":100//账户余额
"avatar"://头像
}
})
*/
... ... @@ -52,7 +53,7 @@ class Person extends Api
if($this->request->isGet()){
$data = Db::table('gc_user')
->where(['id'=>$this->user_id])
->field('id,username,mobile,type,address,id_num,id_img,company_name,license_num,license_img,money')
->field('id,nickname,username,mobile,type,address,id_num,id_img,company_name,license_num,license_img,money,avatar')
->find();
$this->success('成功', $data);
}else{
... ...
此 diff 太大无法显示。
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'gbanner/index',
add_url: 'gbanner/add',
edit_url: 'gbanner/edit',
del_url: 'gbanner/del',
multi_url: 'gbanner/multi',
table: 'gbanner',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'image', title: __('Image'), formatter: Table.api.formatter.image},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
// {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
// {field: 'deletetime', title: __('Deletetime'), operate:'RANGE', addclass:'datetimerange', 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;
});
\ No newline at end of file
... ...