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.

393 lines
15 KiB
PHP

<?php
namespace Payment\Controller;
/**
* 后台首页控制器
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
class ExcelPaymentController 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 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['time_start']) && isset($_REQUEST['time_end'])) {
$time_start = strtotime($_REQUEST['time_start']);
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$map["_string"] = "(i.statement_begin_time BETWEEN {$time_start} AND {$time_end}) OR (i.statement_end_time BETWEEN {$time_start} AND {$time_end})";
} elseif (isset($_REQUEST['time_start'])) {
$time_start = strtotime($_REQUEST['time_start']);
$map["_string"] = "(i.statement_begin_time >= {$time_start} ) OR (i.statement_end_time >= {$time_start})";
} elseif (isset($_REQUEST['time_end'])) {
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$map["_string"] = "(i.statement_begin_time <= {$time_end} ) OR (i.statement_end_time <= {$time_end})";
}
if (isset($_REQUEST['pay_time_start']) && isset($_REQUEST['pay_time_end'])) {
$map['i.pay_time'] = ['between', [strtotime($_REQUEST['pay_time_start']), strtotime($_REQUEST['pay_time_end']) + 86399]];
} elseif (isset($_REQUEST['pay_time_start'])) {
$map['i.pay_time'] = ['EGT', strtotime($_REQUEST['pay_time_start'])];
} elseif (isset($_REQUEST['pay_time_end'])) {
$map['i.pay_time'] = ['ELT', strtotime($_REQUEST['pay_time_end']) + 86399];
}
if(isset($_REQUEST['company_name'])){
$map['i.company_name'] = ['LIKE',"%".$_REQUEST['company_name']."%"];
}
if(isset($_REQUEST['pay_status'])){
$map['i.pay_status'] = $_REQUEST['pay_status'];
}
if(isset($_REQUEST['batch_num'])){
$map['i.batch_num'] = ["LIKE","%{$_REQUEST['batch_num']}%"];
}
$CompanyInfo = M("excel_statement_info","tab_")
->alias('i')
->field("i.*")
->where($map)
->page($page,$row)
->order("FIELD(pay_status,0,-1,1)")
->select();
foreach($CompanyInfo as $k=>&$v){
$v['can_pay'] = 1;
if($v['pay_status'] == 1){ $v['can_pay'] = 0; }
if($v['statement_money'] < 0.1){ $v['can_pay'] = 0; }
$v['company_type'] = $this->CompanyType[$v['company_type']];
$v["pay_status_str"] = $this->PayStatus[$v['pay_status']];
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
// $v['statement_begin_time'] = date('Y-m-d',$v['statement_begin_time']);
// $v['statement_end_time'] = date('Y-m-d',$v['statement_end_time']);
if(empty($v['pay_time'])){
$v['pay_time'] = "--";
}else{
$v['pay_time'] = date('Y-m-d H:i:s',$v['pay_time']);
}
// $v["valid"] = "{$v['statement_begin_time']} ~ {$v['statement_end_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";
$money = M("excel_statement_info","tab_")->alias('i')->field( $field)->where($map)->find();
$count = M("excel_statement_info","tab_")->alias('i')->field("count(id) count")->where($map)->find();
$page = set_pagination_all($count['count'], $row);
if ($page) {
$this->assign('_page', $page);
}
// echo($page);die();
$this->meta_title = 'EXCEL打款';
$this->assign("data",$CompanyInfo);
$this->assign("money",$money);
$this->assign("CompanyType", $this->CompanyType);
$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;
// $statement_begin_time = strtotime($p['statement_begin_time']);
// $statement_end_time = strtotime($p['statement_end_time'])+86399;
$batch = $p['batch'];
$checkarr = $p['checkarr'];
//循环获取添加
if(count($checkarr) < 1){
$this->ajaxReturn(["status"=>1,"msg"=>"ok"]);
}
$ExcelStatementInfo = M('ExcelStatementInfo',"tab_");
foreach ($checkarr as $k => &$v) {
$company_info = $v['company_info'];
// $v['statement_begin_time'] = $statement_begin_time;
// $v['statement_end_time'] = $statement_end_time;
$v['batch_num'] = $batch;
$v['statement_info'] = json_encode($v['statement_info'],JSON_UNESCAPED_UNICODE);
$v['company_info'] = json_encode($v['company_info'],JSON_UNESCAPED_UNICODE);
$v['company_type'] = 2;
$v['create_time'] = time();
$v['statement_num'] = "JS_".date('Ymd').date('His').$v['company_id'].sp_random_string(5);
$dm = [
"mobile"=>$this->admininfo['mobile'],
"real_name"=>$this->admininfo['real_name'],
"time"=>date("Y-m-d H:i:s")
];
$v['document_maker'] = json_encode($dm,JSON_UNESCAPED_UNICODE);
if(!isset($company_info['ali_user']) || !isset($company_info['ali_account']) || $company_info['ali_user'] == '' || $company_info['ali_account'] == ''){
M('ExcelStatementInfo',"tab_")->where("batch_num = '{$v['batch_num']}'")->delete();
$this->ajaxReturn(["status"=>0,"msg"=>"支付宝真实姓名及登陆账号不允许为空"]);
}
$res = $ExcelStatementInfo->add($v);
if($res === false){
M('ExcelStatementInfo',"tab_")->where("batch_num = '{$v['batch_num']}'")->delete();
$this->ajaxReturn(["status"=>0,"msg"=>"添加失败"]);
}
}
$this->ajaxReturn(["status"=>1,"msg"=>"ok"]);
}
//查看
public function viewPool()
{
if(!isset($_REQUEST['id'])){
$this->error('参数错误');
}
$id = $_REQUEST['id'];
$is_export= false;
if (isset($_REQUEST['export']) && $_REQUEST['export']==1){
$is_export = true;
}
//获取基本信息
if($is_export && isset($_REQUEST['exporttype']) && $_REQUEST['exporttype']=='all'){
$dbres = M("ExcelStatementInfo","tab_")->where("id in ({$id})")->select();
$title = date("YmdHis");
}else{
$dbres = M("ExcelStatementInfo","tab_")->where("id ='{$id}'")->select();
$title = $dbres[0]['company_name'].date("YmdHis");
}
$this->assign("title",$title);
$this->viewPuPool($dbres,$is_export);
}
public function delItem()
{
if(!isset($_REQUEST['ids'])){
$this->error('参数错误');
}
$ids = $_REQUEST['ids'];
$map = [
"pay_status"=>["NEQ",1],
"id"=>["IN",$ids]
];
$dbres = M("ExcelStatementInfo","tab_")->where($map)->delete();
if($dbres === false){
$this->ajaxReturn(["status"=>0,"info"=>"删除失败"]);
}
$this->ajaxReturn(["status"=>1,"info"=>"删除成功"]);
}
//个人汇总结算查看
public function viewPuPool(&$infolist,$is_export){
$line = 1;
$count = [];
//获取对接人
foreach($infolist as $k=>&$v){
$v['statement_info'] = json_decode($v['statement_info'],true);
$v['company_info'] = json_decode($v['company_info'],true);
// $v['statement_begin_time'] = date('Y-m-d',$v['statement_begin_time']);
// $v['statement_end_time'] = date('Y-m-d',$v['statement_end_time']);
$cline = $line+1;
if($is_export){
$v['sum_money_exp'] = "=";
$hh = "\n";
}else{
$hh = "<br>";
}
$dm = json_decode($v['document_maker'],true);
$v['document_maker'] = $dm['mobile'].$hh."({$dm['real_name']})";
if(!empty($v['payment_user'])){
$pu = json_decode($v['payment_user'],true);
$v['payment_user'] = $pu['mobile'].$hh."({$pu['real_name']})";
}else{
$v['payment_user'] = "--";
}
$v["pay_status_str"] = $this->PayStatus[$v['pay_status']];
if(!empty($v['pay_time'])){
$v['pay_time'] = date('Y-m-d H:i:s',$v['pay_time']);
}else{
$v['pay_time'] = '--';
}
$row = 0;
foreach($v['statement_info'] as $ke=>&$va){
$va['row'] = count($va['game_list']);
$row += count($va['game_list']);
foreach($va['game_list'] as $key=>&$val){
$line ++;
if(isset($val['ratio'])){
$val['increment_ratio'] = 0;
}else{
$val['ratio'] = 0;
}
if($is_export){
$val['ratio'] = $val['ratio']*100;
$val['increment_ratio'] = $val['increment_ratio']*100;
//J3*(K3+L3)+M3-N3
$val['sum_money'] = "=J{$line}*(K{$line}+L{$line})+M{$line}-N{$line}";
}else{
$count['platform_amount'] += $val['pay_amount'];
$count['sum_money'] += $val['sum_money'];
}
}
}
$v['row'] = $row;
}
if($is_export){
$count["platform_amount"] = "=SUM(J2:J".$line.")";
$count["sum_money"] = "=SUM(O2:O".$line.")";
}
$this->assign("data",$infolist);
$this->assign("count",$count);
$this->assign("is_export",$is_export);
$this->display("viewPuPool");
}
public function showPayment()
{
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$CompanyInfo = M("ExcelStatementInfo","tab_")
->alias('i')
->field("i.id,i.company_name,i.company_info,i.statement_money,i.batch_num,i.remark,i.pay_status")
->where("i.id in ({$ids})")
->select();
foreach($CompanyInfo as $k=>&$v){
$v['company_info'] = json_decode($v['company_info'],true);
$v['company_info']['ali_user'] ?? '';
$v['company_info']['ali_account'] ?? '';
}
$count = M("ExcelStatementInfo","tab_")->field("sum(statement_money) statement_money")->where("id in ({$ids})")->find();
$this->getAccountMoney();
// dd($CompanyInfo);
$this->assign("CompanyInfo",$CompanyInfo);
$this->assign("mobile",$this->admininfo['mobile']);
$this->assign("count",$count);
$this->display();
// $this->display();
}
public function getAccountMoney(){
Vendor("Alipay2020/Fund");
$fund = new \Fund();
$money = $fund->account();
if($money !== -1){
$money = $money['amount'];
}else{
$money = "--";
}
$this->assign("money",$money);
}
//以下打款流程
public function checkVerify()
{
$mobile = $this->admininfo['mobile'];
$verify = $_REQUEST['verify'];
if (!A("Public")->checksafecode($mobile, $verify)) {
$this->ajaxReturn(["error"=>"验证码错误"]);
}
$this->ajaxReturn(["success"=>"验证码验证成功","data"=>[]]);
}
//执行打款
public function doPayment()
{
$id = $_REQUEST['id'];
$remark = $_REQUEST['remark'];
Vendor("Alipay2020/Fund");
$fund = new \Fund();
$dbres = M("ExcelStatementInfo","tab_")->where("id='{$id}'")->find();
$company_info = json_decode($dbres['company_info'],true);
if($dbres['pay_status'] != 1){
//执行打款
$title = $remark;
$amount = $dbres['statement_money'];
$amount = 0.1; //测试金额必须去除
$payres = $fund->transfer($company_info['ali_account'],$company_info['ali_user'],$dbres['statement_num'],$amount, $title);
$resultCode = $payres->code;
$savedata = ["id"=>$dbres['id']];
if(!empty($resultCode)&&$resultCode == 10000){
$savedata["pay_status"]=1;
} else {
$savedata["pay_status"]=-1;
}
$payres = json_decode( json_encode($payres),true);
$payres["remark"] = $remark;
$savedata["pay_info"] = json_encode($payres,JSON_UNESCAPED_UNICODE);
$savedata["pay_time"]=time();
$pu = [
"mobile"=>$this->admininfo['mobile'],
"real_name"=>$this->admininfo['real_name'],
"time"=>date("Y-m-d H:i:s")
];
$savedata['payment_user'] = json_encode($pu,JSON_UNESCAPED_UNICODE);
}
M("ExcelStatementInfo","tab_")->save($savedata);
$this->ajaxReturn(["success"=>"打款成功","data"=>[]]);
}
/**
* 打款详情
*/
public function paymentInfo()
{
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
$info = M("ExcelStatementInfo","tab_")->field("pay_info")->where("id='{$id}'")->find()['pay_info'];
$info = json_decode($info,true);
$senddata = [];
foreach($info as $k => &$v){
if(isset($this->ALIRSP[$k])){
$senddata[$this->ALIRSP[$k]] = $v;
}else{
$senddata[$k] = $v;
}
}
$this->assign("info",$senddata);
$this->display();
}
}