You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
7.6 KiB
PHTML

3 years ago
<?php
namespace Payment\Controller;
/**
* 后台首页控制器
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
class WxPaymentController extends BaseController
{
public $PayStatus=[
"-1"=>"打款失败",
"0"=>"未打款",
"1"=>"打款成功"
];
public $CompanyType = [
"1"=>"下游公司",
"2"=>"下游个人",
"3"=>"上游CP"
];
public $ALIRSP=[
"out_biz_no"=>"商户订单号",
"order_id"=>"支付订单号",
"pay_fund_order_id"=>"资金流水号",
"status"=>"转账状态",
"trans_date"=>"订单支付时间",
"msg"=>"支付信息",
"sub_msg"=>"失败描述",
"sub_code"=>"失败码",
"remark"=>"打款备注",
"code"=>"打款状态码"
];
public function _initialize()
{
$this->admininfo = session('payment_user');;
// $this->DBModel = M("CompanyStatementPool","tab_");
parent::_initialize();
}
public function customerLists()
{
$params = I('get.');
$page = $params['p'] ? intval($params['p']) : 1;
$row = $params['row'] ? intval($params['row']) : 10;
$where = [];
if(isset($_REQUEST['nickname'])){
$where['nickname'] = ["LIKE","%{$_REQUEST['nickname']}%"];
}
$data = M('mini_program_user', 'tab_')
->field("wx_json",true)
->where($where)
->page($page,$row)
->select();
foreach ($data as $key => $value) {
$data[$key]['create_time'] = date('Y-m-d H:i:s',$value['create_time']);
}
$count = M('mini_program_user', 'tab_')->where($where)->count();
$page = set_pagination_all($count['count'], $row);
if ($page) {
$this->assign('_page', $page);
}
$this->assign('data', $data);
$this->display();
}
public function customerExport()
{
$where["_string"]="1=1";
if($_REQUEST['ids']){
$where = [
"id"=>["in",$_REQUEST['ids']]
];
}
$data = M('mini_program_user', 'tab_')
->field("wx_json",true)
->where($where)
->select();
header("Content-type: text/html; charset=utf-8");
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
Vendor("PHPExcel.PHPExcel");
$objPHPExcel = new \PHPExcel();
$objReader = \PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load("Public/Admin/excel/customer.xlsx");
$line = 2;
//设置模板文件
foreach ($data as $key => $value) {
$objPHPExcel->getActiveSheet()->setCellValue('A'.$line, $line-1)->setCellValue('B'.$line, $value['openid']);
$line++;
}
$fileName = "微信打款模板";
ob_end_clean();//清除缓冲区,避免乱码
header('pragma:public');
header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $fileName .'".xlsx');
header("Content-Disposition:attachment;filename={$fileName}.xlsx");//attachment新窗口打印inline本窗口打印
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
}
public function lists()
{
$params = I('get.');
$page = $params['p'] ? intval($params['p']) : 1;
$row = $params['row'] ? intval($params['row']) : 10;
$map=[
"_string"=>"1=1",
];
if (isset($_REQUEST['pay_time_start']) && isset($_REQUEST['pay_time_end'])) {
$map['pay_time'] = ['between', [strtotime($_REQUEST['pay_time_start']), strtotime($_REQUEST['pay_time_end']) + 86399]];
} elseif (isset($_REQUEST['pay_time_start'])) {
$map['pay_time'] = ['EGT', strtotime($_REQUEST['pay_time_start'])];
} elseif (isset($_REQUEST['pay_time_end'])) {
$map['pay_time'] = ['ELT', strtotime($_REQUEST['pay_time_end']) + 86399];
}
if(isset($_REQUEST['realname'])){
$map['realname'] = ['LIKE',"%".$_REQUEST['realname']."%"];
}
if(isset($_REQUEST['pay_status'])){
$map['pay_status'] = $_REQUEST['pay_status'];
}
if(isset($_REQUEST['batch_num'])){
$map['batch_num'] = ["LIKE","%{$_REQUEST['batch_num']}%"];
}
if (isset($_REQUEST['export']) && $_REQUEST['export']==1) {
$data = M("excel_statement_info","tab_")
->alias('i')
->field("i.*")
->where($map)
->order("FIELD(pay_status,0,-1,1)")
->select();
$ids = array_column($data, 'id');
$ids = implode(',', $ids);
$this->viewPool($ids);
return ;
}
3 years ago
$data = M("wx_payment","tab_")
->field("*")
3 years ago
->where($map)
->page($page,$row)
->order("FIELD(pay_status,0,-1,1)")
->select();
3 years ago
foreach($data as $k=>&$v){
3 years ago
$v["pay_status_str"] = $this->PayStatus[$v['pay_status']];
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
if(empty($v['pay_time'])){
$v['pay_time'] = "--";
}else{
$v['pay_time'] = date('Y-m-d H:i:s',$v['pay_time']);
}
}
//统计待打款金额
$field = "IFNULL(SUM(CASE WHEN pay_status = 1 THEN statement_money ELSE 0 END),0) as success_money,
IFNULL(SUM(CASE WHEN pay_status = 0 THEN statement_money ELSE 0 END),0) as statement_money,
IFNULL(SUM(CASE WHEN pay_status = -1 THEN statement_money ELSE 0 END),0) as error_money";
3 years ago
$money = M("wx_payment","tab_")->field( $field)->where($map)->find();
3 years ago
3 years ago
$count = M("wx_payment","tab_")->field("count(id) count")->where($map)->find();
3 years ago
$page = set_pagination_all($count['count'], $row);
if ($page) {
$this->assign('_page', $page);
}
3 years ago
$this->assign("data",$data);
3 years ago
$this->assign("money",$money);
$this->assign("PayStatus", $this->PayStatus);
$this->display();
}
public function add()
{
$batch = date('Ymd').date('His').sp_random_num(3);
$this->assign("batch",$batch);
$this->meta_title = 'EXCEL导入';
$this->display();
}
public function loopAdd()
{
$p = $_REQUEST;
$batch = $p['batch'];
$checkarr = $p['checkarr'];
//循环获取添加
if(count($checkarr) < 1){
$this->ajaxReturn(["status"=>1,"msg"=>"ok"]);
}
$wxPayment = M('wx_payment',"tab_");
foreach ($checkarr as $k => &$v) {
if(!isset($v['realname']) || !isset($v['openid']) || !isset($v['statement_money']) || $v['realname'] == '' || $v['openid'] == '' || $v['statement_money'] <= 0){
$wxPayment->where("batch_num = '{$v['batch_num']}'")->delete();
$this->ajaxReturn(["status"=>0,"msg"=>"真实姓名,openid,打款金额均不允许为空"]);
}
$v['batch_num'] = $batch;
3 years ago
$v['create_time'] = time();
3 years ago
$res = $wxPayment->add($v);
if($res === false){
$wxPayment->where("batch_num = '{$v['batch_num']}'")->delete();
$this->ajaxReturn(["status"=>0,"msg"=>"添加失败"]);
}
}
$this->ajaxReturn(["status"=>1,"msg"=>"ok"]);
}
}