コード例 #1
0
 public function dashboard($domain, $gen_id, $base_id = null)
 {
     //        $current_gen = Gen::getCurrentGen();
     if ($this->user->role == 0) {
         return $this->responseUnAuthorized('Bạn không có quyền truy cập dữ liệu này');
     }
     $data = [];
     if ($gen_id) {
         $current_gen = Gen::find($gen_id);
     } else {
         return response()->json([message => "gen_id is required"], 400);
     }
     $data['current_gen'] = $this->genTransformer->transform($current_gen);
     if ($base_id == null) {
         $zero_paid_num = Register::where('gen_id', $current_gen->id)->where('status', '=', 1)->where('money', '=', 0)->count();
         $total_money = Register::where('gen_id', $current_gen->id)->sum('money');
         $num = Register::where('gen_id', $current_gen->id)->count();
         $paid_number = Register::where('gen_id', $current_gen->id)->where('code', "!=", "")->count();
         $uncalled_number = Register::where('gen_id', $current_gen->id)->where('call_status', 0)->groupBy('user_id')->count();
         $total_classes = $current_gen->studyclasses->count();
         $remain_days = strtotime($current_gen->end_time) - time();
         $registers_by_date = Register::select(DB::raw('count(1) as num'))->where('gen_id', $current_gen->id)->groupBy(DB::raw('DATE(created_at)'))->pluck('num')->toArray();
         $money_by_date = Register::select(DB::raw('sum(money) as money'))->where('gen_id', $current_gen->id)->groupBy(DB::raw('DATE(paid_time)'))->pluck('money')->toArray();
         $registers_by_hour = Register::select(DB::raw('HOUR(created_at) as \'hour\', count(1) as num'))->where('gen_id', $current_gen->id)->groupBy(DB::raw('HOUR(created_at)'))->get();
         $registers_hour_array = array();
         for ($i = 0; $i < 24; $i++) {
             $registers_hour_array[$i] = 0;
         }
         foreach ($registers_by_hour as $regis) {
             $registers_hour_array[$regis->hour] = $regis->num;
         }
         $data['money_by_date'] = $money_by_date;
         $data['zero_paid_num'] = $zero_paid_num;
         $data['classes'] = $this->classTransformer->transformCollection($current_gen->studyclasses);
         $data['total_money'] = is_numeric($total_money) ? $total_money : 0;
         $data['register_number'] = is_numeric($num) ? $num : 0;
         $data['paid_number'] = is_numeric($paid_number) ? $paid_number : 0;
         $data['uncalled_number'] = is_numeric($uncalled_number) ? $uncalled_number : 0;
         $data['total_classes'] = is_numeric($total_classes) ? $total_classes : 0;
         $data['remain_days'] = round((is_numeric($remain_days) ? $remain_days : 0) / (24 * 3600), 2);
         $data['date_array'] = createDateRangeArray(strtotime($current_gen->start_time), strtotime($current_gen->end_time));
         $data['registers_by_date'] = $registers_by_date;
         $data['registers_by_hour'] = $registers_hour_array;
     } else {
         $base = Base::find($base_id);
         $classes = $base->classes()->where('gen_id', $current_gen->id);
         $registers = Register::where('gen_id', $current_gen->id)->where('gen_id', $current_gen->id)->whereIn('class_id', $classes->pluck('id'));
         $zero_paid_num = Register::where('status', '=', 1)->where('money', '=', 0)->whereIn('class_id', $classes->pluck('id'))->count();
         $total_money = $registers->sum('money');
         $num = $registers->count();
         $paid_number = $registers->where('gen_id', $current_gen->id)->where('code', "!=", "")->count();
         $uncalled_number = $registers->where('call_status', 0)->groupBy('user_id')->count();
         $total_classes = $classes->count();
         $remain_days = strtotime($current_gen->end_time) - time();
         $classes_id = $classes->pluck("id");
         $registers_by_date = Register::select(DB::raw('count(1) as num'))->whereIn("class_id", $classes_id)->where('gen_id', $current_gen->id)->groupBy(DB::raw('DATE(created_at)'))->pluck('num')->toArray();
         $registers_by_hour = Register::select(DB::raw('HOUR(created_at) as \'hour\', count(1) as num'))->whereIn("class_id", $classes_id)->where('gen_id', $current_gen->id)->groupBy(DB::raw('HOUR(created_at)'))->get();
         $money_by_date = Register::select(DB::raw('sum(money) as money'))->whereIn("class_id", $classes_id)->where('gen_id', $current_gen->id)->groupBy(DB::raw('DATE(paid_time)'))->pluck('money')->toArray();
         $registers_hour_array = array();
         for ($i = 0; $i < 24; $i++) {
             $registers_hour_array[$i] = 0;
         }
         foreach ($registers_by_hour as $regis) {
             $registers_hour_array[$regis->hour] = $regis->num;
         }
         $data['money_by_date'] = $money_by_date;
         $data['zero_paid_num'] = $zero_paid_num;
         $data['classes'] = $this->classTransformer->transformCollection($current_gen->studyclasses);
         $data['total_money'] = is_numeric($total_money) ? $total_money : 0;
         $data['register_number'] = is_numeric($num) ? $num : 0;
         $data['paid_number'] = is_numeric($paid_number) ? $paid_number : 0;
         $data['uncalled_number'] = is_numeric($uncalled_number) ? $uncalled_number : 0;
         $data['total_classes'] = is_numeric($total_classes) ? $total_classes : 0;
         $data['remain_days'] = round((is_numeric($remain_days) ? $remain_days : 0) / (24 * 3600), 2);
         $data['date_array'] = createDateRangeArray(strtotime($current_gen->start_time), strtotime($current_gen->end_time));
         $data['registers_by_date'] = $registers_by_date;
         $data['registers_by_hour'] = $registers_hour_array;
     }
     return response()->json($data, 200);
 }
