From ebb5c92cb5cdd2517485b02277aa9895832b5ce9 Mon Sep 17 00:00:00 2001 From: vguanyiwgd Date: Wed, 5 Jun 2024 09:51:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=85=E5=80=BC=E8=B5=A0?= =?UTF-8?q?=E9=80=81=E5=8A=9F=E8=83=BD(=E5=90=8E=E7=AB=AF=E5=85=85?= =?UTF-8?q?=E5=80=BC+=E9=85=8D=E7=BD=AE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I17e6561c5edfbbcb9194d5387966e3560370f814 --- .../api/controllers/api/Recharge.php | 7 + .../application/api/models/User_model.php | 7 + .../backstage/controllers/Recharge.php | 224 ++++++++++++- .../backstage/models/Recharge_model.php | 4 + .../backstage/views/recharge/config/edit.php | 293 ++++++++++++++++++ .../backstage/views/recharge/config/index.php | 172 ++++++++++ .../backstage/views/recharge/config/list.php | 76 +++++ .../js/bootstrap-datetimepicker.js | 17 +- .../system/libraries/Recharge_config.php | 119 +++++++ show/include/pay.inc.php | 2 + 10 files changed, 918 insertions(+), 3 deletions(-) create mode 100644 backstage/application/backstage/views/recharge/config/edit.php create mode 100644 backstage/application/backstage/views/recharge/config/index.php create mode 100644 backstage/application/backstage/views/recharge/config/list.php create mode 100644 backstage/system/libraries/Recharge_config.php diff --git a/backstage/application/api/controllers/api/Recharge.php b/backstage/application/api/controllers/api/Recharge.php index f571bbf..811fa4d 100644 --- a/backstage/application/api/controllers/api/Recharge.php +++ b/backstage/application/api/controllers/api/Recharge.php @@ -919,4 +919,11 @@ class Recharge extends REST_Controller } return $result; } + + public function get_give_fee_post(){ + $fee = $this->input->post('fee'); + $userInfo = $this->user; + $this->load->library('Recharge_config'); + echo $this->recharge_config->rechargeRule((object)$userInfo, $userInfo->company_id, $fee, 1); + } } \ No newline at end of file diff --git a/backstage/application/api/models/User_model.php b/backstage/application/api/models/User_model.php index b5d53dd..7c3161a 100644 --- a/backstage/application/api/models/User_model.php +++ b/backstage/application/api/models/User_model.php @@ -172,6 +172,13 @@ class User_model extends CI_Model return $query->row(); } + /** + * @param $ids id字符串列表 + */ + public function get_user_type_by_ids($ids){ + return $this->db->query("select * from tb_user_type where enabled=1 and company_id='".$this->session->userdata('companyId')."' and id in ({$ids})")->result_array(); + } + public function get_payqr($uid) { $query = $this->db->query("select * from tb_payqr where uid = {$uid} and oid=0 order by expire desc limit 1"); diff --git a/backstage/application/backstage/controllers/Recharge.php b/backstage/application/backstage/controllers/Recharge.php index 98193ee..c45c731 100644 --- a/backstage/application/backstage/controllers/Recharge.php +++ b/backstage/application/backstage/controllers/Recharge.php @@ -495,6 +495,36 @@ class Recharge extends CI_Controller } //print_r($detail);exit; $r = gpay_add_user_account_uid($detail['user_id'], floatval($detail['jf']), $payInfo, $updateInfo); + + // 判断充值是否成功 + if($r == 'suc'){ + // 判断是否是现金账户充值 + if($jobInfo['account_type_id'] == 2){ + // 判断是否有充值赠送 + $this->load->library('Recharge_config'); + $rechargeInfo = $this->recharge_config->rechargeRule((object)$rowUser, $rowUser['company_id'], floatval($detail['jf']), 2); + $rechargeInfo = json_decode($rechargeInfo, 1); + if($rechargeInfo['status'] == 1) { + $giveFee = $rechargeInfo['data']['gift_fee']; + if($giveFee > 0){ + $rechargePayInfo = array( + 'admin_id' => $adminId, + 'rtype' => 1, + 'ac_type' => 1, + 'supplier_id' => $supplierId, + 'notes' => '充值赠送', + ); + $r = gpay_add_user_account_uid($detail['user_id'], floatval($giveFee), $rechargePayInfo); + if ($r == 'suc') { + $giveContent = ",赠送金额充值成功。"; + }else{ + $giveContent = ",赠送金额充值失败。"; + } + } + + } + } + } break; case 6: $action = '扣费'; @@ -1050,7 +1080,30 @@ class Recharge extends CI_Controller $sms = array($cellphone, $content); $smsList = array($sms); //send_sms_p($smsList); - lwReturn(true, array('msg' => '充值成功')); + // 获取充值在赠送金额 + $this->load->library('Recharge_config'); + $rechargeInfo = $this->recharge_config->rechargeRule((object)$userInfo, $userInfo['company_id'], $count, 2); + $rechargeInfo = json_decode($rechargeInfo, 1); + if($rechargeInfo['status'] == 1){ + $giveFee = $rechargeInfo['data']['gift_fee']; + if($giveFee > 0){ + $rechargePayInfo = array( + 'admin_id' => $adminId, + 'rtype' => 1, + 'ac_type' => 1, + 'supplier_id' => $supplierId, + 'notes' => '充值赠送', + ); + $r = gpay_add_user_account_uid($userInfo['id'], floatval($giveFee), $rechargePayInfo); + if ($r == 'suc') { + $giveContent = ",赠送金额充值成功。"; + }else{ + $giveContent = ",赠送金额充值失败。"; + } + } + } + + lwReturn(true, array('msg' => '充值成功'.$giveContent)); } else { lwReturn(false, array('msg' => '充值失败')); } @@ -1306,5 +1359,174 @@ class Recharge extends CI_Controller return true; } + // 充值赠送配置 + public function rechargeConfigIndex(){ + $data['asset'] = $this->asset; + $data['pageTitle'] = '充值赠送配置'; + $data['breadcrumb'] = array(array('充值赠送配置',null)); + // 只能查询当前公司的配置 + $this->lw_load->normalLoad($data,'recharge/config/index'); + } + + // 列表 + public function rechargeConfigList($page){ + $this->load->library('lw_pagination2'); + $param = $this->input->post('param'); + $start_day = $this->input->post('start_day'); + $end_day = $this->input->post('end_day'); + $start_time = $this->input->post('start_time'); + $end_time = $this->input->post('end_time'); + $name = $this->input->post('name'); + + $companyId = $this->session->userdata('companyId'); + + $this->load->model('user_model'); + + $where = " company_id='{$companyId}' "; + if($start_day){ + $where .= " and start_day>='{$start_day}' "; + } + if($end_day){ + $where .= " and end_day<='{$end_day}' "; + } + if($start_time){ + $where .= " and start_time>='{$start_time}' "; + } + if($end_time){ + $where .= " and end_time<='{$end_time}' "; + } + if($name){ + $where .= " and name like '%{$name}%' "; + } + + $sql = "SELECT + * + from + tb_recharge_config + where {$where} + "; + + $hasWhere = true; + $group = null; + $order = "gift_type asc, idx desc"; + $action = "getListByPage"; + $dataName='dataList'; + $paramFilter = array('name'); + $data = $this->lw_pagination2->lists($sql,$param,$page,$hasWhere,$group,$order,$action,$dataName,$paramFilter); + + foreach ($data['dataList'] as $k => $v){ + if($v['user_type_id'] == '*'){ + $data['dataList'][$k]['user_type_id'] = "全部"; + }else{ + $user_type_id = explode(',', $v['user_type_id']); + // 去重 + $user_type_id = array_unique($user_type_id); + $user_type_ids = join(",", $user_type_id); + $user_type_list = $this->user_model->get_user_type_by_ids($user_type_ids); + $user_type_name = array_column($user_type_list, 'name'); + $data['dataList'][$k]['user_type_id'] = join(',', $user_type_name); + } + $data['dataList'][$k]['effective_type'] = $v['effective_type'] == 1 ? "app充值" : "后台充值"; + $data['dataList'][$k]['gift_type'] = $v['gift_type'] == 1 ? "每年" : "每次"; + } + echo $this->load->view('recharge/config/list',$data,true); + } + + + // 修改充值赠送配置 + public function rechargeConfigEdit($id){ + $this->load->model('recharge_model'); + $companyId = $this->session->userdata('companyId'); + $this->load->library('lw_db', array('tb_name' => 'tb_recharge_config'), 'tb_recharge_config'); + + $info = $this->input->post(); + if(isset($info['doSubmit'])){ + $data['name'] = trim($info['name']); + $data['price'] = trim($info['price']); + $data['start_amount_range'] = trim($info['start_amount_range']); + $data['end_amount_range'] = trim($info['end_amount_range']); + $data['start_day'] = trim($info['start_day']); + $data['end_day'] = trim($info['end_day']); + + $data['start_time'] = trim($info['start_time']); + $data['end_time'] = trim($info['end_time']); + + $data['many_times_consume_start'] = trim($info['many_times_consume_start']); + $data['many_times_consume_end'] = trim($info['many_times_consume_end']); + + $data['user_type_id'] = $info['user_type_id']; + $data['effective_type'] = $info['effective_type']; + $data['gift_type'] = $info['gift_type']; + $data['status'] = $info['status']; + + if(empty($data['name'])){ + echo $this->lw_load->jsonResult(false,array('msg'=>'备注不能为空')); + exit; + }elseif($data['price'] === '' || $data['price'] === null) { + echo $this->lw_load->jsonResult(false, array('msg' => '赠送金额不能为空')); + exit; + }elseif($data['start_amount_range'] === '' || $data['start_amount_range'] === null) { + echo $this->lw_load->jsonResult(false, array('msg' => '起始金额不能为空')); + exit; + }elseif($data['end_amount_range'] === '' || $data['end_amount_range'] === null) { + echo $this->lw_load->jsonResult(false, array('msg' => '结束金额不能为空')); + exit; + }elseif($data['start_day'] > $data['end_day']) { + echo $this->lw_load->jsonResult(false, array('msg' => '开始日期不能大于结束日期')); + exit; + }elseif(empty($data['start_time'])){ + echo $this->lw_load->jsonResult(false,array('msg'=>'开始时间不能为空')); + exit; + }elseif(empty($data['end_time'])){ + echo $this->lw_load->jsonResult(false,array('msg'=>'结束时间不能为空')); + exit; + }elseif($data['start_time'] > $data['end_time']){ + echo $this->lw_load->jsonResult(false, array('msg' => '开始时间不能大于结束时间')); + exit; + }elseif($data['many_times_consume_start'] === '' || $data['many_times_consume_start'] == null){ + echo $this->lw_load->jsonResult(false,array('msg'=>'消费起始次数不能为空')); + exit; + }elseif($data['many_times_consume_end'] == '' || $data['many_times_consume_end'] == null){ + echo $this->lw_load->jsonResult(false,array('msg'=>'消费结束次数不能为空')); + exit; + }elseif(empty($data['user_type_id'])){ + echo $this->lw_load->jsonResult(false,array('msg'=>'用户类型不能为空')); + exit; + }elseif(empty($data['effective_type'])){ + echo $this->lw_load->jsonResult(false,array('msg'=>'充值生效类型不能为空')); + exit; + }elseif(empty($data['gift_type'])){ + echo $this->lw_load->jsonResult(false,array('msg'=>'赠送类型不能为空')); + exit; + } + + if(in_array("*", $data['user_type_id'])){ + $data['user_type_id'] = '*'; + }else{ + $data['user_type_id'] = ",".join(",", $data['user_type_id']).","; + } + + echo $this->lw_load->jsonResult($this->tb_recharge_config->update($data, "id='{$id}'"),array('msg'=>'修改规则成功!')); + }else{ + $this->asset = $this->lw_assets->select2($this->asset); + $data['asset'] = $this->asset; + $configInfo = $this->recharge_model->getRechargeConfigById($id); + if(empty($configInfo)){ + echo $this->lw_load->jsonResult(false,array('msg'=>'获取规则信息失败!')); + exit; + } + + $user_type_id = explode(',', $configInfo['user_type_id']); + // 去重 + $user_type_ids = array_unique($user_type_id); + $data['config_user_type_id'] = $user_type_ids; + + $data['user_type_list'] = $this->db->query("select id,name from tb_user_type where enabled=1 and company_id='".$companyId."'")->result_array(); + $data['info'] = $configInfo; + $data['id'] = $configInfo['id']; + echo $this->load->view('recharge/config/edit',$data,true); + + } + } } diff --git a/backstage/application/backstage/models/Recharge_model.php b/backstage/application/backstage/models/Recharge_model.php index 5fdefbd..ebf877d 100644 --- a/backstage/application/backstage/models/Recharge_model.php +++ b/backstage/application/backstage/models/Recharge_model.php @@ -481,4 +481,8 @@ class Recharge_model extends CI_Model $data['pageHtml'] = $this->load->view('template/pagination', $data, true); return $data; } + + public function getRechargeConfigById($id){ + return $this->db->get_where('tb_recharge_config', array('id' => $id))->row_array(); + } } diff --git a/backstage/application/backstage/views/recharge/config/edit.php b/backstage/application/backstage/views/recharge/config/edit.php new file mode 100644 index 0000000..d80e971 --- /dev/null +++ b/backstage/application/backstage/views/recharge/config/edit.php @@ -0,0 +1,293 @@ + + + + \ No newline at end of file diff --git a/backstage/application/backstage/views/recharge/config/index.php b/backstage/application/backstage/views/recharge/config/index.php new file mode 100644 index 0000000..7603d7b --- /dev/null +++ b/backstage/application/backstage/views/recharge/config/index.php @@ -0,0 +1,172 @@ + +
+ + +
+
+
+

