海工商新版后台
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.
 
 

633 lines
21 KiB

<?php
namespace App\Http\Controllers;
use App\Models\AllocationDormitoryBed;
use App\Models\Bed;
use App\Models\Building;
use App\Models\Config;
use App\Models\DormitoryNumber;
use App\Models\DormitoryType;
use App\Models\Floor;
use App\Models\LivingArea;
use App\Models\MultipleWorld;
use App\Models\SecondaryCollege;
use App\Models\SelectedDormitory;
use App\Models\Speciality;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class AllocationDormitoryApi extends Controller
{
/**
* 获取几人间(床位列表模块)
* @return array
*/
public function getMultipleWorldsByList(Request $request)
{
$q = $request->input("q");
$dormitoryType = MultipleWorld::query()->where([
"status" => MultipleWorld::STATUS_YES,
"dormitory_type_id" => $q,
])->get(["id", "people"])->toArray();
$result = [];
foreach($dormitoryType as $item){
$result[] = [
"id" => $item["id"],
"text" => $item["people"]
];
}
return $result;
}
/**
* 返回性别列表
* @return array[]
*/
public function getSex(Request $request)
{
$sex = $request->input("sex");
$sex = rtrim($sex, "?");
if($sex == 1){
return [
[
"id" => 1,
"text" => "",
],
];
}else if($sex == 2){
return [
[
"id" => 2,
"text" => "",
],
];
}
}
/**
* 获取专业信息
* @param Request $request
* @return array
*/
public function getSpeciality(Request $request)
{
$where = [
"status" => Speciality::STATUS_YES,
];
$specialityList = Speciality::query()->where($where)->get(["id", "speciality_name", "secondary_college_id"])->toArray();
$result = [];
foreach($specialityList as $item){
//二级学院
$college = SecondaryCollege::query()->where("id", $item["secondary_college_id"])->first();
$str = "(未找到二级学院信息)";
if(!empty($college)){
$str = "{$college->name}";
}
$result[] = [
"id" => $item["id"],
"text" => $item["speciality_name"].$str,
];
}
return $result;
}
/**
* 获取宿舍类型
* @return array
*/
public function getDormitoryType(Request $request)
{
$dormitory_type = rtrim($request->input("dormitory_type"), "?");
$dormitoryTypeModel = DormitoryType::query()->where([
"id" => $dormitory_type
]);
$dormitoryType = $dormitoryTypeModel->get(["id", "dormitory"])->toArray();
$result = [];
foreach($dormitoryType as $item){
$result[] = [
"id" => $item["id"],
"text" => $item["dormitory"],
];
}
return $result;
}
/**
* 获取几人间
* @return array
*/
public function getMultipleWorlds(Request $request)
{
$multiple_worlds = rtrim($request->input("multiple_worlds"), "?");
$dormitoryTypeModel = MultipleWorld::query()->where([
"id" => $multiple_worlds
]);
$dormitoryType = $dormitoryTypeModel->get(["id", "people"])->toArray();
$result = [];
foreach($dormitoryType as $item){
$result[] = [
"id" => $item["id"],
"text" => $item["people"]
];
}
return $result;
}
/**
* 获取生活区
* @return array
*/
public function getLiving(Request $request)
{
$living_quarters = rtrim($request->input("living_quarters"), "?");
$dormitoryType = LivingArea::query()->where([
"id" => $living_quarters
])->get(["id", "title"])->toArray();
$result = [];
foreach($dormitoryType as $item){
$result[] = [
"id" => $item["id"],
"text" => $item["title"]
];
}
return $result;
}
/**
* 获取楼栋
* @return array
*/
public function getBuilding(Request $request)
{
$building_id = rtrim($request->input("building_id"), "?");
$dormitoryType = Building::query()->where([
"id" => $building_id
])->get(["id", "building_title"])->toArray();
$result = [];
foreach($dormitoryType as $item){
$result[] = [
"id" => $item["id"],
"text" => $item["building_title"]
];
}
return $result;
}
/**
* 获取楼层
* @return array
*/
public function getFloor(Request $request)
{
$floor_id = rtrim($request->input("floor_id"), "?");
$dormitoryType = Floor::query()->where([
"id" => $floor_id
])->get(["id", "floor_title"])->toArray();
$result = [];
foreach($dormitoryType as $item){
$result[] = [
"id" => $item["id"],
"text" => $item["floor_title"]
];
}
return $result;
}
/**
* 获取宿舍号
* @return array
*/
public function getDormitoryNumber(Request $request)
{
$dormitory_number = rtrim($request->input("dormitory_number"), "?");
$dormitoryType = DormitoryNumber::query()->where([
"id" => $dormitory_number
])->get(["id", "dormitory_number"])->toArray();
$result = [];
foreach($dormitoryType as $item){
$result[] = [
"id" => $item["id"],
"text" => $item["dormitory_number"]
];
}
return $result;
}
/**
* 获取床位号
* @return array
*/
public function getBed(Request $request)
{
$bed_id = rtrim($request->input("bed_id"), "?");
$dormitoryType = Bed::query()->where([
"id" => $bed_id
])->get(["id", "bed_number"])->toArray();
$result = [];
foreach($dormitoryType as $item){
$result[] = [
"id" => $item["id"],
"text" => $item["bed_number"]
];
}
return $result;
}
/**
* 获取专业信息(联动)
* @param Request $request
* @return array
*/
public function getSpecialityLoad(Request $request)
{
$where = [
"status" => Speciality::STATUS_YES,
];
$specialityList = Speciality::query()->where($where)->get(["id", "speciality_name", "secondary_college_id"])->toArray();
$result = [];
foreach($specialityList as $item){
//二级学院
$college = SecondaryCollege::query()->where("id", $item["secondary_college_id"])->first();
$str = "(未找到二级学院信息)";
if(!empty($college)){
$str = "{$college->name}";
}
$result[] = [
"id" => $item["id"],
"text" => $item["speciality_name"].$str,
];
}
return $result;
}
/**
* 获取宿舍类型(联动)
* @param Request $request
* @return array
*/
public function getDormitoryTypeLoad(Request $request)
{
$sex = $request->input("sex");
$speciality_id = $request->input("q");
$DormitoryType = DormitoryType::query()->where("status", 1)->get(["id", DB::raw('dormitory as text')])->toarray();
$data = [];
foreach ($DormitoryType as $v) {
$data[] = [
"id" => json_encode([
"id" => $v["id"],
"sex" => $sex,
"speciality_id" => $speciality_id
]),
"text" => $v["text"]
];
}
return $data;
}
/**
* 获取几人间(联动)
* @param Request $request
* @return array
*/
public function getMultiplWorldsLoad(Request $request)
{
$dormitory_type = json_decode($request->get("q"), 1);
if (empty($dormitory_type)) {
return [];
}
$MultipleWorlds = MultipleWorld::query()->where("dormitory_type_id", $dormitory_type["id"])->get(["id", DB::raw('people as text'), "price"])->toarray();
$data = [];
foreach ($MultipleWorlds as $v) {
$data[] = [
"id" => json_encode([
"id" => $v["id"],
"dormitory_type" => $dormitory_type["id"],
"sex" => $dormitory_type["sex"],
"speciality_id" => $dormitory_type["speciality_id"],
]),
"text" => $v["text"]."{$v['price']}元)"
];
}
return $data;
}
/**
* 获取生活区(联动)
* @param Request $request
* @return array
*/
public function getLivingAreaLoad(Request $request)
{
$dormitory_type = json_decode($request->get("q"), 1);
if (empty($dormitory_type)) {
return [];
}
//取出当前年份
$config = Config::query()->where([
"unique_identification" => "annual_session"
])->first();
$living_area = AllocationDormitoryBed::query()
->where("multiple_worlds", $dormitory_type["id"])
->where("dormitory_type", $dormitory_type["dormitory_type"])
->where("sex", $dormitory_type["sex"])
->where("speciality_id", $dormitory_type["speciality_id"])
->where("annual_session", $config->data)
->where("status", AllocationDormitoryBed::STATUS_YES)
->distinct()->get("living_area")->toArray();
if (empty($living_area)) {
return [];
}
$LivingArea = LivingArea::query()->whereIn("id", $living_area)->get(["id", DB::raw('title as text')])->toarray();
$data = [];
foreach ($LivingArea as $v) {
$data[] = [
"id" => json_encode([
"multiple_worlds" => $dormitory_type["id"],
"dormitory_type" => $dormitory_type["dormitory_type"],
"living_area" => $v["id"],
"sex" => $dormitory_type["sex"],
"speciality_id" => $dormitory_type["speciality_id"],
]),
"text" => $v["text"]
];
}
return $data;
}
/**
* 获取楼栋(联动)
* @param Request $request
* @return array
*/
public function getBuildingLoad(Request $request)
{
$living_quarters = json_decode($request->get("q"), 1);
if (empty($living_quarters)) {
return [];
}
//取出当前年份
$config = Config::query()->where([
"unique_identification" => "annual_session"
])->first();
$building = AllocationDormitoryBed::query()
->where("living_area", $living_quarters["living_area"])
->where("multiple_worlds", $living_quarters["multiple_worlds"])
->where("dormitory_type", $living_quarters["dormitory_type"])
->where("sex", $living_quarters["sex"])
->where("speciality_id", $living_quarters["speciality_id"])
->where("annual_session", $config->data)
->where("status", AllocationDormitoryBed::STATUS_YES)
->distinct()
->get("building_id")->toArray();
if (empty($building)) {
return [];
}
$Building = Building::query()->whereIn("id", $building)->get(["id", DB::raw('building_title as text')])->toarray();
$data = [];
foreach ($Building as $v) {
$data[] = [
"id" => json_encode([
"multiple_worlds" => $living_quarters["multiple_worlds"],
"dormitory_type" => $living_quarters["dormitory_type"],
"living_area" => $living_quarters["living_area"],
"building" => $v["id"],
"sex" => $living_quarters["sex"],
"speciality_id" => $living_quarters["speciality_id"],
]),
"text" => $v["text"]
];
}
return $data;
}
/**
* 获取楼层(联动)
* @param Request $request
* @return array
*/
public function getFloorLoad(Request $request)
{
$building = json_decode($request->get("q"), 1);
if (empty($building)) {
return [];
}
//取出当前年份
$config = Config::query()->where([
"unique_identification" => "annual_session"
])->first();
$floor_id = AllocationDormitoryBed::query()
->where("living_area", $building["living_area"])
->where("multiple_worlds", $building["multiple_worlds"])
->where("dormitory_type", $building["dormitory_type"])
->where("building_id", $building["building"])
->where("sex", $building["sex"])
->where("speciality_id", $building["speciality_id"])
->where("annual_session", $config->data)
->where("status", AllocationDormitoryBed::STATUS_YES)
->distinct()
->get("floor_id")->toArray();
if (empty($floor_id)) {
return [];
}
$Building = Floor::query()->whereIn("id", $floor_id)->get(["id", DB::raw('floor_title as text')])->toarray();
$data = [];
foreach ($Building as $v) {
$data[] = [
"id" => json_encode([
"multiple_worlds" => $building["multiple_worlds"],
"dormitory_type" => $building["dormitory_type"],
"living_area" => $building["living_area"],
"building" => $building["building"],
"floor" => $v["id"],
"sex" => $building["sex"],
"speciality_id" => $building["speciality_id"],
]),
"text" => $v["text"]
];
}
return $data;
}
/**
* 获取宿舍号(联动)
* @param Request $request
* @return array
*/
public function getDormitoryNumberLoad(Request $request)
{
$floor = json_decode($request->get("q"), 1);
if (empty($floor)) {
return [];
}
//取出当前年份
$config = Config::query()->where([
"unique_identification" => "annual_session"
])->first();
$dormitory_number = AllocationDormitoryBed::query()
->where("living_area", $floor["living_area"])
->where("multiple_worlds", $floor["multiple_worlds"])
->where("dormitory_type", $floor["dormitory_type"])
->where("building_id", $floor["building"])
->where("floor_id", $floor["floor"])
->where("sex", $floor["sex"])
->where("speciality_id", $floor["speciality_id"])
->where("annual_session", $config->data)
->where("status", AllocationDormitoryBed::STATUS_YES)
->distinct()
->get("dormitory_number")->toArray();
if (empty($dormitory_number)) {
return [];
}
$DormitoryNumber = DormitoryNumber::query()->whereIn("id", $dormitory_number)->get(["id", DB::raw('dormitory_number as text')])->toarray();
$data = [];
foreach ($DormitoryNumber as $v) {
$data[] = [
"id" => json_encode([
"multiple_worlds" => $floor["multiple_worlds"],
"dormitory_type" => $floor["dormitory_type"],
"living_area" => $floor["living_area"],
"building" => $floor["building"],
"floor" => $floor["floor"],
"dormitory_number" => $v["id"],
"sex" => $floor["sex"],
"speciality_id" => $floor["speciality_id"],
]),
"text" => $v["text"]
];
}
return $data;
}
/**
* 获取床号(联动)
* @param Request $request
* @return array
*/
public function getBedLoad(Request $request)
{
$dormitory_number = json_decode($request->get("q"), 1);
if (empty($dormitory_number)) {
return [];
}
//取出当前年份
$config = Config::query()->where([
"unique_identification" => "annual_session"
])->first();
$bed = AllocationDormitoryBed::query()
->where("living_area", $dormitory_number["living_area"])
->where("multiple_worlds", $dormitory_number["multiple_worlds"])
->where("dormitory_type", $dormitory_number["dormitory_type"])
->where("building_id", $dormitory_number["building"])
->where("floor_id", $dormitory_number["floor"])
->where("dormitory_number", $dormitory_number["dormitory_number"])
->where("sex", $dormitory_number["sex"])
->where("speciality_id", $dormitory_number["speciality_id"])
->where("annual_session", $config->data)
->where("status", AllocationDormitoryBed::STATUS_YES)
->distinct()
->get("bed_id")->toArray();
if (empty($bed)) {
return [];
}
$DormitoryNumber = Bed::query()->whereIn("id", $bed)->get(["id", DB::raw('bed_number as text')])->toarray();
$data = [];
foreach ($DormitoryNumber as $v) {
//检测当前床位是否被选择
$bedInfo = AllocationDormitoryBed::query()
->where("living_area", $dormitory_number["living_area"])
->where("multiple_worlds", $dormitory_number["multiple_worlds"])
->where("dormitory_type", $dormitory_number["dormitory_type"])
->where("building_id", $dormitory_number["building"])
->where("floor_id", $dormitory_number["floor"])
->where("dormitory_number", $dormitory_number["dormitory_number"])
->where("bed_id", $v["id"])
->first();
if (empty($bedInfo)) {
$data[] = [
"id" => json_encode([
"multiple_worlds" => $dormitory_number["multiple_worlds"],
"dormitory_type" => $dormitory_number["dormitory_type"],
"living_area" => $dormitory_number["living_area"],
"building" => $dormitory_number["building"],
"floor" => $dormitory_number["floor"],
"dormitory_number" => $dormitory_number["dormitory_number"],
"id" => $v["id"],
"sex" => $dormitory_number["sex"],
"speciality_id" => $dormitory_number["speciality_id"],
]),
"text" => $v["text"] . "(以上条件下未分配床位)"
];
continue;
}
$selectedInfo = SelectedDormitory::query()->where([
"allocation_dormitory_id" => $bedInfo->id,
"status" => SelectedDormitory::STATUS_YES
])->first();
if (empty($selectedInfo)) {
$data[] = [
"id" => json_encode([
"multiple_worlds" => $dormitory_number["multiple_worlds"],
"dormitory_type" => $dormitory_number["dormitory_type"],
"living_area" => $dormitory_number["living_area"],
"building" => $dormitory_number["building"],
"floor" => $dormitory_number["floor"],
"dormitory_number" => $dormitory_number["dormitory_number"],
"id" => $v["id"]
]),
"text" => $v["text"] . "(可分配)"
];
} else {
$data[] = [
"id" => json_encode([
"multiple_worlds" => $dormitory_number["multiple_worlds"],
"dormitory_type" => $dormitory_number["dormitory_type"],
"living_area" => $dormitory_number["living_area"],
"building" => $dormitory_number["building"],
"floor" => $dormitory_number["floor"],
"dormitory_number" => $dormitory_number["dormitory_number"],
"id" => $v["id"]
]),
"text" => $v["text"] . "(不可分配)"
];
}
}
return $data;
}
}