From 669bfa8f25cc98f110ce71af11151fb0539306b5 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Fri, 29 May 2020 11:13:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CompanyStatementController.class.php | 1006 +++++++++++++++++ .../CompanyStatementSetController.class.php | 8 +- .../Admin/View/CompanyStatement/lists.html | 550 +++++++++ Data/update.sql | 9 +- 4 files changed, 1569 insertions(+), 4 deletions(-) create mode 100644 Application/Admin/Controller/CompanyStatementController.class.php create mode 100644 Application/Admin/View/CompanyStatement/lists.html diff --git a/Application/Admin/Controller/CompanyStatementController.class.php b/Application/Admin/Controller/CompanyStatementController.class.php new file mode 100644 index 000000000..5c0a212a6 --- /dev/null +++ b/Application/Admin/Controller/CompanyStatementController.class.php @@ -0,0 +1,1006 @@ +"上游cp公司", + "2"=>"联运下游渠道公司" + ]; + public $CompanyBelong = [ + "0"=>"下游内团", + "1"=>"下游外团", + "2"=>"下游分发", + "3"=>"下游无", + "9"=>"上游" + ]; + public $VerifyStatus=[ + "-2"=>"汇总撤销", + "-1"=>"审批拒绝", + "0"=>"未审批", + "1"=>"审核通过", + "2"=>"对外发起", + "3"=>"合作确认", + "4"=>"已汇总" + ]; + public function lists() { + $params = I('get.'); + $page = $params['p'] ? intval($params['p']) : 1; + $row = $params['row'] ? intval($params['row']) : 10; + + $map = []; + 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})"; + } 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['time_start2']) && isset($_REQUEST['time_end2'])) { + $map['op_time'] = ['between', [strtotime($_REQUEST['time_start2']), strtotime($_REQUEST['time_end2']) + 86399]]; + } elseif (isset($_REQUEST['time_start2'])) { + $map['op_time'] = ['EGT', strtotime($_REQUEST['time_start2'])]; + } elseif (isset($_REQUEST['time_end2'])) { + $map['op_time'] = ['ELT', strtotime($_REQUEST['time_end2']) + 86399]; + } + + $typeflag = false; + if (isset($_REQUEST['withdraw_type'])) { + if($_REQUEST['withdraw_type'] == 1){ + $typeflag = 1;//月结 + $map["withdraw_type"] = 1; + }else{ + $typeflag = 2;//周结 + $map["withdraw_type"] = ["in",[0,2]]; + } + } + if (isset($_REQUEST['withdraw_type2'])) { + if($_REQUEST['withdraw_type2'] == 2){ + if($typeflag == 1){ //月结的补点找不到 + $map['withdraw_type'] = 999; + }else{ //周结的补点就是补点 + $map['withdraw_type'] = 2; + } + }else{ + if($typeflag == 1){//月结的正常=月结 + $map['withdraw_type'] = 1; + }elseif($typeflag == 2){//周结的正常=周结 + $map['withdraw_type'] = 0; + }else{//没选的正常是 非补点 + $map['withdraw_type'] = ["in",[0,1]]; + } + } + } + //其他 + if(isset($_REQUEST['company_type'])){ + if($_REQUEST['company_type'] == 1){ + $map['_string'] .= " AND company_belong='9'"; + }else{ + $map['_string'] .= " AND company_belong <> '9'"; + } + } + if(isset($_REQUEST['company_belong'])){ + $map['company_belong'] = $_REQUEST['company_belong']; + } + if(isset($_REQUEST['verify_status'])){ + $map['verify_status'] = $_REQUEST['verify_status']; + } + //条件end + $data = M("company_statement","tab_") + ->field("id,withdraw_type,company_name,company_belong,statement_begin_time,statement_end_time,statement_money,platform_amount,verify_status,verify_log,op_time") + ->where($map) + ->order("op_time Desc")->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['company_belong'] = $this->CompanyBelong[$v['company_belong']]; + $v['op_time'] = date('Y-m-d H:i:s',$v['op_time']); + $v["valid"] = "{$v['statement_begin_time']} ~ {$v['statement_end_time']}"; + + + $v['withdraw_type_1'] = ($v['withdraw_type'] == 1 ? "月结" :"周结"); + $v['withdraw_type_2'] = ($v['withdraw_type'] == 2 ? "补点" :"正常结算"); + + $v['verify_log'] = json_decode($v['verify_log'], true); + if (isset($params['export'])) { + $symbol = "\n"; + } else { + $symbol = "
"; + } + // $v["create"]= "{$v['verify_log']['create_user']} {$symbol} {$v['verify_log']['create_time']}"; + if(isset($v['verify_log']['verify_user'])){ + if($v['status'] == -1){ + $ts = "审核拒绝"; + }else{ + $ts = "审核通过"; + } + $v["verify"]= "{$ts}({$v['verify_log']['verify_user']}) {$symbol} {$v['verify_log']['verify_time']}"; + }else{ + $v["verify"] = '--'; + } + + if(isset($v['verify_log']['launch_user'])){ + $ts = "已发起"; + $v["launch"]= "{$ts}({$v['verify_log']['launch_user']}) {$symbol} {$v['verify_log']['launch_time']}"; + }else{ + $v["launch"] = '--'; + } + + if(isset($v['verify_log']['confirm_user'])){ + $ts = "已确认"; + $v["confirm"]= "{$ts}({$v['verify_log']['confirm_user']}) {$symbol} {$v['verify_log']['confirm_time']}"; + }else{ + $v["confirm"] = '--'; + } + if(isset($v['verify_log']['pool_user'])){ + if($v['status'] == -2){ + $ts = "撤销汇总"; + }else{ + $ts = "已汇总"; + } + $v["pool"]= "{$ts}({$v['verify_log']['pool_user']}) {$symbol} {$v['verify_log']['pool_time']}"; + }else{ + $v["pool"] = '--'; + } + } + // dd($data); + $count = M("company_statement","tab_")->field("count(id) count")->where($map)->find(); + $parameter['p'] = $page; + $parameter['row'] = $row; + $page = set_pagination($count['count'], $row, $parameter); + if ($page) { + $this->assign('_page', $page); + } + + $this->assign('data',$data); + + $this->assign('CompanyType',$this->CompanyType); + $this->assign('CompanyBelong',$this->CompanyBelong); + $this->assign('VerifyStatus',$this->VerifyStatus); + $this->display(); + + } + + public function createDownstreamOrder() { + + $this->display(); + + } + + public function saveDownstreamOrder() { + + + + $second_party_info = $_REQUEST['second_party_info']; + $first_party_info = $_REQUEST['first_party_info']; + $statement_info = $_REQUEST['statement_info']; + $sumData = $_REQUEST['sum_data']; + + if ($second_party_info['settlement_type']=='补点订单') { + $second_party_info['order_type'] = 1; + } else { + $second_party_info['order_type'] = 0; + } + + if (!$second_party_info||!$first_party_info||!$statement_info||!$statement_info) { + $this->ajaxReturn(['code'=>0, 'msg'=>'数据错误' ]); + } + $insert['statement_type'] = 1; + $insert['company_id'] = $_REQUEST['company_id']; + $insert['company_name'] = $second_party_info['partner']; + $insert['link_phone'] = $second_party_info['link_phone'];; + + $statement_begin_time = strtotime($statement_info[0]['statement_begin_time']); + $statement_end_time = strtotime($statement_info[0]['statement_end_time']); + + foreach($statement_info as $key => $value) { + + if ($statement_begin_time>strtotime($value['statement_begin_time'])&&$value['statement_begin_time']) { + $statement_begin_time = strtotime($value['statement_begin_time']); + } +// var_dump(strtotime($value['statement_begin_time']); + + if ($statement_end_timewhere(['ext_field'=>$_REQUEST['ext_field']])->find())) { + + addOperationLog(['op_type'=>0,'key'=>$second_party_info['partner'].'/'.getNowDate(),'op_name'=>'新增下游对账单','url'=>U('StatementMangement/lists'),'menu'=>'推广员-结算管理-结算单管理-新增下游对账单']); + + M('statement','tab_')->add($insert); + $this->ajaxReturn(['code'=>1, 'msg'=>'生成结算单成功']); + } else { + $this->ajaxReturn(['code'=>0, 'msg'=>'生成结算单失败,结算单已经存在']); + } + + } + + public function editDownstreamOrder() { + + $this->display('edit'); + + } + + public function editDownstreamOrderSave() { + $second_party_info = $_REQUEST['second_party_info']; + $first_party_info = $_REQUEST['first_party_info']; + $statement_info = $_REQUEST['statement_info']; + $sumData = $_REQUEST['sum_data']; + + if (!$second_party_info||!$first_party_info||!$statement_info||!$statement_info) { + $this->ajaxReturn(['code'=>0, 'msg'=>'数据错误' ]); + } + $insert['statement_type'] = 1; + $insert['company_id'] = $_REQUEST['company_id']; + $insert['company_name'] = $second_party_info['partner']; + $insert['link_phone'] = $second_party_info['link_phone'];; + + $statement_begin_time = strtotime($statement_info[0]['statement_begin_time']); + $statement_end_time = strtotime($statement_info[0]['statement_end_time']); + + foreach($statement_info as $key => $value) { + + if ($statement_begin_time>strtotime($value['statement_begin_time'])&&$value['statement_begin_time']) { + $statement_begin_time = strtotime($value['statement_begin_time']); + } +// var_dump(strtotime($value['statement_begin_time']); + + if ($statement_end_timewhere(['ext_field'=>$_REQUEST['ext_field']])->save($insert))) { + + addOperationLog(['op_type'=>1,'key'=>$second_party_info['partner'].'/'.getNowDate(),'op_name'=>'编辑下游对账单','url'=>U('StatementMangement/lists'),'menu'=>'推广员-结算管理-结算单管理-新增下游对账单']); + + $this->ajaxReturn(['code'=>1, 'msg'=>'结算单编辑成功']); + } else { + $this->ajaxReturn(['code'=>0, 'msg'=>'结算单编辑失败']); + } + } + + public function delStatementData() { + + $id = $_REQUEST['id']; + if (!$id) { + $this->ajaxReturn(['code'=>2000,'error'=>'no']); + } + $statementData = M('statement','tab_')->where(['id'=>$id])->find(); + + $is_del = M('statement','tab_')->where(['id'=>$id])->delete(); + + if ($is_del) { + + addOperationLog(['op_type'=>2,'key'=>$statementData['company_name'].'/'.date('YmdHis',$statementData['statement_begin_time']).'/'.date('YmdHis',$statementData['statement_end_time']),'op_name'=>'删除下游对账单','url'=>U('StatementMangement/lists'),'menu'=>'推广员-结算管理-结算单管理-删除下游对账单']); + + $this->ajaxReturn(['code'=>0,'success'=>'ok']); + } else { + $this->ajaxReturn(['code'=>2000,'error'=>'no']); + } + + } + + public function rewardManageList($row = 10, $p = 1) + { + $map = []; + if (!empty(I("game_name"))) { + $game_ids = array_column(getGameByName(I("game_name")), 'id'); + if ($game_ids) { + $map['relation_game_id'] = ['in', $game_ids]; + } + } + if (!empty(I('partner_id'))) { + $map['company_id'] = I('partner_id'); + } + if (strlen(I('company_type'))) { + $map['company_type'] = I('company_type'); + } + if (!empty(I('account'))) { + $map['accounts'] = ['like', '%' . I('account') . '%']; + } + $list = M('reward_record', 'tab_')->where($map)->page($p, $row)->select(); + if ($list) { + $companys[1] = array_column(M('partner', 'tab_')->field('id, partner as name')->select(), 'name', 'id'); + $companys[2] = array_column(M('promote_company', 'tab_')->field('id, company_name as name')->select(), 'name', 'id'); + $games = array_column(M('game', 'tab_')->field('relation_game_id, relation_game_name')->group('relation_game_id')->select(), 'relation_game_name', 'relation_game_id'); + foreach ($list as &$item) { + $item['company_name'] = $companys[$item['company_type']][$item['company_id']]; + $item['accounts'] = json_decode($item['accounts'], true) ?: []; + $item['reward_type_desc'] = $item['reward_type'] == 1 ? "奖励" : "惩罚"; + $item['company_type_desc'] = $item['company_type'] == 1 ? "上游公司" : "下游公司"; + $item['relation_game_name'] = $games[$item['relation_game_id']]; + $item['reward_time'] = $item['reward_time'] ? date('Y-m-d H:i:s', $item['reward_time']) : '-'; + // if ($item['company_type'] == 1) { + + // } else { + + // } + } + } + $count = M('reward_record', 'tab_')->where($map)->count(); + $page = set_pagination($count, $row); + if ($page) { + $this->assign('_page', $page); + } + $this->assign('list', $list); + $this->display(); + } + + public function rewardManageSave($id=0) + { + if (IS_POST) { + $data = [ + 'reward_type' => I('reward_type'), + 'company_type' => I('company_type'), + 'company_id' => I('company_id'), + 'relation_game_id' => I('relation_game_id'), + 'money' => I('money'), + 'content' => I('content'), + 'remark' => I('remark'), + 'reward_time' => strtotime(I('reward_time')) + ]; + + $accounts = I('account'); + $user_types = I('user_type'); + if ($accounts) { + + foreach ($accounts as $index => $account) { + + if (checkAccount($user_types[$index],$account)==1) { + $data['accounts'][] = array_merge(['account'=>$account], ['user_type'=>$user_types[$index]]); + } else { + return $this->error('账号'.$account.'不存在,请重新输入'); + } +// $data['accounts'][] = array_merge(['account'=>$account], ['user_type'=>$user_types[$index]]); + } + } else { + $data['accounts'] = []; + } + $data['accounts']=a_array_unique($data['accounts']); +// dump($data['accounts']);die(); + $data['accounts'] = json_encode($data['accounts']); + if (!is_numeric(I('money'))) { + return $this->error('请输入正确的金额'); + } + if (empty(I('content'))) { + return $this->error('请填写事件内容'); + } + if ($id) { + $upt = M('reward_record', 'tab_')->where(['id'=>$id])->save($data); + if ($upt === false) { + $this->error('保存失败'); + } else { + $companyName = M('partner','tab_')->field('partner')->where(['id'=>$data['company_id']])->find(); + addOperationLog(['op_type'=>1,'key'=>$companyName['partner'].'/'.(($data['reward_type']==1)?'奖励':'惩罚').'/'.$data['money'],'op_name'=>'修改奖惩记录','url'=>U('Query/settlement'),'menu'=>'推广员-结算单管理-奖罚记录管理-修改奖惩记录']); + + $this->success('保存成功', U('StatementMangement/rewardManageList')); + } + } else { + $data['create_time'] = time(); + $data['creater_id'] = is_login(); + $ins = M('reward_record', 'tab_')->add($data); + + $companyName = M('partner','tab_')->field('partner')->where(['id'=>$data['company_id']])->find(); + addOperationLog(['op_type'=>0,'key'=>$companyName['partner'].'/'.(($data['reward_type']==1)?'奖励':'惩罚').'/'.$data['money'],'op_name'=>'新增奖惩记录','url'=>U('Query/settlement'),'menu'=>'推广员-结算单管理-奖罚记录管理-新增奖惩记录']); + + return $ins ? $this->success('新增成功', U('StatementMangement/rewardManageList')) : $this->error('新增失败'); + } + } else { + $games = M('game', 'tab_')->field('relation_game_id, relation_game_name')->group('relation_game_id')->select(); + $this->assign('games', $games); + if ($id) { + if (I('delete')) { + + $rewardRecordData = M('reward_record', 'tab_')->where(['id'=>$id])->find(); + + $upt = M('reward_record', 'tab_')->where(['id'=>$id])->delete(); + + $companyName = M('partner','tab_')->field('partner')->where(['id'=>$rewardRecordData['company_id']])->find(); + + addOperationLog(['op_type'=>2,'key'=>$companyName['partner'].'/'.(($rewardRecordData['reward_type']==1)?'奖励':'惩罚').'/'.$rewardRecordData['money'],'op_name'=>'删除奖惩记录','url'=>U('StatementMangement/rewardManageList'),'menu'=>'推广员-结算单管理-奖罚记录管理']); + + return $upt ? $this->success('删除成功') : $this->error('删除失败'); + } else { + $data = M('reward_record', 'tab_')->where(['id'=>$id])->find(); + if (!$data) return $this->error("未找到该记录"); + $data['accounts'] = json_decode($data['accounts'], true) ?: []; + $this->assign('data', $data); + } + } else { + $data['reward_time'] = strtotime(date('Y-m-01')); + $this->assign('data', $data); + } + $this->display(); + } + + } + + public function getCompanys($type=1) + { + if ($type == 1) { + $data = M('partner', 'tab_')->field('id, partner as name')->select(); + } elseif ($type == 0) { + $data = []; + } else { + $data = M('promote_company', 'tab_')->field('id, company_name as name')->select(); + } + return $this->success($data, '', true); + } + + public function PersonOrderList() { + + if ($_REQUEST['time_start'] || $_REQUEST['time_end'] ) { + $withdrawMap = []; + if ($_REQUEST['time_start']&&!$_REQUEST['time_end']) { + $withdrawMap['settlement_begin_time'] = ['egt',strtotime($_REQUEST['time_start'])]; + } + + if (!$_REQUEST['time_start']&&$_REQUEST['time_end']) { + $withdrawMap['settlement_end_time'] = ['elt',strtotime($_REQUEST['time_end'])]; + } + + if ($_REQUEST['time_start']&&$_REQUEST['time_end']) { + $withdrawMap['settlement_begin_time'] = ['egt',strtotime($_REQUEST['time_start'])]; + $withdrawMap['settlement_end_time'] = ['elt',strtotime($_REQUEST['time_end'])]; + } + + $data = M('withdraw',"tab_") + ->field("widthdraw_number,settlement_begin_time,settlement_end_time,settlement_type,promote_account") + ->join('left join tab_promote_belong on tab_withdraw.promote_id=tab_promote_belong.promote_id') + ->join("left join tab_statement as statement on tab_withdraw.widthdraw_number = statement.ext_field") + ->where("ext_field is null and tab_promote_belong.company_type=2") + ->where($withdrawMap) + ->select(); + + $statement = M('statement','tab_') + ->field('ext_field') + ->where(['ext_field'=>['like','%,%']]) + ->select(); + + $withdrawData = []; + + foreach($statement as $key => $value) { + + $handleData = explode(',',$value['ext_field']); + + foreach ($handleData as $hk => $hv) { + array_push($withdrawData,$hv); + } + + } + + foreach ($data as $key => $value) { + $data[$key]['settlement_begin_time'] = date("Y-m-d H:i:s", $data[$key]['settlement_begin_time']); + $data[$key]['settlement_end_time'] = date("Y-m-d H:i:s", $data[$key]['settlement_end_time']); + + if (in_array($value['widthdraw_number'],$withdrawData)) { + unset($data[$key]); + } + + } + + $this->assign('withdraw_data',$data); + + } + + if ($_REQUEST['withdraw']&&$data) { + + $map = []; + + $map['widthdraw_number'] = ['in',$_REQUEST['withdraw']]; + + $data = M('withdraw','tab_') + ->field("tab_withdraw.id,pc.company_name,pc.id as cid,tab_withdraw.promote_id,tab_withdraw.promote_account,username,'个人' as type,game_ratio + ,mobile_phone,real_name,pc.bank_card,bank_address as account_openin,tab_promote.address,pc.settlement_contact as bank_account") + ->join('left join tab_promote_belong on tab_withdraw.promote_id=tab_promote_belong.promote_id') + ->join("left join tab_statement as statement on tab_withdraw.widthdraw_number = statement.ext_field") + ->join("left join tab_promote on tab_promote.id=tab_promote_belong.promote_id") + ->join("left join tab_promote_company as pc on pc.id = tab_promote.company_id") + ->join("left join sys_ucenter_member on sys_ucenter_member.id=tab_promote.admin_id") + ->where("ext_field is null and tab_promote_belong.company_type=2") + ->where($map) + ->select(); + + + $game_ratio = []; + foreach($data as $dkey => &$dval) { + $gameStr = []; +// $address = ''; +// if (is_array($data['address'])) { +// foreach($data['address'] as $key => $value) { +// $address = $address.' '.$value; +// } +// } +// $dval['address'] = $address; + $rowspan = 0; + $dval['rowspan'] = 0; + + $dval['game_ratio'] = json_decode($dval['game_ratio'],true); + + if (is_array($dval['game_ratio'])) { + foreach ($dval['game_ratio'] as $key => &$value) { + + foreach ($value as $k => &$v) { + +// $v['game_id'] = $key; + + $v['game_name'] = substr(get_gamename($key),0,strpos(get_gamename($key), '(')); + + if (!in_array($v['game_name'],$gameStr)) { + array_push($gameStr,$v['game_name']); + + } else { +// var_dump($key); + if (!$game_ratio[$v['game_name']]) { + $game_ratio[$v['game_name']] = $v; + } + else { + $game_ratio[$v['game_name']]['sum_amount'] += $v['sum_amount']; + } + unset($value[$k]); + } +// + } + if (!$value) { + unset($dval['game_ratio'][$key]); + } + + } + + foreach ($dval['game_ratio'] as $key => $val) { + + $val[0]['reward'] = 0; + $val[0]['forfeit'] = 0; + $startTime = strtotime($val[0]['begin_time']); + $endTime = strtotime($val[0]['end_time']); + + $rewardData = M('reward_record','tab_') + ->field("sum(tab_reward_record.money) as money,reward_type,relation_game_name") + ->join("left join (select * from tab_game group by relation_game_id)tab_game on tab_reward_record.relation_game_id=tab_game.relation_game_id") + ->where(['company_type'=>2,'relation_game_name'=>['like',"%{$val[0]['game_name']}%"],'reward_time'=>['between',[$startTime,$endTime]]]) + ->group('reward_type') + ->select(); + + foreach ($rewardData as $rk => $rv) { + + if ($rv['reward_type'] == 1) { + $val[0]['reward'] = $rv['money']; + } else { + $val[0]['forfeit'] = $rv['money']; + } + + } + + foreach ($val as $k => &$v) { + + if ($game_ratio[$v['game_name']]) { + + $v['sum_amount'] = number_format($v['sum_amount'] + $game_ratio[$v['game_name']]['sum_amount'],2,'.',''); + + } + //计算结算金额 + $val[0]['real_amount'] = number_format($val[0]['sum_amount'] * ($val[0]['selle_ratio']/100)+$val[0]['reward']-$val[0]['forfeit'],2,'.',''); + } + + $rowspan++; + unset($dval['game_ratio'][$key]); + array_push($dval['game_ratio'],$val[0]); + + } + + $dval['rowspan'] = $rowspan; + + } + } + + $this->assign('data',$data); + + } + $this->display(); + + } + + public function savePersonOrder() { + +// dump($_POST); + + + + $data['statement_info'] = $_POST['statement_info']; + $data['first_party_info'] = json_encode([]); + $data['second_party_info'] = $_POST['second_party_info']; + $data['statement_begin_time'] = strtotime($_POST['time_start']); + $data['statement_end_time'] = strtotime($_POST['time_end']); + $data['create_time'] = time(); + $data['statement_money'] = 0; + $data['pay_amount'] = 0; + $data['ext_field'] = ''; + $data['company_name'] = '个人结账单'; + $data['statement_type'] = 2; + + if($data['second_party_info'] == '[]' || $data['statement_info'] == '[]') { + $this->ajaxReturn(['status'=>1,'msg'=>'数据错误']); + } + + + $statement_info = json_decode($data['statement_info'],true); + + foreach($statement_info as $key => $value) { + $data['statement_money'] += $value['sum_amount']; + $data['pay_amount'] += $value['real_amount']; + } + + $second_party_info = json_decode($data['second_party_info'],true); + + foreach($second_party_info as $key => $value) { + $data['ext_field'] = $data['ext_field'].$value['widthdraw_number'].','; + } + + $is_exist = M('statement','tab_')->where(['ext_field'=>$data['ext_field'],'statement_type'=>2])->find(); + if ($is_exist) { + $this->ajaxReturn(['status'=>0,'msg'=>'请勿重复添加']); + } + + $is_save = M('statement','tab_')->add($data); + + if ($is_save) { + + addOperationLog(['op_type'=>0,'key'=>'个人结算单'.'/'.getNowDate(),'op_name'=>'生成下游个人结算单','url'=>U('StatementMangement/lists'),'menu'=>'推广员-结算管理-结算单管理-生成下游个人结算单']); + + $this->ajaxReturn(['status'=>1,'msg'=>'生成成功']); + } else { + $this->ajaxReturn(['status'=>0,'msg'=>'生成失败']); + } + + } + + public function PersonOrderEdit() { + + if ($_REQUEST['time_start'] || $_REQUEST['time_end'] ) { + $withdrawMap = []; + if ($_REQUEST['time_start']&&!$_REQUEST['time_end']) { + $withdrawMap['settlement_begin_time'] = ['egt',strtotime($_REQUEST['time_start'])]; + } + + if (!$_REQUEST['time_start']&&$_REQUEST['time_end']) { + $withdrawMap['settlement_end_time'] = ['elt',strtotime($_REQUEST['time_end'])]; + } + + if ($_REQUEST['time_start']&&$_REQUEST['time_end']) { + $withdrawMap['settlement_begin_time'] = ['egt',strtotime($_REQUEST['time_start'])]; + $withdrawMap['settlement_end_time'] = ['elt',strtotime($_REQUEST['time_end'])]; + } + + $data = M('withdraw',"tab_") + ->field("widthdraw_number,settlement_begin_time,settlement_end_time,settlement_type,promote_account") + ->join('left join tab_promote_belong on tab_withdraw.promote_id=tab_promote_belong.promote_id') + ->join("left join tab_statement as statement on tab_withdraw.widthdraw_number = statement.ext_field") + ->where("tab_promote_belong.company_type=2") + ->where($withdrawMap) + ->select(); +// dump($data);die(); + + $statement = M('statement','tab_') + ->field('ext_field') + ->where('ext_field is not null') + ->select(); + + $withdrawData = []; + + foreach($statement as $key => $value) { + + $handleData = explode(',',$value['ext_field']); + + foreach ($handleData as $hk => $hv) { + array_push($withdrawData,$hv); + } + + } + +// $thisWithdraw = explode(',',$_REQUEST['withdraw']); + $thisWithdraw = explode(',',M('statement','tab_')->where(['id'=>$_REQUEST['id']])->find()['ext_field']); +// dump($thisWithdraw);die(); + + + foreach ($data as $key => $value) { +// $data[$key]['settlement_begin_time'] = date("Y-m-d H:i:s", $data[$key]['settlement_begin_time']); +// $data[$key]['settlement_end_time'] = date("Y-m-d H:i:s", $data[$key]['settlement_end_time']); + +// var_dump($value['widthdraw_number'].$_REQUEST['withdraw']);die(); + + if (in_array($value['widthdraw_number'],$withdrawData)&&!in_array($value['widthdraw_number'],$thisWithdraw)) { + unset($data[$key]); + } + + } + + foreach ($data as $key => $value) { + $data[$key]['settlement_begin_time'] = date("Y-m-d H:i:s", $data[$key]['settlement_begin_time']); + $data[$key]['settlement_end_time'] = date("Y-m-d H:i:s", $data[$key]['settlement_end_time']); + + } + + $this->assign('withdraw_data',$data); + + } + + if ($_REQUEST['withdraw']&&$data) { + + $map = []; + + $map['widthdraw_number'] = ['in',$_REQUEST['withdraw']]; + + $data = M('withdraw','tab_') + ->field("tab_withdraw.id,pc.company_name,pc.id as cid,tab_withdraw.promote_id,tab_withdraw.promote_account,username,'个人' as type,game_ratio + ,mobile_phone,real_name,pc.bank_card,bank_address as account_openin,tab_promote.address,pc.settlement_contact as bank_account") + ->join('left join tab_promote_belong on tab_withdraw.promote_id=tab_promote_belong.promote_id') + ->join("left join tab_statement as statement on tab_withdraw.widthdraw_number = statement.ext_field") + ->join("left join tab_promote on tab_promote.id=tab_promote_belong.promote_id") + ->join("left join tab_promote_company as pc on pc.id = tab_promote.company_id") + ->join("left join sys_ucenter_member on sys_ucenter_member.id=tab_promote.admin_id") + ->where("tab_promote_belong.company_type=2") + ->where($map) + ->select(); + + + $game_ratio = []; + foreach($data as $dkey => &$dval) { + $gameStr = []; + + $rowspan = 0; + $dval['rowspan'] = 0; + + $dval['game_ratio'] = json_decode($dval['game_ratio'],true); + + if (is_array($dval['game_ratio'])) { + foreach ($dval['game_ratio'] as $key => &$value) { + + foreach ($value as $k => &$v) { + +// $v['game_id'] = $key; + + $v['game_name'] = substr(get_gamename($key),0,strpos(get_gamename($key), '(')); + + if (!in_array($v['game_name'],$gameStr)) { + array_push($gameStr,$v['game_name']); + + } else { +// var_dump($key); + if (!$game_ratio[$v['game_name']]) { + $game_ratio[$v['game_name']] = $v; + } + else { + $game_ratio[$v['game_name']]['sum_amount'] += $v['sum_amount']; + } + unset($value[$k]); + } +// + } + if (!$value) { + unset($dval['game_ratio'][$key]); + } + + } + + foreach ($dval['game_ratio'] as $key => $val) { + + $val[0]['reward'] = 0; + $val[0]['forfeit'] = 0; + $startTime = strtotime($val[0]['begin_time']); + $endTime = strtotime($val[0]['end_time']); + + $rewardData = M('reward_record','tab_') + ->field("sum(tab_reward_record.money) as money,reward_type,relation_game_name") + ->join("left join (select * from tab_game group by relation_game_id)tab_game on tab_reward_record.relation_game_id=tab_game.relation_game_id") + ->where(['company_type'=>2,'relation_game_name'=>['like',"%{$val[0]['game_name']}%"],'reward_time'=>['between',[$startTime,$endTime]]]) + ->group('reward_type') + ->select(); + + foreach ($rewardData as $rk => $rv) { + + if ($rv['reward_type'] == 1) { + $val[0]['reward'] = $rv['money']; + } else { + $val[0]['forfeit'] = $rv['money']; + } + + } + + foreach ($val as $k => &$v) { + + if ($game_ratio[$v['game_name']]) { + + $v['sum_amount'] = number_format($v['sum_amount'] + $game_ratio[$v['game_name']]['sum_amount'],2,'.',''); + + } + //计算结算金额 + $val[0]['real_amount'] = number_format($val[0]['sum_amount'] * ($val[0]['selle_ratio']/100)+$val[0]['reward']-$val[0]['forfeit'],2,'.',''); + } + + $rowspan++; + unset($dval['game_ratio'][$key]); + array_push($dval['game_ratio'],$val[0]); + + } + + $dval['rowspan'] = $rowspan; + + } + } + + $this->assign('data',$data); + + } + $this->display(); + + } + + public function savePersonOrderEdit() { + + $data['statement_info'] = $_POST['statement_info']; + $data['first_party_info'] = json_encode([]); + $data['second_party_info'] = $_POST['second_party_info']; + $data['statement_begin_time'] = strtotime($_POST['time_start']); + $data['statement_end_time'] = strtotime($_POST['time_end']); + $data['create_time'] = time(); + $data['statement_money'] = 0; + $data['pay_amount'] = 0; + $data['ext_field'] = ''; + $data['company_name'] = '个人结账单'; + $data['statement_type'] = 2; + + + if($data['second_party_info'] == '[]' || $data['statement_info'] == '[]') { + $this->ajaxReturn(['status'=>1,'msg'=>'数据错误']); + } + + + $statement_info = json_decode($data['statement_info'],true); + + foreach($statement_info as $key => $value) { + $data['statement_money'] += $value['sum_amount']; + $data['pay_amount'] += $value['real_amount']; + } + + $second_party_info = json_decode($data['second_party_info'],true); + + foreach($second_party_info as $key => $value) { + $data['ext_field'] = $data['ext_field'].$value['widthdraw_number'].','; + } + $data['ext_field'] = rtrim($data['ext_field'], ","); + + $is_save = M('statement','tab_')->where(['id'=>$_REQUEST['withdraw_id']])->save($data); + +// echo M('statement','tab_')->_sql();die(); + + if ($is_save) { + + addOperationLog(['op_type'=>1,'key'=>'个人结算单'.'/'.getNowDate(),'op_name'=>'编辑下游个人结算单','url'=>U('StatementMangement/lists'),'menu'=>'推广员-结算管理-结算单管理-编辑下游个人结算单']); + + $this->ajaxReturn(['status'=>1,'msg'=>'修改成功']); + } else { + $this->ajaxReturn(['status'=>0,'msg'=>'修改失败']); + } + + } + + + public function personOrderDetail() { + + $id = $_REQUEST['id']; + + $map['id'] = $id; + + $data = M('statement','tab_') + ->field("second_party_info,statement_info") + ->where($map) + ->find(); + + + $data['second_party_info'] = json_decode($data['second_party_info'],true); + $data['statemnt_info'] = json_decode($data['statement_info'],true); + +// dump($data['statemnt_info']);die(); + + $this->assign('second_party_info',$data['second_party_info']); + $this->assign('statemnt_info',$data['statemnt_info']); + + $this->display(); + } + + public function verifyStatementStatus() { + + $order = $_REQUEST['order']; + + if ($order) { + + $isVerify = M('statement','tab_')->where(['id'=>['in',$order]])->save(['verify_status'=>1]); + + if ($isVerify) { + + $data = M('statement','tab_')->where(['id'=>['in',$order]])->select(); + + foreach ($data as $key => $value) { + + addOperationLog(['op_type'=>1,'key'=>$value['company_name'].'/'.date('YmdHis',$value['statement_begin_time']).'/'.date('YmdHis',$value['statement_end_time']),'op_name'=>'编辑结算单审核通过','url'=>U('StatementMangement/lists'),'menu'=>'推广员-结算管理-结算单管理-结算单审核通过']); + + } + + $this->ajaxReturn(['status'=>1]); + } else { + $this->ajaxReturn(['status'=>0]); + } + } else { + $this->ajaxReturn(['status'=>0]); + } + + } + + public function rejectStatementStatus() { + + $order = $_REQUEST['order']; + + if ($order) { + + $isVerify = M('statement','tab_')->where(['id'=>['in',$order]])->save(['verify_status'=>2]); + + if ($isVerify) { + + $data = M('statement','tab_')->where(['id'=>['in',$order]])->select(); + + foreach ($data as $key => $value) { + + addOperationLog(['op_type'=>1,'key'=>$value['company_name'].'/'.date('YmdHis',$value['statement_begin_time']).'/'.date('YmdHis',$value['statement_end_time']),'op_name'=>'编辑结算单审核通过','url'=>U('StatementMangement/lists'),'menu'=>'推广员-结算管理-结算单管理-结算单审核通过']); + + } + + $this->ajaxReturn(['status'=>1]); + } else { + $this->ajaxReturn(['status'=>0]); + } + } else { + $this->ajaxReturn(['status'=>0]); + } + + } + +} diff --git a/Application/Admin/Controller/CompanyStatementSetController.class.php b/Application/Admin/Controller/CompanyStatementSetController.class.php index 655f72cf6..0d24e6865 100644 --- a/Application/Admin/Controller/CompanyStatementSetController.class.php +++ b/Application/Admin/Controller/CompanyStatementSetController.class.php @@ -122,7 +122,7 @@ class CompanyStatementSetController extends Controller { $cp_id = implode(",",array_flip(array_flip(array_keys($cpList)))); $js_id = implode(",",array_unique($js_id)); //获取cp公司 - $tmpp = M("Partner","tab_")->field("id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank,channel_rate,invoice_rate")->where(["id"=>['in',$cp_id]])->select(); + $tmpp = M("Partner","tab_")->field("id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank,channel_rate,invoice_rate,company_type")->where(["id"=>['in',$cp_id]])->select(); $cp =[]; foreach ($tmpp as $v) { $cp[$v['id']]=$v; @@ -212,6 +212,8 @@ class CompanyStatementSetController extends Controller { $add_data['verify_log'] = $verify_log; $add_data['op_time'] =time(); $add_data['statement_info'] =[]; + $add_data['company_belong']=9;//上游 + $add_data['company_type']=$cp[$add_data['company_id']]['company_type']; //获取渠道及发票税率 $promote_ratio = $cp[$add_data['company_id']]['channel_rate'] ?? 0; $fax_ratio = $cp[$add_data['company_id']]['invoice_rate'] ?? 0; @@ -398,7 +400,7 @@ class CompanyStatementSetController extends Controller { return ; } //获取pc公司 - $tmpp = M("PromoteCompany","tab_")->field("id,company_name partner,settlement_contact link_man,contact_phone link_phone,address,bank_address opening_bank,bank_card bank_account,fax_ratio,company_belong")->where(["id"=>['in',$pc_id]])->select(); + $tmpp = M("PromoteCompany","tab_")->field("id,company_name partner,settlement_contact link_man,contact_phone link_phone,address,bank_address opening_bank,bank_card bank_account,fax_ratio,company_belong,company_type")->where(["id"=>['in',$pc_id]])->select(); $pc =[]; foreach ($tmpp as $v) { $pc[$v['id']]=$v; @@ -449,6 +451,8 @@ class CompanyStatementSetController extends Controller { //获取渠道及发票税率 $fax_ratio = $pc[$add_data['company_id']]['fax_ratio'] ?? 0; $company_belong = $pc[$add_data['company_id']]['company_belong']; + $add_data['company_belong']=$company_belong; + $add_data['company_type']=$pc[$add_data['company_id']]['company_type']; //游戏统计 foreach($v['list'] as $ke=>$va){ $game =[]; diff --git a/Application/Admin/View/CompanyStatement/lists.html b/Application/Admin/View/CompanyStatement/lists.html new file mode 100644 index 000000000..5e9c3c6df --- /dev/null +++ b/Application/Admin/View/CompanyStatement/lists.html @@ -0,0 +1,550 @@ + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+ +
+ +
+ +
+ +
+
+ +
+ +
+ +  -  +
+ + +
+
+ +
+ +
+ +
+ +  -  +
+ + +
+
+ +
+ 搜索 +
+ +
+
+ + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
合作公司结算单类型结算时间结算周期结算类型结算金额流水金额审批状态对外发起合作确认汇总状态操作
aOh! 暂时还没有内容!
+ 上游对账单下游对账单下游补点对账单下游个人结算单{$data.create_time}{$data.company_name}{$data.statement_begin_time}-{$data.statement_end_time}{$data.statement_money}未审核审核通过审核拒绝未确认确认 + 查看 + + 编辑 + + 撤销 +
合计公司对账金额合计:{$sum[1]}     cp对账金额合计:{$sum[0]+$sum[2]}
+
+ +
+
+ + 导出 + + {$_page|default=''} +
+ + +
+ + + + if(C('COLOR_STYLE')=='blue_color') echo ' + + '; + + + + + + + + + diff --git a/Data/update.sql b/Data/update.sql index 5641cfd18..411dfb573 100644 --- a/Data/update.sql +++ b/Data/update.sql @@ -1853,11 +1853,14 @@ CREATE TABLE `tab_company_statement` ( `withdraw_type` tinyint(2) DEFAULT '0' COMMENT '对账类型(0-周结 1月结 2补点)', `company_id` int(11) DEFAULT '0' COMMENT '对账公司id', `company_name` varchar(60) NOT NULL DEFAULT '' COMMENT '对账公司名称', + `company_belong` tinyint(1) NOT NULL DEFAULT '0' COMMENT '工会归属:0-下游内团;1-下游外团 2-下游分发联盟 3 下游无,9:上游', + `company_type` tinyint(3) NOT NULL DEFAULT '1' COMMENT '公司性质:1-公司 2-个人', `statement_begin_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账开始时间', `statement_end_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账截止时间', `statement_money` decimal(10,2) DEFAULT '0.00' COMMENT '对账金额', - `pay_amount` decimal(10,2) DEFAULT '0.00' COMMENT '流水金额', + `pay_amount` decimal(10,2) DEFAULT '0.00' COMMENT '总计', + `platform_amount` decimal(10,2) DEFAULT '0.00' COMMENT '平台流水金额', `verify_status` tinyint(2) NOT NULL DEFAULT '0' COMMENT '审核状态 -2:汇总驳回 -1审批拒绝 0:系统生成 1:审核通过 2:对外发起 3:合作确认 4:汇总', `verify_log` text NOT NULL DEFAULT '' COMMENT '审批相关信息json', @@ -1879,6 +1882,8 @@ CREATE TABLE `tab_company_statement_pool` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键', `company_id` int(11) DEFAULT '0' COMMENT '对账公司id', `company_name` varchar(60) NOT NULL DEFAULT '' COMMENT '对账公司名称', + `company_belong` tinyint(1) NOT NULL DEFAULT '0' COMMENT '工会归属:0-下游内团;1-下游外团 2-下游分发联盟 3 下游无,9:上游', + `company_type` tinyint(3) NOT NULL DEFAULT '1' COMMENT '公司性质:1-公司 2-个人', `statement_id` varchar(500) COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '涉及的结算单id', `statement_begin_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账开始时间', @@ -1902,7 +1907,7 @@ CREATE TABLE `tab_company_statement_pool` ( `op_time` int(11) NOT NULL DEFAULT '0' COMMENT '操作时间', PRIMARY KEY (`id`), KEY `company_id` (`company_id`) USING BTREE, - KEY `statement_end_time` (`statement_end_time`) USING BTREE, + KEY `statement_begin_time` (`statement_begin_time`) USING BTREE, KEY `statement_end_time` (`statement_end_time`) USING BTREE, KEY `verify_status` (`verify_status`) USING BTREE, KEY `op_time` (`op_time`) USING BTREE