|
@@ -3,6 +3,7 @@
|
|
namespace App\Http\Controllers\Api\mini;
|
|
namespace App\Http\Controllers\Api\mini;
|
|
|
|
|
|
use App\Models\Order;
|
|
use App\Models\Order;
|
|
|
|
+use App\Models\OrderDevice;
|
|
use App\Models\Project;
|
|
use App\Models\Project;
|
|
use Carbon\Carbon;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
@@ -12,9 +13,12 @@ class DataController extends BaseController
|
|
{
|
|
{
|
|
protected $order;
|
|
protected $order;
|
|
|
|
|
|
|
|
+ protected $order_device;
|
|
|
|
+
|
|
public function __construct()
|
|
public function __construct()
|
|
{
|
|
{
|
|
$this->order = new Order();
|
|
$this->order = new Order();
|
|
|
|
+ $this->order_device = new OrderDevice();
|
|
}
|
|
}
|
|
|
|
|
|
public function getYearsAndMonths(Request $request)
|
|
public function getYearsAndMonths(Request $request)
|
|
@@ -59,7 +63,23 @@ class DataController extends BaseController
|
|
$date_data = $this->parseDate($date);
|
|
$date_data = $this->parseDate($date);
|
|
$date = Carbon::createFromDate($date_data['year'], $date_data['month'], $date_data['day'])->toDateTimeString();
|
|
$date = Carbon::createFromDate($date_data['year'], $date_data['month'], $date_data['day'])->toDateTimeString();
|
|
$ids = $request->input('project_ids');
|
|
$ids = $request->input('project_ids');
|
|
- $orders = $this->order->whereIn('project_id', $ids)->where('created_at', '>=', $date)->orderBy('created_at')->get();
|
|
|
|
|
|
+ $order_devices = $this->order_device->whereIn('project_id', $ids);
|
|
|
|
+
|
|
|
|
+ $in_items = ['device_ids', 'device_name_ids', 'spec_ids', 'rent_type_ids'];
|
|
|
|
+ $key_items = ['device_id', 'device_name_id', 'spec_id', 'rent_type_id'];
|
|
|
|
+ foreach ($in_items as $key => $item) {
|
|
|
|
+ if($request->input($item)) {
|
|
|
|
+ $item_ids = collect($request->input($item))->filter(function($id) {
|
|
|
|
+ return $id;
|
|
|
|
+ });
|
|
|
|
+ if($item_ids->count() > 0) {
|
|
|
|
+ $order_devices = $order_devices->whereIn($key_items[$key], $item_ids);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $order_ids = $order_devices->pluck('order_id')->unique();
|
|
|
|
+ $orders = $this->order->whereIn('id', $order_ids)->get();
|
|
$names = [];
|
|
$names = [];
|
|
$values = [];
|
|
$values = [];
|
|
// year|month
|
|
// year|month
|