123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- <?php
- require_once(BASE_HELPER_PATH . '/PHPExcel/PHPExcel.php');
- class merchant_infoControl extends SystemControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- $mod = Model('merchant_info');
- $condition = [];
- if(!empty($_GET['mchid'])) {
- $condition['mchid'] = $_GET['mchid'];
- }
- $merchants = [];
- $merchant_list = $this->merchants();
- foreach ($merchant_list as $key => $value) {
- $merchants[$value['mchid']] = $value;
- }
- $info_list = $mod->getMerchantInfoList($condition,50);
- foreach ($info_list as $key => $value) {
- $info_list[$key]['merchant_name'] = $merchants[$value['mchid']]['name'];
- $info_list[$key]['company_name'] = $merchants[$value['mchid']]['company_name'];
- }
- Tpl::output('merchants', $merchants);
- Tpl::output('info_list', $info_list);
- Tpl::output('page', $mod->showpage());
- Tpl::showpage('merchant.info');
- }
- public function addOp()
- {
- if (chksubmit()) {
- $obj_validate = new Validator();
- $obj_validate->validateparam = [
- ["input" => $_POST["mchid"], "require" => "true", "message" => '机构不能为空'],
- ["input" => $_POST["bank_name"], "require" => "true", "message" => '收款银行名称不能为空'],
- ["input" => $_POST["bank_username"], "require" => "true", "message" => '开户人名称不能为空'],
- ["input" => $_POST["bank_card_no"], "require" => "true", "message" => '收款卡号不能为空']
- ];
- $error = $obj_validate->validate();
- if ($error != '') {
- showMessage($error);
- } else {
- $merchant = Model('merchant')->getMerchantInfo(['mchid' => $_POST['mchid']]);
- if(empty($merchant)) {
- showMessage('此机构不存在!');
- }
- $mod = Model('merchant_info');
- $insert_array['mchid'] = $_POST['mchid'];
- $insert_array['bank_name'] = $_POST['bank_name'];
- $insert_array['bank_username'] = $_POST['bank_username'];
- $insert_array['bank_card_no'] = $_POST['bank_card_no'];
- $insert_array['bz'] = $_POST['bz'] ?? '';
- $result = $mod->addInfo($insert_array);
- if ($result) {
- showMessage('添加成功', 'index.php?act=merchant_info&op=index');
- } else {
- showMessage('添加失败');
- }
- }
- }
- else
- {
- $merchant_list = Model('')->table('merchant')->limit(1000)->select();
- Tpl::output('merchant_list', $merchant_list);
- Tpl::showpage('merchant.info.add');
- }
- }
- public function editOp()
- {
- $info_id = $_GET['info_id'] ?? $_POST['info_id'];
- $mod = Model('merchant_info');
- $merchant_info = $mod->getMerchantInfo(['info_id' => $info_id]);
- if (empty($merchant_info)) {
- showMessage('机构信息不存在');
- }
- if (chksubmit()) {
- $update['bank_name'] = trim($_POST['bank_name']);
- $update['bank_username'] = trim($_POST['bank_username']);
- $update['bank_card_no'] = trim($_POST['bank_card_no']);
- $update['bz'] = trim($_POST['bz']) ?? '';
- $result = $mod->editMerchantInfo($update, ['info_id' => $info_id]);
- if (!$result) {
- showMessage('编辑失败');
- }
- showMessage('编辑成功','index.php?act=merchant_info&op=index');
- }
- else
- {
- Tpl::output('info', $merchant_info);
- Tpl::showpage('merchant.info.edit');
- }
- }
- public function delOp()
- {
- $info_id = $_GET['info_id'];
- $mod = Model('merchant_info');
- $merchant_info = $mod->getMerchantInfo(['info_id' => $info_id]);
- if (empty($merchant_info)) {
- showMessage('机构信息不存在');
- }
- $result = $mod->DelMerchantInfo(['info_id' => $info_id]);
- if (!$result) {
- showMessage('删除失败');
- }
- showMessage('删除成功','index.php?act=merchant_info&op=index');
- }
- public function merchant_evidenceOp()
- {
- $mod = Model('merchant_evidence');
- $condition = [];
- if (trim($_GET['company_name']) != '') {
- $condition['company_name'] = ['like', '%' . $_GET['company_name'] . '%'];
- }
- if (trim($_GET['to_bank_username']) != '') {
- $condition['to_bank_username'] = ['like', '%' . $_GET['to_bank_username'] . '%'];
- }
- if (trim($_GET['to_bank_name']) != '') {
- $condition['to_bank_name'] = ['like', '%' . $_GET['to_bank_name'] . '%'];
- }
- $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['apply_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
- } elseif ($start_unixtime > 0) {
- $condition['apply_time'] = ['egt', $start_unixtime];
- } elseif ($end_unixtime > 0) {
- $condition['apply_time'] = ['lt', $end_unixtime];
- }
- if(!empty($_GET['export'])) {
- $this->MerchantEvidenceExport($condition);
- }
- //上游充值申请列表
- $evidence_list = $mod->getMerchantEvidence($condition, 30, '*', 'apply_time desc');
- $stats = $mod->field('sum(amount) as amounts')->where($condition)->find();
- Tpl::output('amounts', $stats['amounts']);
- Tpl::output('evidence_list', $evidence_list);
- Tpl::output('page', $mod->showpage());
- Tpl::showpage('merchant.evidence.list');
- }
- public function importOp()
- {
- if(chksubmit()) {
- $merchant = [];
- $merchant_list = Model('')->table('merchant')->limit(1000)->select();
- foreach ($merchant_list as $key => $value) {
- $merchant[$value['mchid']] = $value['company_name'];
- }
- if(empty($merchant)) {
- showMessage('机构通道为空,不可导入');
- }
- //得到导入文件
- $filename = $_FILES['csv']['name'];
- $tmp_name = $_FILES['csv']['tmp_name'];
- $extend = strrchr($filename,'.');
- $extendLower = strtolower($extend);
- if (!in_array($extendLower, ['.xls', '.xlsx', '.csv']))
- {
- showMessage('文件格式有误');
- }
- $filePath = BASE_ROOT_PATH . '/data/upload/upfile/provider/';
- /** Error reporting */
- error_reporting(E_ALL);
- //注意设置时区
- $time=date("m-d-H-i-s");//去当前上传的时间
- //根据当前时间外加后五位产生一个 防止多个用户同时操作产生的重复概率
- $randnum = 'MerchantEvidenceImport_'.$time.str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
- //上传后的文件名
- $name=$randnum.$extendLower;
- $upload_filename=$filePath.$name;//上传后的文件名地址
- $result=move_uploaded_file($tmp_name,$upload_filename);
- if(!$result){
- showMessage('上传失败,稍后再试!');
- }
- $fileType = PHPExcel_IOFactory::identify($upload_filename);
- $objReader = PHPExcel_IOFactory::createReader($fileType);
- $objPHPExcel = $objReader->load($upload_filename);
- $time = time();
- $mod = Model('merchant_evidence');
- foreach ($objPHPExcel->getWorkSheetIterator() as $sheet)
- {
- foreach ($sheet->getRowIterator() as $row)
- {
- $index = $row->getRowIndex();
- if ($index == 1) continue;
- $items = [];
- foreach ($row->getCellIterator() as $cell) {
- $data = $cell->getValue();
- $items[] = $data;
- }
- if(empty($items) || count($items) < 7){
- Log::record("items empty or length err",LOG::DEBUG);
- continue;
- }
- $mchid = intval($items[0]);
- $params = [
- 'mchid' => $mchid,
- 'company_name' => $merchant[$mchid],
- 'amount' => $items[1] ?? '',
- 'bank_username' => trim($items[4]) ?? '',
- 'bank_name' => trim($items[5]) ?? '',
- 'to_bank_username' => trim($items[2]) ?? '',
- 'to_bank_name' => trim($items[3]) ?? '',
- 'apply_time' => strtotime($items[6]) ?? '',
- 'add_time' => $time
- ];
- if(!empty($items[7])) {
- $params['bz'] = $items[7];
- }
- $json_txt = json_encode($params);
- Log::record("import data: {$json_txt}",LOG::DEBUG);
- if(empty($params['mchid']) || empty($params['company_name'])) {
- Log::record("merchant evidence import err,not find merchant info, mchid: {$mchid}, amount: {$params['amount']}",LOG::DEBUG);
- }
- $res = $mod->addMerchantEvidence($params);
- if(!$res){
- Log::record("merchant evidence import err, mchid: {$mchid}, amount: {$params['amount']}",LOG::DEBUG);
- showMessage('导入失败');
- }
- }
- }
- showMessage('操作完成');
- exit;
- }
- else
- {
- Tpl::showpage('merchant.evidence.import');
- }
- }
- public function apply_delOp()
- {
- $apply_id = $_GET['apply_id'] ?? $_POST['apply_id'];
- $mod = Model('merchant_evidence');
- $provider_evidence_info = $mod->getMerchantEvidenceInfo(['apply_id' => $apply_id]);
- if (empty($provider_evidence_info)) {
- showMessage('申请信息不存在');
- }
- $result = $mod->DelMerchantEvidence(['apply_id' => $apply_id]);
- if (!$result) {
- showMessage('删除失败');
- }
- showMessage('删除成功','index.php?act=merchant_info&op=merchant_evidence');
- }
- private function MerchantEvidenceExport($condition)
- {
- $i = 0;
- $result = [];
- while (true) {
- $start = $i * 1000;
- $evidence_list = Model('')->table('merchant_evidence')->where($condition)->order('apply_time desc')->limit("{$start},1000")->select();
- if (empty($evidence_list)) {
- break;
- }
- $i++;
- foreach ($evidence_list as $value) {
- $result[] = $value;
- }
- }
- $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' => '备注');
- //data
- foreach ((array)$data as $v) {
- $tmp = array();
- $tmp[] = array('data' => $v['company_name']);
- $tmp[] = array('data' => $v['amount']);
- $tmp[] = array('data' => $v['bank_username']);
- $tmp[] = array('data' => $v['bank_name']);
- $tmp[] = array('data' => $v['to_bank_username']);
- $tmp[] = array('data' => $v['to_bank_name']);
- $tmp[] = array('data' => date('Y-m-d H:i:s', $v['apply_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;
- }
- }
|