78 lines
No EOL
1.9 KiB
PHP
78 lines
No EOL
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\SyS;
|
|
|
|
use Request;
|
|
use Carbon;
|
|
use App\Models\SySetting;
|
|
use App\Models\ShoppingOrder;
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
|
class SalesController extends Controller
|
|
{
|
|
protected $userRepo;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->middleware('sysadmin');
|
|
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$start = 2019;
|
|
$end = date('Y');
|
|
$years = range($start, $end);
|
|
|
|
if(Request::get('filter_sales_year')){
|
|
$active_year = Request::get('filter_sales_year');
|
|
}else{
|
|
$active_year = $end;
|
|
}
|
|
|
|
$date1 = Carbon::parse('01.01.'.$active_year." 00:00:00")->format('Y-m-d H:i:s');
|
|
$date2 = Carbon::parse('31.12.'.$active_year." 23:59:59")->toDateString();
|
|
|
|
|
|
$values = ShoppingOrder::where('shopping_orders.auth_user_id', '!=', NULL) //::with('shopping_user', )->select('shopping_orders.*')
|
|
->where('mode', '=', 'live')
|
|
->where('paid', '=', 1)
|
|
->whereHas('shopping_order_items', function($q) {
|
|
|
|
$q->where('product_id', 34)->OrWhere('product_id', 35)->OrWhere('product_id', 36)->OrWhere('product_id', 67)->OrWhere('product_id', 69);
|
|
})
|
|
->whereBetween('created_at', [$date1, $date2])
|
|
->get();
|
|
|
|
$data = [
|
|
'years' => $years,
|
|
'active_year' => $active_year,
|
|
'values' => $values,
|
|
];
|
|
return view('sys.sales.index', $data);
|
|
}
|
|
|
|
|
|
public function store()
|
|
{
|
|
|
|
$data = Request::all();
|
|
|
|
$data['active'] = isset($data['active']) ? true : false;
|
|
if($data['id'] === "new"){
|
|
$model = SySetting::create($data);
|
|
}else{
|
|
$model = SySetting::find($data['id']);
|
|
$model->fill($data);
|
|
$model->save();
|
|
}
|
|
|
|
|
|
\Session()->flash('alert-save', '1');
|
|
return redirect(route('sysadmin_settings'));
|
|
|
|
}
|
|
|
|
|
|
} |