191 lines
6.9 KiB
PHP
191 lines
6.9 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
|
// +----------------------------------------------------------------------
|
|
// | Author: yunwuxin <448901948@qq.com>
|
|
// +----------------------------------------------------------------------
|
|
namespace app\activity\admin;
|
|
|
|
use think\Db;
|
|
use app\admin\controller\Admin;
|
|
use app\common\builder\ZBuilder;
|
|
use app\activity\model\Award as AwardModel;
|
|
use app\member\model\Member as MemberModel;
|
|
|
|
|
|
class Award extends Admin
|
|
{
|
|
//主播列表
|
|
public function index(){
|
|
// 获取查询条件
|
|
$map = $this->getMap();
|
|
|
|
// 排序
|
|
$order = $this->getOrder('sort asc');
|
|
|
|
// 数据列表
|
|
$map[] = ['id','neq',9];
|
|
$data_list = AwardModel::where($map)->order($order)->paginate();
|
|
|
|
//加载模板
|
|
return ZBuilder::make('table')
|
|
->setPageTitle('奖品设置')// 设置页面标题
|
|
->setTableName('award')
|
|
->addOrder('create_time') // 添加排序
|
|
->addColumns([ // 批量添加列
|
|
['sort', '排序(升序排序)','text.edit'],
|
|
['thumb', '奖品图片','picture'],
|
|
['title', '奖品名称'],
|
|
['jp_number', '开奖累计次数'],
|
|
['open_num', '已开奖次数'],
|
|
['right_button', '操作', 'btn']
|
|
])
|
|
//->addTopButton('add',['class'=>'btn btn-primary','icon' => 'fa fa-plus-circle','title'=>'新增', 'href' => url('add')],['area' => ['600px', '60%']])
|
|
->addTopButton('export',[
|
|
'title' => '设置抽奖扣除金币数量',
|
|
'icon' => 'fa fa-fw fa-minus',
|
|
'class' => 'btn btn-info export confirm',
|
|
'href' => url('setgoldcoin'),
|
|
'data-url' => url('setgoldcoin')
|
|
],['area' => ['600px', '60%']]) // 导出
|
|
->addRightButton('edit',['title'=>'編輯','icon'=>'fa fa-pencil','href'=>url('edit',['id' => '__id__'])],['area' => ['600px', '60%']])
|
|
//->addRightButton('delete', ['title' => '删除', 'icon' => 'fa fa-remove', 'href' => url('delete', ['id' => '__id__'])])
|
|
->setRowList($data_list)// 设置表格数据
|
|
->fetch(); // 渲染模板
|
|
}
|
|
|
|
public function setgoldcoin(){
|
|
if($this->request->isPost()){
|
|
$data = $this->request->post();
|
|
|
|
if(empty($data['jp_number'])){
|
|
return $this->error('请输入需要扣除的金币');
|
|
}
|
|
|
|
$data['update_time'] = time();
|
|
$result = AwardModel::update($data);
|
|
if($result){
|
|
$this->success('修改成功', url('index'),'_parent_reload');
|
|
}else{
|
|
$this->error('修改失败');
|
|
}
|
|
} else {
|
|
$info = AwardModel::where('id',9)->find();
|
|
return ZBuilder::make('form')
|
|
->addFormItems([//批量添加表单项
|
|
['hidden', 'id'],
|
|
['text', 'jp_number', '扣除金币'],
|
|
])
|
|
->setFormData($info)
|
|
->fetch();
|
|
}
|
|
}
|
|
|
|
|
|
//添加
|
|
public function add(){
|
|
if($this->request->isPost()){
|
|
$data = $this->request->post();
|
|
|
|
if(empty($data['title'])){
|
|
return $this->error('奖品名称不能为空');
|
|
}
|
|
|
|
$result = AwardModel::create($data);
|
|
if($result){
|
|
$this->success('新增成功', url('index'),'_parent_reload');
|
|
}else{
|
|
$this->error('新增失败');
|
|
}
|
|
}else{
|
|
return ZBuilder::make('form')
|
|
->addFormItems([//批量添加表单项
|
|
['image', 'thumb', '奖品图片', '<code>必上传</code>'],
|
|
['text', 'title', '奖品名称'],
|
|
['text', 'jp_number', '开奖累计次数'],
|
|
['text', 'sort', '排序(升序排序)','',9999],
|
|
])
|
|
->fetch();
|
|
}
|
|
}
|
|
|
|
//编辑
|
|
public function edit($id=null){
|
|
if ($id === null) return $this->error('缺少参数');
|
|
|
|
if($this->request->isPost()){
|
|
$data = $this->request->post();
|
|
|
|
if(empty($data['title'])){
|
|
return $this->error('奖品名称不能为空');
|
|
}
|
|
$data['update_time'] = time();
|
|
$result = AwardModel::update($data);
|
|
if($result){
|
|
$this->success('修改成功', url('index'),'_parent_reload');
|
|
}else{
|
|
$this->error('修改失败');
|
|
}
|
|
} else {
|
|
$info = AwardModel::get($id);
|
|
|
|
if($id==1){
|
|
$formitems = [
|
|
['hidden', 'id'],
|
|
['image', 'thumb', '奖品图片', '<code>必上传</code>'],
|
|
['text', 'title', '奖品名称'],
|
|
['text', 'jp_number', '开奖累计次数(谢谢参与中奖次数)'],
|
|
['text', 'sort', '排序(升序排序)','',9999],
|
|
];
|
|
}
|
|
|
|
if($id==2 || $id==3 || $id==4){
|
|
$formitems = [
|
|
['hidden', 'id'],
|
|
['image', 'thumb', '奖品图片', '<code>必上传</code>'],
|
|
['text', 'title', '奖品名称'],
|
|
['text', 'sort', '排序(升序排序)','',9999],
|
|
];
|
|
}
|
|
|
|
if($id==5 || $id==6 || $id==7 || $id==8){
|
|
$formitems = [
|
|
['hidden', 'id'],
|
|
['image', 'thumb', '奖品图片', '<code>必上传</code>'],
|
|
['text', 'title', '奖品名称'],
|
|
['text', 'jp_number', '开奖累计次数(抽奖累次次数)'],
|
|
['text', 'sort', '排序(升序排序)','',9999],
|
|
];
|
|
}
|
|
|
|
return ZBuilder::make('form')
|
|
->addFormItems($formitems)
|
|
->setFormData($info)
|
|
->fetch();
|
|
}
|
|
}
|
|
|
|
//删除
|
|
public function delete($id = null)
|
|
{
|
|
if ($id === null) {
|
|
$this->error('缺少参数');
|
|
}
|
|
|
|
$data = AwardModel::where('id',$id)->find();
|
|
if (empty($data)) {$this->error('删除成功!'); }
|
|
|
|
$result = AwardModel::where('id',$id)->delete();
|
|
if($result) {
|
|
return $this->success('删除成功!');
|
|
}else{
|
|
return $this->error('删除失败!');
|
|
}
|
|
}
|
|
|
|
|
|
} |