ShortVideoFollow.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace addons\ShortVideo\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\user\User;
  5. use Yii;
  6. /**
  7. * This is the model class for table "{{%addons_short_video_follow}}".
  8. *
  9. * @property int $id
  10. * @property int $mall_id
  11. * @property int $user_id 用户ID
  12. * @property int $follow_id
  13. * @property int $status 状态[-1:删除;0:禁用;1启用]
  14. * @property int $created_at 创建时间
  15. * @property int $updated_at 修改时间
  16. */
  17. class ShortVideoFollow extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_short_video_follow}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'user_id', 'follow_id'], 'required'],
  33. [['mall_id', 'user_id', 'follow_id', 'status', 'created_at', 'updated_at'], 'integer'],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'mall_id' => 'Mall ID',
  44. 'user_id' => 'User ID',
  45. 'follow_id' => 'Follow ID',
  46. 'status' => 'Status',
  47. 'created_at' => 'Created At',
  48. 'updated_at' => 'Updated At',
  49. ];
  50. }
  51. public static function getList(int $mall_id, int $user_id, string $type, int $page = 1, int $limit = 10)
  52. {
  53. $wheres[] = ['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED];
  54. if ('follow' == $type) {
  55. $wheres[] = ['user_id' => $user_id];
  56. $field = 'follow_id';
  57. }
  58. if ('fans' == $type) {
  59. $wheres[] = ['follow_id' => $user_id];
  60. $field = 'user_id';
  61. };
  62. $params = [
  63. 'select' => 'id,user_id,follow_id',
  64. 'where' => $wheres,
  65. 'order' => 'created_at desc,id desc',
  66. 'page' => $page,
  67. 'limit' => $limit,
  68. ];
  69. $follow_list = ShortVideoFollow::listPage($params);
  70. if (empty($follow_list['list'])) return $follow_list['list'];
  71. $user_ids = array_column($follow_list['list'], $field);
  72. $user_params = [
  73. 'select' => 'id,nickname,mobile,username,avatar_url,signature_title,signature_content',
  74. 'where' => [['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids]],
  75. 'order' => 'created_at desc,id desc',
  76. ];
  77. $users = User::lists($user_params);
  78. return $users;
  79. }
  80. public static function setData(int $mall_id, array $data)
  81. {
  82. $model = self::findOne(['mall_id' => $mall_id, 'user_id' => $data['user_id'], 'follow_id' => $data['follow_id']]);
  83. if (empty($model)) {
  84. $model = new self();
  85. $model->loadDefaultValues();
  86. $model->mall_id = $mall_id;
  87. }
  88. foreach ($data as $key => $val) {
  89. $model->$key = $val;
  90. }
  91. // dd($model);
  92. if (!$model->save()) {
  93. self::$static_error = '保存数据失败:' . $model->getErrorMessage();
  94. return false;
  95. }
  96. return $model;
  97. }
  98. }