getPage($params), $this->getLimit($params), function ($query) { $query->andWhere(['mall_id' => $this->mall_id]); },'level asc,id desc' ); } /** * 获取等级列表 * * @return array */ public function getLevelList() { return Level::getOpenLevelList($this->mall_id); } /** * 获取等级数据 * * @param integer|null $id * @return array */ public function getLevelData(int $id = null) { $detail = []; $weights = Level::getLevelWeights($this->mall_id); if ($id) $detail = Level::getLevelDetail($this->mall_id, $id); if (!empty($detail)) { $detail = $detail->jsonDecode(); $detail = $detail->toArray(); } return compact('weights', 'detail'); } /** * 编辑等级 * * @param int|null $id * @param array $data * @return boolean */ public function setLevelData($id, array $data) { $model = empty($id) ? new Level() : Level::getLevelDetail($this->mall_id, $id); $res = $model->setLevelData(array_merge($data, ['mall_id' => $this->mall_id])); return $res === true ? true : $this->modelError($res); } /** * 切换状态 * * @param integer $id * @param integer $status * @return boolean */ public function switchStatus(int $id, int $status) { $model = Level::getLevelDetail($this->mall_id, $id); if (empty($model)) return $this->error('等级不存在'); $res = $model->setLevelData(['status' => $status]); return $res === true ? true : $this->modelError($res); } /** * 删除等级 * * @param integer $id * @return boolean */ public function delLevel(int $id) { $model = Level::getLevelDetail($this->mall_id, $id); if (empty($model)) return $this->error('等级不存在'); // 被使用等级无法删除 if (UserCenter::hasLevel($model)) return $this->error('该等级已被使用 无法删除'); $res = $model->delLevel(); return $res === true ? true : $this->modelError($res); } }