信息

+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/backstage/application/backstage/views/recharge/config/list.php b/backstage/application/backstage/views/recharge/config/list.php new file mode 100644 index 0000000..f4aa55e --- /dev/null +++ b/backstage/application/backstage/views/recharge/config/list.php @@ -0,0 +1,76 @@ + +
+
+ + + + + + + + + + + + + + + + + + + + 当前没有数据"; + } else { + $i = 1; + foreach ($dataList as $data): ?> + + + + + + + + + + + + + + + + + +
#备注日期段时间段赠送金额充值金额范围消费起始次数消费结束次数用户类型生效的类型赠送的类型是否启用操作
+ + + + ~ + + + + + +
+
+
diff --git a/backstage/assets/plugins/datetimepicker/js/bootstrap-datetimepicker.js b/backstage/assets/plugins/datetimepicker/js/bootstrap-datetimepicker.js index 9f0bb79..3ae19c9 100644 --- a/backstage/assets/plugins/datetimepicker/js/bootstrap-datetimepicker.js +++ b/backstage/assets/plugins/datetimepicker/js/bootstrap-datetimepicker.js @@ -778,7 +778,16 @@ html.push('' + hours + ':' + (i < 10 ? '0' + i : i) + ''); } } - this.picker.find('.datetimepicker-minutes td').html(html.join('')); + // this.picker.find('.datetimepicker-minutes td').html(html.join('')); + var addSec = /,s{1,2},/.test( ',' + this.format.parts.join( ',') + ','), sSec = addSec ? '
秒:
'; + } + this.picker.find( '.datetimepicker-minutes td').html(html.join( '') + sSec); var currentYear = this.date.getUTCFullYear(); var months = this.setTitle('.datetimepicker-months', year) @@ -919,6 +928,8 @@ click: function (e) { e.stopPropagation(); e.preventDefault(); + ///防止选择秒钟选择器日期控件层隐藏 + if (e.target.tagName == 'SELECT' || e.target.tagName == 'OPTION') return; var target = $(e.target).closest('span, td, th, legend'); if (target.is('.' + this.icontype)) { target = $(target).parent().closest('span, td, th, legend'); @@ -996,7 +1007,9 @@ day = this.viewDate.getUTCDate(), hours = this.viewDate.getUTCHours(), minutes = this.viewDate.getUTCMinutes(), - seconds = this.viewDate.getUTCSeconds(); + // seconds = this.viewDate.getUTCSeconds(); +//修改datetimepicker秒钟获取方式 + seconds = this.addSec ? this.picker.find( 'select').val() : this.viewDate.getUTCSeconds(); if (target.is('.month')) { this.viewDate.setUTCDate(1); diff --git a/backstage/system/libraries/Recharge_config.php b/backstage/system/libraries/Recharge_config.php new file mode 100644 index 0000000..e5f0850 --- /dev/null +++ b/backstage/system/libraries/Recharge_config.php @@ -0,0 +1,119 @@ +CI = &get_instance(); + $this->CI->load->database(); + } + + /** + * @param $userInfo 用户信息 object + * @param $companyId 公司ID + * @param $fee 充值金额 + * @param $effective_type 生效的类型:1app,2后台 + * @return void + */ + public function rechargeRule($userInfo, $companyId, $fee, $effective_type=1){ + $gift_fee = 0; + + // 把金额转换为分 + $where = " + status='1' + and company_id='{$companyId}' + and '{$fee}' between start_amount_range and end_amount_range + and effective_type='{$effective_type}' + "; + + $rule_where = $where . " and (CURDATE() BETWEEN start_day and end_day) and (CURTIME() BETWEEN start_time and end_time) "; + $datetime_pz = $this->get_recharge_rule($rule_where); + + $pz = array(); + if(!empty($datetime_pz)){ + $pz = $datetime_pz; + } + + $rule_where = $where . " and CURTIME() BETWEEN start_time and end_time and start_day is null and end_day is null"; + $time_pz = $this->get_recharge_rule($rule_where); + $pz = array_merge($pz, $time_pz); + + if($pz) { + foreach ($pz as $k => $v) { + $user_type_id = explode(',', $v['user_type_id']); + if ($v['user_type_id'] != '*' || (!in_array($userInfo->type_id, $user_type_id) && !in_array('*', $user_type_id))) { + // 如果规则不含有用户类型 && 不含有*,则跳过 + continue; + } + if($v['gift_type'] == 1){ + // 每年赠送 + // 获取今年的充值次数 + $year_count = $this->get_recharge_count($userInfo->id, $v['gift_type']); + + if($year_count != 0){ + $year_count = $year_count+1; + } + if($v['many_times_consume_start'] == 0 && $v['many_times_consume_end'] == 0){ + // 无限制 + $gift_fee = $v['price']; + }elseif($year_count >= $v['many_times_consume_start'] && $year_count <= $v['many_times_consume_end']){ + // 在规则的次数内 + $gift_fee = $v['price']; + }else{ + // 不在规则的次数内,pass + continue; + } + }else{ + $count = $this->get_recharge_count($userInfo->id, $v['gift_type']); + if($count != 0){ + $count = $count+1; + } + // 每次赠送 + if($v['many_times_consume_start'] == 0 && $v['many_times_consume_end'] == 0) { + // 无限制 + $gift_fee = $v['price']; + }elseif($count >= $v['many_times_consume_start'] && $count <= $v['many_times_consume_end']){ + // 在规则的次数内 + $gift_fee = $v['price']; + }else{ + // 不在规则的金额内,pass + continue; + } + } + } + } + + return json_encode(array( + 'status' => 1, + 'message' => 'success', + 'data' => array( + 'recharge_fee' => $fee, + 'gift_fee' => $gift_fee + ) + )); + } + + private function get_recharge_rule($where){ + $sql = "select * from tb_recharge_config where {$where} order by gift_type asc, idx desc"; + return $this->CI->db->query($sql)->result_array(); + } + + /** + * @param $userId 用户ID + * @param $gift_type 赠送类型:1每年赠送,2每次赠送 + * @return mixed + */ + private function get_recharge_count($userId, $gift_type){ + if($gift_type == 1){ + // 每年赠送 + return $this->CI->db->query("select count(id) as num from tb_recharge where user_id=? and type=1 and YEAR(record_datetime) = YEAR(CURDATE())", array($userId))->row()->num; + }else{ + // 每次赠送 + return $this->CI->db->query("select count(id) as num from tb_recharge where user_id=? and type=1", array($userId))->row()->count; + } + } + + +} + diff --git a/show/include/pay.inc.php b/show/include/pay.inc.php index 094c70e..644efa6 100644 --- a/show/include/pay.inc.php +++ b/show/include/pay.inc.php @@ -528,6 +528,7 @@ function gpay_add_user_account($account_id, $ac, $info, &$updateInfo = '') $extra_fee = intval($info['extra_fee']); $to_account_id = intval($info['to_account_id']); $from_account_id = intval($info['from_account_id']); + $notes = addslashes($info['notes']) ?: null; if ($ac < 0) return 'err'; $aInfo = gpay_get_account_by_id($account_id); @@ -558,6 +559,7 @@ function gpay_add_user_account($account_id, $ac, $info, &$updateInfo = '') 'extra_fee' => $extra_fee, 'to_account_id' => $to_account_id, 'from_account_id' => $from_account_id, + 'notes' => $notes, ); $isql = ''; foreach ($jinfo as $key => $value) {