コード例 #2
0
ファイル: HomeController.php プロジェクト: Kaelcao/colormev2
 public function get_dashboard_data(Request $request)
 {
     $base_id = $request->base_id;
     $current_gen = Gen::getCurrentGen();
     $gen_id = $request->gen_id;
     if ($gen_id) {
         $current_gen = Gen::find($gen_id);
     }
     $this->data['current_gen'] = $current_gen;
     if ($base_id == null) {
         $zero_paid_num = Register::where('gen_id', $current_gen->id)->where('status', '=', 1)->where('money', '=', 0)->count();
         $total_money = Register::where('gen_id', $current_gen->id)->sum('money');
         $num = Register::where('gen_id', $current_gen->id)->count();
         $paid_number = Register::where('gen_id', $current_gen->id)->where('code', "!=", "")->count();
         $uncalled_number = Register::where('gen_id', $current_gen->id)->where('call_status', 0)->groupBy('user_id')->count();
         $total_classes = $current_gen->studyclasses->count();
         $remain_days = strtotime($current_gen->end_time) - time();
         $registers_by_date = Register::select(DB::raw('count(1) as num'))->where('gen_id', $current_gen->id)->groupBy(DB::raw('DATE(created_at)'))->pluck('num')->toArray();
         $money_by_date = Register::select(DB::raw('sum(money) as money'))->where('gen_id', $current_gen->id)->groupBy(DB::raw('DATE(paid_time)'))->pluck('money')->toArray();
         $registers_by_hour = Register::select(DB::raw('HOUR(created_at) as \'hour\', count(1) as num'))->where('gen_id', $current_gen->id)->groupBy(DB::raw('HOUR(created_at)'))->get();
         $orders_by_hour = Order::select(DB::raw('DATE(created_at) as date,count(1) as num'))->groupBy(DB::raw('DATE(created_at)'))->get();
         $e = date('Y-m-d', time());
         $s = date('Y-m-d', time() - 24 * 60 * 60 * 7 * 4);
         $month_ago = createDateRangeArray(strtotime($s), strtotime($e));
         $orders = [];
         foreach ($orders_by_hour as $i) {
             $orders[$i->date] = $i->num;
         }
         $return_orders = [];
         foreach ($month_ago as $day) {
             if (array_key_exists($day, $orders)) {
                 $return_orders[$day] = $orders[$day];
             } else {
                 $return_orders[$day] = 0;
             }
         }
         $registers_hour_array = array();
         for ($i = 0; $i < 24; $i++) {
             $registers_hour_array[$i] = 0;
         }
         foreach ($registers_by_hour as $regis) {
             $registers_hour_array[$regis->hour] = $regis->num;
         }
         $this->data['money_by_date'] = json_encode($money_by_date);
         $this->data['zero_paid_num'] = $zero_paid_num;
         $this->data['classes'] = $current_gen->studyclasses;
         $this->data['total_money'] = is_numeric($total_money) ? $total_money : 0;
         $this->data['register_number'] = is_numeric($num) ? $num : 0;
         $this->data['paid_number'] = is_numeric($paid_number) ? $paid_number : 0;
         $this->data['uncalled_number'] = is_numeric($uncalled_number) ? $uncalled_number : 0;
         $this->data['total_classes'] = is_numeric($total_classes) ? $total_classes : 0;
         $this->data['remain_days'] = round((is_numeric($remain_days) ? $remain_days : 0) / (24 * 3600), 2);
         $this->data['date_array'] = json_encode(createDateRangeArray(strtotime($current_gen->start_time), strtotime($current_gen->end_time)));
         $this->data['registers_by_date'] = json_encode($registers_by_date);
         $this->data['registers_by_hour'] = json_encode($registers_hour_array);
         $this->data['orders_by_hour'] = json_encode(array_values($return_orders));
         $this->data['month_ago'] = json_encode($month_ago);
     } else {
         $base = Base::find($base_id);
         $classes = $base->classes()->where('gen_id', $current_gen->id);
         $registers = Register::where('gen_id', $current_gen->id)->where('gen_id', $current_gen->id)->whereIn('class_id', $classes->pluck('id'));
         $zero_paid_num = Register::where('status', '=', 1)->where('money', '=', 0)->whereIn('class_id', $classes->pluck('id'))->count();
         $total_money = $registers->sum('money');
         $num = $registers->count();
         $paid_number = $registers->where('gen_id', $current_gen->id)->where('code', "!=", "")->count();
         $uncalled_number = $registers->where('call_status', 0)->groupBy('user_id')->count();
         $total_classes = $classes->count();
         $remain_days = strtotime($current_gen->end_time) - time();
         $classes_id = $classes->pluck("id");
         $registers_by_date = Register::select(DB::raw('count(1) as num'))->whereIn("class_id", $classes_id)->where('gen_id', $current_gen->id)->groupBy(DB::raw('DATE(created_at)'))->pluck('num')->toArray();
         $registers_by_hour = Register::select(DB::raw('HOUR(created_at) as \'hour\', count(1) as num'))->whereIn("class_id", $classes_id)->where('gen_id', $current_gen->id)->groupBy(DB::raw('HOUR(created_at)'))->get();
         $money_by_date = Register::select(DB::raw('sum(money) as money'))->whereIn("class_id", $classes_id)->where('gen_id', $current_gen->id)->groupBy(DB::raw('DATE(paid_time)'))->pluck('money')->toArray();
         $registers_hour_array = array();
         for ($i = 0; $i < 24; $i++) {
             $registers_hour_array[$i] = 0;
         }
         foreach ($registers_by_hour as $regis) {
             $registers_hour_array[$regis->hour] = $regis->num;
         }
         $this->data['money_by_date'] = json_encode($money_by_date);
         $this->data['zero_paid_num'] = $zero_paid_num;
         $this->data['classes'] = $classes->get();
         $this->data['total_money'] = is_numeric($total_money) ? $total_money : 0;
         $this->data['register_number'] = is_numeric($num) ? $num : 0;
         $this->data['paid_number'] = is_numeric($paid_number) ? $paid_number : 0;
         $this->data['uncalled_number'] = is_numeric($uncalled_number) ? $uncalled_number : 0;
         $this->data['total_classes'] = is_numeric($total_classes) ? $total_classes : 0;
         $this->data['remain_days'] = round((is_numeric($remain_days) ? $remain_days : 0) / (24 * 3600), 2);
         $this->data['date_array'] = json_encode(createDateRangeArray(strtotime($current_gen->start_time), strtotime($current_gen->end_time)));
         $this->data['registers_by_date'] = json_encode($registers_by_date);
         $this->data['registers_by_hour'] = json_encode($registers_hour_array);
     }
     return view('components.dashboard_data', $this->data);
 }