30], [['content'], 'string'], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'name' => '规则名称', 'reply_type' => '回复类型', 'is_follow_reply' => '是否关注自动回复,0/否 1/是', 'type' => '【0 模糊匹配, 1 精准匹配】', 'content' => 'Content', 'status' => '状态【1启用 0禁用 -1删除】', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public function getRuleKeyword() { return $this->hasMany(RuleKeyword::class, ['rule_id' => 'id'])->andWhere(['<>','status',StatusEnum::DELETE])->orderBy(['created_at' => SORT_DESC]); } /** * 保存数据 * @Author lun * @DateTime 2021-09-17 14:16:24 * @copyright: Copyright (c) 2020 广东七件事集团 * @param array $params * @return object|boolean */ public static function setData($mall_id, array $params){ $trans = Yii::$app->db->beginTransaction(); try{ if(!empty($params['id'])){ $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $mall_id],['<>','status',StatusEnum::DELETE]]); if(empty($model)) throw new \Exception('信息不存在或已删除'); }else{ $model = new self(); $model->mall_id = $mall_id; $model->type = 0; } $model->attributes = $params; if(!$model->save()){ throw new \Exception($model->getErrorMessage()); } // 保存匹配关键字 $res = RuleKeyword::setData($mall_id, $model->id, $params); if ($res == false) throw new \Exception($model->getErrorMessage()); $trans->commit(); return true; }catch(\Exception $e){ self::$static_error = $e->getMessage(); $trans->rollBack(); return false; } } /** * 获取回复列表 * @Author lun * @DateTime 2021-09-17 13:00:11 * @copyright: Copyright (c) 2020 广东七件事集团 * @param array $cond * @param array $with * @param integer $is_array * @return array|null */ public static function getReplyRule(array $cond,array $with=[],bool $is_array=true,string $select='*') { $default_cond = [['<>', 'status', StatusEnum::DELETE]]; $cond = array_merge($cond, $default_cond); $query = self::find()->select($select); self::paramPack(['where' => $cond, 'with' => $with],$query); $list = $query->asArray($is_array)->all(); return $list; } }