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 @@ + + +
# | +备注 | +日期段 | +时间段 | +赠送金额 | +充值金额范围 | +消费起始次数 | +消费结束次数 | +用户类型 | +生效的类型 | +赠送的类型 | +是否启用 | +操作 | +
---|---|---|---|---|---|---|---|---|---|---|---|---|
=$i?> | +=$data['name']?> | ++ + if($data['start_day'] && $data['end_day']) { + echo $data['start_day'] . ' 至 ' . $data['end_day']; + }else{ + echo '-'; + } + ?> + | ++ + if($data['start_time'] && $data['end_time']) { + echo $data['start_time'] . ' 至 ' . $data['end_time']; + }else{ + echo '-'; + } + ?> + | +=$data['price'] ?> | +=$data['start_amount_range']?> ~ =$data['end_amount_range']?> | ++ + echo $data['many_times_consume_start'] == 0 && $data['many_times_consume_end'] == 0 ? '不限' : "第" . $data['many_times_consume_start'] . '次'; + ?> + | ++ + echo $data['many_times_consume_start'] == 0 && $data['many_times_consume_end'] == 0 ? '不限' : "第" . $data['many_times_consume_end'] . '次'; + ?> + | +=$data['user_type_id'] ?> | +=$data['effective_type'] ?> | +=$data['gift_type'] ?> | +=$data['status'] == 1?"启用":"停用" ?> | ++ + | +