*/ class RefundController extends ThinkController { public function userCount(){ // if(!array_key_exists("count_date",$_REQUEST) && !array_key_exists("user_account",$_REQUEST)){ // $this->redirect(ACTION_NAME, array('count_date' => date('Y-m'))); // } $page = I('p', 1); $row = I('row', 10); if(isset($_REQUEST['user_account'])){ $map['tab_spend_refund.user_account']=array('like','%'.trim($_REQUEST['user_account']).'%'); } if(isset($_REQUEST['partner'])){ $map['partner']=array('like','%'.trim($_REQUEST['partner']).'%'); } if(isset($_REQUEST['company_name'])){ $map['company_name']=array('like','%'.trim($_REQUEST['company_name']).'%'); } if(isset($_REQUEST['status'])){ $map['tab_spend_refund.status']= $_REQUEST['status']; } // if(isset($_REQUEST['count_date'])){ // $map['pay_time'] = ["BETWEEN",$this->getMonthTimeRange($_REQUEST['count_date'])]; // } if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) { $time_start = strtotime($_REQUEST['time_start']); $time_end = strtotime($_REQUEST['time_end'])+ 86399; $map["_string"] = "(tab_spend_refund.pay_time BETWEEN {$time_start} AND {$time_end})"; } elseif (isset($_REQUEST['time_start'])) { $time_start = strtotime($_REQUEST['time_start']); $map["_string"] = "(tab_spend_refund.pay_time >= {$time_start} )"; } elseif (isset($_REQUEST['time_end'])) { $time_end = strtotime($_REQUEST['time_end'])+ 86399; $map["_string"] = "(tab_spend_refund.pay_time <= {$time_end} )"; } if (isset($_REQUEST['usetime_start']) && isset($_REQUEST['usetime_end'])) { $time_start = strtotime($_REQUEST['usetime_start']); $time_end = strtotime($_REQUEST['usetime_end'])+ 86399; $map["_string"] = "( (check_time BETWEEN {$time_start} AND {$time_end}))"; } elseif (isset($_REQUEST['usetime_start'])) { $time_start = strtotime($_REQUEST['usetime_start']); $map["_string"] = "( (check_time >= {$time_start} ) )"; } elseif (isset($_REQUEST['usetime_end'])) { $time_end = strtotime($_REQUEST['usetime_end'])+ 86399; $map["_string"] = "( (check_time <= {$time_end} ) )"; } // dump($map);die(); $gameSql = M("game","tab_") ->field("tab_game.id game_id,partner,relation_game_name") ->join("left join tab_partner on tab_game.partner_id=tab_partner.id") ->where("1=1") ->select(false); // $model = SM("spend_refund",'tab_'); $data = $model ->field("tab_spend_refund.id,IFNULL(if(substring_index(substring_index(`chain`,'/',2),'/',-1)='',s.promote_id,substring_index(substring_index(`chain`,'/',2),'/',-1)),0) p_id, s.`pay_time` pay_time,tab_spend_refund.user_id,tab_spend_refund.user_account,refund_amount,partner,relation_game_name game_name,company_name,promote.account,tab_spend_refund.status,admin,check_time") ->join("left join tab_spend s on tab_spend_refund.s_id=s.id") ->join("left join ({$gameSql}) g on s.game_id=g.game_id") ->join("tab_promote promote ON s.promote_id = promote.id","left") ->join("tab_promote_company company ON promote.company_id = company.id","left") ->where($map) ->select(false); $data = M()->table("(".$data.") a") ->join("left join tab_promote pr on a.p_id = pr.id") ->group("a.id") ->order("month desc,refund_amount desc"); if(isset($_REQUEST['export'])){ $data = $data->field("a.id,CONCAT(' ',FROM_UNIXTIME(`pay_time`,'%Y-%m')) as month,user_id,user_account,sum(refund_amount) refund_amount,partner,game_name,company_name,pr.account top_account,a.status,admin,check_time")->select(); foreach ($data as $k => &$v) { $status = $v['status']?'已退款':"未退款"; $time = date("Y-m-d H:i:s",$v['check_time']); if ($v['status']) { $v['check_detail'] = "{$status}({$v['admin']}){$time}"; } else { $v['check_detail'] = "-----"; } } data2csv($data,'退款统计',array( "month"=>"月份", "partner"=>"上游cp", "game_name"=>"游戏", "user_account"=>"玩家账号", "company_name"=>"工会名称", "top_account"=>"会长账号", "check_detail"=>"退款状态", "refund_amount"=>"退款金额" )); } $data = $data->field("a.id,FROM_UNIXTIME(`pay_time`,'%Y-%m') as month,user_id,user_account,sum(refund_amount) refund_amount,partner,game_name,company_name,pr.account top_account,a.status,admin,check_time")->page($page, $row)->select(); // var_dump($data);die(); foreach ($data as $k => &$v) { $status = $v['status']?'已退款':"未退款"; $time = date("Y-m-d H:i:s",$v['check_time']); if ($v['status']) { $v['check_detail'] = "{$status}({$v['admin']}){$time}"; } else { $v['check_detail'] = "-----"; } $between = $this->getMonthTimeRange($v['month'],true); $v['jump_url'] = U("Spend/lists",['timestart'=>$between[0],'timeend'=>$between[1],'user_account'=>$v['user_account'],'is_refund'=>1]); } // dump($data);die(); $allcount = $model->where($map)->getField("sum(refund_amount) refund_amount"); $count_sql = $model->field("FROM_UNIXTIME(`pay_time`,'%Y-%m') as month,user_id")->group("month,user_id")->where($map)->select(false); $count = SM()->table( '('.$count_sql.') a' )->count(); $page = set_pagination($count, $row); if ($page) { $this->assign('_page', $page); } // dump($_SESSION['onethink_admin']['user_auth']['username']);die(); $Rule = strtolower(MODULE_NAME . '/' . CONTROLLER_NAME . '/' . ACTION_NAME . "_check"); if ($this->checkRule($Rule, array('in', '1,2')) || IS_ROOT) { $this->assign("check",true); } $this->assign("allcount",$allcount); $this->assign("data",$data); $this->assign("date_count",showMonthRange('2019-09-01',date('Y-m-d',time()))); $this->display(); } protected function getMonthTimeRange($date,$isdate = false) { $start = strtotime( $date . "-1 00:00:00" ); $mdays = date('t', $start); if($isdate){ return [$date."-1",$date.'-'.$mdays]; } $end = strtotime( $date.'-'.$mdays.' 23:59:59'); return [$start,$end]; } public function refund() { $status = $_REQUEST['status']; $id = $_REQUEST['ids']; // dump($_REQUEST);die(); if (!$id) { $this->ajaxReturn(['status'=>0,'msg'=>'数据错误']); } $is_save = M("spend_refund","tab_") ->where(['id'=>['in',$id]]) ->save(['status'=>$status,'check_time'=>time(),'admin'=>$_SESSION['onethink_admin']['user_auth']['username']]); if ($is_save) { $this->ajaxReturn(['status'=>1,'msg'=>'操作成功']); } else { $this->ajaxReturn(['status'=>0,'msg'=>'操作失败']); } } // public function lists(){ // if(isset($_REQUEST['user_account'])){ // $map['user_account']=array('like','%'.trim($_REQUEST['user_account']).'%'); // unset($_REQUEST['user_account']); // } // if(isset($_REQUEST['time-start'])&&isset($_REQUEST['time-end'])){ // $map['pay_time'] =array('BETWEEN',array(strtotime($_REQUEST['time-start']),strtotime($_REQUEST['time-end'])+24*60*60-1)); // unset($_REQUEST['time-start']);unset($_REQUEST['time-end']); // } // if(isset($_REQUEST['game_name'])){ // if($_REQUEST['game_name']=='全部'){ // unset($_REQUEST['game_name']); // }else{ // $map['game_name']=$_REQUEST['game_name']; // unset($_REQUEST['game_name']); // } // } // if(isset($_REQUEST['pay_order_number'])){ // $map['pay_order_number']=array('like','%'.trim($_REQUEST['pay_order_number']).'%'); // unset($_REQUEST['pay_order_number']); // } // if(isset($_REQUEST['pay_status'])){ // $map['tui_status']=$_REQUEST['pay_status']; // unset($_REQUEST['pay_status']); // } // if(isset($_REQUEST['pay_way'])){ // $map['pay_way']=$_REQUEST['pay_way']; // unset($_REQUEST['pay_way']); // } // $model = array( // 'm_name' => 'RefundRecord', // 'map' => $map, // 'order' =>'id desc', // 'title' => '退款记录', // 'template_list' =>'lists', // ); // $total=null_to_0(M('RefundRecord','tab_')->where(['tui_status'=>1])->sum('tui_amount')); // $ttotal=null_to_0(M('RefundRecord','tab_')->where('pay_time'.total(1))->where(array('tui_status'=>1))->sum('tui_amount')); // $ytotal=null_to_0(M('RefundRecord','tab_')->where('pay_time'.total(5))->where(array('tui_status'=>1))->sum('tui_amount')); // $this->assign('total',$total); // $this->assign('ttotal',$ttotal); // $this->assign('ytotal',$ytotal); // $user = A('User','Event'); // $user->user_join_($model,$_GET['p']); // } }