|
|
|
@ -2,9 +2,9 @@ |
|
|
|
|
|
|
|
namespace App\Services; |
|
|
|
|
|
|
|
use App\Exceptions\CustomException; |
|
|
|
use App\Models\EventCalendar; |
|
|
|
use App\Models\ParkingPattern; |
|
|
|
use App\Models\ParkingPatternSpace; |
|
|
|
use Exception; |
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
@ -101,10 +101,13 @@ class EventCalendarService extends BaseService |
|
|
|
DB::beginTransaction(); |
|
|
|
$existsWhere = [ |
|
|
|
['pattern_id', '=', $data['pattern_id']], |
|
|
|
['status', 'in', [0, 1]], |
|
|
|
['id', '<>', $id] |
|
|
|
]; |
|
|
|
if (EventCalendar::query()->where($existsWhere)->exists()) { |
|
|
|
if (EventCalendar::query()->where($existsWhere)->whereIn( |
|
|
|
'status', |
|
|
|
[0, 1] |
|
|
|
)->exists() |
|
|
|
) { |
|
|
|
throw new Exception( |
|
|
|
__('service.event_calendar.pattern_exists') |
|
|
|
); |
|
|
|
@ -236,11 +239,8 @@ class EventCalendarService extends BaseService |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
$where = [ |
|
|
|
['pattern_id', '=', $pattern_id], |
|
|
|
['status', 'in', [0,1]] |
|
|
|
]; |
|
|
|
$query = EventCalendar::query()->where($where)->first(); |
|
|
|
$query = EventCalendar::query()->where('pattern_id', $pattern_id) |
|
|
|
->whereIn('status', [0, 1])->first(); |
|
|
|
|
|
|
|
$end_time = get_datetime('datetime', strtotime($end_time)); |
|
|
|
$save = [ |
|
|
|
@ -268,6 +268,8 @@ class EventCalendarService extends BaseService |
|
|
|
$this->logService->logCreated($model, 'event_calendar.create'); |
|
|
|
} |
|
|
|
|
|
|
|
// 切换活动模式,将模式所有车位类型 全部更新当前车位 |
|
|
|
$this->syncUpdateSpaceType($pattern_id); |
|
|
|
// 生成警报信息消息 |
|
|
|
AdminNoticeService::addChangeModeNotice($pattern_id, $user_id); |
|
|
|
|
|
|
|
@ -279,6 +281,7 @@ class EventCalendarService extends BaseService |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 返回当前模式的模式信息 |
|
|
|
public static function targetModel() |
|
|
|
{ |
|
|
|
$pattern_id = EventCalendar::query()->where('status', 1)->value('pattern_id'); |
|
|
|
@ -290,4 +293,32 @@ class EventCalendarService extends BaseService |
|
|
|
} |
|
|
|
return $data; |
|
|
|
} |
|
|
|
|
|
|
|
// 返回当前模式的模式id |
|
|
|
public static function getTargetModeId() |
|
|
|
{ |
|
|
|
$data = self::targetModel(); |
|
|
|
return $data['pattern_id'] ?? ''; |
|
|
|
} |
|
|
|
|
|
|
|
// 切换模式后 - 同步更新所有车位类型 |
|
|
|
public function syncUpdateSpaceType($pattern_id) |
|
|
|
{ |
|
|
|
// 查询当前模式是否 |
|
|
|
$data = ParkingPatternSpace::query()->where('pattern_id', $pattern_id) |
|
|
|
->select() |
|
|
|
->get()->toArray(); |
|
|
|
foreach ($data as $item) { |
|
|
|
$space_id = $item['space_id']; |
|
|
|
$space_type_id = $item['space_type_id']; |
|
|
|
(new ParkingSpaceService( |
|
|
|
$this->logService |
|
|
|
))->syncUpdateSpaceType( |
|
|
|
$space_id, |
|
|
|
$space_type_id, |
|
|
|
$pattern_id, |
|
|
|
false |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|