123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- /**
- * Created by PhpStorm.
- * User: hanl
- * Date: 2018/10/26
- * Time: 10:13
- */
-
- namespace App\Services;
-
-
- use DB;
- use App\Common\Api;
- use App\Models\Admin;
- use App\Models\Corps;
- use App\Models\Orders;
- use App\Services\ActivityService;
- use Illuminate\Support\Facades\Redis;
-
- class LogService
- {
- public function __construct($configs = [])
- {
-
- }
-
- /**
- * 获取日志统计数据
- * @param $params
- * @return array
- */
- public static function eventCount($params){
- $keyEvent = empty($params['event_type']) || $params['event_type'] == 'all'?'':$params['event_type'];
- $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']);
-
- $adminIds = [];
- $data = [];
- if(!empty($keyCorp) || !empty($keyAdmin)){
- $type = 'corp';
- //存在搜索条件,搜索该企业或该管理员的详细信息
- $corpInfo = Corps::where('corp_short_name', $keyCorp)->where('status', 1)->first();
- if(!empty($keyAdmin)){
- if(!empty($keyCorp)) {
- $adminInfo = Admin::where('username', $keyAdmin)->where('corp_id', $corpInfo['corp_id'])->first();
- $adminIds[] = $adminInfo['id'];
- } else {
- $adminInfo = Admin::where('username', $keyAdmin)->first();
- $adminIds[] = $adminInfo['id'];
- }
- } else {
- $adminIds = Admin::where('corp_id', $corpInfo['corp_id'])->pluck('id');
- }
-
- //获取企业或管理员的行为日志
- $curl = env('APP_LOG_URL').'/EventLog/statistics?event_type='.$keyEvent."&admin_ids=".json_encode(collect($adminIds)->toArray()).'&start_time='.$startTime.'&end_time='.$endTime;
- $corpData = Api::curl($curl);
-
- $corpData = json_decode($corpData,true);
- $data = [];
- foreach($corpData as $k=>$v){
- $adminInfo = Admin::where('id', $v['admin_id'])->first();
- $data[$k]['visit_name'] = $adminInfo['name'];
- switch ($v['event']){
- case 'changeScene1':
- $data[$k]['event_type'] = '体验案例1';
- break;
- case 'changeScene2':
- $data[$k]['event_type'] = '体验案例2';
- break;
- case 'changeScene3':
- $data[$k]['event_type'] = '体验案例3';
- break;
- case 'changeScene4':
- $data[$k]['event_type'] = '体验案例4';
- break;
- case 'openClick1':
- $data[$k]['event_type'] = '点击付费购买体验版';
- break;
- case 'openClick10':
- $data[$k]['event_type'] = '点击付费购买专业版';
- break;
- case 'openClick100':
- $data[$k]['event_type'] = '点击付费购买企业版';
- break;
- case 'chatClick1':
- $data[$k]['event_type'] = '头部客服访问';
- break;
- case 'chatClick2':
- $data[$k]['event_type'] = '图标客服访问';
- break;
- }
- $data[$k]['visit_time'] = date('Y-m-d H:i:s', $v['create_time']);
- }
-
- } else {
- $type = 'all';
- //不存在搜索条件,则搜索全部企业的总计信息
- $corpIds = Admin::groupBy('corp_id')->pluck('corp_id');
- foreach($corpIds as $corpId){
- if($corpId == 0){
- continue;
- }
- $corpAdminIds = Admin::where('corp_id', $corpId)->pluck('id');
- $curl = env('APP_LOG_URL').'/EventLog/statistics?event_type='.$keyEvent."&admin_ids=".json_encode(collect($corpAdminIds)->toArray()).'&start_time='.$startTime.'&end_time='.$endTime;
- $res = Api::curl($curl);
-
- $corpInfo = Corps::where('corp_id', $corpId)->first();
- $data[$corpId]['corp_short_name'] = $corpInfo['corp_short_name'];
- $data[$corpId]['agh_corp_id'] = $corpInfo['source_id'];
- $data[$corpId]['register_time'] = date('Y-m-d H:i:s', $corpInfo['register_time']);
- $data[$corpId]['clickCount'] = count(json_decode($res, true));
- }
- }
-
- return Api::arr(config('code.success'), trans('msg.success'), $data);
- }
-
- /**
- * 获取订单信息
- * @param $params
- * @return mixed
- */
- public static function orderList($params){
- $sql = Orders::where('status', 1)->whereBetween('create_time', [$params['order_start_time'], $params['order_end_time']]);
-
- if(!empty($params['corp_name'])){
- $corpIds = Corps::where('corp_name', 'like', '%'.$params['corp_name'].'%')->pluck('corp_id');
- $sql = $sql->whereIn('corp_id', $corpIds);
- }
-
- $data = $sql->orderBy('create_time')->get();
-
- foreach($data as $k=>$v){
- $data[$k]['corp_name'] = Corps::where('corp_id', $v['corp_id'])->value('corp_name');
- $data[$k]['admin_name'] = Admin::where('id', $v['admin_id'])->value('name');
-
- if($params['vip_start_time'] > $v['create_time'] + 30*3600*24*$v['months'] || $params['vip_end_time'] < $v['create_time'] + 30*3600*24*$v['months']){
- unset($data[$k]);
- }
- }
-
- return $data;
- }
- }
- ?>
|