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.
1579 lines
59 KiB
PHP
1579 lines
59 KiB
PHP
<?php
|
|
namespace Payment\Controller;
|
|
/**
|
|
* 后台首页控制器
|
|
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
|
*/
|
|
class PaymentController extends BaseController
|
|
{
|
|
public $PayStatus=[
|
|
"-2"=>"信息配置不全",
|
|
"-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=[
|
|
"s.verify_status"=>["in","-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"] = "(s.statement_begin_time BETWEEN {$time_start} AND {$time_end}) OR (s.statement_end_time BETWEEN {$time_start} AND {$time_end})";
|
|
} elseif (isset($_REQUEST['time_start'])) {
|
|
$time_start = strtotime($_REQUEST['time_start']);
|
|
$map["_string"] = "(s.statement_begin_time >= {$time_start} ) OR (s.statement_end_time >= {$time_start})";
|
|
} elseif (isset($_REQUEST['time_end'])) {
|
|
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
|
|
$map["_string"] = "(s.statement_begin_time <= {$time_end} ) OR (s.statement_end_time <= {$time_end})";
|
|
}
|
|
|
|
if (isset($_REQUEST['pay_time_start']) && isset($_REQUEST['pay_time_end'])) {
|
|
$map['s.pay_time'] = ['between', [strtotime($_REQUEST['pay_time_start']), strtotime($_REQUEST['pay_time_end']) + 86399]];
|
|
} elseif (isset($_REQUEST['pay_time_start'])) {
|
|
$map['s.pay_time'] = ['EGT', strtotime($_REQUEST['pay_time_start'])];
|
|
} elseif (isset($_REQUEST['pay_time_end'])) {
|
|
$map['s.pay_time'] = ['ELT', strtotime($_REQUEST['pay_time_end']) + 86399];
|
|
}
|
|
|
|
if (isset($_REQUEST['verifytime_start']) && isset($_REQUEST['verifytime_end'])) {
|
|
$map['s.verify_time'] = ['between', [strtotime($_REQUEST['verifytime_start']), strtotime($_REQUEST['verifytime_end']) + 86399]];
|
|
} elseif (isset($_REQUEST['verifytime_start'])) {
|
|
$map['s.verify_time'] = ['EGT', strtotime($_REQUEST['verifytime_start'])];
|
|
} elseif (isset($_REQUEST['verifytime_end'])) {
|
|
$map['s.verify_time'] = ['ELT', strtotime($_REQUEST['verifytime_end']) + 86399];
|
|
}
|
|
|
|
if(isset($_REQUEST['company_type'])){
|
|
$map['s.company_type'] = $_REQUEST['company_type'];
|
|
}
|
|
if(isset($_REQUEST['company_id'])){
|
|
$map['s.company_id'] = $_REQUEST['company_id'];
|
|
}
|
|
|
|
if(isset($_REQUEST['pay_status'])){
|
|
if($_REQUEST['pay_status'] == -2){
|
|
$map['s.verify_status'] = -1;
|
|
}else{
|
|
$map['s.pay_status'] = $_REQUEST['pay_status'];
|
|
}
|
|
}
|
|
|
|
if(isset($_REQUEST['pay_type'])){
|
|
$map['s.pay_type'] = $_REQUEST['pay_type'];
|
|
}
|
|
|
|
// dump($map);die();
|
|
$sum = M("pay_statement_info","tab_")
|
|
->alias('c')
|
|
->field("sum(if(c.pay_status=0,c.statement_money,0)) unpay_amount,sum(if(c.pay_status>0,c.statement_money,0)) pay_amount,sum(if(c.pay_status<0,c.statement_money,0)) faild_pay_amount")
|
|
->join("left join tab_company_statement_info s on c.statement_info_id = s.id")
|
|
->where($map)
|
|
->find();
|
|
|
|
$this->assign('sum',$sum);
|
|
// dump($sum);die();
|
|
|
|
|
|
$CompanyInfo = M("company_statement_info","tab_")
|
|
->alias('s')
|
|
->field("s.*,p.statement_num statement_pool_num")
|
|
->join("left join tab_company_statement_pool p ON p.id = s.pool_id")
|
|
->where($map)
|
|
->page($page,$row)
|
|
->order("statement_num desc")
|
|
->select();
|
|
|
|
$handleData = [];
|
|
|
|
foreach($CompanyInfo as $k=>&$v){
|
|
$handleData[] = $v['id'];
|
|
$v['can_pay'] = 1;
|
|
if($v['verify_status'] == -1){
|
|
$v['verify_status_str']="信息配置不全";
|
|
$v['can_pay'] = 0;
|
|
}else{
|
|
if($v['pay_status'] == 1){ $v['can_pay'] = 0; }
|
|
$v['verify_status_str'] = $this->PayStatus[$v['pay_status']];
|
|
if($v['pay_status'] == 1){
|
|
$v['pay_type'] = $v['pay_type'] == 1 ? "提现" :"线上打款";
|
|
$v['verify_status_str'] .= ("/". $v['pay_type']);
|
|
}
|
|
}
|
|
$companypay_info = json_decode($v['company_info'],true);
|
|
if (empty($companypay_info['ali_user']) || empty($companypay_info['ali_account'])) {
|
|
$v['verify_status'] = -1;
|
|
$v['verify_status_str']="信息配置不全";
|
|
$v['can_pay'] = 0;
|
|
}
|
|
$v['ali_user'] = $companypay_info['ali_user'];
|
|
$v['ali_account'] = $companypay_info['ali_account'];
|
|
|
|
if($v['pay_check'] == 0){
|
|
$v['pay_check_detail'] = "--";
|
|
}else {
|
|
$member = M("payment_member")
|
|
->field("name")
|
|
->where(['id'=>$v['pay_check_member_id']])
|
|
->find();
|
|
$v['pay_check_detail'] = $member['name'].(($v['pay_check'] == 1)?'已确认':'未确认')."<br>".date('Y-m-d H:i:s', $v['pay_check_time']);;
|
|
}
|
|
|
|
// if ($v['pay_check'] == 0) {
|
|
// $v['pay_check_str'] = "未确认";
|
|
// } else {
|
|
// $v['pay_check_str'] = "已确认";
|
|
// }
|
|
|
|
$v['company_type'] = $this->CompanyType[$v['company_type']];
|
|
$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']}";
|
|
}
|
|
|
|
if ($handleData) {
|
|
$statementInfo = M("pay_statement_info","tab_")
|
|
->alias('s')
|
|
->field("s.*,p.statement_num statement_pool_num")
|
|
->join("left join tab_company_statement_info i ON s.statement_info_id = i.id")
|
|
->join("left join tab_company_statement_pool p ON p.id = i.pool_id")
|
|
->where(['statement_info_id'=>['in',$handleData]])
|
|
->order("FIELD(s.pay_status,0,-1,1),s.verify_status desc")
|
|
->select();
|
|
|
|
$handleData = [];
|
|
foreach ($statementInfo as $key => $value) {
|
|
|
|
$value['can_pay'] = 1;
|
|
if($value['verify_status'] == -1){
|
|
$value['verify_status_str']="信息配置不全";
|
|
$value['can_pay'] = 0;
|
|
}else{
|
|
if($value['pay_status'] == 1){ $value['can_pay'] = 0; }
|
|
$value['verify_status_str'] = $this->PayStatus[$value['pay_status']];
|
|
if($value['pay_status'] == 1){
|
|
$value['pay_type'] = $value['pay_type'] == 1 ? "提现" :"线上打款";
|
|
$value['verify_status_str'] .= ("/". $value['pay_type']);
|
|
}
|
|
}
|
|
|
|
$value['company_type'] = $this->CompanyType[$value['company_type']];
|
|
$value['statement_begin_time'] = date('Y-m-d',$value['statement_begin_time']);
|
|
$value['statement_end_time'] = date('Y-m-d',$value['statement_end_time']);
|
|
if(empty($value['pay_time'])){
|
|
$value['pay_time'] = "--";
|
|
}else{
|
|
$value['pay_time'] = date('Y-m-d H:i:s',$value['pay_time']);
|
|
}
|
|
$value["valid"] = "{$value['statement_begin_time']} ~ {$value['statement_end_time']}";
|
|
|
|
$handleData[$value['statement_info_id']]['data'][] = $value;
|
|
|
|
if ($value['pay_status'] != 1) {
|
|
$handleData[$value['statement_info_id']]['ids'][] = $value['id'];
|
|
}
|
|
}
|
|
|
|
foreach ($CompanyInfo as $key=>$value) {
|
|
$CompanyInfo[$key]['son_info'] = $handleData[$value['id']]['data'];
|
|
$CompanyInfo[$key]['ids'] = implode(',',$handleData[$value['id']]['ids']);
|
|
}
|
|
}
|
|
|
|
//统计待打款金额
|
|
$countmap = $map;
|
|
$countmap['pay_status']=["neq",1];
|
|
$money = M("company_statement_info","tab_")->alias('s')->field("sum(statement_money) statement_money")->where($countmap)->find();
|
|
|
|
$count = M("company_statement_info","tab_")->alias('s')->field("count(id) count")->where($map)->find();
|
|
$page = set_pagination($count['count'], $row);
|
|
if ($page) {
|
|
$this->assign('_page', $page);
|
|
}
|
|
$this->meta_title = '打款结算单';
|
|
// dd($CompanyInfo);
|
|
$this->assign("data",$CompanyInfo);
|
|
$this->assign("money",$money);
|
|
$this->assign("CompanyType", $this->CompanyType);
|
|
$this->assign("PayStatus", $this->PayStatus);
|
|
$this->display();
|
|
}
|
|
//是否需要更新支付信息
|
|
public function IsCanChangeCompanyInfo($id = 0)
|
|
{
|
|
//获取原值
|
|
list($oldInfo, $newCompanyInfo) = $this->getStatementCompanyInfo($id);
|
|
$oldCompanyInfo = json_decode($oldInfo['company_info'],true);
|
|
if( ($oldCompanyInfo['ali_user'] == $newCompanyInfo['ali_user']) && ($oldCompanyInfo['ali_account'] == $newCompanyInfo['ali_account']) ){
|
|
$this->ajaxReturn(['status' =>0 ,'msg'=>'支付宝打款信息已是最新,无需更新','data'=>[]]);
|
|
}
|
|
$this->ajaxReturn(['status' =>1 ,'msg'=>'ok','data'=>[
|
|
'id'=>$id,
|
|
'company_name'=>$oldInfo['company_name'],
|
|
'old_ali_user'=>$oldCompanyInfo['ali_user'],
|
|
'old_ali_account'=>$oldCompanyInfo['ali_account'],
|
|
'new_ali_user'=>$newCompanyInfo['ali_user'],
|
|
'new_ali_account'=>$newCompanyInfo['ali_account']
|
|
]]);
|
|
}
|
|
//执行更新支付信息
|
|
public function DoChangeCompanyInfo()
|
|
{
|
|
$id = I("post.id",0);
|
|
list($oldInfo, $newCompanyInfo) = $this->getStatementCompanyInfo($id);
|
|
//子单修改
|
|
$sWhere = [
|
|
'company_id' => $oldInfo['company_id'],
|
|
'pay_status'=> ['neq',1],
|
|
'statement_info_id' => $id
|
|
];
|
|
$PayStatementDB = M("pay_statement_info","tab_");
|
|
$statementInfo = $PayStatementDB
|
|
->where($sWhere)
|
|
->field('id,company_info')
|
|
->select();
|
|
foreach ($statementInfo as $k => $v) {
|
|
$v['company_info'] = $this->changeAliInfo($v['company_info'],$newCompanyInfo);
|
|
$PayStatementDB->save($v);
|
|
}
|
|
//修改结算单
|
|
if($oldInfo['company_type'] != 2 || $oldInfo['withdraw_type'] == 3){
|
|
//获取汇总单号
|
|
$statement_num = M("company_statement_pool","tab_")->where("id = {$oldInfo['pool_id']}")->getField("statement_num");
|
|
$StatementDB = M("company_statement","tab_");
|
|
$statementList = $StatementDB->field('id,pay_type,first_party_info,second_party_info')->where(['verify_log'=>["like","%{$statement_num}%"],'company_id'=>$oldInfo['company_id']])->select();
|
|
foreach ($statementList as $k => $v) {
|
|
if($v['pay_type'] == 1){
|
|
$v['first_party_info'] = $this->changeAliInfo($v['first_party_info'],$newCompanyInfo);
|
|
}else{
|
|
$v['second_party_info'] = $this->changeAliInfo($v['second_party_info'],$newCompanyInfo);
|
|
}
|
|
$StatementDB->save($v);
|
|
}
|
|
}
|
|
//修改自身
|
|
$oldInfo['company_info'] = $this->changeAliInfo($oldInfo['company_info'],$newCompanyInfo);
|
|
$res = M("company_statement_info","tab_")->save($oldInfo);
|
|
if(empty($res)){
|
|
$this->ajaxReturn(['status' =>0 ,'msg'=>'更新信息失败','data'=>[]]);
|
|
}
|
|
$this->ajaxReturn(['status' =>1 ,'msg'=>'支付信息更新成功','data'=>[]]);
|
|
|
|
}
|
|
//获取新旧公司信息
|
|
protected function getStatementCompanyInfo($id = 0){
|
|
$oldInfo = M("company_statement_info","tab_")->field("id,company_info,company_id,company_type,company_name,pool_id,withdraw_type")->where("id = {$id}")->find();
|
|
if(empty($oldInfo)){
|
|
$this->ajaxReturn(['status' =>0 ,'msg'=>'未找到此结算单信息','data'=>[]]);
|
|
}
|
|
//获取新值
|
|
if($oldInfo['company_type'] == 3){
|
|
$Model = M("partner","tab_");
|
|
}else{
|
|
$Model = M("promote_company","tab_");
|
|
}
|
|
$newCompanyInfo = $Model->field("ali_user,ali_account")->where("id = {$oldInfo['company_id']}")->find();
|
|
return [$oldInfo,$newCompanyInfo];
|
|
}
|
|
//改变支付宝信息
|
|
protected function changeAliInfo($item,$newInfo)
|
|
{
|
|
$companyInfo = json_decode($item,true);
|
|
$companyInfo['ali_user'] = $newInfo['ali_user'];
|
|
$companyInfo['ali_account'] = $newInfo['ali_account'];
|
|
return json_encode($companyInfo,JSON_UNESCAPED_UNICODE);
|
|
}
|
|
//线上转线下
|
|
public function setStatementPayType()
|
|
{
|
|
$id = I("post.id",0);
|
|
|
|
$oldInfo = M("company_statement_info","tab_")->field("id,company_info,remark")->where("id = {$id}")->find();
|
|
if(empty($oldInfo)){
|
|
$this->ajaxReturn(['status' =>0 ,'msg'=>'未找到此结算单信息','data'=>[]]);
|
|
}
|
|
$company_info = json_decode($oldInfo['company_info'],true);
|
|
|
|
$PayStatementDB = M("pay_statement_info","tab_");
|
|
//判断线上打款
|
|
$sWhere = [
|
|
'company_id' => $oldInfo['company_id'],
|
|
'statement_info_id' => $id
|
|
];
|
|
$sCount = $PayStatementDB->where($sWhere)->where("pay_status = 1")->count();
|
|
if($sCount > 0) {
|
|
$this->ajaxReturn(['status' =>0 ,'msg'=>'已有付款成功的子单,无法转线下','data'=>[]]);
|
|
}
|
|
//删除打款
|
|
$PayStatementDB->where($sWhere)->delete();
|
|
//获取自身
|
|
$remark = ($oldInfo['remark'] .'该打款由线上转为线下付款,原支付宝用户:'. $company_info['ali_user'].',支付宝账号为:'.$company_info['ali_account']);
|
|
//修改自身
|
|
$res = M("company_statement_info","tab_")->where("id = {$id}")->save(['verify_status' => 2, 'pay_check' => 0, 'pay_check_member_id' => 0, 'pay_check_time' => 0, 'remark' => $remark]);
|
|
if(empty($res)){
|
|
$this->ajaxReturn(['status' =>0 ,'msg'=>'转换失败','data'=>[]]);
|
|
}
|
|
$this->ajaxReturn(['status' =>1 ,'msg'=>'成功转为线下确认','data'=>[]]);
|
|
}
|
|
|
|
//导出
|
|
public function export() {
|
|
|
|
if(!isset($_REQUEST['id'])){
|
|
$this->error('参数错误');
|
|
}
|
|
$id = $_REQUEST['id'];
|
|
$data = M("company_statement_info","tab_")
|
|
->alias('s')
|
|
->field("s.*,p.statement_num statement_pool_num")
|
|
->join("left join tab_company_statement_pool p ON p.id = s.pool_id")
|
|
->where(['s.id'=>['in',$id]])
|
|
->order("statement_num desc")
|
|
->select();
|
|
|
|
foreach ($data as $key => $value) {
|
|
$company_info = json_decode($value['company_info'],true);
|
|
$data[$key]['ali_user'] = $company_info['ali_user'];
|
|
$data[$key]['ali_account'] = $company_info['ali_account'];
|
|
$data[$key]['statement_time'] = date("Y-m-d",$value['statement_begin_time']).'-'.date("Y-m-d",$value['statement_end_time']);
|
|
|
|
if($value['pay_check'] == 0){
|
|
$v['pay_check_detail'] = "--";
|
|
}else {
|
|
$member = M("payment_member")
|
|
->field("name")
|
|
->where(['id'=>$value['pay_check_member_id']])
|
|
->find();
|
|
$data[$key]['pay_check_detail'] = $member['name'].(($value['pay_check'] == 1)?'已确认':'未确认').date('Y-m-d H:i:s', $value['pay_check_time']);;
|
|
}
|
|
|
|
$data[$key]['pay_status_str'] = $value['pay_status']==1?"已打款":($value['pay_status']==-1?'打款失败':'未打款');
|
|
$data[$key]['pay_time'] = $value['pay_time']?date("Y-m-d H:i:s",$value['pay_time']):'未支付';
|
|
}
|
|
|
|
$title = [
|
|
'num'=>'序号',
|
|
'company_name' => '公司名称',
|
|
'statement_time' => '结算时间',
|
|
'statement_money' => '结算金额',
|
|
'ali_user' => '支付宝真实姓名',
|
|
'ali_account'=>'支付宝账号',
|
|
'remark'=>'备注',
|
|
'statement_pool_num'=>'汇总单号',
|
|
'pay_check_detail'=>'打款信息确认',
|
|
'pay_status_str'=>'打款状态',
|
|
'pay_time'=>'打款时间',];
|
|
$sum = M("pay_statement_info","tab_")
|
|
->alias('c')
|
|
->field("sum(if(c.pay_status=0,c.statement_money,0)) unpay_amount,sum(if(c.pay_status>0,c.statement_money,0)) pay_amount,sum(if(c.pay_status<0,c.statement_money,0)) faild_pay_amount")
|
|
->join("left join tab_company_statement_info s on c.statement_info_id = s.id")
|
|
->where(['statement_info_id'=>['in',$id]])
|
|
->find();
|
|
// $sum = M("pay_statement_info","tab_")
|
|
// ->alias('s')
|
|
// ->field("sum(if(s.pay_status=0,s.statement_money,0)) unpay_amount,sum(if(s.pay_status>0,s.statement_money,0)) pay_amount,sum(if(s.pay_status<0,s.statement_money,0)) faild_pay_amount")
|
|
// ->join("left join tab_company_statement_info c on s.statement_info_id = c.id")
|
|
// ->where(['statement_info_id'=>['in',$id]])
|
|
// ->find();
|
|
|
|
$sumData = [
|
|
'company_name'=>'合计',
|
|
'statement_time' => "待打款金额: {$sum['unpay_amount']} 打款成功金额: {$sum['pay_amount']} 打款失败金额: {$sum['faild_pay_amount']}",
|
|
];
|
|
|
|
$data = array_merge($data,[$sumData]);
|
|
|
|
foreach($data as $key => $value) {
|
|
|
|
$data[$key]['num'] = $key + 1;
|
|
|
|
}
|
|
// dump($data);die();
|
|
data2csv($data,'线上打款',$title);
|
|
// $this->ajaxReturn(['stauts'=>1,'msg'=>'导出成功']);
|
|
|
|
}
|
|
|
|
//查看
|
|
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;
|
|
}
|
|
//获取基本信息
|
|
$dbres = M("company_statement_info","tab_")->where("id='{$id}'")->select();
|
|
$title = $dbres[0]['company_name'];
|
|
$this->assign("title",$title);
|
|
|
|
if($dbres[0]['company_type'] == 3){
|
|
//上游
|
|
$this->viewCpPool($dbres,$is_export);
|
|
}elseif($dbres[0]['company_type'] == 1){
|
|
//下游公司
|
|
$this->viewPcPool($dbres,$is_export);
|
|
}else{
|
|
$this->viewPuPool($dbres,$is_export);
|
|
}
|
|
|
|
}
|
|
|
|
//改变结构
|
|
public function changeDataStruct($statement_info = [],$is_export = 0,&$week_line = 1) {
|
|
|
|
$game_list = [];
|
|
$old_line = $week_line;
|
|
|
|
//使用时间与会长账号作为键值分离数据
|
|
foreach($statement_info as $sk=>$sv){
|
|
|
|
foreach($sv['game_list'] as $gk=>$gv){
|
|
|
|
$gv['account'] = $sv['account'];
|
|
$game_list[$gv['statement_begin_time'].'-'.$gv['statement_end_time']][$gv['account']][] = $gv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$game_data = [];
|
|
$handle_data = [];
|
|
//处理游戏金额数据
|
|
foreach($game_list as $gk => $gv) {
|
|
|
|
foreach ($gv as $sk => $sv) {
|
|
$game_data['account'] = $sk;
|
|
$game_data['row'] = count($sv);
|
|
|
|
if ($game_data['row'] == '0') {
|
|
$game_data['row'] = 1;
|
|
}
|
|
|
|
$game_data['time_row'] = count($sv);
|
|
|
|
if ($game_data['time_row'] == '0') {
|
|
$game_data['time_row'] = 1;
|
|
}
|
|
|
|
$game_data['time'] = $gk;
|
|
$game_data['week_amount'] = 0;
|
|
//周结算金额计算
|
|
for ($i=0;;$i++) {
|
|
if ($sv[$i]['sum_money']) {
|
|
$game_data['week_amount'] += $sv[$i]['sum_money']- $sv[$i]['withhold']+$sv[$i]['reward']-$sv[$i]['fine'];
|
|
$game_data['withhold_amount'] += $sv[$i]['withhold'];
|
|
$game_data['fine'] += $sv[$i]['fine'];
|
|
$game_data['reward'] += $sv[$i]['reward'];
|
|
} else {
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
$game_data['game_list'] = $sv;
|
|
array_push($handle_data,$game_data);
|
|
$game_data = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$substract = 1;
|
|
|
|
//添加周结算金额,合并相同的结算时间
|
|
|
|
foreach($handle_data as $hk => $hv) {
|
|
|
|
if($hk > 0) {
|
|
|
|
for (;;) {
|
|
|
|
if (!$handle_data[$hk-$substract]['time']) {
|
|
$substract++;
|
|
} else {
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
if ($hv['time'] == $handle_data[$hk-$substract]['time']) {
|
|
|
|
$handle_data[$hk-$substract]['time_row'] += $handle_data[$hk]['time_row'];
|
|
|
|
$handle_data[$hk-$substract]['week_amount'] += $handle_data[$hk]['week_amount'];
|
|
$handle_data[$hk-$substract]['withhold_amount'] += $handle_data[$hk]['withhold_amount'];
|
|
|
|
unset($handle_data[$hk]['time']);
|
|
unset($handle_data[$hk]['time_row']);
|
|
unset($handle_data[$hk]['week_amount']);
|
|
}
|
|
$substract = 1;
|
|
}
|
|
|
|
}
|
|
|
|
// foreach($handle_data as $hk => $hv) {
|
|
// $substract = 1;
|
|
// if ($is_export) {
|
|
//
|
|
// for (;;) {
|
|
//
|
|
// if (!$handle_data[$hk+$substract]['time']&&$handle_data[$hk+$substract]['account']) {
|
|
//// if (
|
|
//// $hv['account'] == 'zj9587' ||
|
|
//// $hv['account'] == 'ruiyou' || $hv['account'] == 'weicheng') {
|
|
//// dump($handle_data[$hk]['time']);
|
|
//// }
|
|
//
|
|
// $week_line++;
|
|
// $substract++;
|
|
// } else {
|
|
// break;
|
|
// }
|
|
//
|
|
// }
|
|
//
|
|
// if (count($hv['game_list'])>1) {
|
|
// $week_line += count($hv['game_list'])-1;
|
|
// }
|
|
//
|
|
// $handle_data[$hk]['week_amount'] = "=ROUND(SUM(O{$old_line}:O{$week_line})+SUM(P{$old_line}:P{$week_line})-SUM(Q{$old_line}:Q{$week_line})-SUM(R{$old_line}:R{$week_line}),2)";
|
|
//
|
|
// if ($hk > 0) {
|
|
// $handle_data[0]['week_amount'] = str_replace($old_line,$week_line,$handle_data[0]['week_amount']);
|
|
// }
|
|
//
|
|
// if (count($hv['game_list'])>1) {
|
|
//
|
|
// $old_line += count($hv['game_list']);
|
|
//
|
|
// } else {
|
|
// $old_line++;
|
|
// }
|
|
//
|
|
// if(count($hv['game_list'])>1) {
|
|
//
|
|
// $week_line = $old_line ;
|
|
// } else {
|
|
// $week_line = $old_line;
|
|
// }
|
|
//
|
|
// }
|
|
//
|
|
// }
|
|
|
|
return $handle_data?$handle_data:[];
|
|
}
|
|
|
|
//个人汇总结算查看
|
|
public function viewPuPool(&$infolist,$is_export){
|
|
$line = 1;
|
|
$count = [];
|
|
$week_line = 2;
|
|
|
|
//获取对接人
|
|
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']);
|
|
if( isset($v['verify_status'])){
|
|
if( $v['verify_status'] ==2 ){
|
|
$v['is_payment'] = 2; //不打款
|
|
}else{
|
|
$v['is_payment'] = 1;
|
|
}
|
|
}
|
|
$cline = $line+1;
|
|
if($is_export){
|
|
$v['statement_money'] = "=ROUND(";
|
|
}
|
|
$handle_data = $this->changeDataStruct($v['statement_info'],$is_export,$week_line);
|
|
|
|
$v['statement_info'] = $handle_data;
|
|
$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($v['withdraw_type'] != 3) {
|
|
// if(!$val['ratio']&&!$val['increment_ratio']) {
|
|
// if(isset($val['ratio'])){
|
|
// $val['increment_ratio'] = 0;
|
|
// }else{
|
|
// $val['ratio'] = 0;
|
|
// }
|
|
// }
|
|
$val['sum_money'] = $val['sum_money']-$val['fine']+$val['reward'];
|
|
if (!$val['increment_ratio']) {
|
|
$val['increment_ratio'] = 0;
|
|
}
|
|
|
|
if (!$val['ratio']) {
|
|
$val['ratio'] = 0;
|
|
}
|
|
|
|
}
|
|
|
|
if($is_export){
|
|
if($v['withdraw_type'] != 3) {
|
|
$val['sum_money'] = "=ROUND((K{$line}-L{$line})*(M{$line}+N{$line}),2)";
|
|
} else {
|
|
$val['sum_money'] = "=ROUND(K{$line}*(N{$line}),2)";
|
|
}
|
|
$v['statement_money'] .= "S{$line}+";
|
|
}else{
|
|
$count['platform_amount'] += $val['pay_amount'];
|
|
|
|
}
|
|
}
|
|
$count['week_money'] += $va['week_amount'];
|
|
$count['sum_money'] += $va['week_amount'];
|
|
}
|
|
|
|
|
|
|
|
$v['row'] = $row;
|
|
|
|
if ($v['row'] == '0') {
|
|
$v['row'] = 1;
|
|
}
|
|
|
|
if($is_export){
|
|
if($v['withdraw_type'] != 3) {
|
|
// $v['statement_money'] .="P{$cline}-Q{$cline},2)";
|
|
$v['statement_money'] = substr($v['statement_money'],0,strlen($v['statement_money'])-1) . ",2)";
|
|
} else {
|
|
$v['statement_money'] = substr($v['statement_money'],0,strlen($v['statement_money'])-1).",2)";
|
|
}
|
|
}
|
|
}
|
|
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");
|
|
}
|
|
//下游汇总结算查看
|
|
public function viewPcPool(&$infolist,$is_export){
|
|
$line = 1;
|
|
$count = [];
|
|
//获取对接人
|
|
$p_id = array_column($infolist,'company_id');
|
|
$map['id'] = ['in',$p_id];
|
|
$pl = M("promote_company","tab_")->field("id,settlement_contact")->where($map)->select();
|
|
$Partner = [];
|
|
foreach($pl as $k=>$v){
|
|
$Partner[$v['id']] = $v['settlement_contact'];
|
|
}
|
|
unset($pl);
|
|
foreach($infolist as $k=>&$v){
|
|
$v['statement_info'] = json_decode($v['statement_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['statement_money_exp'] = "=";
|
|
}
|
|
foreach($v['statement_info'] as $ke=>&$va){
|
|
$line ++;
|
|
if(isset($va['ratio'])){
|
|
$va['increment_ratio'] = 0;
|
|
}else{
|
|
$va['ratio'] = 0;
|
|
}
|
|
|
|
if($is_export){
|
|
$v['statement_money_exp'] .= "H{$line}+";
|
|
|
|
$va['d_statement_money'] = "=D{$line}*(1-G{$line})*(E{$line}+F{$line})";
|
|
|
|
$count['platform_amount_exp'] .= "D{$line}+";
|
|
$count['d_statement_money_exp'] .= "H{$line}+";
|
|
|
|
}else{
|
|
$va['d_statement_money'] = round($va['pay_amount']*($va['ratio']+$va['increment_ratio'])*(100-$va['fax_ratio'])/100/100,2);
|
|
|
|
$count['platform_amount'] += $va['pay_amount'];
|
|
|
|
$count['d_statement_money'] += $va['d_statement_money'];
|
|
}
|
|
}
|
|
$v['settlement_contact'] = $Partner[$v['company_id']];
|
|
|
|
if($is_export){
|
|
$v['statement_money_exp'] .= "J{$cline}-I{$cline}";
|
|
$v['statement_money'] = $v['statement_money_exp'];
|
|
|
|
$count['fine_exp'] .= "I{$cline}+";
|
|
$count['reward_exp'] .= "J{$cline}+";
|
|
|
|
$count['statement_money_exp'] .= "K{$cline}+";
|
|
}else{
|
|
$count['fine'] += $v['fine'];
|
|
$count['reward'] += $v['reward'];
|
|
$count['statement_money'] += $v['statement_money'];
|
|
}
|
|
$v['statement_count'] = count($v['statement_info']);
|
|
|
|
}
|
|
if($is_export){
|
|
$count["d_statement_money"] = "=".trim($count["d_statement_money_exp"],"+");
|
|
$count["platform_amount"] = "=".trim($count["platform_amount_exp"],"+");
|
|
$count["fine"] = "=".trim($count["fine_exp"],"+");
|
|
$count["reward"] = "=".trim($count["reward_exp"],"+");
|
|
$count["statement_money"] = "=".trim($count["statement_money_exp"],"+");
|
|
}
|
|
|
|
$this->assign("data",$infolist);
|
|
$this->assign("count",$count);
|
|
$this->assign("is_export",$is_export);
|
|
$this->display("viewPcPool");
|
|
|
|
}
|
|
|
|
//上游汇总查看及导出
|
|
public function viewCpPool(&$infolist,$is_export)
|
|
{
|
|
$line = 2;
|
|
$count = [];
|
|
//获取平台名
|
|
$p_id = array_column($infolist,'company_id');
|
|
$map['id'] = ['in',$p_id];
|
|
$pl = M("Partner","tab_")->field("id,matche_platform")->where($map)->select();
|
|
$Partner = [];
|
|
foreach($pl as $k=>$v){
|
|
$Partner[$v['id']] = $v['matche_platform'];
|
|
}
|
|
unset($pl);
|
|
//
|
|
foreach($infolist as $k=>&$v){
|
|
$v['statement_info'] = json_decode($v['statement_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['statement_money_exp'] = "=";
|
|
}
|
|
foreach($v['statement_info'] as $ke=>&$va){
|
|
$line ++;
|
|
$va['company_ratio'] = 100-$va['ratio'];
|
|
if($is_export){
|
|
$v['statement_money_exp'] .= "K{$line}+";
|
|
$va['d_statement_money'] = "=F{$line}*G{$line}";
|
|
$count['platform_amount_exp'] .= "E{$line}+";
|
|
$count['platform_amount_exp2'] .= "F{$line}+";
|
|
$count['d_statement_money_exp'] .= "K{$line}+";
|
|
}else{
|
|
$va['d_statement_money'] = round($va['pay_amount']*$va['ratio']/100,2);
|
|
$count['platform_amount'] += $va['pay_amount'];
|
|
$count['platform_amount2'] += $va['pay_amount'];
|
|
$count['d_statement_money'] += $va['d_statement_money'];
|
|
}
|
|
}
|
|
$v['matche_platform'] = $Partner[$v['company_id']];
|
|
if($is_export){
|
|
$v['statement_money_exp'] .= "M{$cline}-L{$cline}";
|
|
$v['statement_money'] = $v['statement_money_exp'];
|
|
$count['fine_exp'] .= "L{$cline}+";
|
|
$count['reward_exp'] .= "M{$cline}+";
|
|
$count['statement_money_exp'] .= "N{$cline}+";
|
|
}else{
|
|
$count['fine'] += $v['fine'];
|
|
$count['reward'] += $v['reward'];
|
|
$count['statement_money'] += $v['statement_money'];
|
|
}
|
|
$v['statement_count'] = count($v['statement_info']);
|
|
|
|
}
|
|
if($is_export){
|
|
$count["d_statement_money"] = "=".trim($count["d_statement_money_exp"],"+");
|
|
$count["platform_amount"] = "=".trim($count["platform_amount_exp"],"+");
|
|
$count["platform_amount2"] = "=".trim($count["platform_amount_exp2"],"+");
|
|
$count["fine"] = "=".trim($count["fine_exp"],"+");
|
|
$count["reward"] = "=".trim($count["reward_exp"],"+");
|
|
$count["statement_money"] = "=".trim($count["statement_money_exp"],"+");
|
|
}
|
|
$this->assign("data",$infolist);
|
|
$this->assign("count",$count);
|
|
$this->assign("is_export",$is_export);
|
|
$this->display("viewCpPool");
|
|
}
|
|
|
|
//打款设置
|
|
public function setPayment(){
|
|
if(!isset($_REQUEST['id'])) $this->error("参数错误");
|
|
$id = $_REQUEST['id'];
|
|
$CompanyInfo = M("company_statement_info","tab_")
|
|
->alias('i')
|
|
->field("i.id,i.pool_id,i.company_name,i.company_info,i.statement_money,i.remark,i.pay_status,i.verify_status,p.statement_num,i.statement_money")
|
|
->join("tab_company_statement_pool p ON p.id = i.pool_id")
|
|
->where("i.id in({$id})")
|
|
->select();
|
|
|
|
$all_money = 0;
|
|
foreach($CompanyInfo as $k=>&$v){
|
|
if($v['verify_status'] == 2){
|
|
$v['is_payment'] = 2;
|
|
}else{
|
|
$v['is_payment'] = 1;
|
|
}
|
|
|
|
$v['company_info'] = json_decode($v['company_info'],true);
|
|
$v['company_info']['ali_user'] ?? '';
|
|
$v['company_info']['ali_account'] ?? '';
|
|
|
|
$all_money += $v['statement_money'];
|
|
|
|
}
|
|
|
|
$this->assign('all_money',$all_money);
|
|
$this->assign("CompanyInfo",$CompanyInfo);
|
|
$this->assign("id",$id);
|
|
$this->display();
|
|
}
|
|
|
|
public function returnSetPayment() {
|
|
|
|
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
|
|
$ids = $_REQUEST['ids'];
|
|
|
|
$ids = explode(',',$ids);
|
|
|
|
$CompanyInfo = M("company_statement_info","tab_");
|
|
|
|
$CompanyInfo
|
|
->where(['id'=>['in',$ids]])
|
|
->save([
|
|
'pay_check'=>0,
|
|
'pay_check_member_id'=>0,
|
|
'pay_check_time'=>0
|
|
]);
|
|
|
|
$this->ajaxReturn(array(
|
|
'status' => 1,
|
|
"info"=>"打款信息编辑成功"
|
|
));
|
|
|
|
}
|
|
|
|
//修改打款设置
|
|
public function editPayment(){
|
|
if(!isset($_REQUEST['info'])) $this->error("参数错误");
|
|
$info = $_REQUEST['info'];
|
|
$id = [];
|
|
|
|
$CompanyInfo = M("company_statement_info","tab_");
|
|
//循环保存
|
|
foreach($info as $k=>$v){
|
|
array_push($id,$k);
|
|
$ydata = $CompanyInfo->where("id= '{$k}'")->find();
|
|
$company_info = json_decode($ydata['company_info'],true);
|
|
if($ydata['verify_status'] == 2){
|
|
$company_info['payee_name'] = $v['payee_name'];
|
|
$company_info['bank_account'] = $v['bank_account'];
|
|
$company_info['opening_bank'] = $v['opening_bank'];
|
|
}else{
|
|
$company_info['ali_user'] = $v['ali_user'];
|
|
$company_info['ali_account'] = $v['ali_account'];
|
|
}
|
|
$savedata = [
|
|
"company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE),
|
|
"remark"=>$v['remark'],
|
|
"pay_check"=>1,
|
|
"pay_check_member_id"=> $_SESSION['onethink_admin']['payment_user']['id'],
|
|
"id"=>$k,
|
|
"pay_check_time"=>time()
|
|
];
|
|
|
|
M("pay_statement_info","tab_")->where(['statement_info_id'=>$k])->save(["company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE)]);
|
|
$CompanyInfo->save($savedata);
|
|
|
|
}
|
|
|
|
$companyStatementInfo = M("company_statement_info","tab_")
|
|
->where([
|
|
'id'=>['in',$id]
|
|
])
|
|
->select();
|
|
|
|
foreach ($companyStatementInfo as $key => $value) {
|
|
if ($value['statement_money'] <= 0) {
|
|
$payres["remark"] = '打款金额非正,直接打款成功';
|
|
|
|
$pay_info = json_encode($payres, JSON_UNESCAPED_UNICODE);
|
|
M("company_statement_info","tab_")
|
|
->where([
|
|
'id'=>['in',$value['id']]
|
|
])
|
|
->save(['pay_status'=>1,'pay_time'=>time(),'pay_type'=>2,'pay_info'=>$pay_info]);
|
|
M("pay_statement_info","tab_")
|
|
->where([
|
|
'statement_info_id'=>['in',$value['id']]
|
|
])
|
|
->save(['pay_status'=>1,'pay_time'=>time(),'pay_type'=>2,'pay_info'=>$pay_info]);
|
|
} else {
|
|
$payres["remark"] = '打款金额非正,直接打款成功';
|
|
|
|
$pay_info = json_encode($payres, JSON_UNESCAPED_UNICODE);
|
|
M("pay_statement_info","tab_")
|
|
->where([
|
|
'statement_info_id'=>['in',$value['id']],
|
|
'statement_money'=>['elt',0]
|
|
])
|
|
->save(['pay_status'=>1,'pay_time'=>time(),'pay_type'=>2,'pay_info'=>$pay_info]);
|
|
|
|
$pay_statement_info = M("pay_statement_info","tab_")
|
|
->where([
|
|
'statement_info_id'=>['in',$value['id']]
|
|
])
|
|
->order("statement_money ASC")
|
|
->select();
|
|
$subtraction = 0;
|
|
foreach ($pay_statement_info as $sk => $sv) {
|
|
|
|
if ($sv['statement_money'] < 0) {
|
|
$subtraction += -($sv['statement_money']);
|
|
$sv['final_statement_money'] = 0;
|
|
} elseif($sv['statement_money'] > 0 && $subtraction > 0) {
|
|
if($sv['statement_money'] >= $subtraction) {
|
|
$sv['final_statement_money'] = $sv['statement_money']-$subtraction;
|
|
$subtraction = 0;
|
|
} else {
|
|
$sv['final_statement_money'] = 0;
|
|
$subtraction =-$sv['final_statement_money'];
|
|
}
|
|
}
|
|
|
|
M("pay_statement_info","tab_")
|
|
->where([
|
|
'id'=>$sv['id']
|
|
])->save($sv);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
$this->ajaxReturn(array(
|
|
'status' => 1,
|
|
"info"=>"打款信息编辑成功"
|
|
));
|
|
|
|
}
|
|
|
|
public function transfer_set()
|
|
{
|
|
$this->getAccountMoney();
|
|
$this->meta_title = '复核账号设置';
|
|
$this->assign("mobile",$this->admininfo['mobile']);
|
|
$this->display();
|
|
}
|
|
|
|
public function memberList()
|
|
{
|
|
$params = I('get.');
|
|
$page = $params['p'] ? intval($params['p']) : 1;
|
|
$row = $params['row'] ? intval($params['row']) : 10;
|
|
|
|
$map=[
|
|
"_string"=>"1=1",
|
|
];
|
|
|
|
$payment_menber = M("payment_member")
|
|
->alias('p')
|
|
->field("p.*")
|
|
->where($map)
|
|
->page($page,$row)
|
|
->select();
|
|
|
|
foreach ($payment_menber as $key => $value) {
|
|
|
|
$payment_menber[$key]['is_payment_str'] = $value['is_payment'] == 1?"是":"否";
|
|
|
|
}
|
|
|
|
$count = M("payment_member")->where($map)->count();
|
|
|
|
$page = set_pagination_all($count['count'], $row);
|
|
if ($page) {
|
|
$this->assign('_page', $page);
|
|
}
|
|
|
|
$this->assign('is_auth',$_SESSION['onethink_admin']['payment_user']['id']);
|
|
$this->assign("data",$payment_menber);
|
|
$this->getAccountMoney();
|
|
$this->meta_title = '复核账号';
|
|
$this->display("memberlist");
|
|
}
|
|
|
|
public function del() {
|
|
|
|
if (!$_REQUEST['id']) {
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'传输数据错误']);
|
|
}
|
|
|
|
if ($_REQUEST['id'] == 1) {
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'管理员账号不能删除']);
|
|
}
|
|
|
|
$is_del = M("payment_member")->where(['id'=>$_REQUEST['id']])->delete();
|
|
|
|
if ($is_del) {
|
|
$this->ajaxReturn(['status'=>1,'msg'=>'删除成功']);
|
|
} else {
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'删除失败']);
|
|
}
|
|
|
|
}
|
|
|
|
public function add() {
|
|
|
|
if (IS_POST)
|
|
{
|
|
$data = $_POST;
|
|
|
|
if(!$data['name']) {
|
|
$this->error('名称不能为空');
|
|
}
|
|
|
|
if(!$data['mobile']) {
|
|
$this->error('手机号不能为空');
|
|
}
|
|
|
|
if(strlen($data['mobile']) < 11) {
|
|
$this->error('手机号格式错误');
|
|
// $this->error('手机号格式错误');
|
|
}
|
|
|
|
$is_hav = M("payment_member")
|
|
->where("mobile = '{$data['mobile']}'")
|
|
->find();
|
|
|
|
if ($is_hav) {
|
|
$this->error('手机号已经存在');
|
|
}
|
|
|
|
$is_success = M("payment_member")
|
|
->add([
|
|
'name'=>$data['name'],
|
|
'mobile'=>$data['mobile']
|
|
]);
|
|
|
|
if ($is_success) {
|
|
$this->success('添加成功',U('Payment/memberList'));
|
|
} else {
|
|
$this->error('添加失败');
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->display();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function edit() {
|
|
|
|
if (IS_POST)
|
|
{
|
|
$data = $_POST;
|
|
|
|
if(!$data['id']) {
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'id不能传输为空']);
|
|
// $this->error('名称不能为空');
|
|
}
|
|
|
|
if(!$data['name']) {
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'名称不能为空']);
|
|
// $this->error('名称不能为空');
|
|
}
|
|
|
|
if(!$data['mobile']) {
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'手机号不能为空']);
|
|
// $this->error('手机号不能为空');
|
|
}
|
|
|
|
$hav_mobile = M("payment_member")
|
|
->where("id = '{$data['id']}'")
|
|
->find();
|
|
|
|
if ($data['id'] == 1 && $hav_mobile['mobile']!=$data['mobile']) {
|
|
$verify = $_REQUEST['verify'];
|
|
|
|
if (!A("Public")->checksafecode($data['old_mobile'], $verify)) {
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'验证码错误']);
|
|
}
|
|
}
|
|
|
|
if(strlen($data['mobile']) < 11) {
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'手机号格式错误']);
|
|
// $this->error('手机号格式错误');
|
|
}
|
|
|
|
$is_hav = M("payment_member")
|
|
->where("id = {$data['id']}")
|
|
->find();
|
|
|
|
if (!$is_hav) {
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'账号不存在']);
|
|
// $this->error('账号不存在');
|
|
}
|
|
|
|
$is_hav = M("payment_member")
|
|
->where("mobile = '{$data['mobile']}' and id != {$data['id']}")
|
|
->find();
|
|
|
|
if($is_hav) {
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'手机号重复请验证']);
|
|
// $this->error('手机号重复请验证');
|
|
}
|
|
|
|
$is_success = M("payment_member")
|
|
->where(['id'=>$data['id']])
|
|
->save([
|
|
'name'=>$data['name'],
|
|
'mobile'=>$data['mobile']
|
|
]);
|
|
|
|
if ($is_success) {
|
|
$this->ajaxReturn(['status'=>1,'msg'=>'修改成功']);
|
|
// $this->success('添加成功',U('Payment/memberList'));
|
|
} else {
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'尚未修改数据,修改失败']);
|
|
// $this->error('添加失败');
|
|
}
|
|
|
|
} else {
|
|
|
|
$data = M("payment_member")
|
|
->where("id = {$_REQUEST['id']}")
|
|
->find();
|
|
|
|
$this->assign('data',$data);
|
|
|
|
$this->display();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function saveTransferSet()
|
|
{
|
|
$mobile = $_REQUEST['mobile'];
|
|
$verify = $_REQUEST['verify'];
|
|
$flag = A("Public")->checksafecode($this->admininfo['mobile'], $verify);
|
|
if (!$flag ) {
|
|
$this->error('验证码错误');
|
|
}
|
|
$dbres = M("Kv")->where("`key`='payment_check_mobile'")->save(['value'=>$mobile]);
|
|
if($dbres !== false){
|
|
$logout = U('Public/logout');
|
|
$this->ajaxReturn(["status"=>1,"msg"=>"验证手机修改成功,即将跳转","url"=>"{$logout}"]);
|
|
}
|
|
$this->ajaxReturn(["status"=>0,"msg"=>"验证手机修改失败"]);
|
|
}
|
|
public function showPayment()
|
|
{
|
|
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
|
|
$ids = $_REQUEST['ids'];
|
|
|
|
$CompanyInfo = M("pay_statement_info","tab_")
|
|
->alias('i')
|
|
->field("i.id,c.pool_id,i.company_name,i.company_info,i.statement_money,p.statement_num,i.remark,i.pay_status,i.final_statement_money")
|
|
->join("left join tab_company_statement_info c ON c.id = i.statement_info_id")
|
|
->join("left join tab_company_statement_pool p ON p.id = c.pool_id")
|
|
->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("pay_statement_info","tab_")->field("sum(final_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");
|
|
if(empty(C("ALI_PAYMENT"))){
|
|
$money = "测试站无法查看";
|
|
}else{
|
|
$fund = new \Fund(C("ALI_PAYMENT"));
|
|
$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'];
|
|
if(empty(C("ALI_PAYMENT"))){
|
|
$this->ajaxReturn(["success"=>"配置错误,无法打款","data"=>["status"=>0]]);
|
|
}
|
|
Vendor("Alipay2020/Fund");
|
|
$fund = new \Fund(C("ALI_PAYMENT"));
|
|
$dbres = M("pay_statement_info", "tab_")->where("id='{$id}'")->find();
|
|
|
|
$company_statement = M("company_statement_info", "tab_")->field("pay_check")->where(['id'=>$dbres['statement_info_id']])->find();
|
|
|
|
if ($company_statement['pay_check']!=1) {
|
|
$this->ajaxReturn(["success"=>"打款信息未确认,打款失败","data"=>["status"=>0]]);
|
|
}
|
|
|
|
$company_info = json_decode($dbres['company_info'], true);
|
|
if ($dbres['pay_status'] != 1 && $dbres['verify_status'] == 1) {
|
|
//执行打款
|
|
$title = $remark;
|
|
$amount = $dbres['final_statement_money'];
|
|
|
|
$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_type"]=2;
|
|
$savedata["pay_time"]=time();
|
|
}
|
|
|
|
M("pay_statement_info","tab_")->save($savedata);
|
|
|
|
if ($savedata["pay_status"] == -1) {
|
|
//支付详单bug修改
|
|
$this->setPayVerifyStatus(-1,$savedata["pay_type"],$id);
|
|
$this->ajaxReturn(["success"=>"打款成功","data"=>["status"=>0],'amount'=>$dbres['final_statement_money']]);
|
|
}
|
|
|
|
//支付详单bug修改
|
|
$this->setPayVerifyStatus(1,$savedata["pay_type"],$id);
|
|
$this->ajaxReturn(["success"=>"打款成功","data"=>["status"=>1]]);
|
|
}
|
|
|
|
/**
|
|
* 支付详单状态修改
|
|
*/
|
|
public function setPayVerifyStatus($change_status,$pay_type,$id) {
|
|
|
|
$pay_info = M("pay_statement_info","tab_")->where(['id'=>$id])->find();
|
|
|
|
$info = M("pay_statement_info","tab_")->where("statement_info_id = {$pay_info['statement_info_id']} AND pay_status <> 1")->select();
|
|
|
|
$dbres['pay_status'] = $change_status;
|
|
$dbres['pay_type'] = $pay_type;
|
|
$dbres['pay_time'] = time();
|
|
if (empty($info)) {
|
|
M("company_statement_info","tab_")->where(['id'=>$pay_info['statement_info_id']])->save($dbres);
|
|
}
|
|
else {
|
|
|
|
if ($change_status == -1) {
|
|
|
|
foreach ($info as $key => $value) {
|
|
|
|
if ($value['pay_status'] == -1) {
|
|
M("company_statement_info","tab_")->where(['id'=>$pay_info['statement_info_id']])->save($dbres);
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 执行最后聚合表统计
|
|
* 整合数据,全部成功则支付成功,否则为支付中
|
|
*/
|
|
public function poolCount(){
|
|
$pool_id = $_REQUEST['pool_id'];
|
|
$CompanyInfo = M("company_statement_info","tab_");
|
|
if(count($pool_id) > 0){
|
|
foreach($pool_id as $k=>$v){
|
|
$f = $CompanyInfo->where("pool_id = {$v} AND pay_status <> 1")->find();
|
|
if(empty($f)){
|
|
//全部完成
|
|
$this->setOneVerifyStatus(4,"payment",$v);
|
|
}else{
|
|
//打款中
|
|
$this->setOneVerifyStatus(3,"payment",$v);
|
|
}
|
|
}
|
|
}
|
|
$this->ajaxReturn(["success"=>"打款成功","data"=>[]]);
|
|
}
|
|
/**
|
|
* 打款详情
|
|
*/
|
|
public function paymentInfo()
|
|
{
|
|
if(!isset($_REQUEST['id'])) $this->error("参数错误");
|
|
$id = $_REQUEST['id'];
|
|
$info = M("pay_statement_info","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();
|
|
|
|
|
|
}
|
|
protected function setOneVerifyStatus($change_status,$op_pre,$id)
|
|
{
|
|
$dbres = M("company_statement_pool","tab_")->field("id,verify_status,verify_log")->where("id = {$id}")->find();
|
|
$dbres['verify_log'] = json_decode($dbres['verify_log'],true);
|
|
$dbres['verify_log'][$op_pre.'_user']=$this->admininfo["mobile"];
|
|
$dbres['verify_log'][$op_pre.'_time']=date("Y-m-d H:i:s");
|
|
$dbres['verify_log'] = json_encode($dbres['verify_log']);
|
|
$dbres['verify_status']=$change_status;
|
|
M("company_statement_pool","tab_")->save($dbres);
|
|
}
|
|
|
|
/**
|
|
* 打款审核
|
|
*/
|
|
public function verify() {
|
|
// dump($_SESSION['onethink_admin']['payment_user']['id']);die();
|
|
if ((!$_REQUEST['id']||!$_REQUEST['status'])&&$_REQUEST['status']!='0') {
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'数据传输错误']);
|
|
}
|
|
|
|
$id = $_REQUEST['id'];
|
|
$status = $_REQUEST['status'];
|
|
$member_id = $_SESSION['onethink_admin']['payment_user']['id'];
|
|
|
|
($status == 1)?($status_str = '已审核通过'):($status_str = '已审核拒绝');
|
|
|
|
$save = [
|
|
'pay_verify_status'=>$status,
|
|
'verify_time'=>time(),
|
|
'verify_member_id'=>$member_id
|
|
];
|
|
|
|
$verify = M("company_statement_info","tab_")
|
|
->where([
|
|
'id'=>['in',$id]
|
|
])
|
|
->save($save);
|
|
|
|
$companyStatementInfo = M("company_statement_info","tab_")
|
|
->where([
|
|
'id'=>['in',$id]
|
|
])
|
|
->select();
|
|
|
|
foreach ($companyStatementInfo as $key => $value) {
|
|
if ($value['statement_money'] <= 0) {
|
|
$payres["remark"] = '打款金额非正,直接打款成功';
|
|
|
|
$pay_info = json_encode($payres, JSON_UNESCAPED_UNICODE);
|
|
M("company_statement_info","tab_")
|
|
->where([
|
|
'id'=>['in',$value['id']]
|
|
])
|
|
->save(['pay_status'=>1,'pay_time'=>time(),'pay_type'=>2,'pay_info'=>$pay_info]);
|
|
M("pay_statement_info","tab_")
|
|
->where([
|
|
'statement_info_id'=>['in',$value['id']]
|
|
])
|
|
->save(['pay_status'=>1,'pay_time'=>time(),'pay_type'=>2,'pay_info'=>$pay_info]);
|
|
} else {
|
|
$payres["remark"] = '打款金额非正,直接打款成功';
|
|
|
|
$pay_info = json_encode($payres, JSON_UNESCAPED_UNICODE);
|
|
M("pay_statement_info","tab_")
|
|
->where([
|
|
'statement_info_id'=>['in',$value['id']],
|
|
'statement_money'=>['elt',0]
|
|
])
|
|
->save(['pay_status'=>1,'pay_time'=>time(),'pay_type'=>2,'pay_info'=>$pay_info]);
|
|
|
|
$pay_statement_info = M("pay_statement_info","tab_")
|
|
->where([
|
|
'statement_info_id'=>['in',$value['id']]
|
|
])
|
|
->order("statement_money ASC")
|
|
->select();
|
|
$subtraction = 0;
|
|
foreach ($pay_statement_info as $sk => $sv) {
|
|
|
|
if ($sv['statement_money'] < 0) {
|
|
$subtraction += -($sv['statement_money']);
|
|
$sv['final_statement_money'] = 0;
|
|
} elseif($sv['statement_money'] > 0 && $subtraction > 0) {
|
|
if($sv['statement_money'] >= $subtraction) {
|
|
$sv['final_statement_money'] = $sv['statement_money']-$subtraction;
|
|
$subtraction = 0;
|
|
} else {
|
|
$sv['final_statement_money'] = 0;
|
|
$subtraction =-$sv['final_statement_money'];
|
|
}
|
|
}
|
|
|
|
M("pay_statement_info","tab_")
|
|
->where([
|
|
'id'=>$sv['id']
|
|
])->save($sv);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
if ($verify) {
|
|
$this->ajaxReturn(['status'=>1,'msg'=>$status_str]);
|
|
} else {
|
|
$this->ajaxReturn(['status'=>0,'msg'=>'审核失败请重新审核']);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* 验证订单
|
|
*/
|
|
public function checkOrder() {
|
|
|
|
if(!$_REQUEST['ids']) {
|
|
$this->ajaxReturn(['data'=>[]]);
|
|
}
|
|
|
|
$ids = $_REQUEST['ids'];
|
|
|
|
$data = M("pay_statement_info","tab_")
|
|
->field("id,statement_money,company_name,statement_begin_time,statement_end_time,pay_time")
|
|
->where(['id'=>['in',implode(',',$ids)]])
|
|
->select();
|
|
// dump($data);die();
|
|
$return = [];
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
$check_data = M("excel_statement_info","tab_")
|
|
->where([
|
|
'statement_money'=>$value['statement_money'],
|
|
'company_name'=>$value['company_name'],
|
|
'statement_begin_time'=>$value['statement_begin_time'],
|
|
'statement_end_time'=>$value['statement_end_time'],
|
|
// 'id'=>['neq',$value['id']],
|
|
'pay_status'=>1
|
|
])
|
|
->select();
|
|
|
|
$check_company_statement_info = M("pay_statement_info","tab_")
|
|
->where([
|
|
'pay_status'=>1,
|
|
'company_name'=>$value['company_name'],
|
|
'statement_begin_time'=>$value['statement_begin_time'],
|
|
'statement_end_time'=>$value['statement_end_time'],
|
|
'statement_money'=>$value['statement_money'],
|
|
'id'=>['neq',$value['id']],
|
|
])
|
|
->select();
|
|
|
|
|
|
|
|
$return = array_merge($return,$check_data,$check_company_statement_info);
|
|
|
|
}
|
|
|
|
foreach ($return as $key => $value) {
|
|
|
|
$return[$key]['time'] = ($value['statement_begin_time']?date("Y-m-d",$value['statement_begin_time']):'无').'-'.($value['statement_end_time']?date("Y-m-d",$value['statement_end_time']):'无');
|
|
$return[$key]['pay_time'] = date("Y-m-d H:m:s",$value['pay_time']);
|
|
|
|
}
|
|
|
|
$this->ajaxReturn(['data'=>$return]);
|
|
|
|
}
|
|
|
|
|
|
}
|