UserFollow.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace common\models\user;
  3. use common\models\base\BaseActiveRecord;
  4. use Yii;
  5. use yii\db\Exception;
  6. use yii\web\IdentityInterface;
  7. /**
  8. * This is the model class for table "qimall_user_follow".
  9. *
  10. *
  11. * @property int $id
  12. * @property int $mall_id 商城ID
  13. * @property int $user_id 用户ID
  14. * @property int $follow_id 关注用户ID
  15. * @property int $created_at 创建时间
  16. * @property int $updated_at 修改时间
  17. * @property int $status 状态:1是关注,0是取消关注
  18. */
  19. class UserFollow extends BaseActiveRecord
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%user_follow}}';
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['mall_id', 'user_id', 'follow_id'], 'required'],
  35. [['mall_id', 'user_id', 'follow_id', 'created_at', 'updated_at', 'status'], 'integer'],
  36. ];
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'id' => 'ID',
  45. 'mall_id' => '商城ID',
  46. 'user_id' => '用户ID',
  47. 'follow_id' => '关注用户ID',
  48. 'created_at' => '创建时间',
  49. 'updated_at' => '修改时间',
  50. 'status' => '状态:1是关注,0是取消关注',
  51. ];
  52. }
  53. /**
  54. * 用户其他信息表
  55. * @Author: lun
  56. * @DateTime: 2021/12/22 0022 10:32
  57. * @Copyright: copyright (c) 2021 广东七件事集团
  58. * @return \yii\db\ActiveQuery
  59. */
  60. public function getUserextra()
  61. {
  62. return $this->hasOne(UserExtra::class, ['user_id' => 'follow_id'])->select('user_id,id,personal_signature');
  63. }
  64. /**
  65. * 用户其他信息表
  66. * @Author: lun
  67. * @DateTime: 2021/12/22 0022 10:32
  68. * @Copyright: copyright (c) 2021 广东七件事集团
  69. * @return \yii\db\ActiveQuery
  70. */
  71. public function getUserextrafans()
  72. {
  73. return $this->hasOne(UserExtra::class, ['user_id' => 'user_id'])->select('user_id,id,personal_signature');
  74. }
  75. /**
  76. * 获取关注表
  77. * @Author: lun
  78. * @DateTime: 2021/12/22 0022 10:32
  79. * @Copyright: copyright (c) 2021 广东七件事集团
  80. * @return \yii\db\ActiveQuery
  81. */
  82. public function getUserFollow()
  83. {
  84. return $this->hasOne(UserFollow::class, ['follow_id' => 'user_id'])->select('user_id,id,follow_id,status');
  85. }
  86. /**
  87. * 关联用户表
  88. * @Author: lun
  89. * @DateTime: 2021/12/22 0022 10:32
  90. * @Copyright: copyright (c) 2021 广东七件事集团
  91. * @return \yii\db\ActiveQuery
  92. */
  93. public function getFollow()
  94. {
  95. return $this->hasOne(User::class, ['id' => 'follow_id'])->select('username,id,nickname,avatar_url');
  96. }
  97. /**
  98. * 关联用户表
  99. * @Author: lun
  100. * @DateTime: 2021/12/22 0022 10:32
  101. * @Copyright: copyright (c) 2021 广东七件事集团
  102. * @return \yii\db\ActiveQuery
  103. */
  104. public function getFans()
  105. {
  106. return $this->hasOne(User::class, ['id' => 'user_id'])->select('username,id,nickname,avatar_url');
  107. }
  108. /**
  109. * 保存数据
  110. * @Author: ltm
  111. * @DateTime: 2021/12/13 0022 17:13
  112. * @Copyright: copyright (c) 2021 广东七件事集团
  113. * @param array $params
  114. * @return AddonsMaterial|bool
  115. */
  116. public static function setData(array $params){
  117. try{
  118. $model = self::findOne(['follow_id'=> $params['follow_id'],'mall_id'=> $params['mall_id'],'user_id' => $params['user_id']]);
  119. if ($model) {
  120. if($model->status == '1') $model->status = '0';else $model->status = '1';
  121. }else{
  122. $model = new self();
  123. $model->loadDefaultValues();
  124. $model->mall_id = $params['mall_id'];
  125. }
  126. if(!$model->load($params,'') || !$model->save()){
  127. throw new Exception($model->getErrorMessage());
  128. }
  129. return $model->status;
  130. }catch(\Exception $e){
  131. self::$static_error = $e->getMessage();
  132. return false;
  133. }
  134. }
  135. }