diff --git a/app/Http/Controllers/Admin/OrdersController.php b/app/Http/Controllers/Admin/OrdersController.php index 85fa95f..fbc1eec 100755 --- a/app/Http/Controllers/Admin/OrdersController.php +++ b/app/Http/Controllers/Admin/OrdersController.php @@ -37,13 +37,14 @@ class OrdersController extends CommonController $project = Project::find($project_id); $status = $request->get('status', 20); - $month = request()->month ?? date("Y-m"); - $months = (new StatisticsController())->_getMonths(); + $month = request()->month ?? '全部'; + $months = (new OrdersController())->_getMonths(); - $start_timestamp = strtotime($month); - $end_timestamp = strtotime("+1 month", strtotime($month)); - - $this->model = $this->model->whereRaw("UNIX_TIMESTAMP(`created_at`) >= " . $start_timestamp . " and UNIX_TIMESTAMP(`created_at`) < " . $end_timestamp); + if($month != '全部'){ + $start_timestamp = strtotime($month); + $end_timestamp = strtotime("+1 month", strtotime($month)); + $this->model = $this->model->whereRaw("UNIX_TIMESTAMP(`created_at`) >= " . $start_timestamp . " and UNIX_TIMESTAMP(`created_at`) < " . $end_timestamp); + } $this->model = $this->model->where("project_id", $project_id); if ($request->keyword) { @@ -113,6 +114,26 @@ class OrdersController extends CommonController return view($this->bladePath . ".index", compact("status", "data", "project_id", "month", "project", "hushizhang", "order_status_list")); } + public function _getMonths() + { + $months = []; + $months[] = '全部'; + for ($i = 1; $i <= 12; $i++) { + $mm = $i < 10 ? "0" . $i : $i; + $months[] = (date("Y") - 2) . "-" . $mm; + } + for ($i = 1; $i <= 12; $i++) { + $mm = $i < 10 ? "0" . $i : $i; + $months[] = (date("Y") - 1) . "-" . $mm; + } + for ($i = 1; $i <= 12; $i++) { + $mm = $i < 10 ? "0" . $i : $i; + $months[] = date("Y") . "-" . $mm; + } + view()->share(compact("months")); + return $months; + } + public function changeItem(Request $request) { $item = OrderItems::with(["order", "siblings"])->find($request->item_id); diff --git a/app/Http/Controllers/Admin/StatisticsController.php b/app/Http/Controllers/Admin/StatisticsController.php index dd3df5e..3f7205b 100755 --- a/app/Http/Controllers/Admin/StatisticsController.php +++ b/app/Http/Controllers/Admin/StatisticsController.php @@ -58,7 +58,6 @@ class StatisticsController extends CommonController public function _getMonths() { $months = []; - $months[] = '全部'; for ($i = 1; $i <= 12; $i++) { $mm = $i < 10 ? "0" . $i : $i; $months[] = (date("Y") - 2) . "-" . $mm; @@ -71,7 +70,7 @@ class StatisticsController extends CommonController $mm = $i < 10 ? "0" . $i : $i; $months[] = date("Y") . "-" . $mm; } - dump($months); + view()->share(compact("months")); return $months; }