123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- <?php
- class refill_refundControl extends SystemControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- $mod = Model('refill_refund');
- $condition = [];
- if(!empty($_GET['provider_id'])) {
- $condition['provider_id'] = $_GET['provider_id'];
- }
- if(!empty($_GET['mchid'])) {
- $condition['mchid'] = $_GET['mchid'];
- }
- if(!empty($_GET['card_nos'])) {
- $card_nos = trim($_GET['card_nos'], ',');
- $condition['card_no'] = ['in', $card_nos];
- }
- $start_unixtime = intval(strtotime($_GET['query_start_time']));
- $end_unixtime = intval(strtotime($_GET['query_end_time']));
- if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
- $condition['refund_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
- } elseif ($start_unixtime > 0) {
- $condition['refund_time'] = ['egt', $start_unixtime];
- } elseif ($end_unixtime > 0) {
- $condition['refund_time'] = ['lt', $end_unixtime];
- }
- $providers = [];
- $provider_list = $this->providers();
- foreach ($provider_list as $provider) {
- $providers[$provider['provider_id']] = $provider;
- }
- $merchants = [];
- $merchant_list = $this->merchants();
- foreach ($merchant_list as $value) {
- $merchants[$value['mchid']] = $value;
- }
- if($_GET['export'] == 1) {
- $this->RefillRefundExport($condition,$providers,$merchants);
- }else{
- $refund_list = $mod->getRefillRefundList($condition,50);
- $refund_list = $this->DataFormat($refund_list,$providers,$merchants);
- }
- Tpl::output('provider_list', $providers);
- Tpl::output('merchants', $merchants);
- Tpl::output('info_list', $refund_list);
- Tpl::output('show_page', $mod->showpage());
- Tpl::showpage('refill.refund');
- }
- private function DataFormat($refund_list,$providers,$merchants)
- {
- $providers[-1] = [
- 'name' => 'yezi',
- 'store_name' => '椰子退费'
- ];
- foreach ($refund_list as $key => $value) {
- $refund_list[$key]['provider_name'] = $providers[$value['provider_id']]['name'];
- $refund_list[$key]['store_name'] = $providers[$value['provider_id']]['store_name'];
- $refund_list[$key]['merchant_name'] = $merchants[$value['mchid']]['name'];
- $refund_list[$key]['company_name'] = $merchants[$value['mchid']]['company_name'];
- $refund_list[$key]['card_type_text'] = $this->scard_type($value['card_type']);
- }
- return $refund_list;
- }
- private function RefillRefundExport($condition,$providers,$merchants)
- {
- $i = 0;
- $result = [];
- while (true) {
- $start = $i * 1000;
- $list = Model('')->table('refill_refund')->where($condition)->order('refund_time desc')->limit("{$start},1000")->select();
- if (empty($list)) {
- break;
- }
- $i++;
- foreach ($list as $value) {
- $result[] = $value;
- }
- }
- $result = $this->DataFormat($result,$providers,$merchants);
- $this->createExcel($result);
- }
- private function createExcel($data = array())
- {
- Language::read('export');
- import('libraries.excel');
- $excel_obj = new Excel();
- $excel_data = array();
- //设置样式
- $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
- //header
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '通道名称');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '通道退款金额');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构编码');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构名称');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构退款金额');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '退款卡号');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '退款卡类型');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '退款面值');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '退款日期');
- $excel_data[0][] = array('styleid' => 's_title', 'data' => '备注');
- //data
- foreach ((array)$data as $v) {
- $mch_name = $v['company_name'] ?? $v['name'];
- $tmp = array();
- $tmp[] = array('data' => "{$v['provider_name']}({$v['store_name']})");
- $tmp[] = array('data' => $v['channel_amount']);
- $tmp[] = array('data' => $v['mchid']);
- $tmp[] = array('data' => $mch_name);
- $tmp[] = array('data' => $v['mch_amount']);
- $tmp[] = array('data' => $v['card_no']);
- $tmp[] = array('data' => $v['card_type_text']);
- $tmp[] = array('data' => $v['refill_amount']);
- $tmp[] = array('data' => date('Y-m-d H:i:s', $v['refund_time']));
- $tmp[] = array('data' => $v['bz']);
- $excel_data[] = $tmp;
- }
- $excel_data = $excel_obj->charset($excel_data, CHARSET);
- $excel_obj->addArray($excel_data);
- $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
- $excel_obj->generateXML($excel_obj->charset(L('exp_od_order'), CHARSET) . date('Y-m-d-H', time()));
- exit;
- }
- public function addOp()
- {
- if (chksubmit()) {
- $obj_validate = new Validator();
- $obj_validate->validateparam = [
- ["input" => $_POST["mchid"], "require" => "true", "message" => '机构不能为空'],
- ["input" => $_POST["provider_id"], "require" => "true", "message" => '通道不能为空'],
- ["input" => $_POST["mch_amount"], "require" => "true", "message" => '机构退款金额不能为空'],
- ["input" => $_POST["channel_amount"], "require" => "true", "message" => '通道退款金额不能为空'],
- ["input" => $_POST["refund_time"], "require" => "true", "message" => '退款日期不能为空'],
- ["input" => $_POST["card_no"], "require" => "true", "message" => '退款卡号不能为空'],
- ["input" => $_POST["card_type"], "require" => "true", "message" => '卡类型不能为空'],
- ["input" => $_POST["refill_amount"], "require" => "true", "message" => '面值不能为空']
- ];
- $error = $obj_validate->validate();
- if ($error != '') {
- showMessage($error);
- } else {
- $merchant = Model('merchant')->getMerchantInfo(['mchid' => $_POST['mchid']]);
- if(empty($merchant)) {
- showMessage('此机构不存在!');
- }
- $provider = Model('refill_provider')->getProviderInfo(['provider_id' => $_POST['provider_id']]);
- if(empty($provider) && $_POST['provider_id'] != -1) {
- showMessage('此上游通道不存在!');
- }
- $mod = Model('refill_refund');
- $insert_array['mchid'] = $_POST['mchid'];
- $insert_array['provider_id'] = $_POST['provider_id'];
- $insert_array['mch_amount'] = $_POST['mch_amount'];
- $insert_array['channel_amount'] = $_POST['channel_amount'];
- $insert_array['refund_time'] = strtotime($_POST['refund_time']);
- $insert_array['card_no'] = $_POST['card_no'];
- $insert_array['card_type'] = $_POST['card_type'];
- $insert_array['refill_amount'] = $_POST['refill_amount'];
- $insert_array['bz'] = $_POST['bz'] ?? '';
- $insert_array['add_time'] = time();
- $result = $mod->addRefund($insert_array);
- if ($result) {
- showMessage('添加成功', 'index.php?act=refill_refund&op=index');
- } else {
- showMessage('添加失败');
- }
- }
- }
- else
- {
- $merchant_list = Model('')->table('merchant')->limit(1000)->select();
- $provider_list = Model('')->table('refill_provider,store')->field('refill_provider.provider_id,store.store_name')->join('inner')
- ->on('store.store_id=refill_provider.store_id')->limit(1000)->select();
- Tpl::output('provider_list', $provider_list);
- Tpl::output('merchant_list', $merchant_list);
- Tpl::showpage('refill.refund.add');
- }
- }
- public function editOp()
- {
- $id = $_GET['id'] ?? $_POST['id'];
- $mod = Model('refill_refund');
- $refund_info = $mod->getRefundInfo(['id' => $id]);
- if (empty($refund_info)) {
- showMessage('退款信息不存在');
- }
- if (chksubmit()) {
- $obj_validate = new Validator();
- $obj_validate->validateparam = [
- ["input" => $_POST["mchid"], "require" => "true", "message" => '机构不能为空'],
- ["input" => $_POST["provider_id"], "require" => "true", "message" => '通道不能为空'],
- ["input" => $_POST["mch_amount"], "require" => "true", "message" => '机构退款金额不能为空'],
- ["input" => $_POST["channel_amount"], "require" => "true", "message" => '通道退款金额不能为空'],
- ["input" => $_POST["refund_time"], "require" => "true", "message" => '退款日期不能为空'],
- ["input" => $_POST["card_no"], "require" => "true", "message" => '退款卡号不能为空'],
- ["input" => $_POST["card_type"], "require" => "true", "message" => '卡类型不能为空'],
- ["input" => $_POST["refill_amount"], "require" => "true", "message" => '面值不能为空']
- ];
- $error = $obj_validate->validate();
- if ($error != '') {
- showMessage($error);
- exit;
- }
- $update['mchid'] = trim($_POST['mchid']);
- $update['provider_id'] = trim($_POST['provider_id']);
- $update['mch_amount'] = trim($_POST['mch_amount']);
- $update['channel_amount'] = trim($_POST['channel_amount']);
- $update['refund_time'] = strtotime($_POST['refund_time']);
- $update['card_no'] = trim($_POST['card_no']);
- $update['card_type'] = trim($_POST['card_type']);
- $update['refill_amount'] = trim($_POST['refill_amount']);
- $update['bz'] = $_POST['bz'] ?? '';
- $result = $mod->editRefund($update, ['id' => $id]);
- if (!$result) {
- showMessage('编辑失败');
- }
- showMessage('编辑成功','index.php?act=refill_refund&op=index');
- }
- else
- {
- $merchant_list = Model('')->table('merchant')->limit(1000)->select();
- $provider_list = Model('')->table('refill_provider,store')->field('refill_provider.provider_id,store.store_name')->join('inner')
- ->on('store.store_id=refill_provider.store_id')->limit(1000)->select();
- Tpl::output('provider_list', $provider_list);
- Tpl::output('merchant_list', $merchant_list);
- Tpl::output('refund_info', $refund_info);
- Tpl::showpage('refill.refund.edit');
- }
- }
- public function delOp()
- {
- $id = $_GET['id'];
- $mod = Model('refill_refund');
- $provider_info = $mod->getRefundInfo(['id' => $id]);
- if (empty($provider_info)) {
- showMessage('退款信息不存在');
- }
- $result = $mod->DelRefund(['id' => $id]);
- if (!$result) {
- showMessage('删除失败');
- }
- showMessage('删除成功','index.php?act=refill_refund&op=index');
- }
- }
|