sms = $sms; $this->userCon = $userCon; } public function dailyStat(Request $request) { $admin_type = $request->session()->get('admin_type'); $start_time = $request->input('start_time', date('Y-m-d 00:00:00')); $end_time = $request->input('end_time'); // if (empty($end_time)) { // $end_time = date('Y-m-d H:i:s', strtotime('+1 day', strtotime($start_time))); // } if (empty($start_time) || $start_time == 'undefined') { $start_time = date('Y-m-d'); } if (empty($end_time)) { $end_time = date('Y-m-d H:i:s'); } // print_r($start_time.'::'.$end_time);die; $courtship_count = User::where('type', 'single')->whereBetween('created_at', [$start_time, $end_time]); $marriage_count = User::where('type', '<>', 'single')->whereBetween('created_at', [$start_time, $end_time]); if ($admin_type == 'worker' || $admin_type == 'matcher') {//红娘或者同工 $openid = Wechat::where('user_id', auth()->id())->value('openid'); $courtship_count = $courtship_count->where('from_openid', $openid); $marriage_count = $marriage_count->where('from_openid', $openid); }elseif ($admin_type == 'admin') {//超级管理员 // $result = $this->getWeekStat([]); //收入 // $income = PayOrder::whereBetween('created_at', [date('Y-m-d',strtotime('this week Monday',time())), date('Y-m-d H:i:s', time())])->where('pay_status', 'PAID')->sum('cash'); }elseif ($admin_type == 'paas_admin') {//平台管理员 //平台信息 $paas_obj = $admin_type = $request->session()->get('paas_obj'); //平台成员 $paas_user_ids = $this->userCon->paasUserIds($paas_obj->name, 'MAIN'); $courtship_count = $courtship_count->whereIn('id', $paas_user_ids); $marriage_count = $marriage_count->whereIn('id', $paas_user_ids); } $courtship_count = $courtship_count->count(); $marriage_count = $marriage_count->count(); //当日进入小程序人数 $wechat_count = (Wechat::whereBetween('created_at', [$start_time, $end_time])->count())?:0; //当天多少通过分享进入的 $invite_count = (Wechat::whereBetween('created_at', [$start_time, $end_time])->whereNotNull('from_openid')->count())?:0; $week_start_time = date('Y-m-d 00:00:00', strtotime('-2 monday', time())); $week_end_time = date('Y-m-d 23:59:59', strtotime('-1 sunday', time())); //上周进入小程序人数 $week_wechat_count = (Wechat::whereBetween('created_at', [$week_start_time, $week_end_time])->count())?:0; //上周分享进入人数 $week_invite_count = (Wechat::whereBetween('created_at', [$week_start_time, $week_end_time])->whereNotNull('from_openid')->count())?:0; //上周分享注册人数 $week_invite_register_count = (User::whereBetween('created_at', [$week_start_time, $week_end_time])->whereNotNull('from_openid')->count())?:0; //上周注册人数 $week_register_count = (User::whereBetween('created_at', [$week_start_time, $week_end_time])->count())?:0; //上周认证人数 $week_approve_count = (User::whereBetween('approve_date', [$week_start_time, $week_end_time])->count())?:0; //上周购买超级会员人数 $week_rank_count = (Order::whereBetween('created_at', [$week_start_time, $week_end_time])->where('type', 'rank')->where('pay_status', 'PAID')->count())?:0; //信息分数 $info_complete_count = (User::where('info_complete_score', '>=', 15)->where('type', 'single')->count())?:0; //上周信息大于20分 $week_register_info_count = (User::whereBetween('created_at', [$week_start_time, $week_end_time])->where('info_complete_score', '>=', 15)->where('type', 'single')->count())?:0; $week_rank_cash = (PayOrder::whereHas('order', function($sql){ $sql->where('type', 'rank'); })->whereBetween('created_at', [$week_start_time, $week_end_time])->sum('cash'))?:0; $week_activity_cash = (PayOrder::whereHas('order', function($sql){ $sql->where('type', 'activity'); })->whereBetween('created_at', [$week_start_time, $week_end_time])->sum('cash'))?:0; //关闭资料用户 $hidden_user_count = User::where('hidden_profile', 'ALLSEX')->where('type', 'single')->count(); //有资料的用户并且没有关闭资料 $profile_single_count = User::where('type', 'single')->whereHas('profileCourtship', function($sql){ $sql->where('id', '>', 0); })->where('hidden_profile','<>', 'ALLSEX')->count(); $single_count = User::where('type', 'single')->count(); //所有单身用户 return $this->success('ok', compact('courtship_count','marriage_count', 'wechat_count', 'invite_count', 'week_wechat_count', 'week_invite_count', 'week_approve_count', 'week_rank_count', 'week_register_count', 'info_complete_count', 'week_register_info_count', 'week_rank_cash', 'week_activity_cash', 'week_invite_register_count', 'hidden_user_count', 'single_count', 'profile_single_count')); } public function monthStat(Request $request) { $start_time = $request->input('start_time', date('Y-m-01')); $end_time = $request->input('end_time', date('Y-m-d H:i:s')); //进入小程序人数 $wechat_count = (Wechat::whereBetween('created_at', [$start_time, $end_time])->count())?:0; $register_count = (User::whereBetween('created_at', [$start_time, $end_time])->count())?:0; $invite_register_count = (User::whereBetween('created_at', [$start_time, $end_time])->whereNotNull('from_openid')->count())?:0; $approve_count = (User::whereBetween('approve_date', [$start_time, $end_time])->count())?:0; $approve_fee = Order::where('type', 'approve')->whereBetween('created_at', [$start_time, $end_time])->where('trade_no', '<>', '123')->sum('price'); $rank_count = (Order::whereBetween('created_at', [$start_time, $end_time])->where('type', 'rank')->where('pay_status', 'PAID')->count())?:0; $rank_fee = (Order::whereBetween('created_at', [$start_time, $end_time])->where('type', 'rank')->where('pay_status', 'PAID')->sum('price'))?:0; $qian_xian_count = Order::where('type', 'single_service')->whereIn('type_id', [2,5])->where('pay_status', 'PAID')->whereBetween('created_at', [$start_time, $end_time])->count()?:0; $qian_xian_fee = Order::where('type', 'single_service')->whereIn('type_id', [2,5])->where('pay_status', 'PAID')->whereBetween('created_at', [$start_time, $end_time])->sum('price')?:0; $tuo_guan_count = Order::where('type', 'single_service')->whereIn('type_id', [3,6])->where('pay_status', 'PAID')->whereBetween('created_at', [$start_time, $end_time])->sum('price')?:0; $tuo_guan_fee = Order::where('type', 'single_service')->whereIn('type_id', [3,6])->where('pay_status', 'PAID')->whereBetween('created_at', [$start_time, $end_time])->sum('price')?:0; $ag_count = Order::where('type', 'single_service')->whereIn('type_id', [1,4])->where('pay_status', 'PAID')->whereBetween('created_at', [$start_time, $end_time])->count()?:0; $ag_fee = Order::where('type', 'single_service')->whereIn('type_id', [1,4])->where('pay_status', 'PAID')->whereBetween('created_at', [$start_time, $end_time])->sum('price')?:0; return $this->success('ok', compact('wechat_count', 'register_count', 'invite_register_count', 'approve_count', 'approve_fee', 'rank_count', 'rank_fee', 'qian_xian_count', 'qian_xian_fee', 'tuo_guan_count', 'tuo_guan_fee', 'ag_count', 'ag_fee')); } public function infoScoreCount(Request $request) { $score = $request->input('score', 23); $info_complete_count = (User::where('info_complete_score', '>=', $score)->where('type', 'single')->count())?:0; return $this->success('ok', compact('info_complete_count')); } public function userCount(Request $request){ $user_id = auth()->id(); //是否是推广团队 // $key = 'user_count'.$user_id; //缓存键 $start_time = $request->start_time ?: '2015-01-01 00:00:00'; $end_time = $request->end_time ?: date('Y-m-d H:i:s'); // if ($request->start_time || $request->end_time){ //有搜索条件 走数据库 if ($start_time){ //有搜索条件 走数据库 $all = User::whereBetween('created_at', [$start_time, $end_time]); $is_approved = User::whereBetween('created_at', [$start_time, $end_time])->where('is_approved', 1)->where('hidden_profile', 'NONE'); $hidden_profile = User::whereBetween('created_at', [$start_time, $end_time])->where('hidden_profile', 'ALLSEX'); $single = User::whereBetween('created_at', [$start_time, $end_time])->where('type', 'single')->where('hidden_profile', 'NONE'); $marriage = User::whereBetween('created_at', [$start_time, $end_time])->where('type', 'marriage')->where('hidden_profile', 'NONE'); $bind_mobile = User::whereBetween('created_at', [$start_time, $end_time])->whereNotNull('mobile'); $no_bind_mobile = User::whereBetween('created_at', [$start_time, $end_time])->whereNull('mobile'); $user_count['all'] = $all->count(); $user_count['is_approved'] = $is_approved->count(); $user_count['hidden_profile'] = $hidden_profile->count(); $user_count['single'] = $single->count(); $user_count['marriage'] = $marriage->count(); $user_count['bind_mobile'] = $bind_mobile->count(); $user_count['no_bind_mobile'] = $no_bind_mobile->count(); return $this->success('ok', compact('user_count')); } // else { //没有搜索条件 有缓存 走缓存 // if (Cache::has($key)){ // $data = Cache::get($key); // return $this->success('ok',$data); // }else{//没有搜索条件 没有缓存 走数据库 并放入缓存 // $all = User::whereBetween('created_at', [$start_time, $end_time]); // $is_approved = User::whereBetween('created_at', [$start_time, $end_time])->where('is_approved', 1)->where('hidden_profile', 'NONE'); // $hidden_profile = User::whereBetween('created_at', [$start_time, $end_time])->where('hidden_profile', 'ALLSEX'); // $single = User::whereBetween('created_at', [$start_time, $end_time])->where('type', 'single')->where('hidden_profile', 'NONE'); // $marriage = User::whereBetween('created_at', [$start_time, $end_time])->where('type', 'marriage')->where('hidden_profile', 'NONE'); // $bind_mobile = User::whereBetween('created_at', [$start_time, $end_time])->whereNotNull('mobile'); // $no_bind_mobile = User::whereBetween('created_at', [$start_time, $end_time])->whereNull('mobile'); // $user_count['all'] = $all->count(); // $user_count['is_approved'] = $is_approved->count(); // $user_count['hidden_profile'] = $hidden_profile->count(); // $user_count['single'] = $single->count(); // $user_count['marriage'] = $marriage->count(); // $user_count['bind_mobile'] = $bind_mobile->count(); // $user_count['no_bind_mobile'] = $no_bind_mobile->count(); // $data = ['user_count'=>$user_count]; // Cache::put($key,$data,86400); // return $this->success('ok', compact('user_count')); // } // } } //数据统计(固定时间) public function statistics(Request $request){ $yesterday_start_time = date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d')-1,date('Y'))); //昨天开始时间 $yesterday_end_time = date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d'),date('Y'))-1); //昨天结束时间 $last_week_start=date("Y-m-d H:i:s", mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'))); $last_week_end=date("Y-m-d H:i:s",mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'))); // $last_month_start=date('Y-m-01 00:00:00',strtotime('-1 month')); // 上个月第一天 $last_month_start = new Carbon('first day of last month'); $last_month_start = $last_month_start->startOfMonth()->toDateTimeString(); // dd($last_month_start); // 上个月最后一天 // $last_month_end=date("Y-m-d 23:59:59", strtotime(-date('d').'day')); $last_month_end = new Carbon('last day of last month'); $last_month_end =$last_month_end->endOfMonth()->toDateTimeString(); // dd($last_month_end); $next_month_start=date('Y-m-01 00:00:00',strtotime('+1 month')); $user_id = auth()->id(); // dd($last_month_start,$last_month_end,$next_month_start); $user_count['all_count'] = User::count(); $info_complete_score = User::where('info_complete_score', '>', 7); $yesterday_count = User::whereBetween('created_at', [$yesterday_start_time, $yesterday_end_time]); $last_week_order_count = Order::where('pay_status', 'PAID')->whereBetween('created_at', [$last_week_start, $last_week_end]); $all_order_count = Order::where('pay_status', 'PAID'); // dd($last_month_start,$last_month_end); $last_month_start = Order::where('pay_status', 'PAID')->whereBetween('created_at', [$last_month_start, $last_month_end]); $price_sum = Order::where('pay_status', 'PAID'); //昨天成交订单 $yesterday_order_count = Order::where('pay_status','PAID')->whereBetween('created_at',[$yesterday_start_time,$yesterday_end_time]); //本月销售额 $this_month_count = Order::where('pay_status','PAID')->whereBetween('created_at',[$last_month_end,$next_month_start]); $user_count['info_complete_score'] = $info_complete_score->count(); $user_count['yesterday_count'] = $yesterday_count->count(); $user_count['last_week_order_count'] = $last_week_order_count->count(); $user_count['all_order_count'] = $all_order_count->count(); $last_month_price_sum = $last_month_start->sum('price'); $user_count['last_month_price_sum'] = round($last_month_price_sum); $price_sum = $price_sum->sum('price'); $user_count['price_sum'] = round($price_sum); $user_count['yesterday_order_count'] = $yesterday_order_count->count(); $user_count['yesterday_price_count'] = $yesterday_order_count->sum('price'); $user_count['this_month_count'] = $this_month_count->sum('price'); return $this->success('ok', compact('user_count')); } //每天推送模板记录 public function dailyRecommendRecord(Request $request){ if($request->start_time && $request->end_time){ $start_time = $request->start_time; $end_time = $request->end_time; //间隔天数 $between_time = ceil((strtotime($end_time) - strtotime($start_time))/3600/24) + 1; for($i=0; $i<$between_time; $i++){ $date[] = date("Y-m-d 00:00:00",strtotime("+$i day", strtotime($start_time))); } } foreach ($date as $start_time) { $end_time = date("Y-m-d 23:59:59",strtotime($start_time)); $date_arr[] = $start_time; //公众号t推送1人模板 $official_count = TemplateMsgLog::where('template_id','i1RR-kXNlHwVHgmKz4I9iN72B0tCYZtLNVpf2wG2i70')->where('status',1)->whereBetween('created_at',[$start_time,$end_time])->count(); $arr['official_count'] = $official_count; $officials_count[] = $official_count; //签到模板 $sign_count = TemplateMsgLog::where('template_id','eM6XgLkFfxjw0iMNtqWmMCM97FXPJH26Je8RSb2tlnU')->where('status',1)->whereBetween('created_at',[$start_time,$end_time])->count(); $arr['sign_count'] = $sign_count; $signs_count[] = $sign_count; //大数据推送模板 $bigdata_count = TemplateMsgLog::where('template_id','rfbjIvh0a70hUXjw3k8tbc7Ai2Rb_CBS_SNivMspLNE')->where('status',1)->whereBetween('created_at',[$start_time,$end_time])->count(); $arr['bigdata_count'] = $bigdata_count; $bigdatas_count[] = $bigdata_count; //预推荐大数据 $pre_res = $pre_count = Redis::get('recommend_num_'.date("Y-m-d",strtotime($start_time)))?:0; if ($pre_res) { $pre_count = json_decode($pre_res)->subscribe_count; } $arr['pre_count'] = $pre_count; $pre_data_count[] = $pre_count; } return $this->success('ok',compact('date_arr','officials_count','signs_count','bigdatas_count', 'pre_data_count')); } public function ageAndSexCount(Request $request){ $user_id = auth()->id(); //是否是推广团队 $is_promote = RoleUser::where('user_id', $user_id)->where('role_id', 6)->count(); $platfroms = Platform::where('paas_id', 33)->pluck('app_id')->toArray(); $platfroms = "'".implode("','", $platfroms)."'"; $start_time = $request->start_time ?: '2015-01-01 00:00:00'; $end_time = $request->end_time ?: date('Y-m-d H:i:s'); // if($is_promote){ // $user_count['age_group'] = DB::select("SELECT age, count( * ) AS count FROM // ( // SELECT // CASE // WHEN age <= 20 THEN '20' // WHEN age <= 30 AND age >= 21 THEN '21-30' // WHEN age <= 40 AND age >= 31 THEN '31-40' // WHEN age <= 50 AND age >= 41 THEN '41-50' // WHEN age <= 60 AND age >= 51 THEN '51-60' // WHEN age >= 61 THEN '61' // END AS age // FROM // `ufutx_users` where created_at between '{$start_time}' and '{$end_time}' and from_platform IN ({$platfroms}) // ) AS a GROUP BY age"); // }else{ $user_count['age_group'] = DB::select("SELECT age, count( * ) AS count FROM ( SELECT CASE WHEN age <= 20 THEN '20' WHEN age <= 30 AND age >= 21 THEN '21-30' WHEN age <= 40 AND age >= 31 THEN '31-40' WHEN age <= 50 AND age >= 41 THEN '41-50' WHEN age <= 60 AND age >= 51 THEN '51-60' WHEN age >= 61 THEN '61' END AS age FROM `ufutx_profile_courtships` where created_at between '{$start_time}' and '{$end_time}' ) AS a GROUP BY age"); // } // if($is_promote){ // // 年龄下的性别分布 // $age_sex[20] = DB::select("select count(id) as count,sex from ufutx_profile_courtships where age < 21 and created_at between '{$start_time}' and '{$end_time}' and from_platform IN ({$platfroms}) group by sex "); // $age_sex['21-30'] = DB::select("select count(id) as count,sex from ufutx_profile_courtships where age between 21 and 30 and created_at between '{$start_time}' and '{$end_time}' and from_platform IN ({$platfroms}) group by sex "); // $age_sex['31-40'] = DB::select("select count(id) as count,sex from ufutx_profile_courtships where age between 31 and 40 and created_at between '{$start_time}' and '{$end_time}' and from_platform IN ({$platfroms}) group by sex "); // $age_sex['41-50'] = DB::select("select count(id) as count,sex from ufutx_profile_courtships where age between 41 and 50 and created_at between '{$start_time}' and '{$end_time}' and from_platform IN ({$platfroms}) group by sex "); // $age_sex['51-60'] = DB::select("select count(id) as count,sex from ufutx_profile_courtships where age between 51 and 60 and created_at between '{$start_time}' and '{$end_time}' and from_platform IN ({$platfroms}) group by sex "); // $age_sex[61] = DB::select("select count(id) as count,sex from ufutx_profile_courtships where age > 60 and created_at between '{$start_time}' and '{$end_time}' and from_platform IN ({$platfroms}) group by sex "); // $sex_group = DB::select("select count(id) as count,sex from ufutx_profile_courtships where created_at between'{$start_time}' and '{$end_time}' and from_platform IN ({$platfroms}) group by sex"); // }else{ // 年龄下的性别分布 $age_sex[20] = DB::select("select count(id) as count,sex from ufutx_profile_courtships where age < 21 and created_at between '{$start_time}' and '{$end_time}' group by sex "); $age_sex['21-30'] = DB::select("select count(id) as count,sex from ufutx_profile_courtships where age between 21 and 30 and created_at between '{$start_time}' and '{$end_time}' group by sex "); $age_sex['31-40'] = DB::select("select count(id) as count,sex from ufutx_profile_courtships where age between 31 and 40 and created_at between '{$start_time}' and '{$end_time}' group by sex "); $age_sex['41-50'] = DB::select("select count(id) as count,sex from ufutx_profile_courtships where age between 41 and 50 and created_at between '{$start_time}' and '{$end_time}' group by sex "); $age_sex['51-60'] = DB::select("select count(id) as count,sex from ufutx_profile_courtships where age between 51 and 60 and created_at between '{$start_time}' and '{$end_time}' group by sex "); $age_sex[61] = DB::select("select count(id) as count,sex from ufutx_profile_courtships where age > 60 and created_at between '{$start_time}' and '{$end_time}' group by sex "); $sex_group = DB::select("select count(id) as count,sex from ufutx_profile_courtships where created_at between'{$start_time}' and '{$end_time}' group by sex "); // } //统一key值,方便前端处理 foreach ($age_sex as &$val){ $val = array_column($val, 'count', 'sex'); } $age_sex['other'][0] = ProfileCourtship::query()->where('sex',0)->whereNull('age')->whereNotNull('updated_at')->count(); $age_sex['other'][1] = ProfileCourtship::query()->where('sex',1)->whereNull('age')->whereNotNull('updated_at')->count(); $age_sex['other'][2] = ProfileCourtship::query()->where('sex',2)->whereNull('age')->whereNotNull('updated_at')->count(); $user_count['age_sex'] = $age_sex; $user_count['sex_group'] = array_column($sex_group, 'count', 'sex'); return $this->success('ok', compact('user_count')); } public function weekStat(Request $request) { //管理员类型 $start_time = $request->start_time; $end_time = $request->end_time; $admin_type = $request->session()->get('admin_type', 'admin'); // return $this->success('ok', date('Y-m-d',strtotime('this week Monday',time()))); if ($admin_type == 'worker' || $admin_type == 'matcher') {//红娘或者同工 $openid = Wechat::where('user_id', auth()->id())->value('openid'); $result = $this->getweekStat($admin_type, [], $openid); //收入 $income = 0; }elseif ($admin_type == 'admin') {//超级管理员 $result = $this->getWeekStat($admin_type); $result['single'] = User::whereBetween('created_at',[$start_time, $end_time])->where('type', 'single')->count(); $result['marriage'] = User::whereBetween('created_at',[$start_time, $end_time])->where('type', 'marriage')->count(); //收入 $income = PayOrder::whereBetween('created_at', [date('Y-m-d',strtotime('this week Monday',time())), date('Y-m-d H:i:s', time())])->where('pay_status', 'PAID')->sum('cash'); }elseif ($admin_type == 'paas_admin') {//平台管理员 //平台信息 $paas_obj = $request->session()->get('paas_obj'); //平台成员 $paas_user_ids = $this->userCon->paasUserIds($paas_obj->name, 'MAIN'); $result = $this->getWeekStat($admin_type, $paas_user_ids); //收入 $income = PayOrder::whereBetween('created_at', [date('Y-m-d',strtotime('this week Monday',time())), date('Y-m-d H:i:s', time())])->where('pay_status', 'PAID')->whereIn('user_id', $paas_user_ids)->sum('cash'); } $courtship_arr = $result['courtship_arr']; $marriage_arr = $result['marriage_arr']; $day_arr = $result['day_arr']; return $this->success('ok', compact('day_arr', 'courtship_arr','marriage_arr', 'income')); } /** * 最近七天增长人数 * @param [type] $user_ids [description] * @param [type] $from_openid [description] * @return [type] [description] */ public function getWeekStat($admin_type, $user_ids=[], $from_openid=null) { $end_time = date('Y-m-d', time()); $start_time = date('Y-m-d', strtotime('-6 day')); //$end_time = date('Y-m-d', strtotime('2019-07-15')); //$start_time = date('Y-m-d', strtotime('2019-06-11')); //时间段 $day_arr = \CommonUtilsService::daliy($start_time, $end_time); $courtship_arr = []; $marriage_arr = []; $income_arr = []; for ($i=0; $i < count($day_arr); $i++) { $day_start_time = $day_arr[$i]; if ($i < count($day_arr) - 1) { $day_end_time = $day_arr[$i + 1]; }else{ $day_end_time = date('Y-m-d', strtotime('+1 day', strtotime($day_start_time))); } $courtship_count = User::where('type', 'single')->whereBetween('created_at', [$day_start_time, $day_end_time]); $marriage_count = User::where('type', '<>', 'single')->whereBetween('created_at', [$day_start_time, $day_end_time]); if ($admin_type == 'paas_admin') { $courtship_count = $courtship_count->whereIn('id', $user_ids); $marriage_count = $marriage_count->whereIn('id', $user_ids); } if ($from_openid) { $courtship_count = $courtship_count->where('from_openid', $from_openid); $marriage_count = $marriage_count->where('from_openid', $from_openid); } $courtship_count = $courtship_count->count(); $marriage_count = $marriage_count->count(); $courtship_arr[] = $courtship_count; $marriage_arr[] = $marriage_count; } return $array = [ 'courtship_arr'=>$courtship_arr, 'marriage_arr'=>$marriage_arr, 'day_arr'=>$day_arr ]; } /** * 前七周数据 * 订单金额、活动金额、退认证费金额、邀请注册金额、注册用户数 * @param Request $request [description] * @return [type] [description] */ public function weeksStat(Request $request) { $time_arr = []; $pay_orders_cash_arr = []; $activity_cash_arr =[]; $approve_refund_cash_arr = []; $award_cash_arr = []; $user_num_arr = []; $i = 0; $num = 7; while ($num) { $unix_start_time = strtotime('-'.$num.' saturday', time()); //当前时间 $unix_end_time = $unix_start_time + 7 * 24 * 3600; $data = []; $start_time = date('Y-m-d', $unix_start_time); $end_time = date('Y-m-d', $unix_end_time); // $new_data[] = $data; //所有订单金额 总和不符 $pay_orders_cash = PayOrder::where('created_at', '>', $start_time)->where('created_at','<',$end_time)->where('is_hooked', 1)->where('pay_status', 'PAID')->sum('cash'); $pay_orders_cash_arr[] = $pay_orders_cash; //trade_no = 123 是赠送的认证(无真实支付) // $pay_orders_cash = Order::where('created_at', '>', $start_time)->where('created_at','<',$end_time)->where('pay_status', 'PAID')->where('trade_no', '<>', '123')->sum('price'); // $pay_orders_cash_arr[] = $pay_orders_cash; //活动金额 $activity_cash = Order::whereHas('payorder',function ($query) { $query->where('is_hooked', 1); })->where('created_at', '>', $start_time)->where('created_at','<',$end_time)->where('pay_status', 'PAID')->where('type', 'activity')->sum('price'); $activity_cash_arr[] = $activity_cash; //认证退费 $approve_refund_cash = RefundOrder::where('created_at', '>', $start_time)->where('created_at','<',$end_time)->where('is_hook', 1)->where('type', 'approve')->sum('refund_fee'); $approve_refund_cash_arr[] = $approve_refund_cash; //VIP金额 $vip_cash = Order::whereHas('payorder',function ($query) { $query->where('is_hooked', 1); })->where('created_at', '>', $start_time)->where('created_at','<',$end_time)->where('pay_status', 'PAID')->where('type', 'rank')->sum('price'); $vip_cash_arr[] = $vip_cash; //AG金额 $ag_cash = Order::whereHas('payorder',function ($query) { $query->where('is_hooked', 1); })->where('created_at', '>', $start_time)->where('created_at','<',$end_time)->where('pay_status', 'PAID')->where('type', 'single_service')->where('type_id', 1)->sum('price'); $ag_cash_arr[] = $ag_cash; //meet $meet_cash = Order::whereHas('payorder',function ($query) { $query->where('is_hooked', 1); })->where('created_at', '>', $start_time)->where('created_at','<',$end_time)->where('pay_status', 'PAID')->where('type', 'meet')->sum('price'); $single_service_cash = Order::where('created_at', '>', $start_time)->where('created_at','<',$end_time)->where('pay_status', 'PAID')->where('type', 'single_service')->where('type_id','<>', 1)->sum('price'); //单身金额 $single_cash_arr[] = $single_service_cash+$meet_cash; //认证费 $approve_cash = Order::whereHas('payorder',function ($query) { $query->where('is_hooked', 1); })->where('created_at', '>', $start_time)->where('created_at','<',$end_time)->where('pay_status', 'PAID')->where('type', 'approve')->where('trade_no','<>', '123')->sum('price'); $approve_cash_arr[]= $approve_cash; //邀请注册金额 $award_cash = ReferreAwardHistory::where('created_at', '>', $start_time)->where('created_at','<',$end_time)->where('is_hooked', 1)->sum('amount'); $award_cash_arr[] = $award_cash; //注册用户 $user_num = User::where('created_at', '>', $start_time)->where('created_at','<',$end_time)->count(); $user_num_arr[] = $user_num; $end_time = $unix_start_time + 6 * 24 * 3600; $time['end_time'] = date('Y-m-d', $end_time); $time['start_time'] = date('Y-m-d', $unix_start_time); $time_arr[] = $time; $num--; } return $this->success('ok', compact('time_arr', 'pay_orders_cash_arr', 'activity_cash_arr', 'approve_refund_cash_arr', 'award_cash_arr', 'user_num_arr', 'vip_cash_arr', 'ag_cash_arr', 'single_cash_arr', 'approve_cash_arr')); } /** * 被邀请的用户(来源推荐人) * @param Request $request [description] * @return [type] [description] */ public function inviteUserFromUsers(Request $request) { $result = $this->getDay($request); $type = $request->input('type'); if (empty($type)) { $start_time = $request->input('start_time', '2018-1-1'); $end_time = $request->input('end_time', date('Y-m-d H:i:s')); }else{ $start_time = $result['start_time']; $end_time = $result['end_time']; } //邀请人openid $from_openids = User::whereBetween('created_at', [$start_time, $end_time])->whereNotNull('from_openid'); $admin_type = $request->session()->get('admin_type'); if ($admin_type == 'paas_admin') { $paas_obj = $request->session()->get('paas_obj'); $paas_user_ids = $this->userCon->paasUserIds($paas_obj->name, 'MAIN'); $from_openids = $from_openids->whereIn("id", $paas_user_ids); } $from_openids = $from_openids->distinct('from_openid')->pluck('from_openid'); //邀请人微信信息 $wechats = Wechat::whereIn('openid', $from_openids)->whereNotNull('user_id'); if ($admin_type == 'paas_admin') { $wechats = $wechats->whereIn('user_id', $paas_user_ids); } $keyword = $request->input('keyword'); if (!empty($keyword)) { $keyword = trim($keyword); $wechats = $wechats->whereHas('user', function($sql) use($keyword){ $sql->where('name', 'like', '%'.$keyword.'%') ->orWhere('mobile', 'like', '%'.$keyword.'%'); }); } $wechats = $wechats->paginate(); foreach ($wechats as $wechat) { if (empty($wechat->user_id)) { $wechat->invite_count = 0; continue; } $user = User::where('id', $wechat->user_id)->first(); if (!empty($user)) { $wechat->name = $user->name; $wechat->circle_avatar = $user->circle_avatar; $wechat->mobile = $user->mobile; $wechat->sex = $user->sex; } $invite_count = User::whereBetween('created_at', [$start_time, $end_time])->where('from_openid', $wechat->openid)->count(); $wechat->invite_count = $invite_count; } return $this->success('ok', $wechats); } /** * 所有推荐平台列表 * @param Request $request [description] * @return [type] [description] */ public function inviteUserFromPlatforms(Request $request) { //开始与结束时间 $start_time = $request->input('start_time'); $end_time = $request->input('end_time'); if (empty($start_time)) { $start_time = '2018-1-1'; } if (empty($end_time)) { $end_time = date('Y-m-d H:i:s'); } //渠道列表 $platforms = User::whereBetween('created_at', [$start_time, $end_time])->whereNotNUll('from_platform')->distinct('from_platform')->pluck('from_platform'); $platforms = Platform::whereIn('app_id', $platforms); $admin_type = $request->session()->get('admin_type'); if ($admin_type == 'paas_admin') { $paas_obj = $request->session()->get('paas_obj'); $paas_platforms = Platform::where('paas_id', $paas_obj->id)->pluck('app_id'); $platforms = $platforms->whereIn('app_id', $paas_platforms); } $keyword = $request->input('keyword'); if (!empty($keyword)) { $keyword = trim($keyword); $platforms = $platforms->where(function($sql) use($keyword){ $sql->where('name', 'like', '%'.$keyword.'%') ->orWhere('app_id', 'like', '%'.$keyword.'%'); }); } $platforms = $platforms->paginate(); foreach ($platforms as $platform) { $invite_count = User::whereBetween('created_at', [$start_time, $end_time])->where('from_platform', $platform->app_id)->count(); $platform->invite_count = $invite_count; $platform->app_id = $platform->name?$platform->name:$platform->app_id; } // $start_time = $request->input('start_time'); // $end_time = $request->input('end_time'); // if (empty($start_time)) { // $start_time = '2018-1-1'; // } // if (empty($end_time)) { // $end_time = date('Y-m-d'); // } // $invite_count_query = DB::raw("(select count(*) from `ufutx_users` where `ufutx_platforms`.`app_id` = `ufutx_users`.`from_platform` and `ufutx_users`.`deleted_at` is null and `ufutx_users`.`created_at` >= '$start_time' and `ufutx_users`.`created_at` <= '$end_time') as `invite_count`"); // $platforms = \DB::table('platforms')->leftJoin('users','users.from_platform','=','platforms.app_id')->select('platforms.id', 'platforms.app_id', 'platforms.name', $invite_count_query); // $keyword = $request->input('keyword'); // if (!empty($keyword)) { // $keyword = trim($keyword); // $platforms->where('platforms.name', 'like', '%'.$keyword.'%'); // } // $admin_type = $request->session()->get('admin_type'); // if ($admin_type == 'paas_admin') { // $paas_obj = $request->session()->get('paas_obj'); // $paas_platforms = Platform::where('paas_id', $paas_obj->id)->pluck('app_id'); // $platforms = $platforms->whereIn('platforms.app_id', $paas_platforms); // } // $platforms = $platforms->orderBy('invite_count', 'desc')->groupBy('platforms.id')->paginate(); if ($request->input('debug')) { return view('welcome'); } return $this->success('ok', $platforms); } public function getDay($request) { $now_time = time(); $end_time = date('Y-m-d H:i:s', $now_time); $type = $request->input('type'); if ($type == 'day') { $start_time = date('Y-m-d 0:0:0', $now_time); }elseif ($type == 'week') { $start_time = date('Y-m-d', ($now_time - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)); }elseif ($type == 'month') { $start_time = date('Y-m-1 0:0:0', $now_time); }else { $start_time = '1970-1-1'; } return $array = ['start_time'=>$start_time, 'end_time'=>$end_time]; } /** * 征婚推荐列表 * @param Request $request [description] * @return [type] [description] */ public function homeRecommends(Request $request) { $recommends = HomeRecommend::with('user')->where('status', 1)->orderBy('id', 'desc'); $admin_type = $request->session()->get('admin_type'); if ($admin_type == 'paas_admin') { $paas_obj = $request->session()->get('paas_obj'); $paas_recommend_ids = PaasHomeRecommend::where('paas_id', $paas_obj->id)->pluck('recommend_id')->toArray(); $recommends = $recommends->whereIn('id', $paas_recommend_ids); } $recommends = $recommends->get(); return $this->success('ok', $recommends); } /** * 推荐人列表 * @param Request $request [description] * @return [type] [description] */ public function homeRecommendsV2(Request $request) { $recommends = HomeRecommend::with('user')->orderBy('id', 'desc'); $status = $request->input('status', 0); if($status != 2){ $recommends = $recommends->where('status', $status); } $keyword = $request->input('keyword'); if ($keyword) { $keyword = trim($keyword); $recommends = $recommends->whereHas('user', function($sql) use($keyword){ $sql->where('name', 'like', '%'.$keyword.'%'); }); } $recommends = $recommends->paginate(); foreach ($recommends as $recommend) { $recommend->photo = $recommend->user->photo; $recommend->user->rank_name = $recommend->user->rankName(); } return $this->success('ok', $recommends); } /** * 审核首页推荐 * @param Request $request [description] * @param HomeRecommend $recommend [description] * @return [type] [description] */ public function checkHomeRecommend(Request $request, HomeRecommend $recommend) { $status = $request->input('status'); if (empty($status)) { return $this->failure('请选择审核结果'); } //修改状态 $recommend->update(['status'=>$status]); //助手消息 $user_id = $recommend->user_id; if ($status == 1) {//通过 $content = '你申请的首页推荐已通过审核!'; }elseif ($status == -1) {//不通过 $content = $request->input('content'); if (empty($content)) { return $this->failure('请输入拒绝理由'); } //删除推荐 $recommend->delete(); } //助手消息 $this->userCon->sendAssistantMessage(compact('user_id'), $content); return $this->success('ok'); } /** * 添加征婚推荐 * @param Request $request [description] * @param [type] $user_id [description] */ public function addHomeRecommend(Request $request) { $user_id = $request->input('user_id'); if (empty($user_id)) { return $this->failure('请选择用户'); } $user = User::find($user_id); if (empty($user)) { return $this->failure('用户不存在'); } $photo = $request->input('photo'); if (empty($photo)) { return $this->failure('请上传照片'); } $recommend = HomeRecommend::create([ 'user_id'=>$user_id, 'photo'=>$photo, 'status'=>1, ]); $admin_type = $request->session()->get('admin_type'); if ($admin_type == 'paas_admin') { $paas_obj = $request->session()->get('paas_obj'); PaasHomeRecommend::create([ 'paas_id'=>$paas_obj->id, 'recommend_id'=>$recommend->id, ]); } return $this->success('ok', $recommend); } /** * 修改征婚推荐人 * @param Request $request [description] * @param [type] $id [description] * @return [type] [description] */ public function updateHomeRecommend(Request $request, $id) { $recommend = HomeRecommend::find($id); if ($request->has('user_id') && $request->user_id != $recommend->user_id) { $recommend->user_id = $request->user_id; } if ($request->has('photo') && $request->photo != $recommend->photo) { $recommend->photo = $request->photo; } if ($request->has('status') && $request->status != $recommend->status) { $recommend->status = $request->status; } $recommend->save(); return $this->success('ok', $recommend); } /** * 刪除征婚推荐人 * @param Request $request [description] * @param [type] $id [description] * @return [type] [description] */ public function deleteHomeRecommend(Request $request, $id) { HomeRecommend::where('id', $id)->delete(); return $this->success('ok'); } /** * 征婚推荐人详情 * @param Request $request [description] * @param [type] $id [description] * @return [type] [description] */ public function homeRecommend(Request $request, $id) { $recommend = HomeRecommend::find($id); return $this->success('ok', $recommend); } /** * 公告列表 * @param Request $request [description] * @return [type] [description] */ public function announcements(Request $request) { $announcements = Announcement::orderBy('id', 'desc'); $admin_type = $request->session()->get('admin_type'); if ($admin_type == 'paas_admin') { $paas_obj = $request->session()->get('paas_obj'); $paas_announcement_ids = PaasAnnouncement::where('paas_id', $paas_obj->id)->pluck('announcement_id')->toArray(); $announcements = $announcements->whereIn('id', $paas_announcement_ids); } $announcements = $announcements->get(); return $this->success('ok', $announcements); } public function announcement(Request $request, $announcement_id) { $announcement = Announcement::findOrFail($announcement_id); return $this->success('ok', $announcement); } public function AddAnnouncement(Request $request) { //删除已有的 Announcement::where('id', '>', 0)->delete(); //创建最新的 $announcement = $request->input('announcement'); if ($announcement && count($announcement)) { foreach ($announcement as $an) { $announcement = Announcement::create([ 'title'=>$an['title'], 'path'=>$an['path'], 'type'=>$an['type'], 'pic'=>isset($an['pic'])?$an['pic']:null, 'start_time'=>$an['start_time'], 'end_time'=>$an['end_time'], ]); $admin_type = $request->session()->get('admin_type'); if ($admin_type == 'paas_admin') { $paas_obj = $request->session()->get('paas_obj'); PaasAnnouncement::create([ 'paas_id'=>$paas_obj->id, 'announcement_id'=>$announcement->id, ]); } } } // $title = $request->input('title'); // if (empty($title)) { // return $this->failure('请输入标题'); // } // $path = $request->input('path'); // if (empty($path)) { // return $this->failure('请输入地址链接'); // } // $type = $request->input('type'); // if (empty($type)) { // return $this->failure('请选择类型'); // } // $start_time = $request->input('start_time'); // if (empty($start_time)) { // return $this->failure('请选择开始时间'); // } // $end_time = $request->input('end_time'); // if (empty($end_time)) { // return $this->failure('请选择结束时间时间'); // } // $announcement = Announcement::create([ // 'title'=>$title, // 'path'=>$path, // 'type'=>$type, // 'start_time'=>$start_time, // 'end_time'=>$end_time // ]); return $this->success('ok'); } public function updateAnnouncement(Request $request, $announcement_id) { $announcement = Announcement::findOrFail($announcement_id); if ($request->input('title') != $announcement->title) { $announcement->title = $request->title; } if ($request->input('path') != $announcement->path) { $announcement->path = $request->path; } if ($request->input('type') != $announcement->type) { $announcement->type = $request->type; } if ($request->input('start_time') != $announcement->start_time) { $announcement->start_time = $request->start_time; } if ($request->input('start_time') != $announcement->start_time) { $announcement->start_time = $request->start_time; } $announcement->save(); return $this->success('ok', $announcement); } public function deleteAnnouncement(Request $request, $announcement_id) { $announcement = Announcement::findOrFail($announcement_id); $announcement->delete(); return $this->success('ok'); } /** * 设置福恋推荐人推荐人 * 推荐人同时成为红娘 * 推荐人推荐注册成功获得一元现金奖励 * 推荐人推荐实名认证成功获得二元现金奖励 * @param Request $request [description] * @param [type] $user_id [description] */ public function setReferre(Request $request, $user_id) { $user = User::findOrFail($user_id); //设置成为推荐人 $referre = Referre::firstOrCreate([ 'user_id'=>$user_id, ]); //设置红娘 $maker = Matchmaker::firstOrCreate([ 'user_id'=>$user_id, ]); $maker->status = 1; $maker->save(); return $this->success('ok'); } /** * 福恋使者列表 * 显示推荐人数和总奖励 * @param Request $request [description] * @return [type] [description] */ public function referres(Request $request) { $start_time = $request->input("start_time"); $end_time = $request->input('end_time'); $referres = Referre::orderBy('num', 'desc')->orderBy('id', 'desc'); $keyword = $request->input('keyword'); if (!empty($keyword)) { $keyword = trim($keyword); $referres = $referres->whereHas('user', function($sql) use($keyword){ $sql->where('name', 'like', '%'.$keyword.'%'); }); } $referres = $referres->paginate(); foreach ($referres as $referre) { $user = User::where('id', $referre->user_id)->select('id', 'name', 'circle_avatar')->first(); if (empty($user)) { continue; } $referre->name = $user->name; $referre->circle_avatar = $user->circle_avatar; if ($start_time && $end_time) { $amount = ReferreAwardHistory::where('user_id', $user->id)->where('is_hooked', 1)->where('created_at','>=', $start_time)->where('created_at', '<', $end_time)->sum('amount'); $num = ReferreAwardHistory::where('user_id', $user->id)->where('type', 'register')->where('is_hooked', 1)->where('created_at','>=', $start_time)->where('created_at', '<', $end_time)->count(); $referre->num = $num; }else{ $amount = ReferreAwardHistory::where('user_id', $user->id)->where('is_hooked', 1)->sum('amount'); } $referre->amount = $amount?$amount:0.00; } return $this->success('ok', $referres); } /** * 修改福恋使者 */ public function updateReferre(Request $request, Referre $referre) { if ($request->input('register_amount') && $referre->register_amount != $request->register_amount && $request->register_amount < 10) { $referre->register_amount = $request->register_amount; } if ($request->input('approve_amount') && $referre->approve_amount != $request->approve_amount && $request->approve_amount < 10) { $referre->approve_amount = $request->approve_amount; } $referre->save(); return $this->success('ok', $referre); } /** * 新增福恋使者人数 * @param Request $request [description] * @return [type] [description] */ public function newReferreNum(Request $request, Referre $referre) { $start_time = $request->input("start_time", date('Y-m-d')); $end_time = $request->input('end_time', date('Y-m-d H:i:s')); if (empty($start_time) || empty($end_time)) { $referre_count = $referre->count(); }else{ $referre_count = $referre->where('created_at', '>=', $start_time)->where('created_at', '<', $end_time)->count(); } return $this->success('ok', compact('referre_count')); } // public function /** * 推荐人推荐奖励记录 * @param Request $request [description] * @param [type] $user_id [description] * @return [type] [description] */ public function referreAwardHistories(Request $request, $user_id) { $histories = ReferreAwardHistory::where('user_id', $user_id); $keyword = $request->input('keyword'); if ($keyword) { $keyword = trim($keyword); $histories = $histories->whereHas("otherUser", function($sql) use($keyword){ $sql->where('name','like', '%'.$keyword.'%') ->orWhere('mobile', 'like', '%'.$keyword.'%'); }); } $histories = $histories->where('is_hooked', 1)->orderBy('id', 'desc')->paginate(); foreach ($histories as $history) { $user = User::where('id', $history->user_id)->select('id', 'name', 'circle_avatar')->first(); if (empty($user)) { continue; } $history->name = $user->name; $history->circle_avatar = $user->circle_avatar; $other_user = User::where('id', $history->other_user_id)->select('id', 'name', 'circle_avatar')->first(); if (empty($other_user)) { continue; } $history->other_user_name = $other_user->name; $history->other_user_circle_avatar = $other_user->circle_avatar; } return $this->success('ok', $histories); } /** * 删除用户推荐 * @param Referre $referre [description] * @return [type] [description] */ public function deleteReferre(Referre $referre) { $referre->delete(); return $this->success('ok'); } /** * 提示消息数 * @param Request $request [description] * @param ApproveHistory $approveHistory [description] * @param User $user [description] * @param FeedbackHistory $feedback [description] * @param ComplaintHistory $complaint [description] * @return [type] [description] */ public function notices(Request $request, ApproveHistory $approveHistory, User $user, FeedbackHistory $feedback, ComplaintHistory $complaint) { $admin_type = $request->session()->get('admin_type'); if ($admin_type == 'paas_admin') { $paas_obj = $request->session()->get('paas_obj'); $paas_user_ids = $this->userCon->paasUserIds($paas_obj->name, 'MAIN'); //未审核实名认证申请 $approve_count = $approveHistory->whereIn('user_id', $paas_user_ids)->where('type', 'name')->where('status', 0)->count(); //未审核头像 $photo_count = $user->whereIn('id', $paas_user_ids)->whereNotNull('photo')->where('is_photo_audited', 0)->count(); //反馈 $feedback_count = $feedback->whereIn('user_id', $paas_user_ids)->whereHas('user', function($sql){ $sql->where('id', '>', 0); })->where('status', 0)->count(); //投诉 $complaint_count = $complaint->whereIn('user_id', $paas_user_ids)->where('status', 0)->count(); // 获取不存在备注的用户数量 $nocommuser_count = User::where('created_at', '>', '2019-12-01 00:00:00')->whereIn('id', $paas_user_ids)->where('tag_num', 0)->count(); // 获取不存在备注的订单数量 $paas_order_ids = Order::where('type', '<>', 'activity')->whereIn('user_id', $paas_user_ids)->pluck('id')->toArray(); $activity_ids = PaasActivity::where('paas_id', $paas_obj->id)->pluck('activity_id'); $paas_activity_order_ids = Order::whereIn('type_id', $activity_ids)->where('type', 'activity')->pluck('id')->toArray(); $new_paas_order_ids = array_merge($paas_order_ids, $paas_activity_order_ids); $nocommorder_count = Order::whereIn('id', $new_paas_order_ids)->where('created_at', '>', '2019-12-01 00:00:00')->where('tag_num', 0)->count(); }else{ //未审核实名认证申请 $approve_count = $approveHistory->where('type', 'name')->where('status', 0)->count(); //未审核头像 $photo_count = $user->whereNotNull('photo')->where('is_photo_audited', 0)->count(); //反馈 $feedback_count = $feedback->whereHas('user', function($sql){ $sql->where('id', '>', 0); })->where('status', 0)->count(); //投诉 $complaint_count = $complaint->where('status', 0)->count(); $admin_user_id = auth()->id(); //是否是推广团队 $is_promote = RoleUser::where('user_id', $admin_user_id)->where('role_id', 6)->count(); $platfroms = Platform::where('paas_id', 33)->pluck('app_id')->toArray(); // 获取不存在备注的用户数量 $nocommuser_count = User::where('created_at', '>', '2019-12-01 00:00:00')->where('tag_num', 0); if($is_promote){ $nocommuser_count = $nocommuser_count->whereIn('from_platform', $platfroms); } $nocommuser_count = $nocommuser_count->count(); // 获取不存在备注的订单数量 $nocommorder_count = Order::where('created_at', '>', '2019-12-01 00:00:00')->where('user_id', '!=', 616)->where('pay_status', 'PAID')->where('tag_num', 0); if($is_promote){ $nocommuser_count = $nocommuser_count->whereHas('user', function($query) use ($platfroms){ $query->whereIn('from_platform', $platfroms); }); } $nocommorder_count = $nocommorder_count->count(); } return $this->success('ok', compact('approve_count', 'photo_count', 'feedback_count', 'complaint_count', 'nocommuser_count', 'nocommorder_count')); } /*意见反馈complaintsMGT/suggestionFeedback * */ // public function newNotices(Request $request, ApproveHistory $approveHistory, User $user, FeedbackHistory $feedback, ComplaintHistory $complaint){ // $path_arr = Menu::whereIn('title', ['人工认证', '用户列表', '订单列表', '反馈列表', '投诉列表', '头像审核', '学历认证'])->pluck('menu_path')->toArray(); // $admin_user_id = auth()->id(); // $is_promote = RoleUser::where('user_id', $admin_user_id)->where('role_id', 6)->count(); // $platfroms = Platform::where('paas_id', 33)->pluck('app_id')->toArray(); // $notices = []; // //一级菜单是否显示红点用,显示消息的菜单都是固定死的,所以写死 // $user_count = 0; // $order_count = 0; // $approve_count = 0; // $educate_count = 0; // foreach ($path_arr as $path){ // switch ($path){ // case '/certificationMGT/realNameCertification': //人工认证 // $user_ids = $approveHistory->where('type','body')->where('ways',1)->where('status',0)->distinct('user_id')->pluck('user_id'); // $count = $user->whereIn('id',$user_ids)->whereNotNull('identification_photos')->count(); // $approve_count += $count; // break; // case '/certificationMGT/educationCertification': //学历认证 // $count = $approveHistory->with('user')->whereHas('user')->where('type', 'educate')->where('status', 0)->count(); // $educate_count += $count; // break; // case '/userMGT/userList': //用户列表 // $count = User::where('created_at', '>', '2019-12-01 00:00:00')->where('tag_num', 0); // if($is_promote){ // $count = $count->whereIn('from_platform', $platfroms); // } // $count = $count->count(); // $user_count += $count; // break; // case '/orderMGT/orderList': //订单列表 // $count = Order::where('created_at', '>', '2019-12-01 00:00:00')->where('user_id', '!=', 616)->where('pay_status', 'PAID')->where('tag_num', 0); // if($is_promote){ // $count = $count->whereHas('user', function($query) use ($platfroms){ // $query->whereIn('from_platform', $platfroms); // }); // } // $count = $count->count(); // $order_count += $count; // break; // case '/userMGT/feedbackList': //反馈列表 // $count = $feedback->whereHas('user',function($sql){ // $sql->where('id','>',0); // })->where('status', 0)->where('type', '!=', 'team')->count(); // $user_count += $count; // break; // case '/userMGT/complaintsList': //投诉列表 // $count = $complaint->whereHas('user')->where('status', 0)->where('type', '!=', 'moment')->count(); // $user_count += $count; // break; // case '/certificationMGT/portraitAudit': //头像审核🐕 // $count = $user->whereNotNull('photo')->where('is_photo_audited', 0)->count(); // $approve_count += $count; // break; // default: // break; // } // $arr['count'] = $count; // $arr['path'] = $path; // $arr['overflowCount'] = 999; // $arr['dot'] = false; // $arr['offset'] = [-4,10]; // $notices[] = $arr; // } // $user_arr = [ // 'count' => $user_count, // 'path' => '/userMGT', // 'overflowCount' => 999, // 'dot' => $user_count ? true:false, // 'offset' =>[0,90], // ]; // $approve_arr = [ // 'count' => $approve_count, // 'path' => '/certificationMGT', // 'overflowCount' => 999, // 'dot' => $approve_count ? true: false, // 'offset' =>[0,90], // ]; // $order_arr = [ // 'count' => $order_count, // 'path' => '/orderMGT', // 'overflowCount' => 999, // 'dot' => $order_count ? true : false, // 'offset' =>[0,90], // ]; // array_push($notices, $user_arr, $approve_arr, $order_arr); // return $this->success('ok', $notices); // } public function newNotices(Request $request, ApproveHistory $approveHistory, User $user, FeedbackHistory $feedback, ComplaintHistory $complaint,Anchor $anchor,ConsultationRecords $record){ $title = ['人工认证'/*, '用户列表'*/,'意见反馈','用户举报','群聊举报', '订单列表', '反馈列表', '投诉列表', '头像认证', '学历认证','入驻管理','咨询管理','友福驿站','置顶推荐','真人认证审核','上墙管理', '关闭资料','兑换商品']; $path_arr = Menu::whereIn('title', $title)->pluck('menu_path')->toArray(); $admin_user_id = auth()->id(); $is_promote = RoleUser::where('user_id', $admin_user_id)->where('role_id', 6)->count(); $platfroms = Platform::where('paas_id', 33)->pluck('app_id')->toArray(); $notices = []; //一级菜单是否显示红点用,显示消息的菜单都是固定死的,所以写死 $user_count = 0; $order_count = 0; $approve_count = 0; $educate_count = 0; $complaint_count = 0; $service_count = 0; $drainage_count = 0; $platform_count = 0;//平台管理 $top_up_mgt_count = 0;//福币管理 $count = 0; foreach ($path_arr as $path){ switch ($path){ case '/CustomerServiceMGT/realNameAuthentication': //人工认证 $user_ids = $approveHistory->where('type','body')->where('ways',1)->where('status',0)->distinct('user_id')->pluck('user_id'); $count = $user->whereIn('id',$user_ids)->whereNotNull('identification_photos')->count(); $approve_count += $count; break; case '/CustomerServiceMGT/eduAntuentication': //学历认证 $count = $approveHistory->with('user')->whereHas('user')/*->whereHas('user.profileCourtship',function($sql){ $sql->whereNotNull('educate_photo'); })*/->where('type', 'educate')->where('status', 0)->count(); $educate_count += $count; break; case '/userMGT/userList': //用户列表 // $count = User::where('created_at', '>', '2019-12-01 00:00:00')->where('tag_num', 0); // if($is_promote){ // $count = $count->whereIn('from_platform', $platfroms); // } // $count = $count->count(); $count = 0; $user_count += $count; break; case '/orderMGT/orderList': //订单列表 $count = Order::where('created_at', '>', '2019-12-01 00:00:00')->where('user_id', '!=', 616)->where('pay_status', 'PAID')->where('tag_num', 0); if($is_promote){ $count = $count->whereHas('user', function($query) use ($platfroms){ $query->whereIn('from_platform', $platfroms); }); } $count = $count->count(); $order_count += $count; break; case '/CustomerServiceMGT/feedbackList': //反馈列表 $count = $feedback->whereHas('user',function($sql){ $sql->where('id','>',0); })->where('status', 0)->where('type', '!=', 'team')->count(); $user_count += $count; break; case '/CustomerServiceMGT/userReport': //投诉列表 $count = $complaint->whereHas('user')->where('status', 0)->whereNotIn('type', ['moment','bless'])->count(); $user_count += $count; break; case '/CustomerServiceMGT/imageAuthentication': //头像审核🐕 $count = $user->whereNotNull('photo')->where('is_photo_audited', 0)->count(); // $count = 0;//头像不需要人工审核 写死 0 ; $approve_count += $count; break; case '/CustomerServiceMGT/feedbackList'://意见反馈 $count = $feedback->whereHas('user',function($sql){ $sql->where('id','>',0); })->where('status', 0)->where('type', '!=', 'team')->count(); $complaint_count += $count; break; case '/CustomerServiceMGT/userReport'://用户举报 $count = $complaint->whereHas('user')->where('status', 0)->whereNotIn('type', ['moment','bless'])->count(); $complaint_count += $count; break; case '/complaintsMGT/groupReport'://群聊举报 $count = $feedback->whereHas('user',function($sql){ $sql->where('id','>',0); })->where('status', 0)->where('type', 'team')->count(); $complaint_count += $count; break; case '/teacherMGT/counselMGT'://咨询管理 $count = $record->where('pay_status',1)->where('status',0)->count();//未跟进 $service_count += $count; break; case '/teacherMGT/enterList'://入驻管理 $count = $anchor->where('status','0')->count();//未跟进 $service_count += $count; break; case '/leadFlowMGT/uLoveStation'://友福驿站 $count = $complaint->where('type','bless')->where('status',0)->count(); $drainage_count += $count; break; case '/CustomerServiceMGT/topRecommend'://置顶推荐 $count = AreaUser::with('user')->whereHas('user')->where('area_id',1)->where('is_audited',0)->count(); // $platform_count += $count; $platform_count =0; break; case '/CustomerServiceMGT/officialAccounts'://上墙管理 $count = UpperWallHistory::with('user')->whereHas('user')->where('status',0)->count(); $approve_count += $count; break; case '/CustomerServiceMGT/closeDataList'://关闭资料 $count = CloseProfileHistory::whereHas('user', function($sql) { $sql->where('hidden_profile', 'ALLSEX'); })->where('status', 0)->count(); $complaint_count += $count; break; case '/topUpMGT/exchangeShop':// $start_datetime = date('Y-m-d H:i:s', strtotime('-15 days')); $where = [['created_at', '>=', $start_datetime]]; $count = CoinExchange::where($where)->whereNull('shipping_no')->count(); $top_up_mgt_count += $count; break; default: break; } $arr['count'] = $count; $arr['path'] = $path; $arr['overflowCount'] = 999; $arr['dot'] = false; $arr['offset'] = [-4,10]; $notices[] = $arr; } $user_arr = [ 'count' => $user_count, 'path' => '/userMGT', 'overflowCount' => 999, 'dot' => $user_count ? true:false, 'offset' =>[0,90], ]; $approve_arr = [ 'count' => $approve_count, 'path' => '/certificationMGT', 'overflowCount' => 999, 'dot' => $approve_count ? true: false, 'offset' =>[0,90], ]; $order_arr = [ 'count' => $order_count, 'path' => '/orderMGT', 'overflowCount' => 999, 'dot' => $order_count ? true : false, 'offset' =>[0,90], ]; $complaint_arr = [ 'count' => $complaint_count, 'path' => '/complaintsMGT', 'overflowCount' => 999, 'dot' => $complaint_count ? true : false, 'offset' =>[0,90], ]; $service_arr = [ 'count' => $service_count, 'path' => '/teacherMGT', 'overflowCount' => 999, 'dot' => $service_count ? true : false, 'offset' =>[0,90], ]; $drainage_arr = [ 'count' => $drainage_count, 'path' => '/leadFlowMGT', 'overflowCount' => 999, 'dot' => $drainage_count ? true : false, 'offset' =>[0,90], ]; $platform_arr = [ 'count' => $platform_count, 'path' => '/platformMGT', 'overflowCount' => 999, 'dot' => $platform_count ? true : false, 'offset' =>[0,90], ]; $top_arr = [ 'count' => $platform_count, 'path' => '/recommendedMGT', 'overflowCount' => 999, 'dot' => $platform_count ? true : false, 'offset' =>[0,90], ]; $top_up_mgt_arr = [ 'count' => $top_up_mgt_count, 'path' => '/topUpMGT', 'overflowCount' => 999, 'dot' => $top_up_mgt_count ? true : false, 'offset' =>[0,90], ]; array_push($notices, $user_arr, $approve_arr, $order_arr,$complaint_arr,$service_arr,$drainage_arr,$platform_arr,$top_arr,$top_up_mgt_arr); return $this->success('ok', $notices); } //客服组 消息提醒 public function lastestNotices(Request $request, User $user,ComplaintHistory $complaint,FeedbackHistory $feedback,ApproveHistory $approveHistory){ $path_arr = Menu::whereIn('title', ['用户举报','意见反馈','真人认证审核','学历认证','置顶推荐','上墙管理'])->pluck('menu_path')->toArray(); $notices = []; $client_count = 0; $count = 0; foreach ($path_arr as $key => $path) { switch ($path) { case '/CustomerServiceMGT/userReport': $count = $complaint->whereHas('user')->where('status', 0)->whereNotIn('type', ['moment','bless'])->count(); $client_count += $count; break; case '/CustomerServiceMGT/feedbackList': $count = $feedback->whereHas('user',function($sql){ $sql->where('id','>',0); })->where('status', 0)->where('type', '!=', 'team')->count(); $client_count += $count; break; case '/CustomerServiceMGT/realNameAuthentication': $user_ids = $approveHistory->where('type','body')->where('ways',1)->where('status',0)->distinct('user_id')->pluck('user_id'); $count = $user->whereIn('id',$user_ids)->whereNotNull('identification_photos')->count(); $client_count += $count; break; case '/CustomerServiceMGT/eduAntuentication': $count = $approveHistory->with('user')->whereHas('user')->where('type', 'educate')->where('status', 0)->count(); $client_count += $count; break; case '/CustomerServiceMGT/topRecommend': $count = AreaUser::with('user')->whereHas('user')->where('area_id',1)->where('is_audited',0)->count(); $client_count += $count; break; case '/CustomerServiceMGT/imageAuthentication': $count = $user->where('is_photo_audited',0)->count(); $client_count += $count; break; case '/CustomerServiceMGT/officialAccounts': // $count = UpperWallHistory::where('status',0)->count(); $count = 1; $client_count += $count; break; default: # code... break; } $arr['count'] = $count; $arr['path'] = $path; $arr['overflowCount'] = 999; $arr['dot'] = false; $arr['offset'] = [-4,10]; $notices[] = $arr; } $client_arr = [ 'count' => $client_count, 'path' => '/CustomerServiceMGT', 'overflowCount' => 999, 'dot' => $client_count ? true : false, 'offset' =>[0,90], ]; array_push($notices, $client_arr); return $this->success('ok', $notices); } //过去十二个月的数据 public function monthCount(Request $request){ $time = date('Y-m-1 00:00:00'); $user_id = auth()->id(); $arr = array(); for($i = 11;$i >= 0; $i--){ $month = (new Carbon)->setTimeFromTimeString($time)->addMonths(-$i)->toDateTimeString(); $month = date('Y-m',strtotime($month)); $months[]=$month; } for($j = 0; $j<=11;$j++){ $start = date('Y-m-01',strtotime($months[$j])); if($j == 11) { $end = date('Y-m-01',strtotime('+1 month',strtotime($months[11]))); }else{ $end = date('Y-m-01',strtotime($months[$j+1])); } $count[] = User::whereBetween('created_at', [$start,$end])->count(); } return $this->success('ok', compact('months', 'count')); } //周小程序、APP、H5用户统计 public function weekUserStat(Request $request){ $key = 'week_user_stat'; if ($request->forget) { Cache::forget($key); } if($request->start_time){ //有搜索条件 走数据库 $start_time = $request->start_time; $date[] = $start_time; for($i=1; $i<7; $i++){ $date[] = date("Y-m-d 00:00:00",strtotime("+$i day", strtotime($start_time))); } $all_app_count = 0; $all_mini_count = 0; $all_h5_count = 0; foreach ($date as $start_time){ $end_time = date("Y-m-d 23:59:59",strtotime($start_time)); $app_user_ids = Db::table('user_register_channels')->where('channel', '!=', 'mini_program')->whereBetween('created_at', [$start_time, $end_time])->pluck('user_id')->toArray(); $app_count = User::whereIn('id', $app_user_ids)->count(); $mini_count = User::whereNotIn('id', $app_user_ids)->whereBetween('created_at', [$start_time, $end_time])->count(); $h5_count = Viewer::whereBetween('created_at', [$start_time, $end_time])->count(); $arr['app_count'] = $app_count; $arr['mini_count'] = $mini_count; $arr['h5_count'] = $h5_count; $date_arr[] = $start_time; $all_app_count += $app_count; $all_mini_count += $mini_count; $all_h5_count += $h5_count; $count[] = $arr; } $all_count = [$all_app_count, $all_mini_count, $all_h5_count]; return $this->success('ok', compact('count', 'date_arr', 'all_count')); }else{ //没有搜索条件 有缓存 走缓存 if (Cache::has($key)){ $data = Cache::get($key); return $this->success('ok',$data); }else{//没有搜索条件 没有缓存 放入缓存 $start_time=date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"))); $date[] = $start_time; for($i=1; $i<7; $i++){ $date[] = date("Y-m-d 00:00:00",strtotime("+$i day", strtotime($start_time))); } $all_app_count = 0; $all_mini_count = 0; $all_h5_count = 0; foreach ($date as $start_time){ $end_time = date("Y-m-d 23:59:59",strtotime($start_time)); $app_user_ids = Db::table('user_register_channels')->where('channel', '!=', 'mini_program')->whereBetween('created_at', [$start_time, $end_time])->pluck('user_id')->toArray(); $app_count = User::whereIn('id', $app_user_ids)->count(); $mini_count = User::whereNotIn('id', $app_user_ids)->whereBetween('created_at', [$start_time, $end_time])->count(); $h5_count = Viewer::whereBetween('created_at', [$start_time, $end_time])->count(); $arr['app_count'] = $app_count; $arr['mini_count'] = $mini_count; $arr['h5_count'] = $h5_count; $date_arr[] = $start_time; $all_app_count += $app_count; $all_mini_count += $mini_count; $all_h5_count += $h5_count; $count[] = $arr; } $all_count = [$all_app_count, $all_mini_count, $all_h5_count]; $data = ['count'=>$count,'date_arr'=>$date_arr,'all_count'=>$all_count]; Cache::put($key,$data,86400); return $this->success('ok', compact('count', 'date_arr', 'all_count')); } } } //服务器报错日志 public function errorLogs(Request $request){ $log = DB::table('error_logs')->orderBy('id', 'desc'); if(is_numeric($request->status)){ $log = $log->where('status', $request->status); } if(is_numeric($request->count)){ $log = $log->where('count', '>=',$request->status); } if($request->keyword){ $log = $log->where('message', 'like', '%'.$request->keyword.'%'); } $log = $log->paginate(); return $this->success('ok', $log); } //处理服务器错误 public function errorUpdate(Request $request, $log_id){ $status = $request->input('status', 1); DB::table('error_logs')->where('id', $log_id)->update(['status'=>$status]); return $this->success('ok'); } public function errorLog(Request $request, $log_id){ $log = DB::table('error_logs')->where('id', $log_id)->first(); return $this->success('ok', $log); } //app更新日志 public function appLogs(Request $request){ $logs = AppLog::orderBy('id', 'desc'); if($request->keyword){ $keyword = $request->keyword; $logs = $logs->where('next_version', 'like', '%'.$keyword.'%'); } if(is_numeric($request->is_forced)){ $logs = $logs->where('is_forced', $request->is_forced); } if(is_numeric($request->is_check_forced)){ $logs = $logs->where('is_check_forced', $request->is_check_forced); } if(is_numeric($request->type)){ $logs = $logs->where('type', $request->type); } $logs = $logs->paginate(); return $this->success('ok', $logs); } public function appLog(Request $request, $log_id){ $log = AppLog::find($log_id); return $this->success('ok', $log); } //创建APP日志 public function addAppLog(Request $request){ $appLog = New AppLog(); $appLog->is_forced = $request->input('is_forced', 0); $appLog->is_check_forced = $request->input('is_check_forced', 0); $appLog->apk = $request->apk; $appLog->type = $request->type ?:0; $appLog->now_version = $request->now_version; $appLog->next_version = $request->next_version; $appLog->start_time = $request->start_time; $appLog->point = $request->point; $appLog->and_app_code = $request->and_app_code ? : '00'; $appLog->save(); return $this->success('ok'); } //更新APP日志 public function updateAppLog(Request $request, $log_id){ $log = AppLog::find($log_id); if(is_numeric($request->is_forced) && $request->is_forced != $log->is_forced){ $log->is_forced = $request->is_forced; } if(is_numeric($request->is_check_forced) && $request->is_check_forced != $log->is_check_forced){ $log->is_check_forced = $request->is_check_forced; } if(is_numeric($request->type) && $request->type != $log->type){ $log->type = $request->type; } if($request->apk && $request->apk != $log->apk){ $log->apk = $request->apk; } if($request->now_version && $request->now_version != $log->now_version){ $log->now_version = $request->now_version; } if($request->next_version && $request->next_version != $log->next_version){ $log->next_version = $request->next_version; } if($request->start_time && $request->start_time != $log->start_time){ $log->start_time = $request->start_time; } if($request->point && $request->point != $log->point){ $log->point = $request->point; } if($request->and_app_code && $request->and_app_code != $log->and_app_code){ $log->and_app_code = $request->and_app_code; } $log->save(); return $this->success('ok'); } //删除APP日志 public function delAppLog(Request $request, $log_id){ AppLog::where('id', $log_id)->delete(); return $this->success('ok'); } //用户签到统计 public function signLog(Request $request){ if($request->start_time && $request->end_time){ $start_time = $request->start_time; $end_time = $request->end_time; //间隔天数 $between_time = ceil((strtotime($end_time) - strtotime($start_time))/3600/24) + 1; for($i=0; $i<$between_time; $i++){ $date[] = date("Y-m-d 00:00:00",strtotime("+$i day", strtotime($start_time))); } } foreach ($date as $start_time) { $end_time = date("Y-m-d 23:59:59",strtotime($start_time)); $date_arr[] = $start_time; $mini_count = SignLog::where('source',1)->whereBetween('sign_date',[$start_time,$end_time])->count(); $minis_count [] = $mini_count; $app_count = SignLog::where('source',2)->whereBetween('sign_date',[$start_time,$end_time])->count(); $apps_count [] = $app_count; } return $this->success('ok',compact('date_arr','minis_count','apps_count')); } // 小程序首页 活动服务推荐 public function setMpRecommendServices(Request $request){ try { $recommend_ids = $request->recommend_ids; if(count($recommend_ids) != count(array_unique($recommend_ids))) return $this->failure('推荐数据重复,请确认后再保存'); if(!in_array(count($recommend_ids),[4,8])) return $this->failure('推荐数目限制在4或8个'); RecommendCommunityActivity::where('id','>',0)->update(['is_show'=>0]); foreach ($recommend_ids as $key => $value) { RecommendCommunityActivity::updateOrCreate(['activity_id'=>$value],['is_show'=>1]); } return $this->success('ok'); } catch (\Exception $e) { $this->getError($e); return $this->failure('服务器休息,请稍后再试'); } } //获取小程序首页推荐服务 public function mpRecommendServices(Request $request){ try { $keyword = trim($request->keyword); $now = date('Y-m-d H:i:s'); $service = CommunityActivity::where('is_mp_show',1)->where(function($sql) use($now){ $sql->where('end_time', ">", $now)->orWhere(function($sq){ $sq->whereNull('start_time')->whereNull('end_time'); }); })->select('id','title','pic','class','is_mp_show'); if($keyword){ $service = $service->where('title','like',"%$keyword%"); } $service = $service->get(); // $activity_ids = RecommendCommunityActivity::where('is_show',1)->orderByDesc('is_top')->pluck('activity_id'); // $return = CommunityActivity::whereIn('id',$activity_ids)->select('id','title','pic','class','is_mp_show','end_time')->get(); $return = RecommendCommunityActivity::join('community_activities as ca', 'recommend_community_activities.activity_id', 'ca.id') ->select('ca.id','ca.title','ca.pic','ca.class','ca.is_mp_show','ca.end_time','recommend_community_activities.is_top') ->where('recommend_community_activities.is_show',1) ->orderByDesc('recommend_community_activities.is_top') ->get(); $now = date('Y-m-d H:i:s'); foreach ($return as $key => $value) { $value->activity_end = 0; if($value->class == 'many') continue; if($value->end_time && $value->end_time < $now){ $value->activity_end = 1; } } return $this->success('ok',compact('service','return')); } catch (\Exception $e) { $this->getError($e); return $this->failure('服务器休息,请稍后再试'); } } public function modifyRecommendService(Request $request) { try { $id = $request->input('id'); $is_top = $request->input('is_top',0); if (!is_numeric($is_top)) { return $this->failure('置顶参数错误'); } $data = RecommendCommunityActivity::query()->where('activity_id',$id)->first(); if ($data){ $data->is_top = $is_top; $data->save(); } return $this->success('ok',compact('is_top')); }catch (\Exception $e){ return $this->failure($e->getMessage()); } } public function statisticsUsers(Request $request){ try { if($request->start_time && $request->end_time){ $start_time = $request->start_time; $end_time = $request->end_time; //间隔天数 $between_time = ceil((strtotime($end_time) - strtotime($start_time))/3600/24) + 1; for($i=0; $i<$between_time; $i++){ $date[] = date("Y-m-d 00:00:00",strtotime("+$i day", strtotime($start_time))); } }else{ return $this->failure('请选择开始和结束时间'); } foreach ($date as $start_time) { $end_time = date("Y-m-d 23:59:59",strtotime($start_time)); $date_arr[] = $start_time; //评论次数 $comment_count[] = LabelHistory::whereBetween('created_at',[$start_time,$end_time])->count(); //关注次数 $follow_count[] = DB::table('followables')->where('followable_type', 'App\\Models\\User')->where('relation', 'follow')->whereBetween('created_at',[$start_time,$end_time])->count(); //打招呼次数 $friend_count[] = LinkingRequest::whereBetween('created_at',[$start_time,$end_time])->count(); //处理好友请求次数 $deal_friend_count[] = LinkingRequest::where('status','<>',0)->whereBetween('created_at',[$start_time,$end_time])->count(); //登录次数 $visit_count[] = DB::table('login_logs')->whereBetween('created_at',[$start_time,$end_time])->groupBy('user_id')->get()->count(); //真人认证次数 $approve_count[] = ApproveHistory::whereBetween('created_at',[$start_time,$end_time])->count(); } return $this->success('ok',compact('date_arr','comment_count','follow_count','friend_count','visit_count','approve_count','deal_friend_count')); } catch (\Exception $e) { $this->getError($e); return $this->failure('服务器休息,请稍后再试'); } } }