"下游公司", "2"=>"下游个人", "3"=>"上游公司" ]; public $IsPayment = [ "1"=>"是", "2"=>"否" ]; public $admininfo; public $DBModel; public function _initialize() { $this->admininfo = $_SESSION['onethink_admin']['user_auth']; $this->DBModel = M("CompanyLackStatementInfo","tab_"); parent::_initialize(); } 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 = [ "is_pool"=>0 ]; if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) { $time_start = strtotime($_REQUEST['time_start']); $time_end = strtotime($_REQUEST['time_end'])+ 86399; $map["_string"] = "(statement_begin_time BETWEEN {$time_start} AND {$time_end}) OR (statement_end_time BETWEEN {$time_start} AND {$time_end}) OR (statement_begin_time <= {$time_end} AND statement_end_time >= {$time_end})"; } elseif (isset($_REQUEST['time_start'])) { $time_start = strtotime($_REQUEST['time_start']); $map["_string"] = "(statement_begin_time >= {$time_start} ) OR (statement_end_time >= {$time_start})"; } elseif (isset($_REQUEST['time_end'])) { $time_end = strtotime($_REQUEST['time_end'])+ 86399; $map["_string"] = "(statement_begin_time <= {$time_end} ) OR (statement_end_time <= {$time_end})"; } //其他 if(isset($_REQUEST['company_type'])){ $map['company_type'] = $_REQUEST['company_type']; } if(isset($_REQUEST['company_name'])){ $map['company_name'] =["LIKE","%{$_REQUEST['company_name']}%"]; } if(isset($_REQUEST['statement_pool_num'])){ $map['statement_pool_num'] =["LIKE","%{$_REQUEST['statement_pool_num']}%"]; } if(isset($_REQUEST['is_payment'])){ $map['is_payment'] = $_REQUEST['is_payment']; } // $this->checkListOrCountAuthRestMap($map);//导出权限 //条件end $data = $this->DBModel ->field("*") ->where($map) ->page($page,$row) ->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['is_payment_str'] = $this->IsPayment[$v['is_payment']]; $v['company_type_str'] = $this->CompanyType[$v['company_type']]; $v["valid"] = "{$v['statement_begin_time']} ~ {$v['statement_end_time']}"; $v['oplist'] = $this->OpAuth($v); } $count = $this->DBModel->field("count(id) count,sum(statement_money) statement_money")->where($map)->find(); // dd($count); $params['p'] = $page; $params['row'] = $row; $page = set_pagination($count['count'], $row, $params); if ($page) { $this->assign('_page', $page); } $this->assign('data',$data); $this->assign('count',$count); $this->assign('CompanyType',$this->CompanyType); $this->assign('IsPayment',$this->IsPayment); $this->display(); } //查看 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 = $this->DBModel->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 pool() { if(!isset($_REQUEST['ids'])) $this->error("参数错误"); $ids = $_REQUEST['ids']; $dbres = $this->DBModel->field("*")->where("id in ({$ids})")->select(); //分单 $basedata = [ "pay_amount"=>0, "statement_money"=>0, "lack_statement_money"=>0, "platform_amount"=>0, "lack_platform_amount"=>0, "del_lack_ids"=>[], "info_ids"=>[], "statement_begin_time"=>0, "statement_end_time"=>0, "fine"=>0, "reward"=>0, "verify_status"=>0, "verify_log"=>json_encode(["create_user"=>$this->admininfo["username"],"create_time"=>date("Y-m-d H:i:s")]), "op_time"=>time(), "company_list"=>[] ]; $datas = ["ups","up","downs","down","user","users"]; //初始化数据 foreach($datas as $k=>$v){ if($v =="ups"){ $basedata['company_type']=3; $basedata['is_payment']=1; } if($v =="up"){ $basedata['company_type']=3; $basedata['is_payment']=2; } if($v =="downs"){ $basedata['company_type']=1; $basedata['is_payment']=1; } if($v =="down"){ $basedata['company_type']=1; $basedata['is_payment']=2; } if($v =="users"){ $basedata['company_type']=2; $basedata['is_payment']=1; } if($v =="user"){ $basedata['company_type']=2; $basedata['is_payment']=2; } $datas[$v]=$basedata; unset($datas[$k]); } foreach ($dbres as $k=>$v) { if($v['company_type'] == 3){ //上游 if($v['is_payment'] == 1){ $this->setDf($datas['ups'],$v); }else{ $this->setDf($datas['up'],$v); } }elseif($v['company_type'] == 1){ if($v['is_payment'] == 1){ $this->setDf($datas['downs'],$v); }else{ $this->setDf($datas['down'],$v); } }else{ if($v['is_payment'] == 1){ $this->setDf($datas['users'],$v); }else{ $this->setDf($datas['user'],$v); } } } $Pool = M("company_statement_pool","tab_"); $Statemen = M("company_statement","tab_"); foreach ($datas as $k => $v) { if(count($v['company_list']) <= 0){continue;} //保存公司信息 $company_list = $v['company_list']; foreach ($company_list as $ke => $va) { $this->addStatementInfo($va,$ke,$v,$k); } if(empty($v['create_lack_ids']) && empty($v['del_lack_ids']) && empty($v['info_ids'])){ continue;} $v['statement_num'] = "QZ_".date('Ymd').date('His').sp_random_num(3); $v['del_lack_ids'] = implode(",",$v['del_lack_ids']) ?? ''; $info = implode(",",$v['info_ids']); unset($v['info_ids']); unset($v['company_list']); $pool_id = $Pool->add($v); if($pool_id == false){ $this->ajaxReturn(array('status' => 0,"info"=>"汇总失败")); } if(!empty($info)){ $save["pool_id"]=$pool_id; M("company_statement_info","tab_")->where("id in ({$info})")->save($save); } if(!empty($v['del_lack_ids'])){ M("company_lack_statement_info","tab_")->where("id in ({$v['del_lack_ids']})")->save(["is_pool"=>1]); } } $this->ajaxReturn(array( 'status' => 1, "info"=>"汇总成功" )); } protected function addStatementInfo($va,$ke,&$v,$k){ if($k=="ups" || $k=='downs' || $k =="users"){ $verify_status = 0; }else{ $verify_status = 2; } $StatementInfo = M("company_statement_info","tab_"); if($va['pay_amount'] > 0){ //存成功 $company =[ "pool_id"=>0, "company_id"=>$ke, "company_type"=>$v['company_type'], "company_name"=>$va['company_name'], "company_info"=>$va['company_info'], "fine"=>$va['fine'], "reward"=>$va['reward'], "statement_money"=>$va['statement_money'], "pay_amount"=>$va['pay_amount'], "platform_amount"=>$va['platform_amount'], "statement_money"=>$va['statement_money'], "statement_begin_time"=>$v['statement_begin_time'], "statement_end_time"=>$v['statement_end_time'], "statement_info"=>json_encode($va['statement_info'],JSON_UNESCAPED_UNICODE), "statement_num"=>$va['statement_num'], "verify_status"=>$verify_status ]; $companyid = $StatementInfo->add($company); $v['info_ids'][] =$companyid; $v['statement_money'] +=$va['statement_money']; $v['pay_amount'] +=$va['pay_amount']; $v['platform_amount'] +=$va['platform_amount']; $v['fine'] +=$va['fine']; $v['reward'] +=$va['reward']; } } //设定组合的子操作 protected function setDf(&$savedata,$v) { $savedata['del_lack_ids'][] = $v['id']; unset($v['id']); $v['statement_info'] = json_decode( $v['statement_info'],true); $fine = $v['fine']; $reward = $v['reward']; if(isset($savedata['company_list'][$v['company_id']])){ //存在游戏合并 $a = &$savedata['company_list'][$v['company_id']]; $a['fine'] += $fine; $a['reward'] += $reward; $a['statement_info'] = array_merge($a['statement_info'],$v['statement_info']); // dump($a['statement_info']); $a['platform_amount'] += $v['platform_amount']; $a['pay_amount'] += $v['pay_amount']; $a['statement_money'] += $v['statement_money']; }else{ //先分配好订单号,防止重复提交 $tdata = [ "company_info"=>$v['company_info'], "company_name"=>$v['company_name'], "platform_amount"=>$v['platform_amount'], "pay_amount"=>$v['pay_amount'], "statement_money"=>$v['statement_money'], "fine"=>$fine, "reward"=>$reward, "statement_info"=>$v['statement_info'], "statement_num"=>"JS_".date('Ymd').date('His').$v['company_id'].sp_random_string(5) ]; $savedata['company_list'][$v['company_id']] = $tdata; } // $savedata['fine'] += $v['fine']; // $savedata['reward'] += $v['reward']; // $savedata['pay_amount'] += $v['pay_amount']; // $savedata['statement_money'] += $v['statement_money']; // $savedata['platform_amount'] += $v['platform_amount']; if($savedata['statement_begin_time'] == 0){ $savedata['statement_begin_time'] = $v['statement_begin_time']; }elseif($v['statement_begin_time'] < $savedata['statement_begin_time']){ $savedata['statement_begin_time'] = $v['statement_begin_time']; } if($savedata['statement_end_time'] == 0){ $savedata['statement_end_time'] = $v['statement_end_time']; }elseif($v['statement_end_time'] > $savedata['statement_end_time']){ $savedata['statement_end_time'] = $v['statement_end_time']; } } //设定并保存数据 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 = [ "pool"=>"发起汇总", "export"=>"批量导出" ]; $resarr = []; foreach ($mentBtn as $k => $v) { if(IS_ROOT){ $resarr[] = $v; }else{ if(in_array($k,$this->OpAuthList)){ $resarr[] = $v; } } } return $resarr; } }