upMerge branch 'master' of 210.16.180.245:/data/git/tiantian2

master
weizong song 2 years ago
commit 3b92d11c68

@ -17,6 +17,7 @@ use App\Models\Project;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Facades\Excel;
use Spatie\Permission\Models\Role;
class OrdersController extends CommonController
{
@ -43,22 +44,27 @@ class OrdersController extends CommonController
$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);
$user = auth()->user();
$areaId = AdminAreaLink::where('project_id', $project_id)->where('admin_id', $user->id)->pluck('area_id');
$bedList = Bed::whereIn('area_id',$areaId)->pluck('id');
if ($request->keyword) {
$this->model = $this->model->where(function ($query) use ($request) {
$query->where("serial", "like", "%" . $request->keyword . "%")
->orWhere("contact", "like", "%" . $request->keyword . "%")
->orWhere("mobile", "like", "%" . $request->keyword . "%");
})->where(function ($query) use ($bedList) {
if ($bedList->isNotEmpty()) {
$query->whereIn('bed_id', $bedList);
}
});
}
// 判断是否护士长
$userId = auth()->id();
$roleId = Role::where('name', 'like', '%护士长%')->where('guard_name', 'admin')->value('id');
$hushizhang = DB::table('model_has_roles')->where('role_id', $roleId)
->where('model_type', 'App\Admin')->where('model_id', $userId)->count();
if ($hushizhang) {
$user = auth()->user();
$areaId = AdminAreaLink::where('project_id', $project_id)->where('admin_id', $user->id)->pluck('area_id');
$bedList = Bed::whereIn('area_id', $areaId)->pluck('id');
$this->model = $this->model->whereIn('bed_id', $bedList);
}
if ($request->date) {
$this->model = $this->model->whereHas("orderItems", function ($query) use ($month, $request) {
$query->where("service_date", $month . "-" . $request->date);
@ -75,7 +81,7 @@ class OrdersController extends CommonController
"customer",
"manager",
"bed" => function ($query) {
$query->with(["room", "building","area"]);
$query->with(["room", "building", "area"]);
}
])
->orderBy("id", "desc");
@ -163,7 +169,7 @@ class OrdersController extends CommonController
$user = auth()->user();
$areaId = AdminAreaLink::where('project_id', $project_id)->where('admin_id', $user->id)->pluck('area_id');
$bedList = Bed::whereIn('area_id',$areaId)->pluck('id');
$bedList = Bed::whereIn('area_id', $areaId)->pluck('id');
$this->model = $this->model->where("project_id", $project_id)->whereNotNull("scored_at");
if (request()->keyword) {
@ -186,7 +192,7 @@ class OrdersController extends CommonController
"customer",
"manager",
"bed" => function ($query) {
$query->with(["room", "building","area"]);
$query->with(["room", "building", "area"]);
}
])
->orderBy("id", "desc")

@ -11,7 +11,9 @@ namespace App\Http\Controllers\Admin;
use App\Customer;
use App\Libs\AlipayF2F;
use App\Libs\WxMicroPay;
use App\Models\AdminAreaLink;
use App\Models\Balance;
use App\Models\Bed;
use App\Models\Factor;
use App\Models\FactorItems;
use App\Models\OrderItems;
@ -25,6 +27,7 @@ use App\Scopes\AdminProjectScope;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Spatie\Permission\Models\Role;
class StatisticsController extends CommonController
{
@ -35,7 +38,7 @@ class StatisticsController extends CommonController
public function _checkProjects()
{
$projects = (new Project())->adminProject()->orderBy("id","desc")->get();
$projects = (new Project())->adminProject()->orderBy("id", "desc")->get();
view()->share(compact("projects"));
return $projects;
}
@ -235,7 +238,27 @@ class StatisticsController extends CommonController
$month = request()->month ?? date("Y-m");
$months = $this->_getMonths();
// 判断是否护士长
$userId = auth()->id();
$roleId = Role::where('name', 'like', '%护士长%')->where('guard_name', 'admin')->value('id');
$hushizhang = DB::table('model_has_roles')->where('role_id', $roleId)
->where('model_type', 'App\Admin')
->where('model_id', $userId)
->count();
// 获取这个护士长病区的订单
$user = auth()->user();
$areaId = AdminAreaLink::where('project_id', $project_id)->where('admin_id', $user->id)->pluck('area_id');
$bedList = Bed::whereIn('area_id', $areaId)->pluck('id');
$orderIds = Orders::whereIn('bed_id', $bedList)->pluck('id');
$recharges = Recharge::with(["manager", "order", "patient"])
->where(function ($query) use ($hushizhang, $orderIds) {
if ($hushizhang) {
$query->whereIn('order_id', $orderIds);
}
})
->withCount("refunds")
->whereNotNull("paid_at")
->whereRaw("DATE_FORMAT(`paid_at`,'%Y-%m') = '{$month}'")
@ -243,7 +266,13 @@ class StatisticsController extends CommonController
$query->where("project_id", $project_id);
})
->get();
$refunds = Refund::whereNotNull("paid_at")
->where(function ($query) use ($hushizhang, $orderIds) {
if ($hushizhang) {
$query->whereIn('order_id', $orderIds);
}
})
->whereRaw("DATE_FORMAT(`paid_at`,'%Y-%m') = '{$month}'")
->whereHas("order", function ($query) use ($project_id) {
$query->where("project_id", $project_id);

Loading…
Cancel
Save