| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace addons\ShortVideo\common\models;
- use common\enums\StatusEnum;
- use Exception;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_short_video_user_watch".
- *
- * @property int $id id
- * @property int $mall_id 商城id
- * @property int $user_id 用户id
- * @property int $video_id 视频id
- * @property int $status 状态(0:未观看,1:已观看)
- * @property int|null $created_at 添加时间
- * @property int|null $updated_at 修改时间
- */
- class ShortVideoUserWatch extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_short_video_user_watch';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'video_id'], 'required'],
- [['mall_id', 'user_id', 'video_id', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'video_id' => 'Video ID',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData(array $params)
- {
- try {
- $model = self::findOne(['user_id' => $params['user_id'], 'mall_id' => $params['mall_id'], 'video_id' => $params['video_id']]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- //更改观看记录状态
- public static function changeWatchStatus($params)
- {
- try {
- $res = ShortVideoUserWatch::updateAll(['status' => StatusEnum::DISABLED], ['mall_id' => $params['mall_id'], 'user_id' => $params['user_id']]);
- if (!$res) throw new Exception(ShortVideoUserWatch::$static_error);
- } catch (\Exception $e) {
- throw new Exception($e->getMessage());
- }
- }
- }
|