<?php
|
|
namespace app\common\model\supplier\member;
|
|
use app\common\model\BaseModel;
|
|
/**
|
* 供应商年卡权限模型
|
* 用于管理年卡套餐对应的权限
|
*/
|
class PlanAccess extends BaseModel
|
{
|
// 表名
|
protected $name = 'supplier_member_plan_access';
|
protected $pk = 'id';
|
|
/**
|
* 获取年卡套餐的所有权限ID
|
*/
|
public static function getAccessIdsByPlanId($planId)
|
{
|
$accessData = self::where(['plan_id' => $planId])->select();
|
$accessIds = [];
|
foreach ($accessData as $item) {
|
$accessIds[] = $item['access_id'];
|
}
|
return $accessIds;
|
}
|
|
/**
|
* 设置年卡套餐的权限
|
*/
|
public static function setPlanAccess($planId, $accessIds)
|
{
|
// 先删除原有权限
|
self::where(['plan_id' => $planId])->delete();
|
|
// 添加新权限
|
$data = [];
|
foreach ($accessIds as $accessId) {
|
$data[] = [
|
'plan_id' => $planId,
|
'access_id' => $accessId,
|
'create_time' => time()
|
];
|
}
|
|
if (!empty($data)) {
|
return (new self())->saveAll($data);
|
}
|
|
return true;
|
}
|
}
|