'ID', 'mall_id' => '商城id', 'user_id' => '用户id', 'note_content_id' => '回复的笔记id', 'level' => '第n级回复', 'reply_id' => '一级评论id', 'content' => '评论内容', 'is_top' => '是否置顶', 'top_time' => '置顶时间', 'status' => '-1是删除,0是禁用 1是启用', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public function getUser() { return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id,username'); } public static function updateData($params) { $t = Yii::$app->db->beginTransaction(); try { if (empty($params['attributes']) || !is_array($params['attributes'])) throw new \Exception('参数有误!'); $attributes = $params['attributes']; $condition = ['id' => $params['id'], 'mall_id' => $params['mall_id']]; self::updateAll($attributes, $condition); $comment_list = self::lists(['where' => [['id' => $params['id']]]]); $note_content_id_arr = array_column($comment_list, 'note_content_id'); $list = self::lists(['where' => [['note_content_id' => $note_content_id_arr], ['status' => StatusEnum::ENABLED]], 'select' => 'count(*) nums,note_content_id', 'group' => 'note_content_id', 'index' => 'note_content_id']); $note_list = AddonsOperatingNoteContent::lists(['where' => [['id' => $note_content_id_arr]]], false); foreach ($note_list as $note) { $note->reply_num = $list[$note['id']]['nums']??0; $note->save(); } $t->commit(); return true; } catch (\Exception $e) { $t->rollBack(); self::setStaticError($e->getMessage()); return false; } } public static function setData($params) { $transaction = \Yii::$app->db->beginTransaction(); try { $content = AddonsOperatingNoteContent::getOne([['id'=>$params['note_content_id']]]); if($content->hidden_comment == 0){ return false; } $params['level'] = 1; if (isset($params['reply_id']) && $params['reply_id'] > 0) { $params['level'] = 2; } $model = new self(); if (!$model->load($params, '') || !$model->save()) { throw new Exception($model->getErrorMessage()); } $content->reply_num++; $content->save(); $transaction->commit(); return $model->toArray(); } catch (Exception $e) { $transaction->rollBack(); var_dump($e->getMessage()); throw new Exception($e->getMessage()); } } public static function editComment($params) { $transaction = \Yii::$app->db->beginTransaction(); try { $detail = self::getOne([['id' => $params['note_comment_id']]]); if ($params['type'] == 1) { if ($detail->is_top == NoteEnum::STATUS_ONE) { $detail->is_top = NoteEnum::STATUS_ZERO; $detail->top_time = 0; } else { $detail->is_top = NoteEnum::STATUS_ONE; $detail->top_time = time(); } } else { $detail->status = StatusEnum::DELETE; } $detail->save(); $transaction->commit(); return true; } catch (Exception $e) { $transaction->rollBack(); var_dump($e->getMessage()); throw new Exception($e->getMessage()); } } }