|
@@ -0,0 +1,324 @@
|
|
|
+<?php
|
|
|
+namespace Mail\Lib;
|
|
|
+
|
|
|
+use Dever;
|
|
|
+
|
|
|
+class Manage
|
|
|
+{
|
|
|
+
|
|
|
+ public function day_api(){
|
|
|
+ $start=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
|
|
|
+ $end=mktime(0,0,0,date('m'),date('d'),date('Y'))-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', strtotime('-0 month')));
|
|
|
+ $w['fstart'] = Dever::maketime($fstart . ' 00:00:00');
|
|
|
+ $w['fend'] = $end;
|
|
|
+ $data = array();
|
|
|
+ $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']);
|
|
|
+ return Dever::render('census', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function zhou_api(){
|
|
|
+ $start=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
|
|
|
+ $end=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
|
|
|
+ $where = array();
|
|
|
+ $where['fstart'] = $start;
|
|
|
+ $where['fend'] = $end;
|
|
|
+ $w = array();
|
|
|
+ $fstart = Dever::input('start', date('Y-m-01', strtotime('-0 month')));
|
|
|
+ $w['fstart'] = Dever::maketime($fstart . ' 00:00:00');
|
|
|
+ $w['fend'] = $end;
|
|
|
+ $data = array();
|
|
|
+ $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']);
|
|
|
+ return Dever::render('census', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function month_api(){
|
|
|
+ $num = Dever::input('num',1);
|
|
|
+ $start = Dever::input('start', date('Y-m-01', strtotime('-'.$num.' month')));
|
|
|
+ $end = date('Y-m-d', strtotime($start." +1 month -1 day"));
|
|
|
+ $time = Dever::maketime(date('Y-m-01'),'00:00:00');
|
|
|
+ $start = Dever::maketime($start . ' 00:00:00');
|
|
|
+ $end = Dever::maketime($end . ' 23:59:59');
|
|
|
+ $where = array();
|
|
|
+ $where['fstart'] = $start;
|
|
|
+ $where['fend'] = $end;
|
|
|
+ $w = array();
|
|
|
+ $fstart = Dever::input('start', date('Y-m-01', strtotime('-1 month')));
|
|
|
+ $w['fstart'] = Dever::maketime($fstart . ' 00:00:00');
|
|
|
+ $w['fend'] = $end;
|
|
|
+ $data = array();
|
|
|
+ $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,2);
|
|
|
+ $data['zhou'] = Dever::json_encode($data['xzhou']);
|
|
|
+ return Dever::render('census', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function content_api($where,$type){
|
|
|
+ $data = array();
|
|
|
+
|
|
|
+ if($type == 2){
|
|
|
+ $data['time'] = date('Y.m',$where['fstart']);
|
|
|
+ }else{
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+
|
|
|
+ $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';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|