diff --git a/Application/Payment/Controller/PaymentController.class.php b/Application/Payment/Controller/PaymentController.class.php index 44f8e5780..45b3e7f79 100644 --- a/Application/Payment/Controller/PaymentController.class.php +++ b/Application/Payment/Controller/PaymentController.class.php @@ -110,7 +110,7 @@ class PaymentController extends BaseController ->join("left join tab_company_statement_pool p ON p.id = s.pool_id") ->where($map) ->page($page,$row) - ->order("FIELD(s.pay_status,0,-1,1),s.verify_status desc") + ->order("statement_num desc") ->select(); $handleData = []; @@ -232,6 +232,93 @@ class PaymentController extends BaseController $this->assign("PayStatus", $this->PayStatus); $this->display(); } + //是否需要更新支付信息 + public function IsCanChangeCompanyInfo($id = 0) + { + //获取原值 + $oldInfo = M("company_statement_info","tab_")->field("company_info,company_id,company_type,company_name")->where("id = {$id}")->find(); + if(empty($oldInfo)){ + $this->ajaxReturn(['status' =>0 ,'msg'=>'未找到此结算单信息','data'=>[]]); + } + $oldCompanyInfo = json_decode($oldInfo['company_info'],true); + //获取新值 + 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(); + 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); + $oldInfo = M("company_statement_info","tab_")->field("id,company_info,company_id,company_type,company_name,pool_id,withdraw_type")->where("id = {$id}")->find(); + $oldCompanyInfo = json_decode($oldInfo['company_info'],true); + //获取新值 + 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(); + //子单修改 + $sWhere = [ + 'company_id' => $oldInfo['company_id'], + 'pay_status'=> ['neq',1], + 'statement_info_id' => $id + ]; + $StatementDB = M("pay_statement_info","tab_"); + $statementInfo = $StatementDB + ->where($sWhere) + ->field('id,company_info') + ->select(); + foreach ($statementInfo as $k => $v) { + $v['company_info'] = $this->changeAliInfo($v['company_info'],$newCompanyInfo); + $StatementDB->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 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 export() { diff --git a/Application/Payment/View/Payment/lists.html b/Application/Payment/View/Payment/lists.html index 9d472d422..73e141960 100644 --- a/Application/Payment/View/Payment/lists.html +++ b/Application/Payment/View/Payment/lists.html @@ -8,7 +8,7 @@ - +