content_api($where,1); $data['money'] = $this->c_api($where); $data['week'] = $this->zhou_api($start); $data['all'] = $this->content_api($w,2); $data['all_money'] = $this->c_api($w); $data['time'] = $this->day_time_api($w); $data['data'] = Dever::json_encode($data['time']); $data['money_time'] = $this->money_time_api($w); $data['qu_money'] = Dever::json_encode($data['money_time']); $data['xzhou'] = $this->button_day_api($w,1); $data['zhou'] = Dever::json_encode($data['xzhou']); return Dever::render('census', $data); } public function zhou_api($time='',$format="Y-m-d"){ $time = $time != '' ? $time : time(); $week = date('w', $time); $date = []; for ($i=1; $i<=7; $i++){ $date[$i] = date($format ,strtotime( '+' . $i-$week .' days', $time)); } $start = strtotime($date[1]); $end = strtotime($date[7])+86400-1; $where = array(); $where['fstart'] = $start; $where['fend'] = $end; $data = array(); $data['week'] = date('Y.m.d',$start).' - '.date('Y.m.d',$end); $data['all'] = $this->content_api($where,2); $data['all_money'] = $this->c_api($where); return $data; } #按时间统计 public function content_api($where,$type){ $data = array(); if($type == 2){ $data['time'] = date('Y.m',$where['fstart']); }elseif($type == 1){ $data['time'] = date('Y.m.d',$where['fstart']); } #确认代理商订单数 $where['status'] = 4; $data['num'] = Dever::db('agent/order')->getNum($where); #确认订单总费用 $money = Dever::db('agent/order')->getCash($where); if($money['total']){ $data['money'] = $money['total']; }else{ $data['money'] = 0; } #确认代理费 $dl_money = Dever::db('agent/order')->getDailiCash($where); if($dl_money['total']){ $data['dl_money'] = $dl_money['total']; }else{ $data['dl_money'] = 0; } #确认软件服务费 $soft_money = Dever::db('agent/order')->getSoftCash($where); if($soft_money['total']){ $data['soft_money'] = $soft_money['total']; }else{ $data['soft_money'] = 0; } $wh['status'] = 3; $wh['fstart'] = $where['fstart']; $wh['fend'] = $where['fend']; $cash = Dever::db('agent/soft_cash')->getTotal($wh); if($cash['total']){ $data['cash'] = $cash['total']; }else{ $data['cash'] = 0; } $data['soft_cash'] = $data['soft_money'] + $data['cash']; #期权价值 $option_money = Dever::db('agent/order')->getOptionPrice($where); if($option_money['total']){ $data['option_money'] = $option_money['total']; }else{ $data['option_money'] = 0; } return $data; } #各角色的金额,数量,原始期权价值,软件服务费 public function c_api($where){ $role = Dever::db('setting/role')->getAll(array('id'=>1,'state'=>1)); foreach($role as $k => $v){ $where['role'] = $v['id']; $data[$k]['name'] = $v['name']; $where['status'] = 2; $data[$k]['num'] = Dever::db('agent/member')->getNum($where); $where['status'] = 4; $dl = Dever::db('agent/order')->getSum($where); if($dl['total']){ $data[$k]['money'] = $dl['total']; }else{ $data[$k]['money'] = 0; } #期权价值: $option_money = Dever::db('agent/order')->getOptionPrice($where); if($option_money['total']){ $data[$k]['option_money'] = $option_money['total']; }else{ $data[$k]['option_money'] = 0; } #软件服务费 $soft_money = Dever::db('agent/order')->getSoftCash($where); if($soft_money['total']){ $data[$k]['soft_money'] = $soft_money['total']; }else{ $data[$k]['soft_money'] = 0; } $wh['role'] = $v['id']; $wh['status'] = 3; $wh['fstart'] = $where['fstart']; $wh['fend'] = $where['fend']; $cash = Dever::db('agent/soft_cash')->getTotal($wh); if($cash['total']){ $data[$k]['cash'] = $cash['total']; }else{ $data[$k]['cash'] = 0; } } return $data; } #数据趋势 public function day_time_api($w){ $time = date('m',time()) - date('m',$w['fstart']); $start = date('Y-m-01',$w['fstart']); if($time<=0){ $w['fend'] = time(); }elseif($time>0){ $w['fend'] = strtotime(date('Y-m-d 23:59:59', strtotime($start."+1 month - 1 day"))); } $days = ($w['fend']-$w['fstart'])/86400+1; // 保存每天日期 $day = array(); $data = array(); for($i=0; $i<$days; $i++){ $day[] = array($w['fstart']+(86400*$i),$w['fstart']+(86400*$i)+86400); } $res = array(); $res['num'] = array(); foreach($day as $k => $v){ $where['fstart'] = $v[0]; $where['fend'] =$v[1]-1; $data[$k]['time'] = date('m.d',$v[0]); #确认代理商订单数 $where['status'] = 4; $res['num'][] = Dever::db('agent/order')->getNum($where); } // print_R($where);die; $data = array(); $data['name'] = '数量'; $data['type'] = 'line'; // $data['stack'] = 'Total'; $data['data'] = $res['num']; return $data; } #金额趋势 public function money_time_api($w){ $time = date('m',time()) - date('m',$w['fstart']); $start = date('Y-m-01',$w['fstart']); if($time<=0){ $w['fend'] = time(); }elseif($time>0){ $w['fend'] = strtotime(date('Y-m-d 23:59:59', strtotime($start."+1 month - 1 day"))); } $days = ($w['fend']-$w['fstart'])/86400+1; // 保存每天日期 $day = array(); $data = array(); for($i=0; $i<$days; $i++){ $day[] = array($w['fstart']+(86400*$i),$w['fstart']+(86400*$i)+86400); } $res = array(); $res['money'] = array(); foreach($day as $k => $v){ $where['fstart'] = $v[0]; $where['fend'] =$v[1]-1; $data[$k]['time'] = date('m.d',$v[0]); #确认订单总费用 $money = Dever::db('agent/order')->getCash($where); if($money['total']){ $res['money'][] = $money['total']; }else{ $res['money'][] = 0; } } $money = array(); $money['name'] = '金额'; $money['type'] = 'line'; $money['data'] = $res['money']; return $money; } #趋势底部日期 public function button_day_api($w,$type){ $time = date('m',time()) - date('m',$w['fstart']); $start = date('Y-m-01',$w['fstart']); if($time<=0){ $w['fend'] = time(); }elseif($time>0){ $w['fend'] = strtotime(date('Y-m-d 23:59:59', strtotime($start."+1 month - 1 day"))); } $days = ($w['fend']-$w['fstart'])/86400+1; if($type ==1){ $daysd = $days-1; }else{ $daysd = $days; } // 保存每天日期 $day = array(); $data = array(); for($i=0; $i<$daysd; $i++){ $day[] = date('m.d',$w['fstart']+(86400*$i)); } $data['type'] = 'category'; $data['boundaryGap'] = false; $data['date'] = $day; return $day; } #代理商日统计 public function index_api(){ $title = '代理商日数据统计'; $data = Dever::db('mail/feature')->find(array('key'=>'lib/cron.day')); $email = explode(',',$data['email_id']); foreach($email as $k => $v){ $res[] = Dever::db('mail/email')->find(array('id'=>$v)); } $content = $this->index_api(); foreach($res as $key => $val){ $this->send($val['email'], $val['name'], $title, $content); } } #代理商周统计 public function week_api(){ $title = '代理商周数据统计'; $data = Dever::db('mail/feature')->find(array('key'=>'lib/cron.week')); $email = explode(',',$data['email_id']); foreach($email as $k => $v){ $res[] = Dever::db('mail/email')->find(array('id'=>$v)); } $content = $this->zhou_api(); foreach($res as $key => $val){ $this->send($val['email'], $val['name'], $title, $content); } } #代理商月统计 public function yue_api(){ $title = '代理商月数据统计'; $data = Dever::db('mail/feature')->find(array('key'=>'lib/cron.yue')); $email = explode(',',$data['email_id']); foreach($email as $k => $v){ $res[] = Dever::db('mail/email')->find(array('id'=>$v)); } $content = $this->month_api(); if(!$content){ return false; } foreach($res as $key => $val){ $this->send($val['email'], $val['name'], $title, $content); } } #代理商统计发送邮件 public function send($email, $username, $title, $content) { $config = Dever::config('base', 'project')->email; Dever::apply('src/PHPMailer', 'email'); Dever::apply('src/Exception', 'email'); Dever::apply('src/SMTP', 'email'); $mail = new \PHPMailer\PHPMailer\PHPMailer(); $mail->isSMTP(); //$mail->SMTPDebug = 2; $mail->CharSet = 'UTF-8'; $mail->Host = $config['smtp']; $mail->Port = 465; $mail->SMTPSecure = 'ssl'; $mail->SMTPAuth = true; $mail->Username = $config['username']; $mail->Password = $config['password']; $mail->setFrom($config['from'][0], '统计'); $mail->addAddress($email, $username); $mail->Subject = "=?utf-8?B?" . base64_encode($title) . "?="; $mail->Body = $content; $mail->isHTML(true); //$mail->addAttachment($file); if (!$mail->send()) { Dever::alert("Mailer Error: " . $mail->ErrorInfo); } else { return 'ok'; } } }