@ -91,6 +91,7 @@ class CompanyStatementOfflineController extends ThinkController
$unPayData = SM("company_statement_info_part","tab_")
->field("sum(statement_money) statement_money,info_id")
->where(["pay_status"=>1])
->group("info_id")
->select();
@ -107,7 +108,7 @@ class CompanyStatementOfflineController extends ThinkController
$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']):($v["pay_status"]!=1?($v["pay_status"]==2?$handleData[$v['id']]:$v['statement_money']):"0.00");
$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'])){
@ -135,6 +136,16 @@ class CompanyStatementOfflineController extends ThinkController
// $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
@ -169,8 +180,8 @@ class CompanyStatementOfflineController extends ThinkController
->where("i.id in({$id})")
->select();
$temp = $this->addPaymentPartInfo($CompanyInfo);
$temp?$CompanyInfo=$temp:"";
// $temp = $this->addPaymentPartInfo($CompanyInfo);
// $temp?$CompanyInfo=$temp:"";
$all_money = 0;
foreach($CompanyInfo as $k=>& $v){
@ -205,7 +216,7 @@ class CompanyStatementOfflineController extends ThinkController
->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]])
->where(['info_id'=>['in',$id],"pay_status"=>0 ])
->select();
@ -324,6 +335,18 @@ class CompanyStatementOfflineController extends ThinkController
->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){
@ -337,9 +360,11 @@ class CompanyStatementOfflineController extends ThinkController
$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);
@ -414,6 +439,8 @@ class CompanyStatementOfflineController extends ThinkController
$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);
}
@ -437,7 +464,7 @@ class CompanyStatementOfflineController extends ThinkController
$data = $CompanyInfo->where(['id'=>['in',$ids]])->select();
foreach ($data as $key => $value) {
if ($value['pay_check'] == 2||($value['pay_check'] == 1& & $value['pay_status'] == 0) ) {
if ($value['pay_check'] == 1& & $value['pay_status'] == 0) {
$CompanyInfo
->where(['id'=>$value['id']])
->save([
@ -446,18 +473,23 @@ class CompanyStatementOfflineController extends ThinkController
'pay_check_time'=>0
]);
M("company_statement_info_part","tab_")->where(['info_id'=>$value['id']])->delete();
}
if ($value['pay_check'] == 2) {
} elseif($value['pay_check'] == 1& & $value['pay_status'] == 2) {
if($value['pay_status'] == 0 ) {
$CompanyInfo
->where(['id'=>$value['id']])
->save([
'pay_check'=>2 ,
'pay_check_member_id'=>$_SESSION['onethink_admin']['user_auth']['uid'] ,
'pay_check_time'=>time()
'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();
}
}
@ -485,7 +517,7 @@ class CompanyStatementOfflineController extends ThinkController
//获取母单未支付完成订单
$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();
// $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();
@ -525,12 +557,32 @@ class CompanyStatementOfflineController extends ThinkController
foreach ($unPayData as $key => $value) {
$time = date("Y-m-d H:i:s",time());
$unPayAmount = $value['statement_money']-$handleData[$value['id']];
$saveData['remark'] = "{$value['remark']}, {$_SESSION['onethink_admin']['user_auth']['username']}于{$time}已打款{$unPayAmount},剩余{$ handleData[$value['id']]}";
$saveData['remark'] = "{$value['remark']} {$_SESSION['onethink_admin']['user_auth']['username']}于{$time}已打款{$handleData[$value['id']]},剩余{$unPayAmount }";
SM("company_statement_info_part","tab_")
->where(['info_id'=>$value['id']])
->save(["pay_status"=>1]);
if($value['statement_money'] - $handleData[$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']
]);
} 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();
// dump($yPoolInfo);
// dump($poolInfo);die();
//全部就打款成功,否则打款中
$companyStatementPool = SM("company_statement_pool","tab_");
foreach ($poolInfo as $k => $v) {