From 10d3156c8eb6bbfd1641bc1c0c03d9de7c9c4f2a Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Wed, 18 Aug 2021 14:06:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=B8=E6=88=8F=E6=8A=98=E6=89=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/DiscountController.class.php | 159 +++++++++++ Application/Admin/View/Discount/form.html | 202 ++++++++++++++ Application/Admin/View/Discount/records.html | 261 ++++++++++++++++++ .../Base/Service/DiscountService.class.php | 101 +++++++ .../Base/Service/VoucherService.class.php | 7 + 5 files changed, 730 insertions(+) create mode 100644 Application/Admin/Controller/DiscountController.class.php create mode 100644 Application/Admin/View/Discount/form.html create mode 100644 Application/Admin/View/Discount/records.html create mode 100644 Application/Base/Service/DiscountService.class.php create mode 100644 Application/Base/Service/VoucherService.class.php diff --git a/Application/Admin/Controller/DiscountController.class.php b/Application/Admin/Controller/DiscountController.class.php new file mode 100644 index 000000000..97a0528d1 --- /dev/null +++ b/Application/Admin/Controller/DiscountController.class.php @@ -0,0 +1,159 @@ + '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'); + } +} diff --git a/Application/Admin/View/Discount/form.html b/Application/Admin/View/Discount/form.html new file mode 100644 index 000000000..0830ab94f --- /dev/null +++ b/Application/Admin/View/Discount/form.html @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
*启用状态 + + + + + 设置该游戏是否开启使用折扣券 公式:需支付金额 = (原价 - 平台币) * 折扣 +
*折扣游戏: + + +
*生效时间(开始): + +
生效时间(结束): + +
首充折扣: +  折 + 首次充值使用该折扣,请输入数字,支持小数点后一位,例如: 7.8;默认为空,表示不打折 +
次充折扣: +  折 + 第二次(包含)充值以后使用该折扣,请输入数字,支持小数点后一位,例如: 7.8;默认为空,表示不打折 +
+
+ +
+ + + 返回 + +
+
+
+
+ + +
+ + + + if(C('COLOR_STYLE')=='blue_color') echo ''; + + + + + \ No newline at end of file diff --git a/Application/Admin/View/Discount/records.html b/Application/Admin/View/Discount/records.html new file mode 100644 index 000000000..09a2a07e3 --- /dev/null +++ b/Application/Admin/View/Discount/records.html @@ -0,0 +1,261 @@ + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+ + - +
+ + +
+
+
+ +
+
+ 搜索 +
+ +
+
+ +
+
+ 新增 +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
游戏名称生效时间失效时间状态首充折扣次充折扣添加人添加时间修改人修改时间操作
aOh! 暂时还没有内容!
{$data.base_game_name}{$data.start_time}{$data.end_time}{$data.status_text} (生效中){$data.first_rate}{$data.second_rate}{$data.create_admin_username}{$data.create_time}{$data.update_admin_username}{$data.update_time}编辑
+
+
+
+ 导出 + {$_page|default=''} +
+ + +
+ + + + + + + + \ No newline at end of file diff --git a/Application/Base/Service/DiscountService.class.php b/Application/Base/Service/DiscountService.class.php new file mode 100644 index 000000000..bf290e093 --- /dev/null +++ b/Application/Base/Service/DiscountService.class.php @@ -0,0 +1,101 @@ +where(['id' => $params['base_game_id']])->find(); + $data = [ + 'base_game_id' => $params['base_game_id'], + 'base_game_name' => $baseGame['name'], + 'start_time' => strtotime($params['start_time']), + 'end_time' => empty($params['end_time']) ? self::FOREVER_TIME : strtotime($params['end_time']), + 'first_rate' => $params['first_rate'], + 'second_rate' => $params['second_rate'], + 'status' => $params['status'], + ]; + + $data['update_time'] = time(); + $data['update_admin_id'] = $admin ? $admin['uid'] : 0; + $data['update_admin_username'] = $admin ? $admin['username'] : ''; + + if ($id > 0) { + M('game_discount', 'tab_')->where(['id' => $id])->save($data); + } else { + $data['create_time'] = time(); + $data['create_admin_id'] = $admin ? $admin['uid'] : 0; + $data['create_admin_username'] = $admin ? $admin['username'] : ''; + M('game_discount', 'tab_')->add($data); + } + } + + public function check($params) + { + $id = $params['id'] ?? 0; + if (empty($params['base_game_id'])) { + throw new \Exception('请选择游戏'); + } + + if (empty($params['start_time'])) { + throw new \Exception('请选择生效时间'); + } + + if (empty($params['base_game_id'])) { + throw new \Exception('请选择游戏'); + } + + $startTime = strtotime($params['start_time'] . ' 00:00:00'); + $endTime = empty($params['end_time']) ? self::FOREVER_TIME : strtotime($params['end_time'] . ' 23:59:59'); + if ($endTime < $startTime) { + throw new \Exception('生效开始时间不能大于结束时间'); + } + + $firstRate = $params['first_rate'] ?? 0; + $secondRate = $params['second_rate'] ?? 0; + // /^[0-9]+(.[0-9]{1,2})?$/ + if (!preg_match('/^[0-9]+(.[0-9]{1})?$/', $firstRate)) { + throw new \Exception('首充折扣为大于等于0的整数或者一位小数'); + } + if (!preg_match('/^[0-9]+(.[0-9]{1})?$/', $secondRate)) { + throw new \Exception('次充折扣为大于等于0的整数或者一位小数'); + } + + if ($id > 0) { + $record = M('game_discount', 'tab_')->where(['id' => $id])->find(); + if ($record['end_time'] < time()) { + throw new \Exception('生效时间已过,不可修改'); + } + } + + $map = []; + $map['base_game_id'] = $params['base_game_id']; + $map['_string'] = 'NOT (end_time < ' . $startTime . ' OR start_time > ' . $endTime . ')'; + if ($id > 0) { + $map['_string'] .= ' and id<>' . $id; + } + $item = M('game_discount', 'tab_')->where($map)->limit(1)->find(); + if ($item) { + throw new \Exception('该游戏在相同时间区间已存在打折规则'); + } + } + + public function delete($id) + { + M('game_discount', 'tab_')->where(['id' => $id])->delete(); + } + + public function isActived($record) + { + if ($record['status'] == 0) { + return false; + } + if ($record['start_time'] <= time() && $record['end_time'] >= time()) { + return true; + } + return false; + } +} \ No newline at end of file diff --git a/Application/Base/Service/VoucherService.class.php b/Application/Base/Service/VoucherService.class.php new file mode 100644 index 000000000..2591cbe87 --- /dev/null +++ b/Application/Base/Service/VoucherService.class.php @@ -0,0 +1,7 @@ +