You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
5.3 KiB
PHP

<?php
namespace Admin\Controller;
use Base\Service\DiscountService;
/**
* 游戏折扣
*/
class DiscountController extends ThinkController
{
public function records()
{
$page = I('p', 1);
$row = I('row', 10);
$baseGameId = I('base_game_id', 0);
$status = I('status', -1);
$where = [
'_string' => '1=1',
];
if ($baseGameId != 0) {
$where['base_game_id'] = $baseGameId;
}
if ($status != -1) {
$where['status'] = $status;
}
if (I('time_start', '') != '') {
$where['_string'] .= ' and end_time>=' . strtotime(I('time_start') . ' 00:00:00');
}
if (I('time_end', '') != '') {
$where['_string'] .= ' and start_time<=' . strtotime(I('time_end') . ' 23:59:59');
}
$query = M('game_discount', 'tab_')->where($where);
$records = [];
if (I('export', 0) == 1 || $row == 'all') {
$records = $query->order('create_time desc')->select();
} else {
$countQuery = clone $query;
$records = $query->order('create_time desc')->page($page, $row)->select();
$count = $countQuery->count();
}
$statusList = [
0 => '关闭',
1 => '开启',
];
$service = new DiscountService();
if (count($records) > 0) {
foreach ($records as $key => $record) {
$isActived = $service->isActived($record);
$records[$key]['status_text'] = $statusList[$record['status']];
$records[$key]['start_time'] = date('Y-m-d H:i:s', $record['start_time']);
$records[$key]['end_time'] = $record['end_time'] == DiscountService::FOREVER_TIME ? '永久' : date('Y-m-d H:i:s', $record['end_time']);
$records[$key]['create_time'] = date('Y-m-d H:i:s', $record['create_time']);
$records[$key]['update_time'] = date('Y-m-d H:i:s', $record['update_time']);
$records[$key]['is_actived'] = $isActived;
$records[$key]['is_actived_text'] = $isActived ? '生效中' : '未生效';
}
if (I('export', 0) == 1) {
$field = [
'base_game_name' => '游戏名称',
'start_time' => '生效时间',
'end_time' => '失效时间',
'status_text' => '状态',
'is_actived_text' => '生效状态',
'first_rate' => '首充折扣',
'second_rate' => '次充折扣',
'create_admin_username' => '添加人',
'create_time' => '添加时间',
'update_admin_username' => '修改人',
'update_time' => '修改时间',
];
addOperationLog(['op_type'=>3,'key'=>getNowDate(),'op_name'=>'导出游戏折扣记录','url'=>U('Discount/records'),'menu'=>'游戏-折扣代金券-游戏折扣-' . '导出游戏折扣记录']);
data2csv($records, '游戏折扣', $field);
exit;
}
}
$page = set_pagination($count, $row == 'all' ? 99999999 : $row);
if($page) {
$this->assign('_page', $page);
}
// $admins = M('ucenter_member', 'sys_')->field(['id', 'username'])->select();
$baseGames = M('base_game', 'tab_')->select();
// $this->assign('admins', $admins);
$this->assign('baseGames', $baseGames);
$this->assign('statusList', $statusList);
$this->assign('records', $records);
$this->display('records');
}
public function delOne()
{
$id = I('id', 0);
try {
$service = new DiscountService();
$service->delete($id);
$this->ajaxReturn([
'status' => 1,
'message' => '操作成功'
]);
} catch (\Exception $e) {
$this->ajaxReturn([
'status' => 0,
'message' => $e->getMessage()
]);
}
}
public function save()
{
$params = I('post.');
try {
$service = new DiscountService();
$service->check($params);
$service->save($params, session('user_auth'));
$this->ajaxReturn([
'status' => 1,
'message' => '操作成功'
]);
} catch (\Exception $e) {
$this->ajaxReturn([
'status' => 0,
'message' => $e->getMessage()
]);
}
}
public function addPage()
{
$this->meta_title = '新增游戏折扣';
$baseGames = M('base_game', 'tab_')->select();
$this->assign('baseGames', $baseGames);
$this->display('form');
}
public function updatePage()
{
$id = I('id', 0);
$gameDiscount = M('game_discount', 'tab_')->where(['id' => $id])->find();
if (is_null($gameDiscount)) {
return $this->error('记录不存在');
}
$this->meta_title = '修改游戏折扣';
$baseGames = M('base_game', 'tab_')->select();
$this->assign('baseGames', $baseGames);
$this->assign('record', $gameDiscount);
$this->display('form');
}
}