Manage.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. <?php
  2. namespace Mail\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. #代理商日数据统计
  7. public function day_api(){
  8. $day = Dever::input('day');
  9. if($day){
  10. $start = strtotime($day);
  11. $end = $start+86400-1;
  12. }else{
  13. $start=mktime(0,0,0,date('m'),date('d'),date('Y'));
  14. $end = $start+86400-1;
  15. }
  16. $time = Dever::maketime(date('Y-m-d'),'00:00:00');
  17. $where = array();
  18. $where['fstart'] = $start;
  19. $where['fend'] = $end;
  20. $w = array();
  21. $fstart = Dever::input('start', date('Y-m-01', $start));
  22. $w['fstart'] = Dever::maketime($fstart . ' 00:00:00');
  23. $w['fend'] = strtotime(date('Y-m-d 23:59:59',
  24. strtotime($fstart."+1 month - 1 day")));;
  25. $data = array();
  26. $data['start'] = date('Y-m-d',$start);
  27. $data['day'] = $this->content_api($where,1);
  28. $data['money'] = $this->c_api($where);
  29. $data['week'] = $this->zhou_api($start);
  30. $data['all'] = $this->content_api($w,2);
  31. $data['all_money'] = $this->c_api($w);
  32. $data['time'] = $this->day_time_api($w);
  33. $data['data'] = Dever::json_encode($data['time']);
  34. $data['money_time'] = $this->money_time_api($w);
  35. $data['qu_money'] = Dever::json_encode($data['money_time']);
  36. $data['xzhou'] = $this->button_day_api($w,1);
  37. $data['zhou'] = Dever::json_encode($data['xzhou']);
  38. return Dever::render('census', $data);
  39. }
  40. public function zhou_api($time='',$format="Y-m-d"){
  41. $time = $time != '' ? $time : time();
  42. $week = date('w', $time);
  43. $date = [];
  44. for ($i=1; $i<=7; $i++){
  45. $date[$i] = date($format ,strtotime( '+' . $i-$week .' days', $time));
  46. }
  47. $start = strtotime($date[1]);
  48. $end = strtotime($date[7])+86400-1;
  49. $where = array();
  50. $where['fstart'] = $start;
  51. $where['fend'] = $end;
  52. $data = array();
  53. $data['week'] = date('Y.m.d',$start).' - '.date('Y.m.d',$end);
  54. $data['all'] = $this->content_api($where,2);
  55. $data['all_money'] = $this->c_api($where);
  56. return $data;
  57. }
  58. #按时间统计
  59. public function content_api($where,$type){
  60. $data = array();
  61. if($type == 2){
  62. $data['time'] = date('Y.m',$where['fstart']);
  63. }elseif($type == 1){
  64. $data['time'] = date('Y.m.d',$where['fstart']);
  65. }
  66. #确认代理商订单数
  67. $where['status'] = 4;
  68. $data['num'] = Dever::db('agent/order')->getNum($where);
  69. #确认订单总费用
  70. $money = Dever::db('agent/order')->getCash($where);
  71. if($money['total']){
  72. $data['money'] = $money['total'];
  73. }else{
  74. $data['money'] = 0;
  75. }
  76. #确认代理费
  77. $dl_money = Dever::db('agent/order')->getDailiCash($where);
  78. if($dl_money['total']){
  79. $data['dl_money'] = $dl_money['total'];
  80. }else{
  81. $data['dl_money'] = 0;
  82. }
  83. #确认软件服务费
  84. $soft_money = Dever::db('agent/order')->getSoftCash($where);
  85. if($soft_money['total']){
  86. $data['soft_money'] = $soft_money['total'];
  87. }else{
  88. $data['soft_money'] = 0;
  89. }
  90. $wh['status'] = 3;
  91. $wh['fstart'] = $where['fstart'];
  92. $wh['fend'] = $where['fend'];
  93. $cash = Dever::db('agent/soft_cash')->getTotal($wh);
  94. if($cash['total']){
  95. $data['cash'] = $cash['total'];
  96. }else{
  97. $data['cash'] = 0;
  98. }
  99. $data['soft_cash'] = $data['soft_money'] + $data['cash'];
  100. #期权价值
  101. $option_money = Dever::db('agent/order')->getOptionPrice($where);
  102. if($option_money['total']){
  103. $data['option_money'] = $option_money['total'];
  104. }else{
  105. $data['option_money'] = 0;
  106. }
  107. return $data;
  108. }
  109. #各角色的金额,数量,原始期权价值,软件服务费
  110. public function c_api($where){
  111. $role = Dever::db('setting/role')->getAll(array('id'=>1,'state'=>1));
  112. foreach($role as $k => $v){
  113. $where['role'] = $v['id'];
  114. $data[$k]['name'] = $v['name'];
  115. $where['status'] = 2;
  116. $data[$k]['num'] = Dever::db('agent/member')->getNum($where);
  117. $where['status'] = 4;
  118. $dl = Dever::db('agent/order')->getSum($where);
  119. if($dl['total']){
  120. $data[$k]['money'] = $dl['total'];
  121. }else{
  122. $data[$k]['money'] = 0;
  123. }
  124. #期权价值:
  125. $option_money = Dever::db('agent/order')->getOptionPrice($where);
  126. if($option_money['total']){
  127. $data[$k]['option_money'] = $option_money['total'];
  128. }else{
  129. $data[$k]['option_money'] = 0;
  130. }
  131. #软件服务费
  132. $soft_money = Dever::db('agent/order')->getSoftCash($where);
  133. if($soft_money['total']){
  134. $data[$k]['soft_money'] = $soft_money['total'];
  135. }else{
  136. $data[$k]['soft_money'] = 0;
  137. }
  138. $wh['role'] = $v['id'];
  139. $wh['status'] = 3;
  140. $wh['fstart'] = $where['fstart'];
  141. $wh['fend'] = $where['fend'];
  142. $cash = Dever::db('agent/soft_cash')->getTotal($wh);
  143. if($cash['total']){
  144. $data[$k]['cash'] = $cash['total'];
  145. }else{
  146. $data[$k]['cash'] = 0;
  147. }
  148. }
  149. return $data;
  150. }
  151. #数据趋势
  152. public function day_time_api($w){
  153. $time = date('m',time()) - date('m',$w['fstart']);
  154. $start = date('Y-m-01',$w['fstart']);
  155. if($time<=0){
  156. $w['fend'] = time();
  157. }elseif($time>0){
  158. $w['fend'] = strtotime(date('Y-m-d 23:59:59',
  159. strtotime($start."+1 month - 1 day")));
  160. }
  161. $days = ($w['fend']-$w['fstart'])/86400+1;
  162. // 保存每天日期
  163. $day = array();
  164. $data = array();
  165. for($i=0; $i<$days; $i++){
  166. $day[] = array($w['fstart']+(86400*$i),$w['fstart']+(86400*$i)+86400);
  167. }
  168. $res = array();
  169. $res['num'] = array();
  170. foreach($day as $k => $v){
  171. $where['fstart'] = $v[0];
  172. $where['fend'] =$v[1]-1;
  173. $data[$k]['time'] = date('m.d',$v[0]);
  174. #确认代理商订单数
  175. $where['status'] = 4;
  176. $res['num'][] = Dever::db('agent/order')->getNum($where);
  177. }
  178. // print_R($where);die;
  179. $data = array();
  180. $data['name'] = '数量';
  181. $data['type'] = 'line';
  182. // $data['stack'] = 'Total';
  183. $data['data'] = $res['num'];
  184. return $data;
  185. }
  186. #金额趋势
  187. public function money_time_api($w){
  188. $time = date('m',time()) - date('m',$w['fstart']);
  189. $start = date('Y-m-01',$w['fstart']);
  190. if($time<=0){
  191. $w['fend'] = time();
  192. }elseif($time>0){
  193. $w['fend'] = strtotime(date('Y-m-d 23:59:59',
  194. strtotime($start."+1 month - 1 day")));
  195. }
  196. $days = ($w['fend']-$w['fstart'])/86400+1;
  197. // 保存每天日期
  198. $day = array();
  199. $data = array();
  200. for($i=0; $i<$days; $i++){
  201. $day[] = array($w['fstart']+(86400*$i),$w['fstart']+(86400*$i)+86400);
  202. }
  203. $res = array();
  204. $res['money'] = array();
  205. foreach($day as $k => $v){
  206. $where['fstart'] = $v[0];
  207. $where['fend'] =$v[1]-1;
  208. $data[$k]['time'] = date('m.d',$v[0]);
  209. #确认订单总费用
  210. $money = Dever::db('agent/order')->getCash($where);
  211. if($money['total']){
  212. $res['money'][] = $money['total'];
  213. }else{
  214. $res['money'][] = 0;
  215. }
  216. }
  217. $money = array();
  218. $money['name'] = '金额';
  219. $money['type'] = 'line';
  220. $money['data'] = $res['money'];
  221. return $money;
  222. }
  223. #趋势底部日期
  224. public function button_day_api($w,$type){
  225. $time = date('m',time()) - date('m',$w['fstart']);
  226. $start = date('Y-m-01',$w['fstart']);
  227. if($time<=0){
  228. $w['fend'] = time();
  229. }elseif($time>0){
  230. $w['fend'] = strtotime(date('Y-m-d 23:59:59',
  231. strtotime($start."+1 month - 1 day")));
  232. }
  233. $days = ($w['fend']-$w['fstart'])/86400+1;
  234. if($type ==1){
  235. $daysd = $days-1;
  236. }else{
  237. $daysd = $days;
  238. }
  239. // 保存每天日期
  240. $day = array();
  241. $data = array();
  242. for($i=0; $i<$daysd; $i++){
  243. $day[] = date('m.d',$w['fstart']+(86400*$i));
  244. }
  245. $data['type'] = 'category';
  246. $data['boundaryGap'] = false;
  247. $data['date'] = $day;
  248. return $day;
  249. }
  250. #代理商日统计
  251. public function index_api(){
  252. $title = '代理商日数据统计';
  253. $data = Dever::db('mail/feature')->find(array('key'=>'lib/cron.day'));
  254. $email = explode(',',$data['email_id']);
  255. foreach($email as $k => $v){
  256. $res[] = Dever::db('mail/email')->find(array('id'=>$v));
  257. }
  258. $content = $this->index_api();
  259. foreach($res as $key => $val){
  260. $this->send($val['email'], $val['name'], $title, $content);
  261. }
  262. }
  263. #代理商统计发送邮件
  264. public function send($email, $username, $title, $content)
  265. {
  266. $config = Dever::config('base', 'project')->email;
  267. Dever::apply('src/PHPMailer', 'email');
  268. Dever::apply('src/Exception', 'email');
  269. Dever::apply('src/SMTP', 'email');
  270. $mail = new \PHPMailer\PHPMailer\PHPMailer();
  271. $mail->isSMTP();
  272. //$mail->SMTPDebug = 2;
  273. $mail->CharSet = 'UTF-8';
  274. $mail->Host = $config['smtp'];
  275. $mail->Port = 465;
  276. $mail->SMTPSecure = 'ssl';
  277. $mail->SMTPAuth = true;
  278. $mail->Username = $config['username'];
  279. $mail->Password = $config['password'];
  280. $mail->setFrom($config['from'][0], '统计');
  281. $mail->addAddress($email, $username);
  282. $mail->Subject = "=?utf-8?B?" . base64_encode($title) . "?=";
  283. $mail->Body = $content;
  284. $mail->isHTML(true);
  285. //$mail->addAttachment($file);
  286. if (!$mail->send()) {
  287. Dever::alert("Mailer Error: " . $mail->ErrorInfo);
  288. } else {
  289. return 'ok';
  290. }
  291. }
  292. #期权统计
  293. public function option_api(){
  294. #主账户数量
  295. $data['account'] = Dever::db('option/account')->getCount(array('state'=>1));
  296. #所有数量
  297. $data['member'] = Dever::db('option/member')->getCount(array('state'=>1));
  298. #已认证完成
  299. $data['y_num'] = Dever::db('option/account')->getCount(array('audit'=>3,'state'=>1));
  300. #尚未任何交付的
  301. $data['no_num'] = Dever::db('option/bill_jiaofu')->getCount(array('status'=>2,'state'=>1));
  302. #原始期权待交付
  303. $yq_nonum = Dever::db('option/bill_jiaofu')->getCash(array('status'=>2,'type'=>2,'state'=>1));
  304. if($yq_nonum['total']){
  305. $data['yq_nonum'] = $yq_nonum['total'];
  306. }else{
  307. $data['yq_nonum'] = 0;
  308. }
  309. #原始期权已交付未发放
  310. $yq_nof = Dever::db('option/bill_jiaofu')->getCash(array('status'=>1,'type'=>2,'state'=>1));
  311. if($yq_nof['total']){
  312. $data['yq_nof'] = $yq_nof['total'];
  313. }else{
  314. $data['yq_nof'] = 0;
  315. }
  316. #原始期权已发放
  317. $yq_fnum = Dever::db('option/bill_fafang')->getCash(array('status'=>1,'type'=>2,'state'=>1));
  318. if($yq_fnum['total']){
  319. $data['yq_fnum'] = $yq_fnum['total'];
  320. }else{
  321. $data['yq_fnum'] = 0;
  322. }
  323. #期权待交付
  324. $q_nonum = Dever::db('option/bill_jiaofu')->getCash(array('status'=>2,'type'=>1,'state'=>1));
  325. if($q_nonum['total']){
  326. $data['q_nonum'] = $q_nonum['total'];
  327. }else{
  328. $data['q_nonum'] = 0;
  329. }
  330. #期权已交付未发放
  331. $q_nof = Dever::db('option/bill_jiaofu')->getCash(array('status'=>1,'type'=>1,'state'=>1));
  332. if($q_nof['total']){
  333. $data['q_nof'] = $q_nof['total'];
  334. }else{
  335. $data['q_nof'] = 0;
  336. }
  337. #期权已发放
  338. $q_fnum = Dever::db('option/bill_fafang')->getCash(array('status'=>1,'type'=>1,'state'=>1));
  339. if($q_fnum['total']){
  340. $data['q_fnum'] = $q_fnum['total'];
  341. }else{
  342. $data['q_fnum'] = 0;
  343. }
  344. return Dever::render('qiquan', $data);
  345. }
  346. #代理商期权待交付
  347. public function option_nopay_api($start,$end,$type=false){
  348. $start = Dever::input('start',$start);
  349. $end = Dever::input('end',$end);
  350. if($start && $end){
  351. $start = strtotime($start);
  352. $end = strtotime($end);
  353. }else{
  354. $start=Dever::maketime(date('Y-m-01') . ' 00:00:00');
  355. $end = strtotime(date('Y-m-d 23:59:59',
  356. strtotime(date('Y-m-01')."+1 month - 1 day")));
  357. }
  358. $where['start'] = $start;
  359. $where['end'] = $end;
  360. $where['state'] = 1;
  361. $rest = array();
  362. $rest['start'] = date('Y-m-d',$start);
  363. $rest['end'] = date('Y-m-d',$end);
  364. $data = Dever::db('agent/order')->getAll($where);
  365. foreach($data as $k => $v){
  366. #单独购买的软件服务费
  367. $cash = Dever::db('agent/soft_cash')->getTotal(array('fstart'=>$start,'fend'=>$end,'mid'=>$v['mid']));
  368. $data[$k]['buy_cash'] = $cash['total'];
  369. $option = Dever::db('agent/soft_cash')->getPrice(array('fstart'=>$start,'fend'=>$end,'mid'=>$v['mid']));
  370. $data[$k]['y_price'] = $option['total'];
  371. }
  372. $rest['data'] = $data;
  373. if($type == 1){
  374. return $rest['data'];
  375. }else{
  376. return Dever::render('option_nopay', $rest);
  377. }
  378. }
  379. #代理商期权待交付导出
  380. public function out_option_nopay_api(){
  381. $start = Dever::input('start');
  382. $end = Dever::input('end');
  383. if($start && $end){
  384. $start = strtotime($start);
  385. $end = strtotime($end);
  386. }else{
  387. $start=Dever::maketime(date('Y-m-01') . ' 00:00:00');
  388. $end = strtotime(date('Y-m-d 23:59:59',
  389. strtotime(date('Y-m-01')."+1 month - 1 day")));
  390. }
  391. $data = $this->option_nopay_api($start,$end,1);
  392. $header = array('用户姓名', '手机号', '身份证号', '软件服务费(订单)', '软件服务费(购买)', '原始期权', '期权赠送');
  393. if($data){
  394. $body = array();
  395. foreach($data as $k => $v){
  396. $d = array
  397. (
  398. $v['name'],
  399. $v['mobile'],
  400. $v['idcard'],
  401. $v['soft_cash'],
  402. $v['buy_cash'],
  403. $v['y_price'],
  404. $v['option_price'],
  405. );
  406. $body[] = $d;
  407. }
  408. $file = '代理商期权待交付';
  409. Dever::excelExport($body, $header, $file);
  410. }
  411. }
  412. #代理商期权发放统计
  413. public function option_grant_api($start,$end,$type=false){
  414. $start = Dever::input('start',$start);
  415. $end = Dever::input('end',$end);
  416. if($start && $end){
  417. $start = strtotime($start);
  418. $end = strtotime($end);
  419. }else{
  420. $start=Dever::maketime(date('Y-m-01') . ' 00:00:00');
  421. $end = strtotime(date('Y-m-d 23:59:59',
  422. strtotime(date('Y-m-01')."+1 month - 1 day")));
  423. }
  424. $data = array();
  425. $data['start'] = date('Y-m-d',$start);
  426. $data['end'] = date('Y-m-d',$end);
  427. $res = Dever::db('agent/member')->getAll(array('start'=>$start,'end'=>$end,'state'=>1));
  428. foreach($res as $k=>$v){
  429. $role = Dever::db('setting/role')->find($v['role']);
  430. $res[$k]['role_name'] = $role['name'];
  431. $res[$k]['cv_num'] = Dever::db('agent/member')->getNum(array('parent_mid'=>$v['id'],'fstart'=>$start,'fend'=>$end,'role'=>8,'state'=>1));
  432. $res[$k]['ck_num'] = Dever::db('agent/member')->getNum(array('parent_mid'=>$v['id'],'fstart'=>$start,'fend'=>$end,'role'=>6,'state'=>1));
  433. }
  434. $data['data'] = $res;
  435. if($type == 1){
  436. return $res;
  437. }else{
  438. return Dever::render('option_grant', $data);
  439. }
  440. }
  441. #期权发放导出
  442. public function out_option_grant_api(){
  443. $start = Dever::input('start',$start);
  444. $end = Dever::input('end',$end);
  445. if($start && $end){
  446. $start = strtotime($start);
  447. $end = strtotime($end);
  448. }else{
  449. $start=Dever::maketime(date('Y-m-01') . ' 00:00:00');
  450. $end = strtotime(date('Y-m-d 23:59:59',
  451. strtotime(date('Y-m-01')."+1 month - 1 day")));
  452. }
  453. $data = $this->option_grant_api($start,$end,1);
  454. $header = array('用户姓名', '手机号', '身份证号', '角色', '完成团队业绩', '完成直推创v', '完成直推创客');
  455. if($data){
  456. $body = array();
  457. foreach($data as $k => $v){
  458. $d = array
  459. (
  460. $v['name'],
  461. $v['mobile'],
  462. $v['idcard'],
  463. $v['role_name'],
  464. $v['group_sell'],
  465. $v['cv_num'],
  466. $v['ck_num'],
  467. );
  468. $body[] = $d;
  469. }
  470. $file = '代理商期权发放';
  471. Dever::excelExport($body, $header, $file);
  472. }
  473. }
  474. // #城市数据统计
  475. // public function city_api(){
  476. // // $provice = Dever::input('provice');
  477. // // $city = Dever::input('city');
  478. // $area = Dever::input('area');
  479. // $role = Dever::input('role');
  480. // $start = Dever::input('start');
  481. // $end = Dever::input('end');
  482. // $where = array();
  483. // // if($provice){
  484. // // $where['provice'] = $provice;
  485. // // }
  486. // // if($city){
  487. // // $where['city'] = $city;
  488. // // }
  489. // if($area){
  490. // $where['area'] = $area;
  491. // }
  492. // if($role){
  493. // $where['role'] = $role;
  494. // }
  495. // if($start && $end){
  496. // $where['start'] = strtotime($start);
  497. // $where['end'] = strtotime($end);
  498. // }else{
  499. // $where['start']=Dever::maketime(date('Y-m-01') . ' 00:00:00');
  500. // $where['end'] = strtotime(date('Y-m-d 23:59:59',
  501. // strtotime(date('Y-m-01')."+1 month - 1 day")));
  502. // }
  503. // $data = Dever::db('agent/order')->getAll($where);
  504. // $rest = array();
  505. // foreach($data as $k => $v){
  506. // $data[$k]['area_name'] = Dever::load("area/api.string", $v['area']);
  507. // $role = Dever::db('setting/role')->find($v['role']);
  508. // $data[$k]['role_name'] = $role['name'];
  509. // }
  510. // $rest['role'] = Dever::db('setting/role')->find();
  511. // $rest['start'] = date('Y-m-d',$where['start']);
  512. // $rest['end'] = date('Y-m-d',$where['end']);
  513. // $rest['data'] = $data;
  514. // return Dever::render('city', $rest);
  515. // }
  516. }