123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- /**
- * Created by PhpStorm.
- * 超级管理员-管理爱答题
- * User: hanl
- * Date: 2018/9/14
- * Time: 11:45
- */
-
- namespace App\Http\Controllers\SuperAdmin;
-
- use App\Models\Admin;
- use App\Models\Corps;
- use App\Services\LogService;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use DB;
- use Excel;
- use App\Common\Api;
-
- class LogController extends Controller
- {
-
- /**
- * 获取日志统计数据
- * @param Request $request
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- */
- public function event(Request $request)
- {
- //参数处理
- $params = $request->all();
-
- $res = LogService::eventCount($params);
-
- $keyCorp = empty($params['keyword_corp']) ?'' :$params['keyword_corp'];
- $keyAdmin = empty($params['keyword_admin'])?'' :$params['keyword_admin'];
- $startTime = empty($params['start_time']) ?time()-3600*24*7 :strtotime($params['start_time']);
- $endTime = empty($params['end_time']) ?time()-3600*24 :strtotime($params['end_time']);
- $type = '';
- if(!empty($keyCorp) || !empty($keyAdmin)){
- $type = 'corp';
- } else {
- $type = 'all';
- }
-
- return view("superadmin.log.event", ['data' => $res['data'], 'type'=>$type, 'start_time'=>$startTime, 'end_time'=>$endTime]);
- }
-
- /**
- * 访问统计数据下载
- * @param Request $request
- */
- public function logDownload(Request $request){
- $params = $request->all();
-
- $res = LogService::eventCount($params);
- $data = $res['data'];
-
- if(!empty($params['keyword_corp']) || !empty($params['keyword_admin'])){
- $hands = array('访问人', '事件名称', '访问时间');
- array_unshift($data, $hands);
-
- Excel::create('访问详情'.date('YmdHis'), function ($excel) use ($data) {
- $excel->sheet('corp_visit', function ($sheet) use ($data) {
- $tot = count($data);
- $sheet->setWidth(array(
- 'A' => 15,
- 'B' => 15,
- 'C' => 25,
- ))->rows($data)->setFontSize(12);
-
- $sheet->setStyle([
- 'font' => [
- 'size' => 12,
- 'bold' => false,
- ]
- ])->cells('A1:C1', function($cells){ //设置单元格格式
- $cells->setAlignment('center'); //文本对齐方式
- $cells->setFontWeight('bold'); //粗体
- $cells->setBackground('#92D050'); //底色
- })->cells('A1:C'.$tot, function($cells){
- $cells->setAlignment('center'); //文本对齐方式
- });
- });
- })->export('xlsx');
- } else {
- $hands = array('企业简称', '爱关怀企业ID', '企业注册时间', '访问次数');
- array_unshift($data, $hands);
-
- Excel::create('企业访问详情'.date('YmdHis'), function ($excel) use ($data) {
- $excel->sheet('all_corp_visit', function ($sheet) use ($data) {
- $tot = count($data);
- $sheet->setWidth(array(
- 'A' => 15,
- 'B' => 15,
- 'C' => 25,
- 'D' => 25,
- ))->rows($data)->setFontSize(12);
-
- $sheet->setStyle([
- 'font' => [
- 'size' => 12,
- 'bold' => false,
- ]
- ])->cells('A1:D1', function($cells){ //设置单元格格式
- $cells->setAlignment('center'); //文本对齐方式
- $cells->setFontWeight('bold'); //粗体
- $cells->setBackground('#92D050'); //底色
- })->cells('A1:D'.$tot, function($cells){
- $cells->setAlignment('center'); //文本对齐方式
- });
- });
- })->export('xlsx');
- }
- }
-
- /**
- * 获取订单列表
- * @param Request $request
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- */
- public function order(Request $request){
- $params = $request->all();
-
- $params['order_start_time'] = empty($params['order_start_time'])?time()-3600*24*7:strtotime($params['order_start_time']);
- $params['order_end_time'] = empty($params['order_end_time']) ?time()-3600*24 :strtotime($params['order_end_time']);
- $params['vip_start_time'] = empty($params['vip_start_time']) ?strtotime('2018-01-01'):strtotime($params['vip_start_time']);
- $params['vip_end_time'] = empty($params['vip_end_time']) ?time()+3600*24*365*5 :strtotime($params['vip_end_time']);
-
- $data = LogService::orderList($params);
-
- $res['data'] = $data;
- $res['order_start_time'] = $params['order_start_time'];
- $res['order_end_time'] = $params['order_end_time'];
- $res['vip_start_time'] = $params['vip_start_time'];
- $res['vip_end_time'] = $params['vip_end_time'];
-
- return view("superadmin.log.order", ['data' => $res]);
- }
-
- /**
- * 订单信息下载
- * @param Request $request
- */
- public function orderDownload(Request $request){
- $params = $request->all();
-
- $params['order_start_time'] = empty($params['order_start_time'])?time()-3600*24*7:strtotime($params['order_start_time']);
- $params['order_end_time'] = empty($params['order_end_time']) ?time()-3600*24 :strtotime($params['order_end_time']);
- $params['vip_start_time'] = empty($params['vip_start_time']) ?strtotime('2018-01-01'):strtotime($params['vip_start_time']);
- $params['vip_end_time'] = empty($params['vip_end_time']) ?time()+3600*24*365*5 :strtotime($params['vip_end_time']);
-
- $res = LogService::orderList($params);
- $res = collect($res)->toArray();
-
- $data = [];
- foreach($res as $k=>$v){
- $data[$k]['corp_name'] = $v['corp_name'];
- $data[$k]['admin_name'] = $v['admin_name'];
- switch ($v['vip_level']){
- case 1:
- $data[$k]['vip_name'] = '体验版';
- break;
- case 10:
- $data[$k]['vip_name'] = '专业版';
- break;
- case 100:
- $data[$k]['vip_name'] = '企业版';
- break;
- }
- $data[$k]['months'] = $v['months'].'个月';
- $data[$k]['prices'] = ($v['money']/100).'元';
- $data[$k]['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
- $data[$k]['vip_end_time'] = date('Y-m-d H:i:s', $v['create_time']+3600*24*30*$v['months']);
- }
-
- $hands = ['公司名称', '管理员名称','会员版本', '购买期限', '支付金额', '下单时间', '订单到期时间'];
- array_unshift($data, $hands);
-
- Excel::create('企业订单'.date('YmdHis'), function ($excel) use ($data) {
- $excel->sheet('all_corp_visit', function ($sheet) use ($data) {
- $tot = count($data);
- $sheet->setWidth(array(
- 'A' => 25,
- 'B' => 25,
- 'C' => 25,
- 'D' => 25,
- 'E' => 25,
- 'F' => 25,
- ))->rows($data)->setFontSize(12);
-
- $sheet->setStyle([
- 'font' => [
- 'size' => 12,
- 'bold' => false,
- ]
- ])->cells('A1:F1', function($cells){ //设置单元格格式
- $cells->setAlignment('center'); //文本对齐方式
- $cells->setFontWeight('bold'); //粗体
- $cells->setBackground('#92D050'); //底色
- })->cells('A1:F'.$tot, function($cells){
- $cells->setAlignment('center'); //文本对齐方式
- });
- });
- })->export('xlsx');
- }
- }
|