Xboard/app/Models/Coupon.php
xboard 1ae8deca99
Some checks failed
Docker Build and Publish / build (push) Has been cancelled
feat(coupon): enhance theme compatibility by converting plan IDs to strings
2025-01-24 02:26:22 +08:00

41 lines
942 B
PHP

<?php
namespace App\Models;
use App\Services\PlanService;
use Illuminate\Database\Eloquent\Model;
class Coupon extends Model
{
protected $table = 'v2_coupon';
protected $dateFormat = 'U';
protected $guarded = ['id'];
protected $casts = [
'created_at' => 'timestamp',
'updated_at' => 'timestamp',
'limit_plan_ids' => 'array',
'limit_period' => 'array'
];
public function getLimitPeriodAttribute($value)
{
return collect(json_decode($value, true))->map(function ($item) {
return PlanService::getPeriodKey($item);
})->toArray();
}
public function getLimitPlanIdsAttribute($value)
{
$planIds = json_decode($value, true);
if (blank($planIds)) {
return null;
}
return collect($planIds)
->map(fn($id) => (string) $id)
->values()
->all();
}
}