"价值分层", 2 => "生命周期", 3 => "营销偏好", 4 => "行为偏好", ]; /** * {@inheritdoc} */ public static function tableName() { return '{{%tag}}'; } /** * {@inheritdoc} */ public function rules() { return [ [['mall_id'], 'required'], [['mall_id', 'type', 'status', 'created_at', 'updated_at'], 'integer'], [['name'], 'string', 'max' => 45], [['condition'], 'string', 'max' => 3000], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'name' => '标签名称', 'type' => '标签类型', 'condition' => '条件', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } /** * @param array $where * @param string $select * @param array $with * @param int $is_array * @return array|Tag[]|\yii\db\ActiveRecord[] */ public static function getTagList(array $where, $select = '*', array $with = [], int $is_array = 0) { $query = self::find(); self::paramPack(['where' => $where, 'with' => $with], $query); return $query->select($select)->asArray($is_array)->all(); } /** * 保存数据 * @param array $params * @return bool|Tag */ public static function setData(array $params) { try { if (!empty($params['id'])) { $model = self::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (empty($model)) throw new Exception('服务不存在或已删除'); } else { $model = new self(); $model->loadDefaultValues(); } if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage()); return $model; } catch (Exception $e) { self::$static_error = $e->getMessage(); return false; } } /** * 删除 * @param $params * @param $status * @return bool */ public static function del($params, $status) { try { $query = self::find()->where(['and', ['id' => $params['id']], ['<>', 'status', StatusEnum::DELETE] ]); $model = $query->one(); $model->status = $status; $res = $model->save(); if ($res === false) throw new Exception('删除失败'); return true; } catch (\Exception $e) { return false; } } }