diff --git a/Application/Admin/Common/extend.php b/Application/Admin/Common/extend.php index c885f03f6..5168c00bd 100644 --- a/Application/Admin/Common/extend.php +++ b/Application/Admin/Common/extend.php @@ -1512,6 +1512,22 @@ function getMonth() { return $range; } +function showMonthRange($start, $end) +{ + $end = date('Y-m', strtotime($end)); // 转换为月 + $range = []; + $i = 0; + do { + $month = date('Y-m', strtotime($start . ' + ' . $i . ' month')); + //echo $i . ':' . $month . ''; + $range[] = $month; + $i++; + } while ($month < $end); + rsort($range); + return $range; +} + + function getPayType($type) { $return = ''; diff --git a/Application/Admin/Controller/RefundController.class.php b/Application/Admin/Controller/RefundController.class.php index e6226e997..fb90d1e54 100644 --- a/Application/Admin/Controller/RefundController.class.php +++ b/Application/Admin/Controller/RefundController.class.php @@ -8,52 +8,112 @@ use User\Api\UserApi as UserApi; * @author 麦当苗儿 */ class RefundController extends ThinkController { - public function lists(){ - if(isset($_REQUEST['user_account'])){ + 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['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['count_date'])){ + $map['pay_time'] = ["BETWEEN",$this->getMonthTimeRange($_REQUEST['count_date'])]; } - - if(isset($_REQUEST['game_name'])){ - if($_REQUEST['game_name']=='全部'){ - unset($_REQUEST['game_name']); - }else{ - $map['game_name']=$_REQUEST['game_name']; - unset($_REQUEST['game_name']); - } + + // + $model = SM("spend_refund",'tab_'); + $data = $model + ->where($map) + ->group("month,user_id") + ->order("month desc,refund_amount desc"); + if(isset($_REQUEST['export'])){ + $data = $data->field("CONCAT(' ',FROM_UNIXTIME(`pay_time`,'%Y-%m')) as month,user_id,user_account,sum(refund_amount) refund_amount")->select(); + data2csv($data,'退款统计',array( + "month"=>"月份", + "user_account"=>"玩家账号", + "refund_amount"=>"退款金额" + )); } - if(isset($_REQUEST['pay_order_number'])){ - $map['pay_order_number']=array('like','%'.trim($_REQUEST['pay_order_number']).'%'); - unset($_REQUEST['pay_order_number']); + $data = $data->field("FROM_UNIXTIME(`pay_time`,'%Y-%m') as month,user_id,user_account,sum(refund_amount) refund_amount")->page($page, $row)->select(); + foreach ($data as $k => &$v) { + $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]); } - if(isset($_REQUEST['pay_status'])){ - $map['tui_status']=$_REQUEST['pay_status']; - unset($_REQUEST['pay_status']); + $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); } - if(isset($_REQUEST['pay_way'])){ - $map['pay_way']=$_REQUEST['pay_way']; - unset($_REQUEST['pay_way']); + $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]; } - $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']); + $end = strtotime( $date.'-'.$mdays.' 23:59:59'); + return [$start,$end]; } + + // 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']); + // } + } \ No newline at end of file diff --git a/Application/Admin/View/Refund/userCount.html b/Application/Admin/View/Refund/userCount.html new file mode 100644 index 000000000..877526bc4 --- /dev/null +++ b/Application/Admin/View/Refund/userCount.html @@ -0,0 +1,202 @@ + + + + + + + + + + + + 退款统计 + + + + + + + + + + + + 请选择月份 + + selected=selected>{$vo} + + + + + + + + + 搜索 + + + + + + + + + + + + + + 月份 + 玩家账号 + 退款金额 + 操作 + + + + + + + + aOh! 暂时还没有内容! + + + + + + {$data.month} + {$data.user_account} + {$data.refund_amount} + + 查看 + + + + + 汇总 + 累计退款: {$allcount|default=0} + + + + + + + + + + 导出 + {$_page|default=''} + + + + + + + + + if(C('COLOR_STYLE')=='blue_color') echo ''; + + + + + +