QuanziComment.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2025 赤店商城 All rights reserved.
  6. */
  7. namespace app\models;
  8. use Yii;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. class QuanziComment extends \yii\db\ActiveRecord
  12. {
  13. const TYPE_COMMENT = 0; //评论帖子
  14. const TYPE_REPLY = 1; //回复评论
  15. const TYPE_GOOD = 2; //点赞
  16. const TYPE_SHARE = 3; //分享
  17. const TYPE_WEIGUI = 4; //举报文章
  18. /**
  19. * @inheritdoc
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%quanzi_comment}}';
  24. }
  25. public function behaviors()
  26. {
  27. return [
  28. [
  29. // 自动更新创建和更新时间
  30. 'class' => TimestampBehavior::class,
  31. 'updatedAtAttribute' => null,
  32. ]
  33. ];
  34. }
  35. public static function type($k = null, $comment = null) {
  36. $arr = [
  37. self::TYPE_COMMENT => '评论',
  38. self::TYPE_REPLY => '回复',
  39. self::TYPE_GOOD => '点赞',
  40. self::TYPE_SHARE => '分享',
  41. self::TYPE_WEIGUI => '举报',
  42. ];
  43. if($k === null){
  44. return $arr;
  45. }
  46. $kname = isset($arr[$k]) ? $arr[$k] : '--';
  47. if($comment){
  48. $for = $comment['at_comment_id'] ? '回复' : ($comment['comment_id'] ? '评论' : '文章');
  49. if(in_array($k, [self::TYPE_WEIGUI, self::TYPE_GOOD])){
  50. $kname .= $for;
  51. }
  52. }
  53. return $kname;
  54. }
  55. public static function typeWeigui($k = null) {
  56. $arr = [
  57. 1 => '低俗色情',
  58. 2 => '涉嫌违法',
  59. 3 => '侵权抄袭',
  60. 4 => '人身攻击',
  61. 5 => '内容不实',
  62. ];
  63. if($k === null){
  64. return $arr;
  65. }
  66. return isset($arr[$k]) ? $arr[$k] : '--';
  67. }
  68. public function afterSave($insert, $changedAttributes) {
  69. parent::afterSave($insert, $changedAttributes);
  70. \app\modules\admin\models\quanzi\QuanziForm::afterCommentSave($this, $insert, $changedAttributes);
  71. }
  72. }