| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace common\models\wechat;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%reply_rule}}".
- *
- *
- * @property int $id
- * @property int $mall_id
- * @property string $name 规则名称
- * @property string|null $reply_type 回复类型
- * @property int|null $is_follow_reply 是否关注自动回复,0/否 1/是
- * @property int $type 【0 模糊匹配, 1 精准匹配】
- * @property string|null $content
- * @property int $status 状态【1启用 0禁用 -1删除】
- * @property int $created_at
- * @property int $updated_at
- */
- class ReplyRule extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%wechat_reply_rule}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'name'], 'required'],
- [['mall_id', 'status', 'created_at', 'updated_at','is_follow_reply'], 'integer'],
- [['name', 'reply_type'], 'string', 'max' => 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;
- }
- }
|