| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace addons\Course\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_course_user_watch".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id
- * @property int $duration 观看时长
- * @property int $register_time 注册时间
- * @property int $status 活动状态,1:启用,0:禁用,-1删除
- * @property int $created_at
- * @property int $updated_at
- */
- class CourseUserWatch extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_course_user_watch}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'duration', 'register_time', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'duration' => '观看时长',
- 'register_time' => '注册时间',
- 'status' => '活动状态,1:启用,0:禁用,-1删除',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData(array $params)
- {
- try {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'user_id' => $params['user_id'],'status' => [StatusEnum::ENABLED]]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- }
- $params['duration'] += $model['duration'];
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|