| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612 |
- <?php
- /**
- * 公会联盟控制器
- *
- */
- namespace app\guildapi\controller;
- use app\guildapi\controller\Guild;
- use think\Db;
- use think\Config;
- use app\common\model\Setting;
- use think\Exception;
- use app\common\library\MakeReport;
- use app\common\library\MakeReportGo;
- use think\Env;
- class Alliance extends Guild {
- protected $nowTime;
- protected $redis; //redis的句柄对象
- /**
- * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
- */
- public function _initialize()
- {
- parent::_initialize();
- $this->nowTime = NOW_TIMESTAMP;
- $this->redis = \think\Cache::store('default')->handler();
- }
- /**
- * 公会联盟结算列表
- * @return [type] [description]
- */
- public function settle()
- {
- //判断当前账号是否有此功能
- if(!in_array($this->_channelLevel,[0])){
- $this->jsonResult('', 0, '您无权限使用该功能');
- }
- $list_rows = $this->input('list_rows',10);
- $page = $this->input('page',1);
- $begin_time = $this->input('begin_time','','trim');
- $end_time = $this->input('end_time','','trim');
- $orderid = $this->input('orderid','','trim'); //收入账号
- $channel_name = $this->input('channel_name','','trim'); //渠道名
- $status = $this->input('status',0,'intval');
- $download = $this->input('download',0,'intval');
- $condition = [];
- $condition['c.parent_id'] = $this->_channelId;
- $condition['c.level'] = 1;
- $condition['a.settle_type'] = 1;
- if($orderid){
- $condition['a.orderid'] = $orderid;
- }
- if($channel_name){
- $condition['a.channel_name'] = $channel_name;
- }
- //申请开始时间和结束时间不为空时
- if ($begin_time != '' && $end_time != '') {
- $condition['a.create_time'] = [
- ['>=', strtotime($begin_time)],
- ['<=', strtotime($end_time . ' 23:59:59')],
- ];
- } //开始时间不为空时
- elseif ($begin_time != '') {
- $condition['a.create_time'] = ['>=', strtotime($begin_time)];
- } //结束时间不为空时
- elseif ($end_time != '') {
- $condition['a.create_time'] = ['<=', strtotime($end_time . ' 23:59:59')];
- }
- // var_dump($condition);
- $whereRaw = '';
- if(input('status')<>''){
- if($status == 1){
- $whereRaw .= ' a.first_audit_status=1 and a.second_audit_status=1 ';
- }
- else if($status == 2){
- $whereRaw .= ' a.first_audit_status=2 or a.second_audit_status=2 ';
- }
- else if($status == 0){
- $whereRaw .= ' a.first_audit_status<>2 and a.second_audit_status=0 ';
- }
- }
- if($download){
- if($whereRaw){
- $sql = model('ChannelDivideSettle')->alias('a')
- ->join('nw_channel c','a.channel_id=c.id','left')
- ->where($condition)
- ->whereRaw($whereRaw)
- ->field("a.id,a.orderid,a.channel_id,a.channel_name,a.total_amount,a.total_divide_amt,a.remark,a.create_time,a.first_audit_status,a.second_audit_status")
- ->order("a.id desc")
- ->fetchSql(true)
- ->select();
- }
- else{
- $sql = model('ChannelDivideSettle')->alias('a')
- ->join('nw_channel c','a.channel_id=c.id','left')
- ->where($condition)
- ->field("a.id,a.orderid,a.channel_id,a.channel_name,a.total_amount,a.total_divide_amt,a.remark,a.create_time,a.first_audit_status,a.second_audit_status")
- ->order("a.id desc")
- ->fetchSql(true)
- ->select();
- }
- // echo $sql;
- // if ((new MakeReport())->addTask('guild.AllianceSettle', $sql, 'cps'.session('guild_info')['id'])){
- if ((new MakeReportGo())->addTask('guild.AllianceSettle', $sql, 'cps'.session('guild_info')['id'])){
- $this->jsonResult('', 20000, '报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
- }
- else{
- $this->jsonResult('', 20013, '报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
- }
- }
- if($whereRaw){
- $settleList = model('ChannelDivideSettle')->alias('a')
- ->join('nw_channel c','a.channel_id=c.id','left')
- ->where($condition)
- ->whereRaw($whereRaw)
- ->field("a.id,a.orderid,a.channel_id,a.channel_name,a.total_amount,a.total_divide_amt,a.remark,a.create_time,a.first_audit_status,a.second_audit_status")
- ->order("a.id desc")
- ->paginate(['list_rows'=>$list_rows,'page'=>$page])
- ->toArray();
- }
- else{
- $settleList = model('ChannelDivideSettle')->alias('a')
- ->join('nw_channel c','a.channel_id=c.id','left')
- ->where($condition)
- ->field("a.id,a.orderid,a.channel_id,a.channel_name,a.total_amount,a.total_divide_amt,a.remark,a.create_time,a.first_audit_status,a.second_audit_status")
- ->order("a.id desc")
- ->paginate(['list_rows'=>$list_rows,'page'=>$page])
- ->toArray();
- }
- foreach ( $settleList["data"] as &$val ) {
- if($val['first_audit_status']==1 && $val['second_audit_status']==1){ //审核通过
- $val['status'] = 1;
- }
- else if($val['first_audit_status']==2 || $val['second_audit_status']==2){ //审核不通过
- $val['status'] = 2;
- }
- else{ //审核中
- $val['status'] = 0;
- }
- unset($val['first_audit_status']); unset($val['second_audit_status']);
- }
- $this->jsonResult($settleList, 20000, '获取列表成功');
- }
- /**
- * 提现列表
- * @return [type] [description]
- */
- public function withdraw()
- {
- //判断当前账号是否有此功能
- if(!in_array($this->_channelLevel,[0])){
- $this->jsonResult('', 0, '您无权限使用该功能');
- }
- $list_rows = $this->input('list_rows',10);
- $page = $this->input('page',1);
- $begin_time = $this->input('begin_time','','trim');
- $end_time = $this->input('end_time','','trim');
- $orderid = $this->input('orderid','','trim');
- $channel_name = $this->input('channel_name','','trim');
- $status = $this->input('status','0','intval');
- $download = $this->input('download','0','intval');
- $condition = [];
- $condition['c.parent_id'] = $this->_channelId;
- $condition['c.level'] = 1;
- if($orderid){
- $condition['a.orderid'] = $orderid;
- }
- if($channel_name){
- $condition['a.channel_name'] = $channel_name;
- }
- if(input('status')<>''){
- $condition['a.status'] = intval($status);
- }
- //申请开始时间和结束时间不为空时
- if ($begin_time != '' && $end_time != '') {
- $condition['a.create_time'] = [
- ['>=', strtotime($begin_time)],
- ['<=', strtotime($end_time . ' 23:59:59')],
- ];
- } //开始时间不为空时
- elseif ($begin_time != '') {
- $condition['a.create_time'] = ['>=', strtotime($begin_time)];
- } //结束时间不为空时
- elseif ($end_time != '') {
- $condition['a.create_time'] = ['<=', strtotime($end_time . ' 23:59:59')];
- }
- // var_dump($condition);
- if($download){
- $sql = model('ChannelWithdraw')->alias('a')
- ->join('nw_channel c','a.channel_id=c.id','left')
- ->where($condition)
- ->field("a.id,a.orderid,a.channel_id,a.channel_name,a.withdraw_amt,a.remark,a.create_time,a.status")
- ->order("a.id desc")
- ->fetchSql(true)
- ->select();
- // echo $sql;
- // if ((new MakeReport())->addTask('guild.AllianceWithdraw', $sql, 'cps'.session('guild_info')['id'])){
- if ((new MakeReportGo())->addTask('guild.AllianceWithdraw', $sql, 'cps'.session('guild_info')['id'])){
- $this->jsonResult('', 20000, '报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
- }
- else{
- $this->jsonResult('', 20013, '报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
- }
- }
- $withdrawList = model('ChannelWithdraw')->alias('a')
- ->join('nw_channel c','a.channel_id=c.id','left')
- ->where($condition)
- ->field("a.id,a.orderid,a.channel_id,a.channel_name,a.withdraw_amt,a.remark,a.create_time,a.status")
- ->order("a.id desc")
- ->paginate(['list_rows'=>$list_rows,'page'=>$page])
- ->toArray();
- // echo model('ChannelWithdraw')->getLastSql()."-----lastsql------<br>";
- $this->jsonResult($withdrawList, 20000, '获取列表成功');
- }
- /**
- * 公会结算数据(外放渠道)
- */
- public function getChanelSettle()
- {
- if ($this->request->isPost()) {
- //判断当前账号是否有此功能
- if(!in_array($this->_channelLevel,[0])){
- $this->jsonResult('', 0, '您无权限使用该功能');
- }
- //只有外放的商务才能为公会结算
- if (!(isset(session('guild_info')['roles'][0]) && session('guild_info')['roles'][0] == 5)) {
- $this->jsonResult('', 0, '您无权限使用该功能');
- }
- else{
- $channel_id = $this->input('channel_id',0,'intval'); //公会ID
- if(!$channel_id){
- $this->jsonResult('', 0, '请选择要进行结算的公会');
- }
- $channelInfoApply = model("ChannelInfo")->field("id,channel_id,real_name,apply_status,type")->where(['channel_id'=>$this->_channelId,'apply_status'=>1])->find();
- if(empty($channelInfoApply)){
- $this->jsonResult('', 0, '您的身份尚未认证通过,不能进行结算');
- }
- $parentChannelInfo = model("Channel")->field("id,name,level,parent_id,status,channel_tg_type")->where(['id'=>$this->_channelId])->find();
- if(empty($parentChannelInfo)){
- $this->jsonResult('', 0, '账号异常,请重新登录后再试');
- }
- else if($parentChannelInfo['channel_tg_type'] <> 1){
- $this->jsonResult('', 0, '您无权限使用该功能!');
- }
- $channelInfo = model("Channel")->field("id,name,level,parent_id,cps_settle_period,mcps_settle_period,status")->where(['id'=>$channel_id,'level'=>1])->find();
- if(empty($channelInfo)){
- $this->jsonResult('', 0, '您要进行结算的公会不存在');
- }
- else if($channelInfo['parent_id'] <> $this->_channelId){
- $this->jsonResult('', 0, '非您所属公会,您不能为他进行结算操作');
- }
- if($channelInfo['cps_settle_period']==2){
- $this->lastTime = strtotime(date('Y-m-d')) - 1;
- }
- else{
- $this->lastTime = strtotime(date('Y-m-d',(time()-((date('w',time())==0?7:date('w',time()))-1)*24*3600))) - 1;
- }
- $list_rows = input('list_rows',10);
- $page = input('page',1);
- $where = array();
- $where['p.status'] = 1;
- $where['p.create_time'] = array('elt', $this->lastTime);
- //所有下级渠道(包括自己)
- $channelIds = get_child_channel_arr($channel_id);
- array_push($channelIds,$channel_id);
- $where['p.channel_id'] = ['in',$channelIds];
- $where['p.settle_id'] = array('eq',0);
- // var_dump($where);
- $GameChannelData = Db::table('cy_pay')->alias('p')
- ->join('cy_game g', 'p.gameid = g.id and g.game_kind=1','inner')
- ->join('nw_game_channel_divide d','p.gameid = d.game_id and d.channel_id='.$channel_id,'left')
- ->field("p.gameid AS game_id,g.name as game_name,g.channel_split_ratio,count(*) as pay_cnt,SUM(p.amount) AS pay_amt,d.id as ratio_id,d.ratio,SUM(p.real_amount) AS pay_real_amt,SUM(p.real_ptb) AS pay_real_ptb")
- ->where($where)
- ->group('p.gameid')
- ->select();
- $retData = array();
- $total_amt = $divide_amt = $total_cnt = 0;
- foreach ( $GameChannelData as &$det ) {
- if(intval($det['ratio_id'])){
- $ratio_id = $det['ratio_id'];
- $ratio = floatval($det['ratio']);
- }
- else{
- $ratio_id = 0;
- $ratio = floatval($det['channel_split_ratio']);
- }
- if(!$ratio){
- $this->jsonResult('', 0, '您的该公会下尚有游戏未配置分成比例,请先联系平台设置');
- }
- else{
- $det['ratio_id'] = $ratio_id;
- $det['ratio'] = $ratio;
- $total_cnt += floatval($det['pay_cnt']);
- $total_amt += floatval($det['pay_amt']);
- $divide_amt += floatval(intval($det['pay_amt'] * $det['ratio']) / 100);
- $det['divide_amt'] = floatval(intval($det['pay_amt'] * $det['ratio']) / 100);
- }
- }
- $settle = array();
- $settle['total_amount'] = $total_amt;
- $settle['divide_amount'] = $divide_amt;
- $settle['total_cnt'] = $total_cnt;
- $detPaylist = Db::table('cy_pay')->alias('p')
- ->join('cy_game g', 'p.gameid = g.id and g.game_kind=1','inner')
- ->join('nw_game_channel_divide d','p.gameid = d.game_id and d.channel_id='.$channel_id,'left')
- ->field("p.orderid AS orderid,p.gameid AS game_id,g.name as game_name,p.amount AS amount,round(p.amount*(case when d.id then d.ratio else g.channel_split_ratio end)/100,2) AS divide_amt,case when d.id then d.id else '0' end as ratio_id,case when d.id then d.ratio else g.channel_split_ratio end as ratio,p.real_amount AS real_amount,p.real_ptb AS real_ptb,p.serverid,p.servername,p.rolename,p.userid,p.username,p.create_time")
- ->where($where)
- ->order("p.id desc")
- ->paginate(['list_rows'=>$list_rows,'page'=>$page])
- ->toArray();
- // var_dump($detPaylist);
- $retData['settle'] = $settle;
- $retData['settleDet'] = $GameChannelData;
- $retData['detPaylist'] = $detPaylist;
- $this->jsonResult($retData, 20000, '获取结算列表成功');
- }
- exit;
- }
- else{
- $this->jsonResult('', 0, '非法请求');
- exit;
- }
- }
- /**
- * 公会结算处理(外放公会)
- */
- public function doChannelSettle()
- {
- if ($this->request->isPost()) {
- $channel_id = $this->input('channel_id',0,'intval'); //公会ID
- $total_amount = $this->input('total_amount',0,'floatval'); //流水
- $divide_amount = $this->input('divide_amount',0,'floatval'); //分成金额
- $total_cnt = $this->input('total_cnt',0,'intval'); //结算订单笔数
- $remark = '外放商务结算申请'; //备注
- if(!in_array($this->_channelLevel,[0])){
- $this->jsonResult('', 0, '您无权限使用该功能');
- }
- //只有外放的商务才能为公会结算
- if (!(isset(session('guild_info')['roles'][0]) && session('guild_info')['roles'][0] == 5)) {
- $this->jsonResult('', 0, '您无权限使用该功能');
- }
- if(!$channel_id){
- $this->jsonResult('', 0, '请选择要进行结算的公会');
- }
- if(!$total_amount || !$divide_amount || !$total_cnt){
- $this->jsonResult('', 0, '没有可结算单的订单');
- }
- /*
- else if($divide_amount < 100){
- $this->jsonResult('', 0, '结算金额不能小于100元!');
- }
- */
- $channelInfoApply = model("ChannelInfo")->field("id,channel_id,real_name,apply_status,type")->where(['channel_id'=>$this->_channelId,'apply_status'=>1])->find();
- if(empty($channelInfoApply)){
- $this->jsonResult('', 0, '您的身份尚未认证通过,不能进行结算');
- }
- $parentChannelInfo = model("Channel")->field("id,name,level,parent_id,status,channel_tg_type")->where(['id'=>$this->_channelId])->find();
- if(empty($parentChannelInfo)){
- $this->jsonResult('', 0, '账号异常,请重新登录后再试');
- }
- else if($parentChannelInfo['channel_tg_type'] <> 1){
- $this->jsonResult('', 0, '您无权限使用该功能!');
- }
- $channelInfo = model("Channel")->field("id,name,level,parent_id,cps_settle_period,mcps_settle_period,status")->where(['id'=>$channel_id,'level'=>1])->find();
- if(empty($channelInfo)){
- $this->jsonResult('', 0, '您要进行结算的公会不存在');
- }
- else if($channelInfo['parent_id'] <> $this->_channelId){
- $this->jsonResult('', 0, '非您所属公会,您不能为他进行结算操作');
- }
- $orderid = 'ZFS'.makeOrderid();
- if($channelInfo['cps_settle_period']==2){ //日结
- $this->lastTime = strtotime(date('Y-m-d')) - 1;
- if(!(date('Hi') >= '02:00' && date('Hi') < '23:59')){
- $this->jsonResult('', 0, '不在结算时间内,请在每日02:00 ~ 23:59分内提交结算申请!');
- }
- }
- else{ //周结
- $this->lastTime = strtotime(date('Y-m-d',(time()-((date('w',time())==0?7:date('w',time()))-1)*24*3600))) - 1;
- if(date("w")<>1 || !(date('Hi') >= '02:00' && date('Hi') < '23:59')){
- $this->jsonResult('', 0, '不在结算时间内,请在每周一02:00~23:59 内提交结算申请!');
- }
- }
- $where = array();
- $where['p.status'] = 1;
- $where['p.create_time'] = array('elt', $this->lastTime);
- //所有下级渠道(包括自己)
- $channelIds = get_child_channel_arr($channel_id);
- array_push($channelIds,$channel_id);
- $where['p.channel_id'] = ['in',$channelIds];
- $where['p.settle_id'] = array('eq',0);
- // var_dump($where);
- $GameChannelData = Db::table('cy_pay')->alias('p')
- ->join('cy_game g', 'p.gameid = g.id and g.game_kind=1','inner')
- ->join('nw_game_channel_divide d','p.gameid = d.game_id and d.channel_id='.$channel_id,'left')
- ->field("p.gameid AS game_id,g.name as game_name,g.channel_split_ratio,min(p.create_time) as begin_time,max(p.create_time) as end_time,count(*) as pay_cnt,SUM(p.amount) AS pay_amt,d.id as ratio_id,d.ratio,SUM(p.real_amount) AS pay_real_amt,SUM(p.real_ptb) AS pay_real_ptb")
- ->where($where)
- ->group('p.gameid')
- ->select();
- $retData = array();
- // echo Db::table('cy_pay')->getLastSql()."----sql-----------<br>";
- $totalAmount = $divideAmount = $totalCnt = 0;
- $beginTime = time();
- $endTime = 0;
- foreach ( $GameChannelData as &$det ) {
- if(intval($det['ratio_id'])){
- $ratio_id = $det['ratio_id'];
- $ratio = floatval($det['ratio']);
- }
- else{
- $ratio_id = 0;
- $ratio = floatval($det['channel_split_ratio']);
- }
- if(!$ratio){
- $this->jsonResult('', 0, '您下属的该公会尚有游戏未配置分成比例,不能进行结算,请先联系平台设置');
- }
- else{
- $det['ratio_id'] = $ratio_id;
- $det['ratio'] = $ratio;
- $totalCnt += floatval($det['pay_cnt']);
- $totalAmount += floatval($det['pay_amt']);
- $divideAmount += floatval(intval($det['pay_amt'] * $det['ratio']) / 100);
- $det['divide_amt'] = floatval(intval($det['pay_amt'] * $det['ratio']) / 100);
- if($beginTime > $det['begin_time']){
- $beginTime = $det['begin_time'];
- }
- if($endTime < $det['end_time']){
- $endTime = $det['end_time'];
- }
- }
- }
- reset($GameChannelData);
- if(!$totalAmount || !$divideAmount || !$totalCnt){
- $this->jsonResult('', 0, '您已没有可结算的订单');
- }
- if(abs($totalAmount-$total_amount)>0.01 || $totalCnt<>$total_cnt || abs($divideAmount-$divide_amount)>0.01){
- $this->jsonResult('', 0, '结算数据与后台计算数据不一致,请重新核对后再提交');
- }
- //指定时间内,禁止重复下单
- if(!requestDuplicateCheck('channel_settle_duplicate_'.$channel_id,10)){
- $this->jsonResult('', 0, '结算请求过多,请于10s以后,再次进行结算操作');
- }
- $detPaylist = Db::table('cy_pay')->alias('p')
- ->join('cy_game g', 'p.gameid = g.id and g.game_kind=1','inner')
- ->join('nw_game_channel_divide d','p.gameid = d.game_id and d.channel_id='.$channel_id,'left')
- ->field("p.id as payid,p.orderid AS orderid,p.gameid AS game_id,p.userid,p.username,g.name as game_name,g.channel_split_ratio,p.channel_id,p.amount AS amount,(p.amount*(case when d.id then d.ratio else g.channel_split_ratio end)/100) AS divide_amt,case when d.id then d.id else '0' end as ratio_id,case when d.id then d.ratio else g.channel_split_ratio end as ratio,p.real_amount AS real_amount,p.real_ptb AS real_ptb,p.create_time,p.serverid,p.servername,p.rolename")
- ->where($where)
- ->select();
- // 启动事务
- Db::startTrans();
- try{
- $settleData = array();
- $settleData['orderid'] = $orderid;
- $settleData['settle_type'] = 1;
- $settleData['channel_id'] = $channel_id;
- $settleData['channel_name'] = $channelInfo['name'];
- $settleData['total_amount'] = $totalAmount;
- $settleData['total_divide_amt'] = $divideAmount;
- $settleData['begin_time'] = $beginTime;
- $settleData['end_time'] = $endTime;
- $settleData['settle_method'] = 2; //外放结算方式
- $settleData['remark'] = $remark;
- $settleData['create_time'] = time();
- $settleData['first_audit_status'] = 1;
- $settleData['first_audit_time'] = time();
- if($channelInfo['cps_settle_period']==2){
- $settleData['settle_period'] = 2;
- }
- else{
- $settleData['settle_period'] = 1;
- }
- $insertSettleId = model('ChannelDivideSettle')->insertGetId($settleData);
- if ( !$insertSettleId) {
- throw new Exception("添加结算单失败");
- }
- while(list($key,$val)=@each($GameChannelData)){
- $detData = array();
- $detData['settle_id'] = $insertSettleId;
- $detData['divide_id'] = $val['ratio_id'];
- $detData['begin_time'] = $val['begin_time'];
- $detData['end_time'] = $val['end_time'];
- $detData['game_id'] = $val['game_id'];
- $detData['channel_id'] = $channel_id;
- $detData['ratio'] = $val['ratio'];
- $detData['pay_cnt'] = $val['pay_cnt'];
- $detData['pay_amt'] = floatval($val['pay_amt']);
- $detData['pay_real_amt'] = floatval($val['pay_real_amt']);
- $detData['pay_real_ptb'] = floatval($val['pay_real_ptb']);
- $detData['divide_amt'] = floatval($val['divide_amt']);
- $detData['create_time'] = time();
- ${'insertDet'.$val['game_id'].'ID'} = model('ChannelDivideSettleDet')->insertGetId($detData);
- if ( !${'insertDet'.$val['game_id'].'ID'}) {
- throw new Exception("添加结算单明细失败");
- }
- }
- $orderIds = array();
- while(list($key,$val)=@each($detPaylist)){
- // echo ${'insertDet'.$val['game_id'].'ID'}."---insertDet".$val['game_id']."ID'--------<br>";
- $orderIds[] = $val['payid'];
- $detPayData['settle_id'] = $insertSettleId;
- $detPayData['settle_det_id'] = ${'insertDet'.$val['game_id'].'ID'};
- $detPayData['orderid'] = $val['orderid'];
- $detPayData['game_id'] = $val['game_id'];
- $detPayData['channel_id'] = $val['channel_id'];
- $detPayData['ratio'] = $val['ratio'];
- $detPayData['userid'] = $val['userid'];
- $detPayData['username'] = $val['username'];
- $detPayData['amount'] = floatval($val['amount']);
- $detPayData['real_amount'] = floatval($val['real_amount']);
- $detPayData['real_ptb'] = floatval($val['real_ptb']);
- $detPayData['divide_amt'] = floatval($val['divide_amt']);
- $detPayData['serverid'] = trim($val['serverid']);
- $detPayData['servername'] = trim($val['servername']);
- $detPayData['rolename'] = trim($val['rolename']);
- $detPayData['create_time'] = $val['create_time'];
- $detPayData['add_time'] = time();
- // var_dump($detPayData);
- $insertDetPayId = model('ChannelDivideSettleDetPay')->insertGetId($detPayData);
- if ( !$insertDetPayId) {
- throw new Exception("添加结算订单明细失败");
- }
- }
- $updPayData = array();
- $updPayData['settle_channel_id'] = $channel_id;
- $updPayData['settle_id'] = $insertSettleId;
- $updPayData['settle_update_time'] = time();
- /*
- $gameids = model('Game')->where(['game_kind'=>1])->column('id');
- $where['p.gameid']= array('IN',$gameids);
- */
- $where['p.id']= array('IN',$orderIds);
- $updResult = model('Pay')->alias('p')->where($where)->update($updPayData);
- if ( !$updResult) {
- throw new Exception("更新订单为已结算失败");
- }
- $this->redis->del('channel_settle_duplicate_'.$channel_id);
- // 提交事务
- Db::commit();
- } catch (\Exception $e) {
- // 回滚事务
- Db::rollback();
- $this->jsonResult('', 0, '结算申请生成失败'.$e->getMessage());
- }
- $result['orderid'] = $orderid;
- $template = '有新的专服结算申请:商务"'.$this->_channelName.'"为下属公会"'.$channelInfo['name'].'" 发起结算申请,订单号:'.$orderid.' 。请及时安排处理,时间:'.date('Y-m-d H:i:s');
- $ddurl = Env::get('operat_url');
- curlDD($template, $ddurl,true);
- $this->jsonResult($result, 20000, '结算申请生成成功');
- exit;
- }
- else{
- $this->jsonResult('', 0, '非法请求');
- exit;
- }
- }
- }
|