"下游公司", "2"=>"下游个人", "3"=>"上游公司" ]; public $IsPayment = [ "1"=>"是", "2"=>"否" ]; public $PayStatus=[ "-1"=>"打款失败", "0"=>"未打款", "1"=>"打款成功" ]; 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"=>["GT",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"] = "(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['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 $data = M("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") ->page($page,$row) ->order("id desc") ->select(); 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["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']})
{$v['pay_info']['payment_time']}"; }else{ $v["payment"] = $v["pay_status_str"]; } $v['oplist'] = $this->OpAuth($v); } $count = M("company_statement_info","tab_")->alias("c")->field("count(c.id) count,sum(c.statement_money) statement_money")->join("tab_company_statement_pool as p ON c.pool_id = p.id")->where($map)->find(); // dd($count); $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->display(); } public function doPayment() { if(!isset($_REQUEST['ids'])) $this->error("参数错误"); $ids = $_REQUEST['ids']; //获取所有的母单id $companyStatementInfo = M("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")->field("pool_id,count(id) count")->group("pool_id")->select(); //修改info $saveData = [ "pay_type"=>3, "pay_status"=>1, "pay_info"=>json_encode(["payment_user"=>$_SESSION['onethink_admin']['user_auth']["username"],"payment_time"=>date("Y-m-d H:i:s")]) ]; $ires = $companyStatementInfo->where("id in ($ids)")->save($saveData); //全部就打款成功,否则打款中 $companyStatementPool = M("company_statement_pool","tab_"); 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 = M("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); } } public function export(){ if(!isset($_REQUEST['ids'])) $this->error("参数错误"); $ids = $_REQUEST['ids']; $dbres = M("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); } } 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']=$_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; M("company_statement_pool","tab_")->save($dbres); } public function OpAuth($info) { $id = $info['id']; $type = $info['company_type']; //原始列表 $opBtn = [ "viewStatement"=>"查看", ]; //操作对应菜单 $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 = [ "doPayment"=>"打款确认", "export"=>"批量导出" ]; $resarr = []; foreach ($mentBtn as $k => $v) { if(IS_ROOT){ $resarr[] = $v; }else{ if(in_array($k,$this->OpAuthList)){ $resarr[] = $v; } } } return $resarr; } }