| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace addons\ShortVideo\common\models;
- use addons\ShortVideo\common\enums\AddonsShortVideoEnum;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_short_video_share}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id 分享视频的会员的id
- * @property int $share_to_user_id 观看分享的会员的id
- * @property int $video_id 视频id
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class ShortVideoShare extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_short_video_share}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'video_id'], 'required'],
- [['mall_id', 'user_id', 'share_to_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',
- 'share_to_user_id' => 'Share To User Id',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData(int $mall_id, array $data)
- {
- $video = ShortVideo::findOne(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $data['video_id'], 'check_status' => AddonsShortVideoEnum::VIDEO_AUDIT_STATUS1, 'is_blacklist' => 0]);
- if (empty($video)) {
- self::$static_error = '视频不存在';
- return false;
- }
- $transaction = \Yii::$app->db->beginTransaction();
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- foreach ($data as $key => $val) {
- $model->$key = $val;
- }
- // dd($model);
- $res = $model->save();
- if (false === $res) {
- $transaction->rollBack();
- self::$static_error = '保存数据失败:' . $model->getErrorMessage();
- return false;
- }
- $video->share_num += 1;
- $res_video = $video->save();
- if (false === $res_video) {
- $transaction->rollBack();
- self::$static_error = ShortVideo::getStaticError();
- return false;
- }
- $transaction->commit();
- return $model;
- }
- }
|