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.

916 lines
34 KiB
PHP

<?php
namespace Admin\Controller;
/**
* 线下打款
* @author cz
*/
class CompanyStatementOfflineController extends ThinkController
{
public $CompanyType = [
"1"=>"下游公司",
"2"=>"下游个人",
"3"=>"上游公司"
];
public $IsPayment = [
"1"=>"",
"2"=>""
];
public $PayStatus=[
"-1"=>"打款失败",
"0"=>"未打款",
"1"=>"打款成功",
"2"=>"部分打款"
];
public function lists() {
$params = I('get.');
$page = $params['p'] ? intval($params['p']) : 1;
$row = $params['row'] ? intval($params['row']) : 10;
//权限分配
if(!IS_ROOT){
$this->OpAuthList= getModuleControllerAuth();
}
$this->assign('menubtn',$this->menuAuth());
$map = [
"c.verify_status"=>2,
"p.verify_status"=>['in',[2,3,4,5]]
];
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
$time_start = strtotime($_REQUEST['time_start']);
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$map["_string"] = "(c.statement_begin_time BETWEEN {$time_start} AND {$time_end}) OR (c.statement_end_time BETWEEN {$time_start} AND {$time_end}) OR (c.statement_begin_time <= {$time_end} AND c.statement_end_time >= {$time_end})";
} elseif (isset($_REQUEST['time_start'])) {
$time_start = strtotime($_REQUEST['time_start']);
$map["_string"] = "(c.statement_begin_time >= {$time_start} ) OR (c.statement_end_time >= {$time_start})";
} elseif (isset($_REQUEST['time_end'])) {
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$map["_string"] = "(c.statement_begin_time <= {$time_end} ) OR (c.statement_end_time <= {$time_end})";
}
if(isset($_REQUEST['pay_status'])){
$map['c.pay_status'] = $_REQUEST['pay_status'];
}
//其他
if(isset($_REQUEST['company_type'])){
$map['c.company_type'] = $_REQUEST['company_type'];
}
if(isset($_REQUEST['company_name'])){
$map['c.company_name'] =["LIKE","%{$_REQUEST['company_name']}%"];
}
if(isset($_REQUEST['statement_pool_num'])){
$map['p.statement_num'] =["LIKE","%{$_REQUEST['statement_pool_num']}%"];
}
//条件end
if (isset($_REQUEST['export']) && $_REQUEST['export']==1) {
$map['c.company_type'] = $_REQUEST['export_company_type'];
$data = SM("company_statement_info","tab_")
->alias("c")
->field("c.*,p.statement_num,p.verify_status")
->where($map)
->join("tab_company_statement_pool as p ON c.pool_id = p.id")
->order("id desc")
->select();
$ids = array_column($data, 'id');
$ids = implode(',', $ids);
$this->export($ids);
return ;
}
$data = SM("company_statement_info","tab_")
->alias("c")
->field("c.*,p.statement_num,p.verify_status")
->where($map)
->join("tab_company_statement_pool as p ON c.pool_id = p.id")
->order("id desc");
if (isset($_REQUEST['list_export']) && $_REQUEST['list_export']==1) {
$data = $data->select();
}else{
$data = $data->page($page,$row)->select();
}
$unPayData = SM("company_statement_info_part","tab_")
->field("sum(statement_money) statement_money,info_id")
->where(["pay_status"=>1])
->group("info_id")
->select();
$handleData = [];
foreach ($unPayData as $key => $value) {
$handleData[$value['info_id']] = $value['statement_money'];
}
foreach($data as $k => &$v) {
$v['statement_begin_time'] = date('Y.m.d',$v['statement_begin_time']);
$v['statement_end_time'] = date('Y.m.d',$v['statement_end_time']);
$v['company_type_str'] = $this->CompanyType[$v['company_type']];
$v["valid"] = "{$v['statement_begin_time']}-{$v['statement_end_time']}";
$v["pay_status_str"] = $this->PayStatus[$v["pay_status"]];
$v['surplus_amount'] = ($v["pay_check"]==2)?($handleData[$v['id']] ? ($v['statement_money']-$handleData[$v['id']]):$v['statement_money'] ):($v["pay_status"]!=1?($v["pay_status"]==2?($v['statement_money']-$handleData[$v['id']]):$v['statement_money']):"0.00");
$v["pay_info"] = json_decode($v['pay_info'], true);
if(isset($v['pay_info']['payment_user'])){
$v["payment"]= "{$v['pay_status_str']}({$v['pay_info']['payment_user']})<br>{$v['pay_info']['payment_time']}";
}else{
$v["payment"] = $v["pay_status_str"];
}
if ($v['pay_check'] == 0) {
$v['pay_check_str'] = "---";
} else {
$member = M("ucenter_member")
->field("username")
->where(['id'=>$v['pay_check_member_id']])
->find();
if ($v['pay_check'] == 1) {
$pay_check = '已确认';
} elseif($v['pay_check'] == 2) {
$pay_check = '部分确认';
} else {
$pay_check = '未确认';
}
$v['pay_check_str'] = $member['username'].$pay_check."<br>".date('Y-m-d H:i:s', $v['pay_check_time']);;
// $v['pay_check_str'] = "已确认";
}
$isUnPay = SM("company_statement_info_part","tab_")
->field("info_id")
->where(["pay_status"=>0,'info_id'=>$v['id']])
->group("info_id")
->find();
if ($isUnPay) {
$v['pay_status'] = 0;
}
$v['oplist'] = $this->OpAuth($v);
}
//pay_status
$field = "count(c.id) count,IFNULL(SUM(CASE WHEN pay_status = 1 and pay_check=1 THEN c.statement_money ELSE 0 END),0) as success_money,
IFNULL(SUM(CASE WHEN pay_status = 0 or pay_status=2 THEN c.statement_money ELSE 0 END),0) as statement_money,
IFNULL(SUM(CASE WHEN pay_status = -1 THEN c.statement_money ELSE 0 END),0) as error_money";
$count = SM("company_statement_info","tab_")
->alias("c")
->field($field)
->join("tab_company_statement_pool as p ON c.pool_id = p.id")
->where($map)
->find();
$countPart = SM("company_statement_info_part","tab_")->alias("c")
->field("IFNULL(SUM(CASE WHEN pay_status = 0 THEN c.statement_money ELSE 0 END),0) as statement_money,
IFNULL(SUM(CASE WHEN pay_status = -1 THEN c.statement_money ELSE 0 END),0) as error_money")
->join("tab_company_statement_pool as p ON c.pool_id = p.id")
->where($map)
->find();
unset($map['c.pay_status']);
$countSuccess = SM("company_statement_info_part","tab_")->alias("c")
->field("IFNULL(SUM(CASE WHEN c.pay_status = 0 THEN c.statement_money ELSE 0 END),0) as statement_money,
IFNULL(SUM(CASE WHEN c.pay_status = 1 THEN c.statement_money ELSE 0 END),0) as success_money")
->join("tab_company_statement_pool as p ON c.pool_id = p.id")
->join("left join tab_company_statement_info i on c.info_id=i.id")
->where($map)
->where(['i.pay_status'=>['neq',1]])
->find();
if ($_REQUEST['pay_status'] != 2) {
$countSuccess = [];
}
// dump($countPart);
// dump($countSuccess);die();
// dump($count);die();
$count['success_money'] += $countSuccess['success_money'];
$count['statement_money'] -= $countSuccess['success_money'];
$count['error_money'] += $countPart['error_money'];
//新增列表导出
if (isset($_REQUEST['list_export']) && $_REQUEST['list_export']==1) {
$data[]=[
'company_name'=>'合计',
'company_type_str'=>"待打款金额:{$count['statement_money']} / 打款成功金额:{$count['success_money']} / 打款失败金额:{$count['error_money']}"
];
data2csv($data,'线下打款确认',array(
'company_name'=>'合作公司',
'company_type_str'=>'公司类型',
'valid'=>'结算时间',
'statement_money'=>'结算金额',
'surplus_amount'=>'剩余未打款金额',
'platform_amount'=>'结算流水',
'pay_check_str'=>'打款信息确认状态',
'payment'=>'打款状态',
'statement_num'=>'汇总单号'
));
}
$params['p'] = $page;
$params['row'] = $row;
$page = set_pagination($count['count'], $row, $params);
if ($page) {
$this->assign('_page', $page);
}
// dd($data);
$this->assign('data',$data);
$this->assign('count',$count);
$this->assign('CompanyType',$this->CompanyType);
$this->assign("PayStatus", $this->PayStatus);
$this->display();
}
//打款设置
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,i.pay_check")
->join("tab_company_statement_pool p ON p.id = i.pool_id")
->where("i.id in({$id})")
->select();
// $temp = $this->addPaymentPartInfo($CompanyInfo);
// $temp?$CompanyInfo=$temp:"";
$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 addPaymentPartInfo($CompanyInfo) {
if ($CompanyInfo[0]['pay_check'] !=2) {
return [];
}
$id = array_column($CompanyInfo,"id");
$data = M("company_statement_info_part","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,info_id")
->join("tab_company_statement_pool p ON p.id = i.pool_id")
->where(['info_id'=>['in',$id],"pay_status"=>0])
->select();
foreach ($data as $key => $value) {
$data[$key]['id'] = $value['id']."-".$value['info_id'];
}
return $data;
}
//修改打款设置
public function editPayment(){
// dump($_SESSION);die();
if(!isset($_REQUEST['info'])) $this->error("参数错误");
$info = $_REQUEST['info'];
$keys = '';
$saveKey = [];
$CompanyInfo = M("company_statement_info","tab_");
//循环保存
foreach($info as $k=>$v){
// dump(explode('-',$k));die();
$exKeys = explode('-',$k);
if (count($exKeys) > 1) {
$keys = $exKeys;
if (!$saveKey[$keys[1]]) {
$saveKey[$keys[1]] = 1;
$ydata = $CompanyInfo->where("id= '{$keys[1]}'")->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 = [
"pay_check"=>1,
"pay_check_member_id"=> $_SESSION['onethink_admin']['user_auth']['uid'],
"id"=>$keys[1],
"pay_check_time"=>time()
];
$CompanyInfo->save($savedata);
}
$ydata = M("company_statement_info_part","tab_")->where("id= '{$keys[0]}'")->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']['user_auth']['uid'],
"id"=>$keys[0],
"pay_check_time"=>time()
];
M("company_statement_info_part","tab_")->save($savedata);
} else {
$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']['user_auth']['uid'],
"id"=>$k,
"pay_check_time"=>time()
];
$CompanyInfo->save($savedata);
}
}
$this->ajaxReturn(array(
'status' => 1,
"info"=>"打款信息编辑成功"
));
}
//打款设置
public function setPartPayment(){
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();
$unPayData = SM("company_statement_info_part","tab_")
->field("sum(statement_money) statement_money,info_id")
->where(["pay_status"=>1])
->group("info_id")
->select();
$handleData = [];
foreach ($unPayData as $key => $value) {
$handleData[$value['info_id']] = $value['statement_money'];
}
$surplurAmount = 0;
$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'];
$surplurAmount += $handleData[$v['id']];
}
$this->assign('surplur_amount',$all_money-$surplurAmount);
$this->assign('all_money',$all_money);
$this->assign("CompanyInfo",$CompanyInfo);
$this->assign("id",$id);
$this->display();
}
//修改打款设置
public function editPartPayment(){
// die();
if (count($_REQUEST['info']) < 2) {
$this->error("未添加剩余打款金额");
}
// dump($_REQUEST['info']);die();
if(!isset($_REQUEST['info'])) $this->error("参数错误");
$info = $_REQUEST['info'];
$ydata = [];
$company_info = [];
$CompanyInfo = M("company_statement_info","tab_");
//循环保存
foreach($info as $k=>$v){
$ydata = $CompanyInfo->where("id= '{$k}'")->find();
$sumPartInfo = M("company_statement_info_part","tab_")
->field("sum(statement_money) statement_money")
->where(['info_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"=>2,
"pay_check_member_id"=> $_SESSION['onethink_admin']['user_auth']['uid'],
"id"=>$k,
"pay_check_time"=>time()
];
$CompanyInfo->save($savedata);
unset($info[$k]);
break;
}
// array_pop($info);
$id = $ydata["id"];
unset($ydata["id"]);
$sumUnPayAmount = array_sum(array_column($info,'unpay_amount'));
if ((int)(($sumUnPayAmount+$sumPartInfo['statement_money'])*100) > (int)($ydata['statement_money']*100) ) {
$this->error("剩余打款金额超过结算金额");
}
foreach ($info as $k=>$v) {
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'];
}
$ydata['company_info'] = json_encode($company_info,JSON_UNESCAPED_UNICODE);
$ydata['statement_money'] = $v['unpay_amount'];
$ydata['pay_amount'] = $v['unpay_amount'];
$ydata['remark'] = $v['remark'];
$ydata['info_id'] = $id;
$ydata['pay_check'] = 0;
$ydata['pay_status'] = 0;
M("company_statement_info_part","tab_")->add($ydata);
}
$this->ajaxReturn(array(
'status' => 1,
"info"=>"打款信息编辑成功"
));
}
public function returnSetPayment() {
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$ids = explode(',',$ids);
$CompanyInfo = M("company_statement_info","tab_");
$data = $CompanyInfo->where(['id'=>['in',$ids]])->select();
foreach ($data as $key => $value) {
if ($value['pay_check'] == 1&&$value['pay_status'] == 0) {
$CompanyInfo
->where(['id'=>$value['id']])
->save([
'pay_check'=>0,
'pay_check_member_id'=>0,
'pay_check_time'=>0
]);
}
if ($value['pay_check'] == 2) {
if($value['pay_status'] == 0) {
$CompanyInfo
->where(['id'=>$value['id']])
->save([
'pay_check'=>0,
'pay_check_member_id'=>0,
'pay_check_time'=>0
]);
}
M("company_statement_info_part","tab_")->where(['info_id'=>$value['id'],'pay_status'=>['neq',1]])->delete();
}
}
$this->ajaxReturn(array(
'status' => 1,
"info"=>"打款信息编辑成功"
));
}
public function doPayment()
{
if(!isset($_REQUEST['ids']) || !isset($_REQUEST['payment_time'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$payment_time = $_REQUEST['payment_time'];
//获取所有的母单id
$companyStatementInfo = SM("company_statement_info","tab_");
$statementPool = $companyStatementInfo->where("id in ($ids) and pay_status <> 1")->field("pool_id,count(id) count")->group("pool_id")->select();
$yPoolInfo = [];
foreach ($statementPool as $k => $v) {
$yPoolInfo[$v['pool_id']] = $v['count'];
}
unset($statementPool);
//获取母单未支付完成订单
$poolIds = implode(",",array_keys($yPoolInfo));
// $poolInfo = $companyStatementInfo->where("pool_id in ($poolIds) and pay_status <> 1 and pay_check !=2")->field("pool_id,count(id) count")->group("pool_id")->select();
$info_id = $companyStatementInfo->field("id")->where("id in ($ids) and pay_check !=2")->select();
$unPayInfoId = $companyStatementInfo->field("id")->where("id in ($ids) and pay_check =2")->select();
$info_id = array_column($info_id,"id");
$unPayInfoId = array_column($unPayInfoId,"id");
//支付确认的部分
$saveData = [
"pay_type"=>3,
"pay_status"=>1,
"pay_info"=>json_encode(["payment_user"=>$_SESSION['onethink_admin']['user_auth']["username"],"payment_time"=>$payment_time]),'pay_time'=>strtotime($payment_time)
];
if($info_id) {
$companyStatementInfo->where(['id'=>['in',$info_id]])->save($saveData);
}
//支付未确认的部分
$saveData = [
"pay_type"=>3,
"pay_status"=>2,
"pay_info"=>json_encode(["payment_user"=>$_SESSION['onethink_admin']['user_auth']["username"],"payment_time"=>$payment_time])
,'pay_time'=>strtotime($payment_time)
];
$unPayData = M("company_statement_info_part","tab_")
->field("sum(statement_money) statement_money,info_id")
->where(["pay_status"=>0])
->group("info_id")
->select();
$handleData = [];
foreach ($unPayData as $key => $value) {
$handleData[$value['info_id']] = $value['statement_money'];
}
$payData = M("company_statement_info_part","tab_")
->field("sum(statement_money) statement_money,info_id")
->group("info_id")
->select();
$handlePayData = [];
foreach ($payData as $key => $value) {
$handlePayData[$value['info_id']] = $value['statement_money'];
}
if ($unPayInfoId) {
$unPayData = $companyStatementInfo->where(['id'=>['in',$unPayInfoId]])->select();
foreach ($unPayData as $key => $value) {
$time = date("Y-m-d H:i:s",time());
$unPayAmount = $value['statement_money']-$handlePayData[$value['id']];
$saveData['remark'] = $value['remark'];
$partInfo = M("company_statement_info_part","tab_")->where(['info_id'=>$value['id']])->order("id desc")->find();
$partCompanyInfo = json_decode($partInfo['company_info'],true);
$saveData['company_info'] = $partInfo['company_info'];
if($handleData[$value['id']]) {
$saveData['remark'] .= ";{$_SESSION['onethink_admin']['user_auth']['username']}{$time}向({$partCompanyInfo['payee_name']}/{$partCompanyInfo['opening_bank']}/{$partCompanyInfo['bank_account']})打款{$handleData[$value['id']]},剩余{$unPayAmount}";
}
M("company_statement_info_part","tab_")
->where(['info_id'=>$value['id'],'pay_status'=>['neq',1]])
->save(["pay_status"=>1,'pay_time'=>strtotime($payment_time)]);
if($value['statement_money'] - $handlePayData[$value['id']] <=0) {
//打款成功
$companyStatementInfo->where(['id'=>$value['id']])->save([
"pay_check"=>1,
"pay_type"=>3,
"pay_status"=>1,
"pay_info"=>json_encode(["payment_user"=>$_SESSION['onethink_admin']['user_auth']["username"],"payment_time"=>$payment_time]),
"remark"=>$saveData['remark'],
'pay_time'=>strtotime($payment_time),
'company_info'=>$partInfo['company_info']
]);
} else {
$companyStatementInfo->where(['id'=>$value['id']])->save($saveData);
}
}
}
$poolInfo = $companyStatementInfo->where("pool_id in ($poolIds) and pay_status <> 1")->field("pool_id,count(id) count")->group("pool_id")->select();
$handlePoolInfo = [];
foreach ($poolInfo as $key => $value) {
$handlePoolInfo[$value['pool_id']] = $value['count'];
}
// dump($yPoolInfo);
// dump($poolInfo);die();
//全部就打款成功,否则打款中
$companyStatementPool = SM("company_statement_pool","tab_");
// dump($yPoolInfo);die();
foreach ($yPoolInfo as $k => $v) {
if (!$handlePoolInfo[$k]) {
//打款成功
$this->setOneVerifyStatus(4,"payment",$k);
} else {
//打款中
$this->setOneVerifyStatus(3,"payment",$k);
}
// if($v['count'] == $yPoolInfo[$v['pool_id']]){
// //打款成功
// $this->setOneVerifyStatus(4,"payment",$v['pool_id']);
// }else{
// //打款中
// $this->setOneVerifyStatus(3,"payment",$v['pool_id']);
// }
}
// foreach ($poolInfo as $k => $v) {
// if($v['count'] == $yPoolInfo[$v['pool_id']]){
// //打款成功
// $this->setOneVerifyStatus(4,"payment",$v['pool_id']);
// }else{
// //打款中
// $this->setOneVerifyStatus(3,"payment",$v['pool_id']);
// }
// }
$this->ajaxReturn(array(
'status' =>1,
"info"=>"打款确认成功"
));
}
public function viewStatement()
{
// if(!isset($_REQUEST['id'])){
// $this->error('参数错误');
// }
// $id = $_REQUEST['id'];
// $is_export= false;
// if (isset($_REQUEST['export']) && $_REQUEST['export']==1){
// $is_export = true;
// }
// //获取基本信息
// $dbres = SM("company_statement_info","tab_")->where("id='{$id}'")->select();
// $title = $dbres[0]['company_name'];
// $this->assign("title",$title);
//
// if($dbres[0]['company_type'] == 3){
// //上游
// A("CompanyStatementPool")->viewCpPool($dbres,$is_export);
// }elseif($dbres[0]['company_type'] == 1){
// //下游公司
// A("CompanyStatementPool")->viewPcPool($dbres,$is_export);
// }else{
// A("CompanyStatementPool")->viewPuPool($dbres,$is_export,["withdraw_type"=>3]);
// }
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,i.pay_check,pay_time")
->join("tab_company_statement_pool p ON p.id = i.pool_id")
->where("i.id in({$id}) and (pay_check=1 or pay_check=2)")
->select();
// $temp = $this->addPaymentPartInfo($CompanyInfo);
// $temp?$CompanyInfo=$temp:"";
if ($CompanyInfo[0]['id']) {
$CompanyInfoSecord = M("company_statement_info_part","tab_")
->alias('i')
->field("info_id 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,i.pay_check,pay_time")
->join("tab_company_statement_pool p ON p.id = i.pool_id")
->where("i.info_id ={$CompanyInfo[0]['id']}")
->select();
}
if($CompanyInfoSecord) {
$CompanyInfo = $CompanyInfoSecord;
}
$unPayData = SM("company_statement_info_part","tab_")
->field("sum(statement_money) statement_money,info_id")
->where(["pay_status"=>1,'info_id'=>['in',$_REQUEST['id']]])
->group("info_id")
->select();
$handleData = [];
foreach ($unPayData as $key => $value) {
$handleData[$value['info_id']] = $value['statement_money'];
}
$payData = SM("company_statement_info","tab_")
->field("id,sum(statement_money) statement_money,pay_status")
->where(['id'=>['in',$_REQUEST['id']]])
->group("id")
->select();
$handleAllData = [];
foreach ($payData as $key => $value) {
$handleAllData[$value['id']] = $value['statement_money'];
}
// dump($payData);
$surplurAmount = array_sum($handleData);
$all_money = array_sum($handleAllData);
foreach ($payData as $key => $value) {
if ($value['pay_status'] == 1) {
$surplurAmount -= $handleData[$value['id']];
$surplurAmount += $value['statement_money'];
}
}
$sAmount = number_format($all_money-$surplurAmount,2,'.','');
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'] ?? '';
$v['time'] = date("Y-m-d H:i:s",$v['pay_time']);
// $all_money += $v['statement_money'];
}
$this->assign('surplur_amount',$sAmount);
$this->assign('all_money',$all_money);
$this->assign("CompanyInfo",$CompanyInfo);
$this->assign("id",$id);
$this->display("viewstatement");
}
public function export($ids=''){
if (!$ids) {
if (!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
}
$dbres = SM("company_statement_info","tab_")->where("id in ({$ids})")->select();
$is_export= false;
if (isset($_REQUEST['export']) && $_REQUEST['export']==1){
$is_export = true;
}
if($dbres[0]['company_type'] == 3){
//上游
$this->assign("title","上游公司线下打款");
A("CompanyStatementPool")->viewCpPool($dbres,$is_export);
}elseif($dbres[0]['company_type'] == 1){
//下游公司
$this->assign("title","下游公司线下打款");
A("CompanyStatementPool")->viewPcPool($dbres,$is_export);
}else{
$this->assign("title","下游个人线下打款");
A("CompanyStatementPool")->viewPuPool($dbres,$is_export,["withdraw_type"=>3]);
}
}
protected function setOneVerifyStatus($change_status,$op_pre,$id)
{
$dbres = SM("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']=$_SESSION['onethink_admin']['user_auth']["username"];
$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;
SM("company_statement_pool","tab_")->save($dbres);
}
public function OpAuth($info)
{
$id = $info['id'];
$type = $info['company_type'];
//原始列表
$opBtn = [
"viewStatement"=>"<a class='confirm viewStatement' data-id='{$id}' data-companytype='{$type}'>查看</a>",
];
//操作对应菜单
$optist = ["viewStatement"];
$resarr = [];
foreach ($optist as $k => $v) {
if(IS_ROOT){
$resarr[] = $opBtn[$v];
}else{
if(in_array($v,$this->OpAuthList)){
$resarr[] = $opBtn[$v];
}
}
}
return $resarr;
}
public function menuAuth()
{
$mentBtn = [
"setPayment"=>"<a class='butn' id='setPayment'>打款信息确认</a>",
"returnSetPayment"=>"<a class='butn' id='returnSetPayment'>打款信息确认撤回</a>",
"doPayment"=>"<a class='butn' id='doPayment'>打款确认</a>",
"export"=>"<a class='butn' id='export'>导出所选记录</a>",
"export_all"=>"<a class='butn' id='export_all'>导出当前记录</a>",
];
$resarr = [];
foreach ($mentBtn as $k => $v) {
if(IS_ROOT){
$resarr[] = $v;
}else{
if(in_array($k,$this->OpAuthList)){
$resarr[] = $v;
}
}
}
return $resarr;
}
}