| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace common\models\user;
- use common\models\base\BaseActiveRecord;
- use Yii;
- use yii\db\Exception;
- use yii\web\IdentityInterface;
- /**
- * This is the model class for table "qimall_user_follow".
- *
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $user_id 用户ID
- * @property int $follow_id 关注用户ID
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- * @property int $status 状态:1是关注,0是取消关注
- */
- class UserFollow extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%user_follow}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'follow_id'], 'required'],
- [['mall_id', 'user_id', 'follow_id', 'created_at', 'updated_at', 'status'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '用户ID',
- 'follow_id' => '关注用户ID',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- 'status' => '状态:1是关注,0是取消关注',
- ];
- }
- /**
- * 用户其他信息表
- * @Author: lun
- * @DateTime: 2021/12/22 0022 10:32
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getUserextra()
- {
- return $this->hasOne(UserExtra::class, ['user_id' => 'follow_id'])->select('user_id,id,personal_signature');
- }
- /**
- * 用户其他信息表
- * @Author: lun
- * @DateTime: 2021/12/22 0022 10:32
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getUserextrafans()
- {
- return $this->hasOne(UserExtra::class, ['user_id' => 'user_id'])->select('user_id,id,personal_signature');
- }
- /**
- * 获取关注表
- * @Author: lun
- * @DateTime: 2021/12/22 0022 10:32
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getUserFollow()
- {
- return $this->hasOne(UserFollow::class, ['follow_id' => 'user_id'])->select('user_id,id,follow_id,status');
- }
- /**
- * 关联用户表
- * @Author: lun
- * @DateTime: 2021/12/22 0022 10:32
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getFollow()
- {
- return $this->hasOne(User::class, ['id' => 'follow_id'])->select('username,id,nickname,avatar_url');
- }
- /**
- * 关联用户表
- * @Author: lun
- * @DateTime: 2021/12/22 0022 10:32
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getFans()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('username,id,nickname,avatar_url');
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2021/12/13 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return AddonsMaterial|bool
- */
- public static function setData(array $params){
- try{
- $model = self::findOne(['follow_id'=> $params['follow_id'],'mall_id'=> $params['mall_id'],'user_id' => $params['user_id']]);
- if ($model) {
- if($model->status == '1') $model->status = '0';else $model->status = '1';
- }else{
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $params['mall_id'];
- }
- if(!$model->load($params,'') || !$model->save()){
- throw new Exception($model->getErrorMessage());
- }
- return $model->status;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|