ShortVideoCommentLike.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace addons\ShortVideo\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_short_video_comment_like}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property int $user_id 用戶id
  11. * @property int $comment_id 评论ID
  12. * @property int $status 状态[-1:删除;0:禁用;1启用]
  13. * @property int $created_at
  14. * @property int $updated_at
  15. */
  16. class ShortVideoCommentLike extends \common\models\base\BaseActiveRecord
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%addons_short_video_comment_like}}';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['mall_id', 'user_id', 'comment_id'], 'required'],
  32. [['mall_id', 'user_id', 'comment_id', 'status', 'created_at', 'updated_at'], 'integer'],
  33. ];
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'mall_id' => 'Mall ID',
  43. 'user_id' => 'User ID',
  44. 'comment_id' => 'Comment ID',
  45. 'status' => 'Status',
  46. 'created_at' => 'Created At',
  47. 'updated_at' => 'Updated At',
  48. ];
  49. }
  50. public static function setData(int $mall_id, array $data)
  51. {
  52. if (!empty($data['id'])) {
  53. $model = self::findOne(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $data['id']]);
  54. if (empty($model)) {
  55. self::$static_error = '评论点赞记录不存在';
  56. return false;
  57. }
  58. } else {
  59. $model = self::findOne(['mall_id' => $mall_id, 'user_id' => $data['user_id'], 'comment_id' => $data['comment_id']]);
  60. if (empty($model)) {
  61. $model = new self();
  62. $model->loadDefaultValues();
  63. $model->mall_id = $mall_id;
  64. }
  65. }
  66. foreach ($data as $key => $val) {
  67. $model->$key = $val;
  68. }
  69. if (!$model->save()) {
  70. self::$static_error = '保存数据失败:' . $model->getErrorMessage();
  71. return false;
  72. }
  73. return $model;
  74. }
  75. }