LogController.php 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * 超级管理员-管理爱答题
  5. * User: hanl
  6. * Date: 2018/9/14
  7. * Time: 11:45
  8. */
  9. namespace App\Http\Controllers\SuperAdmin;
  10. use App\Models\Admin;
  11. use App\Models\Corps;
  12. use App\Services\LogService;
  13. use Illuminate\Http\Request;
  14. use App\Http\Controllers\Controller;
  15. use DB;
  16. use Excel;
  17. use App\Common\Api;
  18. class LogController extends Controller
  19. {
  20. /**
  21. * 获取日志统计数据
  22. * @param Request $request
  23. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  24. */
  25. public function event(Request $request)
  26. {
  27. //参数处理
  28. $params = $request->all();
  29. $res = LogService::eventCount($params);
  30. $keyCorp = empty($params['keyword_corp']) ?'' :$params['keyword_corp'];
  31. $keyAdmin = empty($params['keyword_admin'])?'' :$params['keyword_admin'];
  32. $startTime = empty($params['start_time']) ?time()-3600*24*7 :strtotime($params['start_time']);
  33. $endTime = empty($params['end_time']) ?time()-3600*24 :strtotime($params['end_time']);
  34. $type = '';
  35. if(!empty($keyCorp) || !empty($keyAdmin)){
  36. $type = 'corp';
  37. } else {
  38. $type = 'all';
  39. }
  40. return view("superadmin.log.event", ['data' => $res['data'], 'type'=>$type, 'start_time'=>$startTime, 'end_time'=>$endTime]);
  41. }
  42. /**
  43. * 访问统计数据下载
  44. * @param Request $request
  45. */
  46. public function logDownload(Request $request){
  47. $params = $request->all();
  48. $res = LogService::eventCount($params);
  49. $data = $res['data'];
  50. if(!empty($params['keyword_corp']) || !empty($params['keyword_admin'])){
  51. $hands = array('访问人', '事件名称', '访问时间');
  52. array_unshift($data, $hands);
  53. Excel::create('访问详情'.date('YmdHis'), function ($excel) use ($data) {
  54. $excel->sheet('corp_visit', function ($sheet) use ($data) {
  55. $tot = count($data);
  56. $sheet->setWidth(array(
  57. 'A' => 15,
  58. 'B' => 15,
  59. 'C' => 25,
  60. ))->rows($data)->setFontSize(12);
  61. $sheet->setStyle([
  62. 'font' => [
  63. 'size' => 12,
  64. 'bold' => false,
  65. ]
  66. ])->cells('A1:C1', function($cells){ //设置单元格格式
  67. $cells->setAlignment('center'); //文本对齐方式
  68. $cells->setFontWeight('bold'); //粗体
  69. $cells->setBackground('#92D050'); //底色
  70. })->cells('A1:C'.$tot, function($cells){
  71. $cells->setAlignment('center'); //文本对齐方式
  72. });
  73. });
  74. })->export('xlsx');
  75. } else {
  76. $hands = array('企业简称', '爱关怀企业ID', '企业注册时间', '访问次数');
  77. array_unshift($data, $hands);
  78. Excel::create('企业访问详情'.date('YmdHis'), function ($excel) use ($data) {
  79. $excel->sheet('all_corp_visit', function ($sheet) use ($data) {
  80. $tot = count($data);
  81. $sheet->setWidth(array(
  82. 'A' => 15,
  83. 'B' => 15,
  84. 'C' => 25,
  85. 'D' => 25,
  86. ))->rows($data)->setFontSize(12);
  87. $sheet->setStyle([
  88. 'font' => [
  89. 'size' => 12,
  90. 'bold' => false,
  91. ]
  92. ])->cells('A1:D1', function($cells){ //设置单元格格式
  93. $cells->setAlignment('center'); //文本对齐方式
  94. $cells->setFontWeight('bold'); //粗体
  95. $cells->setBackground('#92D050'); //底色
  96. })->cells('A1:D'.$tot, function($cells){
  97. $cells->setAlignment('center'); //文本对齐方式
  98. });
  99. });
  100. })->export('xlsx');
  101. }
  102. }
  103. /**
  104. * 获取订单列表
  105. * @param Request $request
  106. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  107. */
  108. public function order(Request $request){
  109. $params = $request->all();
  110. $params['order_start_time'] = empty($params['order_start_time'])?time()-3600*24*7:strtotime($params['order_start_time']);
  111. $params['order_end_time'] = empty($params['order_end_time']) ?time()-3600*24 :strtotime($params['order_end_time']);
  112. $params['vip_start_time'] = empty($params['vip_start_time']) ?strtotime('2018-01-01'):strtotime($params['vip_start_time']);
  113. $params['vip_end_time'] = empty($params['vip_end_time']) ?time()+3600*24*365*5 :strtotime($params['vip_end_time']);
  114. $data = LogService::orderList($params);
  115. $res['data'] = $data;
  116. $res['order_start_time'] = $params['order_start_time'];
  117. $res['order_end_time'] = $params['order_end_time'];
  118. $res['vip_start_time'] = $params['vip_start_time'];
  119. $res['vip_end_time'] = $params['vip_end_time'];
  120. return view("superadmin.log.order", ['data' => $res]);
  121. }
  122. /**
  123. * 订单信息下载
  124. * @param Request $request
  125. */
  126. public function orderDownload(Request $request){
  127. $params = $request->all();
  128. $params['order_start_time'] = empty($params['order_start_time'])?time()-3600*24*7:strtotime($params['order_start_time']);
  129. $params['order_end_time'] = empty($params['order_end_time']) ?time()-3600*24 :strtotime($params['order_end_time']);
  130. $params['vip_start_time'] = empty($params['vip_start_time']) ?strtotime('2018-01-01'):strtotime($params['vip_start_time']);
  131. $params['vip_end_time'] = empty($params['vip_end_time']) ?time()+3600*24*365*5 :strtotime($params['vip_end_time']);
  132. $res = LogService::orderList($params);
  133. $res = collect($res)->toArray();
  134. $data = [];
  135. foreach($res as $k=>$v){
  136. $data[$k]['corp_name'] = $v['corp_name'];
  137. $data[$k]['admin_name'] = $v['admin_name'];
  138. switch ($v['vip_level']){
  139. case 1:
  140. $data[$k]['vip_name'] = '体验版';
  141. break;
  142. case 10:
  143. $data[$k]['vip_name'] = '专业版';
  144. break;
  145. case 100:
  146. $data[$k]['vip_name'] = '企业版';
  147. break;
  148. }
  149. $data[$k]['months'] = $v['months'].'个月';
  150. $data[$k]['prices'] = ($v['money']/100).'元';
  151. $data[$k]['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
  152. $data[$k]['vip_end_time'] = date('Y-m-d H:i:s', $v['create_time']+3600*24*30*$v['months']);
  153. }
  154. $hands = ['公司名称', '管理员名称','会员版本', '购买期限', '支付金额', '下单时间', '订单到期时间'];
  155. array_unshift($data, $hands);
  156. Excel::create('企业订单'.date('YmdHis'), function ($excel) use ($data) {
  157. $excel->sheet('all_corp_visit', function ($sheet) use ($data) {
  158. $tot = count($data);
  159. $sheet->setWidth(array(
  160. 'A' => 25,
  161. 'B' => 25,
  162. 'C' => 25,
  163. 'D' => 25,
  164. 'E' => 25,
  165. 'F' => 25,
  166. ))->rows($data)->setFontSize(12);
  167. $sheet->setStyle([
  168. 'font' => [
  169. 'size' => 12,
  170. 'bold' => false,
  171. ]
  172. ])->cells('A1:F1', function($cells){ //设置单元格格式
  173. $cells->setAlignment('center'); //文本对齐方式
  174. $cells->setFontWeight('bold'); //粗体
  175. $cells->setBackground('#92D050'); //底色
  176. })->cells('A1:F'.$tot, function($cells){
  177. $cells->setAlignment('center'); //文本对齐方式
  178. });
  179. });
  180. })->export('xlsx');
  181. }
  182. }