123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- <?php
- namespace Mail\Lib;
- use Dever;
- class Manage
- {
-
- public function day_api(){
- $day = Dever::input('day');
- if($day){
- $start = strtotime($day);
- $end = $start+86400-1;
- }else{
- $start=mktime(0,0,0,date('m'),date('d'),date('Y'));
- $end = $start+86400-1;
- }
-
- $time = Dever::maketime(date('Y-m-d'),'00:00:00');
- $where = array();
- $where['fstart'] = $start;
- $where['fend'] = $end;
- $w = array();
- $fstart = Dever::input('start', date('Y-m-01', $start));
- $w['fstart'] = Dever::maketime($fstart . ' 00:00:00');
- $w['fend'] = $end;
- $data = array();
- $data['start'] = date('Y-m-d',$start);
- $data['day'] = $this->content_api($where,1);
- $data['money'] = $this->c_api($where);
- $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']);
- $data['week'] = $this->zhou_api($start);
- 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){
- $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);
- }
- $data = array();
- $data['name'] = '数量';
- $data['type'] = 'line';
-
- $data['data'] = $res['num'];
- return $data;
- }
-
- public function money_time_api($w){
- $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){
- $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->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);
-
- if (!$mail->send()) {
- Dever::alert("Mailer Error: " . $mail->ErrorInfo);
- } else {
- return 'ok';
- }
- }
-
- }
|