| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace addons\ShortVideo\common\models;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "{{%addons_short_video_follow}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id 用户ID
- * @property int $follow_id
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class ShortVideoFollow extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_short_video_follow}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'follow_id'], 'required'],
- [['mall_id', 'user_id', 'follow_id', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'follow_id' => 'Follow ID',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function getList(int $mall_id, int $user_id, string $type, int $page = 1, int $limit = 10)
- {
- $wheres[] = ['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED];
- if ('follow' == $type) {
- $wheres[] = ['user_id' => $user_id];
- $field = 'follow_id';
- }
- if ('fans' == $type) {
- $wheres[] = ['follow_id' => $user_id];
- $field = 'user_id';
- };
- $params = [
- 'select' => 'id,user_id,follow_id',
- 'where' => $wheres,
- 'order' => 'created_at desc,id desc',
- 'page' => $page,
- 'limit' => $limit,
- ];
- $follow_list = ShortVideoFollow::listPage($params);
- if (empty($follow_list['list'])) return $follow_list['list'];
- $user_ids = array_column($follow_list['list'], $field);
- $user_params = [
- 'select' => 'id,nickname,mobile,username,avatar_url,signature_title,signature_content',
- 'where' => [['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids]],
- 'order' => 'created_at desc,id desc',
- ];
- $users = User::lists($user_params);
- return $users;
- }
- public static function setData(int $mall_id, array $data)
- {
- $model = self::findOne(['mall_id' => $mall_id, 'user_id' => $data['user_id'], 'follow_id' => $data['follow_id']]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- }
- foreach ($data as $key => $val) {
- $model->$key = $val;
- }
- // dd($model);
- if (!$model->save()) {
- self::$static_error = '保存数据失败:' . $model->getErrorMessage();
- return false;
- }
- return $model;
- }
- }
|