新增重算

master
chenzhi 4 years ago
parent d05d6e2159
commit 79a9a8c68c

@ -507,55 +507,161 @@ class CompanyStatementPoolController extends ThinkController
public function cancelPool(){
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
//获取基础信息
//获取基础信息
$db_res = $this->DBModel->where("id='{$id}'")->find();
$is_qz = (substr($db_res['statement_num'],0,2) == "QZ" ? true :false); //强制汇总的都允许回退
if($is_qz){
//强制汇总回退
$this->cancelQzPool($db_res);
}
$re_op = true;
$create_lack_ids = $db_res['create_lack_ids'];
if(!empty($create_lack_ids) && !$is_qz){
$clsi = M("company_lack_statement_info","tab_")->where("is_pool = 1 and id in ({$create_lack_ids})")->find();
$re_op = true;
if(!empty($clsi)){
$re_op = false; //被引用无法重算
}
}
if($re_op){
//公司及上游回退
if($db_res['company_type'] == 2){
$this->retry($db_res); //个人重算
}else{
$this->cancelCompanyPool($db_res);//公司撤回
}
}
}
/**
* 重算 先全删再进行二次生成
*/
public function retry($info)
{
//执行删除
$dids = $info['del_lack_ids'];
$cids = $info['create_lack_ids'];
M()->startTrans();
//删除info
$infores = M("company_statement_info","tab_")->where("pool_id = {$info['id']}")->delete();
if($infores === false){
M()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"重算失败"));
}
//删除自己
$poolres = $this->DBModel->where("id = {$info['id']}")->delete();
if($poolres === false){
M()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"重算失败"));
}
//修改引用不足单
if(!empty($dids)){
$dres = M("company_lack_statement_info","tab_")->where("id in ({$dids})")->save(['is_pool'=>0]);
if($dres === false){
M()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"重算失败"));
}
}
//删除创建的不足单
if(!empty($cids)){
$cres = M("company_lack_statement_info","tab_")->where("id in ({$cids})")->delete();
if($cres === false){
M()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"重算失败"));
}
}
//重新计算
$stime = $info['statement_end_time']-0+1;
$type = $info['withdraw_type'];
A("CompanyStatementSet")->promoteUserPool($type,$stime,true);
M()->commit();
$this->ajaxReturn(array(
'status' => 1,
'info' => "重算成功"
));
}
public function cancelQzPool($info){
if(!empty($info['del_lack_ids'])){
M()->startTrans();//事务
$dbres = M("company_lack_statement_info","tab_")->where("id in ({$info['del_lack_ids']})")->save(['is_pool'=>0]);
$poolres = $this->DBModel->where("id = {$info['id']}")->delete();
$infores = M("company_statement_info","tab_")->where("pool_id = {$info['id']}")->delete();
if($dbres !== false && $poolres !== false && $infores !== false){
M()->commit();
$this->ajaxReturn(array(
'status' => 1,
'info' => "撤销汇总成功"
));
}
}
M()->rollback();
$this->ajaxReturn(array(
'status' => 0,
'info' => "撤销汇总失败"
));
}
public function cancelCompanyPool($info)
{
if(in_array($info['verify_status'],[3,4])) return;//有打款就不允许回退
$sids = $info['statement_ids'];
$dids = $info['del_lack_ids'];
$cids = $info['create_lack_ids'];
M()->startTrans();//事务
//删除info
$infores = M("company_statement_info","tab_")->where("pool_id = {$info['id']}")->delete();
if($infores === false){
M()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败"));
}
//删除自己
$poolres = $this->DBModel->where("id = {$info['id']}")->delete();
if($poolres === false){
M()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败"));
}
//修改结算单信息
$st_res = M("company_statement","tab_")->field("id,verify_status,verify_log")->where("id in ({$sids})")->select();
foreach($st_res as $k=>&$v){
$v['verify_log'] = json_decode($v['verify_log'],true);
$v['verify_log'][$op_pre.'_user']=$this->admininfo["username"];
$v['verify_log'][$op_pre.'_time']=date("Y-m-d H:i:s");
$v['verify_log'] = json_encode($v['verify_log']);
$v['verify_status']=-2;
$stres = M("company_statement","tab_")->save($v);
if($stres === false){
M()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败"));
}
}
//修改引用不足单
if(!empty($dids)){
$dres = M("company_lack_statement_info","tab_")->where("id in ({$dids})")->save(['is_pool'=>0]);
if($dres === false){
M()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败"));
}
}
//删除创建的不足单
if(!empty($cids)){
$cres = M("company_lack_statement_info","tab_")->where("id in ({$cids})")->delete();
if($cres === false){
M()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败"));
}
}
M()->commit();
$this->ajaxReturn(array(
'status' => 1,
"info"=>"重算金额成功"
));
}
// public function cancelPool()
// {
// //开启事务
// if(!isset($_REQUEST['ids'])) $this->error("参数错误");
// $ids = $_REQUEST['ids'];
// $dbres = $this->DBModel->field("id,statement_ids,verify_status")->where("id in ({$ids})")->select();
// $sids = [];
// foreach($dbres as $k=>$v){
// if(in_array($v['verify_status'],[3,4])) continue; //有打款就不允许回退
// $statement_ids = explode(",",$v['statement_ids']);
// $sids = array_merge($sids,$statement_ids);
// }
// $sids = implode(",",$sids);
// M()->startTrans();//事务
// //删除info
// $infores = M("company_statement_info","tab_")->where("pool_id in ($ids)")->delete();
// if($infores === false){
// M()->rollback();
// $this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败"));
// }
// //删除自己
// $poolres = $this->DBModel->where("id in ({$ids})")->delete();
// if($poolres === false){
// M()->rollback();
// $this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败"));
// }
// //修改结算单信息
// $st_res = M("company_statement","tab_")->field("id,verify_status,verify_log")->where("id in ({$sids})")->select();
// foreach($st_res as $k=>&$v){
// $v['verify_log'] = json_decode($v['verify_log'],true);
// $v['verify_log'][$op_pre.'_user']=$this->admininfo["username"];
// $v['verify_log'][$op_pre.'_time']=date("Y-m-d H:i:s");
// $v['verify_log'] = json_encode($v['verify_log']);
// $v['verify_status']=-2;
// $stres = M("company_statement","tab_")->save($v);
// if($stres === false){
// M()->rollback();
// $this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败"));
// }
// }
// M()->commit();
// $this->ajaxReturn(array(
// 'status' => 1,
// "info"=>"重算金额成功"
// ));
// }

@ -720,6 +720,7 @@ class CompanyStatementSetController extends Controller {
"pay_amount"=>0,
"statement_money"=>0,
"lack_statement_money"=>0,
"withdraw_type"=>$type,
"platform_amount"=>0,
"create_lack_ids"=>[],
"del_lack_ids"=>[],

@ -1896,6 +1896,7 @@ CREATE TABLE `tab_company_statement_pool` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键',
`statement_num` varchar(500) COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '结算批量单号',
`statement_ids` varchar(500) COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '涉及的结算单id',
`withdraw_type` tinyint(2) DEFAULT '3' COMMENT '对账类型(0-周结 1月结 2补点 3无)',
`create_lack_ids` varchar(500) COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '生成的lackid',
`del_lack_ids` varchar(500) COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '合并计算的lackid',

Loading…
Cancel
Save