You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.8 KiB
62 lines
1.8 KiB
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: weizongsong
|
|
* Date: 2019-04-12
|
|
* Time: 22:34
|
|
*/
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Models\Orders;
|
|
use App\Models\Project;
|
|
use Illuminate\Http\Request;
|
|
|
|
class OrdersController extends CommonController
|
|
{
|
|
public $bladePath = "admin.orders";
|
|
public $urlPrefix = "admin/orders";
|
|
public $modelName = "订单";
|
|
public $modelClass = Orders::class;
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$projects = (new StatisticsController())->_checkProjects();
|
|
if (!$projects->count()) {
|
|
return $this->error($this->noProjects);
|
|
}
|
|
$project_id = request()->project_id ?? $projects->first()->id;
|
|
$project = Project::find($project_id);
|
|
|
|
$month = request()->month ?? date("Y-m");
|
|
$months = (new StatisticsController())->_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);
|
|
$this->model = $this->model->where("project_id", $project_id);
|
|
|
|
$data = $this->model
|
|
->with([
|
|
"orderItems",
|
|
"firstItem",
|
|
"lastItem",
|
|
"project",
|
|
"product",
|
|
"customer",
|
|
"manager",
|
|
"bed" => function ($query) {
|
|
$query->with(["room", "building"]);
|
|
}
|
|
])
|
|
->orderBy("id", "desc")
|
|
->paginate(10);
|
|
foreach ($data as $order) {
|
|
$order = $order->refreshTotal();
|
|
}
|
|
|
|
return view($this->bladePath . ".index", compact("data", "project_id", "month", "project"));
|
|
}
|
|
}
|