where($map) ->order("create_time Desc") ->select(); // var_dump($data);die(); foreach ($data as $key => $value) { $data[$key]['order'] = json_decode($value['second_party_info'],true)['order_type']; } $sumData = M("statement","tab_") ->field('sum(`statement_money`) as sum_money,statement_type') ->where($map) ->group('statement_type') ->select(); $handleSumData = []; foreach ($sumData as $key => $value) { $handleSumData[$value['statement_type']] = $value['sum_money']; } if (!$handleSumData[1]) { $handleSumData[1] = 0; } if (!$handleSumData[0]) { $handleSumData[0] = 0; } $this->assign('sum',$handleSumData); // dump($sumData);die(); foreach($data as $key => $value) { $data[$key]['create_time'] = date('Y-m-d H:i:s',$value['create_time']); $data[$key]['statement_begin_time'] = date('Y-m-d H:i:s',$value['statement_begin_time']); $data[$key]['statement_end_time'] = date('Y-m-d H:i:s',$value['statement_end_time']+86399); // $data[$key]['is_confirm'] = $data[$key]['is_confirm']?'确认':'未确认'; // $data[$key]['statement_type'] = $value['statement_type']?'公会对账单':'CP对账单'; } $this->meta_title = '结算单管理'; $this->assign('data',$data); $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())) { 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))) { $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']); } $is_del = M('statement','tab_')->where(['id'=>$id])->delete(); if ($is_del) { $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'] = 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) { $data['accounts'][] = array_merge(['account'=>$account], ['user_type'=>$user_types[$index]]); } } else { $data['accounts'] = []; } $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); return $upt ? $this->success('更新成功', U('StatementMangement/rewardManageList')) : $this->error('更新失败'); } else { $data['create_time'] = time(); $data['creater_id'] = is_login(); $ins = M('reward_record', 'tab_')->add($data); 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')) { $upt = M('reward_record', 'tab_')->where(['id'=>$id])->delete(); 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() { $map = []; $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,tab_promote.bank_card,account_openin,tab_promote.address,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(); $gameStr = []; $game_ratio = []; foreach($data as $dkey => &$dval) { $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) { $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,'.',''); } } unset($dval['game_ratio'][$key]); array_push($dval['game_ratio'],$val[0]); } } } dump($data); $this->display(); } }