64], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => '商城ID', 'name' => '名称', 'level' => '等级', 'item_commission' => '项目佣金', 'item_commission_type' => '0百分比;1固定值', 'enable_distribution_commission' => '享受分销提成奖励; 0关闭,1开启', 'level1_commission' => '一级佣金', 'level1_commission_type' => '0百分比;1固定值', 'level2_commission' => '一级佣金', 'level2_commission_type' => '0百分比;1固定值', 'status' => '状态;1正常,0禁用,-1删除', 'created_at' => '创建时间', 'updated_at' => '更新时间', ]; } public static function getLevelWeights($mall_id) { $list = self::find()->select('level')->where(['status' => [StatusEnum::DISABLED, StatusEnum::ENABLED], 'mall_id' => $mall_id])->column(); $newList = []; for ($i = 1; $i <= 10; $i++) { $newList[] = [ 'name' => '等级' . $i, 'level' => $i, 'disabled' => in_array($i, $list), ]; } return $newList; } public static function setData(array $params) { try { if (!empty($params['id'])) { if (!empty(self::getOne([['status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]], ['level' => $params['level']], ['mall_id' => $params['mall_id']], ['<>', 'id', $params['id']]]))) throw new \Exception("当前等级已经存在"); $model = self::findOne(['and', ['id' => $params['id'], 'mall_id' => $params['mall_id']], ['<>', 'status', StatusEnum::DELETE]]); if (empty($model)) throw new \Exception('等级不存在或已删除'); // 判断等级是否有被修改 if ($model->level != $params['level']) { // 判断该等级下是否有用户存在 $boss = ReservationServiceUser::find()->where(['mall_id' => $model->mall_id, 'level' => $model->level, 'status' => StatusEnum::ENABLED])->asArray()->one(); if ($boss) throw new \Exception('该等级下存在技师,不能被修改'); } } else { // 判断当前等级是否已经存在 if (!empty(self::getOne([['status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]], ['mall_id' => $params['mall_id']], ['level' => $params['level']]]))) throw new \Exception("当前等级已经存在"); $model = new self(); $model->loadDefaultValues(); $model->mall_id = $params['mall_id']; } if (!$model->load($params, '') || !$model->save()) { throw new \Exception($model->getErrorMessage()); } return $model; } catch (\Exception $e) { self::$static_error = $e->getMessage(); return false; } } }