10 changed files with 196 additions and 22 deletions
@ -0,0 +1,30 @@ |
|||
<?php |
|||
|
|||
namespace App\Models; |
|||
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Illuminate\Database\Eloquent\SoftDeletes; |
|||
|
|||
class ParkingSpaceTypeAttr extends Model |
|||
{ |
|||
use HasFactory; |
|||
|
|||
protected $table = 'parking_space_type_attr'; |
|||
|
|||
protected $fillable |
|||
= [ |
|||
'space_type_id', |
|||
'space_attr_id', |
|||
'color_occupy', |
|||
'color_vacant', |
|||
'color_warning', |
|||
'is_warning', |
|||
'is_flicker' |
|||
]; |
|||
protected $hidden |
|||
= [ |
|||
'created_at', |
|||
'updated_at' |
|||
]; |
|||
} |
|||
@ -0,0 +1,79 @@ |
|||
<?php |
|||
|
|||
namespace App\Services; |
|||
|
|||
use App\Models\ParkingSpaceTypeAttr; |
|||
|
|||
class ParkingSpaceTypeAttrService |
|||
{ |
|||
/** |
|||
* @var OperationLogService |
|||
*/ |
|||
private OperationLogService $logService; |
|||
|
|||
/** |
|||
* 构造函数 |
|||
* @param OperationLogService $logService |
|||
*/ |
|||
public function __construct(OperationLogService $logService) |
|||
{ |
|||
$this->logService = $logService; |
|||
$this->logService->menuTitle = 'cat_type'; |
|||
} |
|||
|
|||
public function createData($space_type_id, $data) |
|||
{ |
|||
$create = [ |
|||
'space_type_id' => $space_type_id, |
|||
'space_attr_id' => $data['space_attr_id'], |
|||
'color_occupy' => $data['color_occupy'], |
|||
'color_vacant' => $data['color_vacant'], |
|||
'color_warning' => $data['color_warning'], |
|||
'is_warning' => $data['is_warning'], |
|||
'is_flicker' => $data['is_flicker'], |
|||
'created_at' => get_datetime(), |
|||
]; |
|||
|
|||
$model = ParkingSpaceTypeAttr::query()->create($create); |
|||
|
|||
$this->logService->logCreated($model, 'space_type_attr.create'); |
|||
} |
|||
|
|||
public function createBatchData($space_type_id, array $data) |
|||
{ |
|||
foreach ($data as $value) { |
|||
$this->createData($space_type_id, $value); |
|||
} |
|||
} |
|||
|
|||
public function deleteBatchData($space_type_id) |
|||
{ |
|||
$data = ParkingSpaceTypeAttr::query()->where('space_type_id', $space_type_id) |
|||
->select()->get()->toArray(); |
|||
$this->logService->logDeletedData( |
|||
new ParkingSpaceTypeAttr(), |
|||
'space_type_attr.delete', |
|||
$data |
|||
); |
|||
ParkingSpaceTypeAttr::query()->where('space_type_id', $space_type_id) |
|||
->delete(); |
|||
} |
|||
|
|||
public static function getTypeAttrData($space_type_id) |
|||
{ |
|||
$columns = [ |
|||
'space_attr_id as attributes_id', |
|||
'color_occupy as attr_color_occupy', |
|||
'color_vacant as attr_color_vacant', |
|||
'color_warning as attr_color_warning', |
|||
'is_warning as attr_is_warning', |
|||
'is_flicker as attr_is_flicker' |
|||
]; |
|||
return ParkingSpaceTypeAttr::query()->where( |
|||
'space_type_id', |
|||
$space_type_id |
|||
) |
|||
->select($columns)->get()->toArray(); |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
<?php |
|||
|
|||
use Illuminate\Database\Migrations\Migration; |
|||
use Illuminate\Database\Schema\Blueprint; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
return new class extends Migration |
|||
{ |
|||
/** |
|||
* Run the migrations. |
|||
*/ |
|||
public function up(): void |
|||
{ |
|||
Schema::create('parking_space_type_attr', function (Blueprint $table) { |
|||
$table->id(); |
|||
$table->integer('space_type_id')->comment('车位类型'); |
|||
$table->integer('space_attr_id')->comment('车位属性'); |
|||
$table->string('color_occupy', 50)->nullable()->comment('指示灯颜色(占用)'); |
|||
$table->string('color_vacant', 50)->nullable()->comment('指示灯颜色(空置)'); |
|||
$table->string('color_warning', 50)->nullable()->comment('报警指示灯颜色'); |
|||
$table->tinyInteger('is_warning')->default(0)->comment('是否报警 0否 1是'); |
|||
$table->tinyInteger('is_flicker')->default(0)->comment('是否闪烁 0否 1是'); |
|||
$table->timestamps(); |
|||
$table->innoDb(); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Reverse the migrations. |
|||
*/ |
|||
public function down(): void |
|||
{ |
|||
Schema::dropIfExists('parking_space_type_attr'); |
|||
} |
|||
}; |
|||
Loading…
Reference in new issue