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.

357 lines
14 KiB
PHTML

<?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'] = $_REQUEST['company_name'];
}
if(isset($_REQUEST['pay_status'])){
$map['i.pay_status'] = $_REQUEST['pay_status'];
}
5 years ago
if(isset($_REQUEST['batch_num'])){
$map['i.batch_num'] = $_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){
5 years ago
$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['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']}";
}
//统计待打款金额
$countmap = $map;
$countmap['pay_status']=["neq",1];
$money = M("excel_statement_info","tab_")->alias('i')->field("sum(statement_money) statement_money")->where($countmap)->find();
$count = M("excel_statement_info","tab_")->alias('i')->field("count(id) count")->where($map)->find();
5 years ago
$page = set_pagination($count['count'], $row);
if ($page) {
$this->assign('_page', $page);
}
$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()
{
$this->display();
}
5 years ago
//
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) {
5 years ago
$company_info = $v['company_info'];
5 years ago
$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);
5 years ago
if(!isset($company_info['ali_user']) || !isset($company_info['ali_account']) || $company_info['ali_user'] == '' || $company_info['ali_account'] == ''){
M('ExcelStatementInfo',"tab_")->where("statement_num = '{$v['statement_num']}'")->delete();
$this->ajaxReturn(["status"=>0,"msg"=>"添加失败"]);
}
5 years ago
$res = $ExcelStatementInfo->add($v);
if($res === false){
5 years ago
M('ExcelStatementInfo',"tab_")->where("statement_num = '{$v['statement_num']}'")->delete();
5 years ago
$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;
}
//获取基本信息
5 years ago
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);
5 years ago
$this->viewPuPool($dbres,$is_export);
5 years ago
}
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'] = "=";
}
5 years ago
$row = 0;
foreach($v['statement_info'] as $ke=>&$va){
5 years ago
$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){
5 years ago
$val['ratio'] = $val['ratio']*100;
$val['increment_ratio'] = $val['increment_ratio']*100;
5 years ago
//J3*(K3+L3)+M3-N3
5 years ago
$val['sum_money'] = "=J{$line}*(K{$line}+L{$line})+M{$line}-N{$line}";
5 years ago
$count['sum_money_exp'] .= "O{$line}+";
$count['platform_amount_exp'] .= "J{$line}+";
}else{
5 years ago
$count['platform_amount'] += $val['pay_amount'];
$count['sum_money'] += $val['sum_money'];
5 years ago
}
}
}
5 years ago
$v['row'] = $row;
}
if($is_export){
$count["platform_amount"] = "=".trim($count["platform_amount_exp"],"+");
$count["sum_money"] = "=".trim($count["sum_money_exp"],"+");
}
$this->assign("data",$infolist);
$this->assign("count",$count);
$this->assign("is_export",$is_export);
$this->display("viewPuPool");
}
5 years ago
public function showPayment()
{
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
5 years ago
$CompanyInfo = M("ExcelStatementInfo","tab_")
->alias('i')
5 years ago
->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'] ?? '';
}
5 years ago
$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();
5 years ago
$dbres = M("ExcelStatementInfo","tab_")->where("id='{$id}'")->find();
$company_info = json_decode($dbres['company_info'],true);
5 years ago
if($dbres['pay_status'] != 1){
//执行打款
5 years ago
$title = $remark;
$amount = $dbres['statement_money'];
5 years ago
$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();
}
5 years ago
M("ExcelStatementInfo","tab_")->save($savedata);
$this->ajaxReturn(["success"=>"打款成功","data"=>[]]);
}
/**
* 打款详情
*/
public function paymentInfo()
{
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
5 years ago
$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();
}
}