*/ class PromoteCompanyController extends ThinkController { private $modelName = 'PromoteCompany'; public $ratio = []; public function _initialize() { $this->admininfo = $_SESSION['onethink_admin']['user_auth']; parent::_initialize(); } //列表 public function lists() { $model = M($this->modelName, 'tab_'); $is_export= false; if (isset($_REQUEST['export']) && $_REQUEST['export']==1){ $is_export = true; } $map = []; $promotemap=[]; $company_name = trim(I('company_name')); //市场部权限begin $pro_id = getMarketAuthPromoteId(); if($pro_id){ $promotemap["_string"]="p.id in ({$pro_id})"; $c_id = throwPromoteIdToCompanyId($pro_id); $map["_string"]="id in ({$c_id})"; } //市场部权限end if($company_name) $map['tab_promote_company.company_name'] = array('like',"%{$company_name}%"); if (isset($_REQUEST['status']) && $_REQUEST['status'] !== '') { $status = intval($_REQUEST['status']); $map['tab_promote_company.status'] = $status; } if (isset($_REQUEST['promote_id'])) { $map['id'] = M("Promote","tab_")->field("company_id")->where("id={$_REQUEST['promote_id']}")->find()['company_id']; $promotemap['p.id']=$_REQUEST['promote_id']; } if (isset($_REQUEST['company_type'])) { $map['company_type'] = $_REQUEST['company_type']; } if (isset($_REQUEST['company_belong'])) { $map['company_belong'] = $_REQUEST['company_belong']; } if (isset($_REQUEST['game_name'])) { //换成id $g_name = $_REQUEST['game_name']; $g_id = M("Game","tab_")->where("relation_game_name = '{$g_name}'")->field("relation_game_id")->find()['relation_game_id']; $reg_str = "([^0-9]|^){$g_id },"; $map["game_ids"]=["EXP","REGEXP '{$reg_str}'"]; } if (isset($_REQUEST['is_sign_contact'])) { $map["is_sign_contact"]=$_REQUEST['is_sign_contact']; } if (isset($_REQUEST['pay_type'])) { $pay_type = $_REQUEST['pay_type']; $promote_id = M("president_deposit","tab_")->where("pay_type = '$pay_type'")->group("promote_id")->getField("promote_id",true); if(empty($promote_id)){ $promote_id = -1; } $promote_id = implode(",",$promote_id); $c_id = throwPromoteIdToCompanyId($promote_id); if(isset($promotemap["_string"])){ $promotemap["_string"] .= " ADN p.id in ($promote_id)"; }else{ $promotemap["_string"] = "p.id in ($promote_id)"; } if(isset($map["_string"])){ $map["_string"] .= " ADN id in ($c_id)"; }else{ $map["_string"] = "id in ($c_id)"; } } // dd($map); $page = intval(I('get.p', 0)); $page = $page ? $page : 1; //默认显示第一页数据 $row = intval(I('row', 0)); $row = empty($row) ? 10 : $row;//每页条数 //获取分页公司数据 $companyres = $model->field("*") ->where($map) ->order("last_up_time desc"); if($is_export){ $companyres = $companyres->select(); }else{ $companyres = $companyres->page($page,$row)->select(); } //获取公司信息 if(!empty($companyres)){ foreach($companyres as $k=>&$v){ $tmpr = D("CompanyRelation")->getCompanyRelation(2,$v['id']); $v["settlement_type"] = $tmpr['settlement_type']; $v["collection"] = $tmpr['collection']; $v["invoice_type"] = $tmpr['invoice_type']; $v["invoice_content"] = $tmpr['invoice_content']; $v["company_belong"] = getCompanyBlong($v["company_belong"]); $v["develop_type"] = getCompanyRelation($v["develop_type"]); $v['company_type'] = $v['company_type'] == 2 ? '个人' : '公司'; $v['is_sign_contact'] = $v['is_sign_contact'] ? '是' : '否'; $contract_start_time = $v['company_info']['contact_begin'] ? time_format($v['company_info']['contact_begin'], 'Y/m/d') : '-'; $contract_end_time = $v['company_info']['contact_end'] ? time_format($v['company_info']['contact_end'], 'Y/m/d') : '-'; $v['contract_time'] = $contract_start_time . '-' . $contract_end_time; $validity_start_time = $v['company_info']['validity_start_time'] ? time_format($v['company_info']['validity_start_time'], 'Y/m/d') : '-'; $validity_end_time = $v['company_info']['validity_end_time'] ? time_format($v['company_info']['validity_end_time'], 'Y/m/d') : '-'; $v['validity_time'] = $validity_start_time . '-' . $validity_end_time; if(!$is_export){ $v['can_del'] = $this->promoteCompanyIsCanDel($v["id"]) ? 1 : 0; } //遍历获取游戏信息 if(empty($v["game_ids"])){ $senddata=false; }else{ if(isset($_REQUEST['game_name'])) { $v["game_ids"] = $g_id; } $senddata = $this->getGamePromoteCompanyRadio($v["id"],$v["game_ids"],$is_export); } $game = $this->getPromoteGameRadio($v["id"],$senddata,$promotemap); $v += $game; } } //公司及会长数量统计 $companycount = $model->field("id")->where($map)->select(); $count = count($companycount); $companyallids = implode(',', array_column($companycount, 'id')); $promotemap['p.company_id']=["in",$companyallids]; $promotemap['p.level']=1; $promotecount = M("Promote","tab_")->alias('p')->where($promotemap)->count(); // dd($companyres); $this->assign('listData', $companyres); $this->assign('count', $count); $this->assign('promotecount', $promotecount); if($is_export){ $getData = $_GET; unset($getData['export']); addOperationLog(['op_type'=>3,'key'=>getNowDate(),'op_name'=>'导出推广公司','url'=>U('PromoteCompany/lists'),'menu'=>'推广员-推广员管理-推广公司管理-导出推广公司']); //导出 $this->display("export"); die(); } //分页 $parameter['p'] = $page; $parameter['row'] = $row; $page = set_pagination($count, $row); if ($page) { $this->assign('_page', $page); } //分配其他页面需要参数 $this->assign('promoteList', getPromoteByLevel(1)); $this->assign('commonset', M('Kuaijieicon')->where(['url' => 'Partner/lists'])->find()); $payTypes = PresidentDepositService::$payTypes; $this->assign('payTypes', $payTypes); $this->meta_title = '下游推广公司'; $this->display(); } public function index() { $page = intval(I('get.p', 0)); $page = $page ? $page : 1; //默认显示第一页数据 $row = intval(I('row', 0)); $row = empty($row) ? 10 : $row;//每页条数 $p = $_REQUEST; if(!IS_ROOT){ $this->OpAuthList= getModuleControllerAuth(); } $map = []; if (!empty(I('company_name'))) { $map['company_name'] = ['like', '%' . I('company_name') . '%']; } if (!empty($p['verify_type'])) { if($p['verify_type'] == 1){ $map['company_id'] = 0; }else{ $map['company_id'] = ["neq",0]; } } if (isset($p['verify_status'])) { $map['verify_status'] = $p['verify_status']; } if (isset($_REQUEST['timestart']) && isset($_REQUEST['timeend'])) { $time_start = strtotime($_REQUEST['timestart']); $time_end = strtotime($_REQUEST['timeend'])+ 86399; $map["create_time"] =['BETWEEN',[$time_start, $time_end]]; } elseif (isset($_REQUEST['timestart'])) { $time_start = strtotime($_REQUEST['timestart']); $map["create_time"] =['EGT',$time_start]; } elseif (isset($_REQUEST['timeend'])) { $time_end = strtotime($_REQUEST['timeend'])+ 86399; $map["create_time"] = ['ELT',$time_end]; } $model = M("promote_company_verify", 'tab_'); $data = $model->where($map)->page($page,$row)->order("FIELD(verify_status,0,1,-1,-2,2),id desc")->select(); foreach ($data as $k => &$v) { $v['company_info'] = json_decode($v['company_info'],true); if($v['company_id'] == 0){ $v['verify_type'] = "新增"; }else{ $v['verify_type'] = "修改"; } $v['company_info']['company_type'] = $v['company_info']['company_type'] == 2 ? '个人' : '公司'; $contract_start_time = $v['company_info']['contact_begin'] ? time_format($v['company_info']['contact_begin'], 'Y/m/d') : '-'; $contract_end_time = $v['company_info']['contact_end'] ? time_format($v['company_info']['contact_end'], 'Y/m/d') : '-'; $v['contract_time'] = $contract_start_time . '-' . $contract_end_time; $validity_start_time = $v['company_info']['validity_start_time'] ? time_format($v['company_info']['validity_start_time'], 'Y/m/d') : '-'; $validity_end_time = $v['company_info']['validity_end_time'] ? time_format($v['company_info']['validity_end_time'], 'Y/m/d') : '-'; $v['validity_time'] = $validity_start_time . '-' . $validity_end_time; $create_time = date("Y-m-d H:i:s",$v["create_time"]); $v['verify_log'] = json_decode($v['verify_log'], true); $v["create"]= "{$v['verify_log']['create_user']}
{$v['verify_log']['create_time']}"; if(isset($v['verify_log']['market_user'])){ if($v['status'] == -1){ $ts = "审核拒绝"; }else{ $ts = "审核通过"; } $v["market"]= "{$ts}({$v['verify_log']['market_user']})
{$v['verify_log']['market_time']}"; }else{ $v["market"] = '--'; } if(isset($v['verify_log']['admin_user'])){ if($v['status'] == -2){ $ts = "审核拒绝"; }else{ $ts = "审核通过"; } $v["admin"]= "{$ts}({$v['verify_log']['admin_user']})
{$v['verify_log']['admin_time']}"; }else{ $v["admin"] = '--'; } } $count = $model->where($map)->count(); $page = set_pagination($count, $row); if ($page) { $this->assign('_page', $page); } $this->assign('menubtn',$this->menuAuth()); $this->assign('listData', $data); $this->assign('count', $count); $this->assign('VerifyStatus', D("PromoteCompanyVerify")->VerifyStatus); $this->meta_title = '下游推广公司审核列表'; $this->display(); } public function marketAgree(){ if(!isset($_REQUEST['ids'])) $this->error("参数错误"); $ids = $_REQUEST['ids']; $dbres = M("PromoteCompanyVerify", 'tab_')->field("id,verify_status,verify_log")->where("id in ({$ids})")->select(); foreach($dbres as $k=>&$v){ if($v['verify_status'] != 0) continue; $v['verify_log'] = json_decode($v['verify_log'],true); $v['verify_log']['market_user']=$this->admininfo["username"]; $v['verify_log']['market_time']=date("Y-m-d H:i:s"); $v['verify_log'] = json_encode($v['verify_log']); $v['verify_status']=1; M("PromoteCompanyVerify", 'tab_')->save($v); addOperationLog(['op_type'=>1,'key'=>$v['id'],"op_name"=>"市场部审核",'url'=>U('index')]); } $this->ajaxReturn(array( 'status' => 1, "info"=>"市场部审核通过成功" )); } public function marketRefuse(){ if(!isset($_REQUEST['ids'])) $this->error("参数错误"); $ids = $_REQUEST['ids']; $dbres = M("PromoteCompanyVerify", 'tab_')->field("id,verify_status,verify_log")->where("id in ({$ids})")->select(); foreach($dbres as $k=>&$v){ if($v['verify_status'] != 0) continue; $v['verify_log'] = json_decode($v['verify_log'],true); $v['verify_log']['market_user']=$this->admininfo["username"]; $v['verify_log']['market_time']=date("Y-m-d H:i:s"); $v['verify_log'] = json_encode($v['verify_log']); $v['verify_status']=-1; M("PromoteCompanyVerify", 'tab_')->save($v); addOperationLog(['op_type'=>1,'key'=>$v['id'],"op_name"=>"市场部审核",'url'=>U('index')]); } $this->ajaxReturn(array( 'status' => 1, "info"=>"市场部审核拒绝成功" )); } public function adminRefuse(){ if(!isset($_REQUEST['ids'])) $this->error("参数错误"); $ids = $_REQUEST['ids']; $dbres = M("PromoteCompanyVerify", 'tab_')->field("id,verify_status,verify_log")->where("id in ({$ids})")->select(); foreach($dbres as $k=>&$v){ if($v['verify_status'] != 1) continue; $v['verify_log'] = json_decode($v['verify_log'],true); $v['verify_log']['admin_user']=$this->admininfo["username"]; $v['verify_log']['admin_time']=date("Y-m-d H:i:s"); $v['verify_log'] = json_encode($v['verify_log']); $v['verify_status']=-2; M("PromoteCompanyVerify", 'tab_')->save($v); addOperationLog(['op_type'=>1,'key'=>$v['id'],"op_name"=>"管理员审核",'url'=>U('index')]); } $this->ajaxReturn(array( 'status' => 1, "info"=>"管理员审核拒绝成功" )); } public function adminAgree(){ if(!isset($_REQUEST['ids'])) $this->error("参数错误"); $ids = $_REQUEST['ids']; $dbres = M("PromoteCompanyVerify", 'tab_')->field("*")->where("id in ({$ids})")->select(); foreach($dbres as $k=>&$v){ if($v['verify_status'] != 1) continue; $v['verify_log'] = json_decode($v['verify_log'],true); $v['verify_log']['admin_user']=$this->admininfo["username"]; $v['verify_log']['admin_time']=date("Y-m-d H:i:s"); $v['verify_log'] = json_encode($v['verify_log']); $v['verify_status']=2; $company_info = json_decode($v['company_info'],true); if($v['company_id'] == 0){ //新增 $v['company_id'] = M("promote_company","tab_")->add($company_info); }else{ //编辑 M("promote_company","tab_")->save($company_info); $this->changePromote($company_info); } //业务逻辑 M("PromoteCompanyVerify", 'tab_')->save($v); addOperationLog(['op_type'=>1,'key'=>$v['id'],"op_name"=>"管理员审核",'url'=>U('index')]); } $this->ajaxReturn(array( 'status' => 1, "info"=>"管理员审核通过成功" )); } //添加 public function add() { if ($_POST) { $time = time(); $save = I('post.');//前端已经验证 $this->checkData($save); $save['create_time'] = $time; $save['turnover_ratio'] = $this->setTurnoverRatio($save); $res = D("PromoteCompanyVerify")->add_db($save); if ($res) { addOperationLog(['op_type'=>0,'key'=>$save['company_name'],'op_name'=>'新增推广公司','url'=>U('PromoteCompany/lists')]); \Think\Log::actionLog('PromoteCompany/add', 'partner', $res); $array=array( "info"=>"添加成功,请联系管理员尽快审核", "status"=>1 ); $this->ajaxReturn($array); } else { $this->ajaxReturn(array( 'status' => 0, 'info' => "保存失败" )); } } else { $this->assign('serviceAgreements', M('service_agreement', 'tab_')->select()); $this->assign('commonset', M('Kuaijieicon')->where(['url' => 'PromoteCompany/add'])->find()); $this->meta_title = '新增下游推广公司'; $this->display(); } } //查看 public function view() { $model = M($this->modelName, 'tab_'); $id = $_REQUEST['id'] ?: 0; $map['id'] = $id; $data = $model->field('*')->find($id); if (empty($data)) { $this->error('数据异常', U('lists')); } if($data['contact_begin'] >0){ $data['contact_begin']=date("Y-m-d",$data['contact_begin']); }else{ $data['contact_begin']=''; } if($data['contact_end'] >0){ $data['contact_end']=date("Y-m-d",$data['contact_end']); }else{ $data['contact_end']=''; } if($data['resources'] == ''){ $data['resources'] ="[]"; } if($data['validity_start_time'] >0){ $data['validity_start_time']=date("Y-m-d",$data['validity_start_time']); }else{ $data['validity_start_time']=''; } if($data['validity_end_time'] >0){ $data['validity_end_time']=date("Y-m-d",$data['validity_end_time']); }else{ $data['validity_end_time']=''; } if($data['resources'] == ''){ $data['resources'] ="[]"; } $data['turnover_ratio'] = $data['turnover_ratio'] ? json_decode($data['turnover_ratio'], true) : $data['turnover_ratio']; $this->assign('data', $data); $this->meta_title ='推广公司信息查看'; $this->display(); } public function verifyView() { if(!isset($_REQUEST['id'])) $this->error('数据异常', U('index')); $id = $_REQUEST['id']; $map['id'] = $id; $dbres = M("PromoteCompanyVerify", 'tab_')->find($id); $data = json_decode($dbres['company_info'],true); if($data['contact_begin'] >0){ $data['contact_begin']=date("Y-m-d",$data['contact_begin']); }else{ $data['contact_begin']=''; } if($data['contact_end'] >0){ $data['contact_end']=date("Y-m-d",$data['contact_end']); }else{ $data['contact_end']=''; } if($data['resources'] == ''){ $data['resources'] ="[]"; } if($data['validity_start_time'] >0){ $data['validity_start_time']=date("Y-m-d",$data['validity_start_time']); }else{ $data['validity_start_time']=''; } if($data['validity_end_time'] >0){ $data['validity_end_time']=date("Y-m-d",$data['validity_end_time']); }else{ $data['validity_end_time']=''; } if($data['resources'] == ''){ $data['resources'] ="[]"; } $data['turnover_ratio'] = $data['turnover_ratio'] ? json_decode($data['turnover_ratio'], true) : $data['turnover_ratio']; $this->assign('data', $data); $this->assign('commonset', M('Kuaijieicon')->where(['url' => 'Partner/edit'])->find()); $this->meta_title ='审核信息查看'; $this->display("view"); } public function verifyDel(){ if(!isset($_REQUEST['id'])) $this->error('数据异常', U('index')); $id = $_REQUEST['id']; M("PromoteCompanyVerify", 'tab_')->where("id = '{$id}'")->delete(); addOperationLog(['op_type'=>2,'key'=>$id,'op_name'=>'删除审核','url'=>U('PromoteCompany/index')]); $this->success('删除成功', U('index')); } public function marketingDirectorShow($ids=[], $isShow=0) { $upt = M('promote_company','tab_')->where(['id'=>['in', $ids]])->save(['marketing_director_show'=>$isShow]); return $upt ? $this->success('更新成功'): $this->error('更新失败'); } //编辑 public function edit() { if ($_POST) { $save = I('post.');//前端已经验证 $this->checkData($save); $save['turnover_ratio'] = $this->setTurnoverRatio($save); $res = D("PromoteCompanyVerify")->edit_db($save); if ($res) { addOperationLog(['op_type'=>1,'key'=>$_POST['company_name'],'op_name'=>'编辑推广公司','url'=>U('PromoteCompany/lists'),'menu'=>'推广员-推广员管理-推广公司管理-编辑推广公司']); $array=array( "info"=>"修改成功,请联系管理员尽快审核", "status"=>1 ); $this->ajaxReturn($array); } else { $this->ajaxReturn(array( 'status' => 0, 'info' => "修改失败" )); } } else { $model = M($this->modelName, 'tab_'); $id = $_REQUEST['id'] ?: 0; $map['id'] = $id; $data = $model->field('*')->find($id); if (empty($data)) { $this->error('数据异常', U('lists')); } if($data['contact_begin'] >0){ $data['contact_begin']=date("Y-m-d",$data['contact_begin']); }else{ $data['contact_begin']=''; } if(empty($data['contact_phone'])){ $data['contact_phone'] = ''; } if($data['contact_end'] >0){ $data['contact_end']=date("Y-m-d",$data['contact_end']); }else{ $data['contact_end']=''; } if($data['validity_start_time'] >0){ $data['validity_start_time']=date("Y-m-d",$data['validity_start_time']); }else{ $data['validity_start_time']=''; } if($data['validity_end_time'] >0){ $data['validity_end_time']=date("Y-m-d",$data['validity_end_time']); }else{ $data['validity_end_time']=''; } if($data['resources'] == ''){ $data['resources'] ="[]"; } $data['turnover_ratio'] = $data['turnover_ratio'] ? json_decode($data['turnover_ratio'], true) : $data['turnover_ratio']; // $data['game_ids'] = explode(',', $data['game_ids']); $this->assign('serviceAgreements', M('service_agreement', 'tab_')->select()); $this->assign('data', $data); $this->display(); } } //删除 public function del() { $model = M($this->modelName, 'tab_'); if (!empty($_POST['id'])) { if (!is_array($_POST['id'])) { $this->error('参数异常'); } $id = $_POST['id']; } else { $id = intval(I('get.id', 0)); if ($id == 0) { $this->error('参数异常'); } } //删除所有资源 $data = $model->field('resources')->find($id)['resources']; $data = json_encode($data,true); if(is_array($data) && count($data) >0){ foreach($data as $k=>$v){ unlink("./".$v['file_path']); } } $companyData = M('promote_company','tab_')->field('company_name')->where(['id'=>$_REQUEST['id']])->find(); $res = $model->delete($id); //删除对应的推广员 if ($res === false) { $this->error('删除失败'); } addOperationLog(['op_type'=>2,'key'=>$companyData['company_name'],'op_name'=>'删除推广公司','url'=>U('PromoteCompany/lists'),'menu'=>'推广员-推广员管理-推广公司管理-删除推广公司']); $this->success('删除成功', U('lists')); } //处理上传图片 public function saveFile() { $path = '/Uploads/'; $upload = new \Think\Upload();// 实例化上传类 $upload->maxSize = 0 ;// 设置附件上传大小 $upload->exts = '';// 设置附件上传类型 $upload->rootPath = '.'.$path; // 设置附件上传根目录 $upload->savePath = ''; // 设置附件上传(子)目录 // 上传文件 $info = $upload->upload(); // dump($info); if(!$info) {// 上传错误提示错误信息 $msg = $upload->getError(); $array= array('status' => 0, 'info' => $msg); }else{// 上传成功 $array=array( "info"=>"上传成功", "status"=>1, "file_path"=>$path.$info['file']['savepath'].$info['file']['savename'], "file_name"=>$_POST['file_name'], "file_type"=>$_FILES['file']['type'], "file_size"=>$_FILES['file']['size'], "upload_time"=>date("Y-m-d H:i:s",time()) ); } $this->ajaxReturn($array); } //删除图片 public function delFile() { $id = $_REQUEST['id']; $file_path = $_REQUEST['file_path'] ?: false; unlink("./".$file_path); if($id == 0){ $this->ajaxReturn(array( 'status' => 1, 'info' => "删除成功" )); }else{ //需要修改 $array = array( "resources"=>json_encode($_REQUEST['resources'],JSON_UNESCAPED_UNICODE) ); $res = M($this->modelName, 'tab_')->where("id='{$id}'")->save($array); if($res === false){ $this->ajaxReturn(array( 'status' => 0, 'info' => "删除保存失败" )); }else{ $this->ajaxReturn(array( 'status' => 1, 'info' => "删除成功" )); } } # code... } public function promoteDataConfigIndex() { if (IS_POST) { $changeData = I('post.',''); $promoteData = M("promote","tab_") ->field("id") ->where(['company_belong'=>2]) ->select(); $promoteData = implode(',',array_column($promoteData,'id')); if ($changeData['admin_type'] == 1) { $num_pend = 0; $num_deposit = 0; if ($promoteData) { $sql_spend = "UPDATE `tab_spend` SET `old_change_promote_id`=`promote_id`,`old_change_promote_account`=`promote_account`,`promote_id`=0,`promote_account`='无' WHERE promote_id in({$promoteData})"; $sql_deposit = "UPDATE `tab_deposit` SET `old_change_promote_id`=`promote_id`,`old_change_promote_account`=`promote_account`,`promote_id`=0,`promote_account`='无' WHERE promote_id in({$promoteData})"; $model = new \Think\Model(); $num_pend = $model->execute($sql_spend,true); $num_deposit = $model->execute($sql_deposit,true); $this->ajaxReturn(['info'=>"处理订单数据".($num_pend+$num_deposit).'条']); } } else if ($changeData['admin_type'] == 2){ $num_pend = 0; $num_deposit = 0; if ($promoteData) { $sql_spend = "UPDATE `tab_spend` SET `promote_id`=`old_change_promote_id`,`promote_account`=`old_change_promote_account`,`old_change_promote_id`=0,`old_change_promote_account`='' WHERE old_change_promote_id in ({$promoteData})"; $sql_deposit = "UPDATE `tab_deposit` SET `promote_id`=`old_change_promote_id`,`promote_account`=`old_change_promote_account`,`old_change_promote_id`=0,`old_change_promote_account`='' WHERE old_change_promote_id in ({$promoteData})"; $model = new \Think\Model(); $num_pend = $model->execute($sql_spend,true); $num_deposit = $model->execute($sql_deposit,true); $this->ajaxReturn(['info'=>"将数据还原,处理订单数据".($num_pend+$num_deposit).'条']); } } } else { $promoteData = M("promote","tab_") ->field("id") ->where(['company_belong'=>2]) ->select(); $promoteData = implode(',',array_column($promoteData,'id')); $spendData = M('spend','tab_')->field("old_change_promote_account")->where(['old_change_promote_id'=>['in',$promoteData]])->find(); // var_dump($spendData);die(); if ($spendData['old_change_promote_account']) { $this->assign('old_change_promote_account',1); } $this->display('promotedataconfigindex'); } } public function serviceAgreementList($row = 10, $p = 1) { $map = []; $map['_string'] = " 1=1 "; if (isset($_GET['time-start'])) { $map['_string'] .= " and created_time >= " . strtotime($_GET['time-start']); } if (isset($_GET['time-end'])) { $map['_string'] .= " and created_time < " . (strtotime($_GET['time-end']) + 86400); } if (isset($_GET['type'])) { $map['type'] = $_GET['type']; } if (!empty($_GET['title'])) { $map['title'] = ['like', "%{$_GET['title']}%"]; } $list = M('service_agreement', 'tab_') ->field("tab_service_agreement.*, group_concat(distinct(tab_promote_company.company_name)) as company_name") ->join('tab_promote_company on tab_promote_company.service_agreement_show = tab_service_agreement.id', 'LEFT')->where($map)->group('tab_service_agreement.id asc')->page($p, $row)->order("status desc")->select(); $count = M('service_agreement', 'tab_')->where($map)->count(); $page = set_pagination($count, $row); if ($page) { $this->assign('_page', $page); } $this->assign('list_data', $list); $this->display('service_agreement_list'); } public function serviceAgreementSave($id=0, $delete=0) { if (IS_POST) { if (!empty(I('ids'))) { $ids = is_array(I('ids')) ? I('ids') : [I('ids')]; if ($delete) { // 获取默认合同id $defaultService = M('service_agreement', 'tab_')->where(['status'=>2])->find(); if(in_array($defaultService['id'], $ids)) { return $this->error('无法删除默认模板'); } $usingService = M('promote_company', 'tab_')->where(['service_agreement_show'=>['in', $ids]])->find(); if (!empty($usingService)) return $this->error('有正在使用该服务合同的公司,无法删除'); $result = M('service_agreement', 'tab_')->where(['id'=>['in', $ids]])->delete(); return $result ? $this->success('删除完成') : $this->error('删除失败'); } } if (empty($_POST['name']) || empty($_POST['content'])) { return $this->error('请填写完整内容'); } if ($id) { $result = M('service_agreement', 'tab_')->where(['id'=>$id])->save($_POST); return $result ? $this->success('更新完成') : $this->error('更新失败'); } else { $data = $_POST; $data['creator'] = is_login(); $data['created_time'] = time(); $result = M('service_agreement', 'tab_')->add($data); return $result ? $this->success('生成协议完成') : $this->error('生成协议失败'); } } else { if (!empty($id)) { if ($delete) { $ids = [$id]; // 获取默认合同id $defaultService = M('service_agreement', 'tab_')->where(['status'=>2])->find(); if(in_array($defaultService['id'], $ids)) { return $this->error('无法删除默认模板'); } $usingService = M('promote_company', 'tab_')->where(['service_agreement_show'=>['in', $ids]])->find(); if (!empty($usingService)) return $this->error('有正在使用该服务合同的公司,无法删除'); $result = M('service_agreement', 'tab_')->where(['id'=>['in', $ids]])->delete(); return $result ? $this->success('删除完成') : $this->error('删除失败'); } $info = M('service_agreement', 'tab_')->where(['id'=>$id])->find(); if (empty($info)) return $this->error('未找到协议'); $this->assign('info', $info); } $this->display('service_agreement_save'); } } public function serviceAgreementSetDefault($id) { M('service_agreement', 'tab_')->where('id > 0')->save(['status'=>1]); M('service_agreement', 'tab_')->where(['id'=>$id])->save(['status'=>2]); return $this->success('设置完成'); } // public function getCompanyGame() { if (IS_AJAX) { //获取所有游戏 $game_list = M('game', 'tab_')->field('relation_game_id id,relation_game_name game_name,short')->where(['game_status'=>1,'down_port'=>1])->group("relation_game_id")->select(); $data['data']['game_list'] = empty($game_list) ? '' : $game_list; //获取推广员信息 $promote_info = M('promote_company', 'tab_')->field('id,company_name,game_ids')->where(['id'=>I('id', 0, 'intval')])->find(); if (!empty($promote_info['game_ids'])) { $promote_info['game_ids'] = explode(',', $promote_info['game_ids']); } $data['data']['promote_info'] = empty($promote_info) ? '' : $promote_info; $data['msg'] = '请求成功'; $data['code'] = 1; $this->ajaxReturn($data); exit; } } //更新推广员可推广游戏 public function saveCompanyGame() { if (IS_AJAX) { $id = I('promote_id', 0, 'intval'); if (empty($id)) { $this->ajaxReturn(['code'=>0,'msg'=>'请选择推广公司']); } $promoter = M('promote_company', 'tab_')->where(['id'=>$id])->find(); if (empty($promoter)) { $this->ajaxReturn(['code'=>0,'msg'=>'未找到推广公司']); } $game_ids = I('game_ids', ''); if (!empty($game_ids)) { $game_ids = implode(',', $game_ids); } else { $game_ids = ''; } // 获取下级id $res = M('promote_company', 'tab_')->where(['id'=>$id])->save(['game_ids'=>$game_ids]); if ($res) { $this->ajaxReturn(['code'=>1,'msg'=>'更新成功']); } else { $this->ajaxReturn(['code'=>0,'msg'=>'数据未发生变化']); } } } // protected function setTurnoverRatio($params) { $save['turnover_ratio'] = []; if (!empty(array_filter($params['turnover'])) || !empty(array_filter($params['turnover_ratio'])) ) { if (is_array($params['turnover']) && is_array($params['turnover_ratio']) && is_array($params['instanceof'])) { foreach ($params['turnover'] as $turnover) { if (empty($turnover)) { $this->error('月流水不能为空'); } } foreach ($params['turnover_ratio'] as $turnoverRatio) { if (empty($turnoverRatio)) { $this->error('月流水分成比例不能为空'); } } foreach ($params['instanceof'] as $intervalClosedStatus) { if (!in_array($intervalClosedStatus, [1, 2])) { $this->error('月流水分符号不能为空'); } } $turnoverCount = count($params['turnover']); $sortTurnover = $params['turnover']; sort($sortTurnover); if ($params['turnover'] != $sortTurnover || $turnoverCount != count(array_unique($params['turnover']))) { $this->error('月流水必须以正序的方式填写,且必须大于上一个月流水'); } $ratio = $params['ratio'] ?? 0; // if ($params['turnover_ratio'][0] <= $ratio) { // $this->error('月流水分成比例必须大于默认分成比例'); // } $turnoverRatioCount = count($params['turnover_ratio']); $sortTurnoverRatio = $params['turnover_ratio']; sort($sortTurnoverRatio); // if ($params['turnover_ratio'] != $sortTurnoverRatio || $turnoverRatioCount != count(array_unique($params['turnover_ratio']))) { // $this->error('月流水分成比例必须以正序的方式填写,且必须大于上一个月流水分成比例'); // } foreach ($params['turnover'] as $key => $turnover) { $save['turnover_ratio'][] = [ 'turnover' => bcdiv($turnover, 1, 2), 'ratio' => bcdiv($params['turnover_ratio'][$key], 1, 2), 'instanceof' => (isset($params['instanceof'][$key]) ? $params['instanceof'][$key] : 1), ]; } } } return json_encode($save['turnover_ratio']); } protected function checkData(&$save) { $company_name = trim($save["company_name"]); $status = intval($save['status']); if (empty($company_name)) { $this->error('请输入推广公司名称'); } $model = M("promote_company", 'tab_'); $map['company_name'] = $company_name; $res = $model->where($map)->field("id")->find(); if ($res) { if(isset($save['id'])){ if($save['id'] !=$res['id']){ $this->error('推广公司已存在'); } }else{ $this->error('推广公司已存在'); } } if(!empty(I("contact_phone")) && !checkPhone(I('contact_phone'))) { $this->error('联系电话格式不正确'); } if(!empty(I('reg_phone')) && !checkPhone(I('reg_phone'))) { $this->error('注册电话格式不正确'); } if(!empty(I('taxation_rate')) && I('taxation_rate') > 0) { if(!checkNumber(I('taxation_rate'))){ $this->error('税费费率格式错误'); }else{ $save['taxation_rate'] = ($save['taxation_rate'] ?: 0); } }else{ $save['taxation_rate']=0; } if(!empty(I('channel_rate')) && I('channel_rate') > 0) { if(!checkNumber(I('channel_rate'))){ $this->error('渠道费率格式不对'); }else{ $save['channel_rate'] = ($save['channel_rate'] ?: 0); } }else{ $save['channel_rate']=0; } if(!empty(I('fax_ratio')) && I('fax_ratio') > 0) { if(!checkNumber(I('fax_ratio'))){ $this->error('开票税点格式不对'); }else{ $save['fax_ratio'] = ($save['fax_ratio'] ?: 0); } }else{ $save['fax_ratio']=0; } if(!empty(I('server_fee')) && !checkNumber(I('server_fee')) && I("has_server_fee") == 1) { $this->error('服务器费用格式不对'); }else{ if(empty(I('server_fee'))){ $save['server_fee']=0; }else{ $save['server_fee']=I('server_fee'); } } $time =time(); $save['contact_begin'] = strtotime($save['contact_begin']); $save['contact_end'] = strtotime($save['contact_end']); $save['validity_start_time'] = strtotime($save['validity_start_time']); $save['validity_end_time'] = strtotime($save['validity_end_time']); $save['last_up_time'] = $time; } /** * 由于修改公司信息引起的会长信息修改 * @param [type] $save * @return void */ protected function changePromote(&$save){ $is_change_belong = false; $is_change_relation =false; $is_change_game =false; if(empty($save['id'])){ return false; } $company_id = $save['id']; $old_info = M("PromoteCompany","tab_")->field("company_belong,develop_type,game_ids")->where("id = {$save['id']}")->find(); if(isset($save['company_belong']) && ($old_info['company_belong'] != $save['company_belong'])){ $is_change_belong = true; } if(isset($save['develop_type']) && ($old_info['develop_type'] != $save['develop_type'])){ $is_change_relation = true; } //获取需要扣除的游戏 if($old_info['game_ids'] != $save['game_ids']){ // $is_change_game = true; $oids = explode(',', $old_info['game_ids']); $nids = explode(',', $save['game_ids']); $diff_ids = []; if(count($oids) == 0){ $is_change_game = false; }elseif(count($nids) == 0){ $diff_ids = $oids; }else{ foreach ($oids as $k => $v) { if(!in_array($v,$nids)){ $diff_ids[] = $v; } } } if(count($diff_ids) > 0){ $is_change_game = true; $diff_ids = $this->changeRelationGameidToGameid($diff_ids,true); } } //处理底下所有会长的公会属性 if($is_change_belong || $is_change_relation || $is_change_game){ if(!$is_change_game){ $savedata = array( "company_belong"=>$save['company_belong'], "company_relation"=>$save['develop_type'] ); M("Promote","tab_")->where("company_id = '{$company_id}'")->save($savedata); }else{ //需要扣除游戏 $Promote = M("Promote","tab_"); $dbres = $Promote->field("id,game_ids,company_belong,company_relation")->where("company_id = '{$company_id}'")->select(); foreach($dbres as $k=>&$v){ $temp_ids = explode(',',$v['game_ids']); $v['game_ids'] = implode(',', array_diff($temp_ids,$diff_ids)); $v['company_belong'] = $save['company_belong']; $v['company_relation'] = $save['develop_type']; $Promote->save($v); } } // 权限跟随 if($is_change_belong){ $authGroup = M('auth_group',"sys_")->where(['title'=>'市场总监'])->find(); $subPromoteIds = M('promote', 'tab_')->where(['level' => 1, 'company_id' => $company_id])->getField('id', true); $dataPresident = explode(',', $authGroup['data_president']); if ($save['company_belong'] == 1 || $save['company_belong'] == 2) { $dataPresident = array_unique(array_merge($dataPresident, $subPromoteIds)); } else { $dataPresident = array_diff($dataPresident, $subPromoteIds); } M('auth_group',"sys_")->where(['title'=>'市场总监'])->save(['data_president'=>implode(',', $dataPresident)]); } } } protected function menuAuth() { $addurl = U("addRelation"); $mentBtn = [ "marketAgree"=>"市场部审批通过", "marketRefuse"=>"市场部审核拒绝", "adminAgree"=>"管理员审核通过", "adminRefuse"=>"管理员审核拒绝" ]; $resarr = []; foreach ($mentBtn as $k => $v) { if(IS_ROOT){ $resarr[] = $v; }else{ if(in_array($k,$this->OpAuthList)){ $resarr[] = $v; } } } return $resarr; } /** * 返回公司的游戏分成比例 * * @param [type] $company_id * @param [type] $game_ids * @param boolean $is_export * @return void */ protected function getGamePromoteCompanyRadio($company_id,$game_ids,$is_export = false){ //判断是否有生效 $senddata = []; $game = $this->getGameInfo($game_ids); //获取cp分成比例 if($is_export){ $CpRadio = $this->getPromoteCompanyCpRadio($game_ids); } $endtime = time(); $rwhere = "(end_time = 0 OR end_time >= '{$endtime}') and company_id='{$company_id}' and relation_game_id in ({$game_ids})"; $cgr_res = M("CompanyGameRatio","tab_")->where($rwhere)->select(); //判断哪些游戏为空 $game_arr = array_flip(explode(",",$game_ids)); if(!empty($cgr_res)){ foreach ($cgr_res as $k => $v) { $t_gid = $v['relation_game_id']; unset($game_arr[$t_gid]); $senddata[$t_gid] = ["turnover_ratio"=>$v['turnover_ratio'],"ratio"=>$v['ratio'],"relation_game_id"=>$v['relation_game_id']]; $senddata[$t_gid] += $game[$t_gid]; $this->setPromoteRadio($senddata[$t_gid]); if($is_export){ if(isset($CpRadio[$t_gid])){ $senddata[$t_gid]["cp_ratio"] = $CpRadio[$t_gid]; if( count($CpRadio[$t_gid]) >= $senddata[$t_gid]['row'] ){ $c = count($CpRadio[$t_gid]) - $senddata[$t_gid]['row']; for ($x=0; $x<$c; $x++) { $senddata[$t_gid]['turnover_ratio'][]=["name"=>"--","ratio"=>"--"]; } $senddata[$t_gid]['row'] = count($CpRadio[$t_gid]); }else{ $c = $senddata[$t_gid]['row'] - count($CpRadio[$t_gid]); for ($x=0; $x<$c; $x++) { $senddata[$t_gid]['cp_ratio'][]=["name"=>"--","ratio"=>"--"]; } } } } } } if(empty($game_arr)){ return $senddata; } $diff_ids = implode(",",array_keys($game_arr)); $company_belong = M("PromoteCompany","tab_")->field("company_belong")->where("id='{$company_id}'")->find()['company_belong']; $mwhere = "company_belong='{$company_belong}' and relation_game_id in ({$diff_ids})"; $m_res = M("GameRatioMould","tab_")->where($mwhere)->select(); if(!empty($m_res)){ foreach ($m_res as $k => $v) { $t_gid = $v['relation_game_id']; unset($game_arr[$t_gid]); $senddata[$t_gid] = ["turnover_ratio"=>$v['turnover_ratio'],"ratio"=>$v['ratio'],"relation_game_id"=>$v['relation_game_id']]; $senddata[$t_gid] += $game[$t_gid]; $this->setPromoteRadio($senddata[$t_gid]); if($is_export){ if(isset($CpRadio[$t_gid])){ $senddata[$t_gid]["cp_ratio"] = $CpRadio[$t_gid]; if( count($CpRadio[$t_gid]) >= $senddata[$t_gid]['row'] ){ $c = count($CpRadio[$t_gid]) - $senddata[$t_gid]['row']; for ($x=0; $x<$c; $x++) { $senddata[$t_gid]['turnover_ratio'][]=["name"=>"--","ratio"=>"--"]; } $senddata[$t_gid]['row'] = count($CpRadio[$t_gid]); }else{ $c = $senddata[$t_gid]['row'] - count($CpRadio[$t_gid]); for ($x=0; $x<$c; $x++) { $senddata[$t_gid]['cp_ratio'][]=["name"=>"--","ratio"=>"--"]; } } } } } } if(empty($game_arr)){ return $senddata; } foreach($game_arr as $k=>$v){ $senddata[$k]= ["turnover_ratio"=>[["name"=>"--","ratio"=>"--"]],"ratio"=>0,"relation_game_id"=>$k,"cp_ratio"=>[["name"=>"--","ratio"=>"--"]],"row"=>1]; $senddata[$k]+= $game[$k];; } return $senddata; } protected function getPromoteGameRadio($company_id,$ratio,$p_map = false){ //获取会长信息 $payWays = PresidentDepositService::$payWays; $payTypes = PresidentDepositService::$payTypes; $statusList = PresidentDepositService::$statusList; $rdata = []; $promotemap['p.company_id']=$company_id; $promotemap['p.level'] = 1; if($p_map){ $promotemap += $p_map;//外界条件 } $company_row = 0; $promoteres = M("Promote","tab_") ->alias('p') ->field("p.id,p.company_id,p.account,p.game_ids,d.amount,IFNULL(d.pay_way,-1) pay_way,d.status,d.pay_type") ->join("tab_president_deposit as d ON p.id = d.promote_id","left") ->where($promotemap) ->select(); // dd($promoteres); $adminList = getMarketAdminsByPromoteIds(array_column($promoteres, 'id')); if(empty($promoteres)){ //无会长 return ["list"=>["account" => "--","list" => ["turnover_ratio"=>[["name"=>"--","ratio"=>"--"]],"ratio"=>0,"relation_game_id"=>$k,"cp_ratio"=>[["name"=>"--","ratio"=>"--"]],"row"=>1,"original_package_name"=>"--","relation_game_name"=>"--","game_type_name"=>"--"]],"row"=>1]; } foreach ($promoteres as $k => &$v) { $v['market_admin_username'] = isset($adminList[$v['id']]) && $adminList[$v['id']]['admin'] ? $adminList[$v['id']]['admin']['username'] : '无'; if($v['pay_way'] == -1){ $v['pay_way'] = "--"; $v['status'] = "--"; $v['pay_type']="--"; }else{ $v['status'] = $statusList[$v['status']] ?? '--'; $v['pay_type'] = $payTypes[$v['pay_type']] ?? '--'; $v['pay_way'] = $payWays[$v['pay_way']] ?? '--'; } if($ratio == false || empty($v['game_ids'])){ $v['row']=1; $v['list'] = ["turnover_ratio"=>[["name"=>"--","ratio"=>"--"]],"ratio"=>0,"relation_game_id"=>$k,"cp_ratio"=>[["name"=>"--","ratio"=>"--"]],"row"=>1,"original_package_name"=>"--","relation_game_name"=>"--","game_type_name"=>"--"]; $rdata[] = $v; $company_row += $v['row']; }else{ $v['list'] = []; $v['row']=0; $v['game_ids'] = $this->changeGameidToRelationGameid($v['game_ids']); $game_arr = array_flip(explode(",",$v['game_ids'])); foreach($game_arr as $ke=>$va){ if(isset($ratio[$ke])){ $v['list'][] = $ratio[$ke]; $v['row'] += $ratio[$ke]["row"]; } } if($v['row'] == 0) $v['row']=1; $rdata[] = $v; $company_row += $v['row']; } // dd($v); } return ["list"=>$rdata,"row"=>$company_row]; } //获取cp分成比例 protected function getPromoteCompanyCpRadio($game_ids) { $cp_game_ratio_map['game_id'] = ["in", $game_ids]; $cp_game_ratio_map['is_del'] = '0'; $gameradiores = M("cp_game_ratio","tab_") ->alias("cg") ->field("cg.ratio,cg.instanceof,cg.game_id,cg.begin_total_amount") ->where($cp_game_ratio_map) ->group('game_id,begin_total_amount') ->order("begin_total_amount asc") ->select(); $parseGameRadiores = array();//合作方分成比例 foreach ($gameradiores as $key =>$val) { $val['row'] = 1; if ($val['begin_total_amount'] == 0) { $val['name'] = '默认比例'; if (isset($parseGameRadiores[$val['game_id']])) { $parseGameRadiores[$val['game_id']] = []; } } else { if($val['instanceof']=='1'){ $val['name']="月流水≥".$val['begin_total_amount']; }else{ $val['name']="月流水>".$val['begin_total_amount']; } } $parseGameRadiores[$val['game_id']][] =['name'=>$val['name'],"ratio"=>$val['ratio']]; } return $parseGameRadiores; } //设置比例阶梯 protected function setPromoteRadio(&$v){ $turnover_ratio = json_decode($v['turnover_ratio'],true); $v['turnover_ratio'] = array( array("ratio"=>$v['ratio']."%","name"=>"默认比例") ); foreach($turnover_ratio as $ke=>$va){ $t=array("ratio"=>$va["ratio"]."%"); if(array_key_exists("instanceof",$va)){ //存在 if($va['instanceof']=='1'){ $t['name']="月流水≥".$va['turnover']; }else{ $t['name']="月流水>".$va['turnover']; } }else{ $t['name']="月流水≥".$va['turnover']; } $v['turnover_ratio'][]=$t; } $v['row'] = count($v['turnover_ratio']); } //获取游戏基础信息 protected function getGameInfo($game_ids){ $gameinfo = []; $dbres = M("Game","tab_")->where("relation_game_id in ($game_ids)")->field("relation_game_id,relation_game_name,game_type_name,original_package_name")->group("relation_game_id")->select(); foreach($dbres as $k=>$v){ $gameinfo[$v['relation_game_id']] = $v; } return $gameinfo; } //普通游戏id转唯一游戏id protected function changeGameidToRelationGameid($ids,$type=false) { $rid = M('game', 'tab_')->field('relation_game_id')->where(["id"=>["in",$ids]])->group("relation_game_id")->select(); if($type){ return array_column($rid,'relation_game_id'); }else{ return implode(",",array_column($rid,'relation_game_id')); } } //唯一游戏id转普通游戏id protected function changeRelationGameidToGameid($ids,$type=false) { $rid = M('game', 'tab_')->field('id')->where(["relation_game_id"=>["in",$ids]])->select(); if($type){ return array_column($rid,'id'); }else{ return implode(",",array_column($rid,'id')); } } protected function promoteCompanyIsCanDel($company_id){ $r = M("Promote","tab_")->where("company_id={$company_id}")->count(); if($r > 0){ return false; }else{ return true; } } }