Share.php
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace app\models;
use Yii;
use common\config\Params;
/**
* This is the model class for table "{{%share}}".
*
* @property integer $id
* @property integer $obj_id
* @property integer $type
* @property string $title
* @property string $content
* @property integer $create_time
* @property integer $update_time
*/
class Share extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%share}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['obj_id', 'type', 'create_time', 'update_time'], 'integer'],
[['content'], 'string'],
[['pic'], 'string', 'max' => 200],
[['title'], 'string', 'max' => 100],
[['obj_id', 'type'], 'unique', 'targetAttribute' => ['obj_id', 'type'], 'message' => 'The combination of Obj ID and Type has already been taken.'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'obj_id' => 'Obj ID',
'type' => 'Type',
'pic' => '分享头图',
'title' => '分享标题',
'content' => '分享内容',
'create_time' => 'Create Time',
'update_time' => 'Update Time',
];
}
public function behaviors()
{
return [
[
'class' => \yii\behaviors\TimestampBehavior::className(),
'createdAtAttribute' => 'create_time',
'updatedAtAttribute' => 'update_time',
]
];
}
/**
* 删除分享
* @param $obj_id
* @param $type
* @return bool
* @throws \Exception
*/
private function del($obj_id,$type)
{
try{
$rowCount = Yii::$app->db->createCommand()->delete(self::tableName(), ['obj_id'=>$obj_id,'type'=>$type])->execute();
return ($rowCount>=0) ? true:false;
}catch (\Exception $e){
throw new \Exception($e->getMessage());
}
}
public function delLivingShare($room_id)
{
return $this->del($room_id,Params::LIVE_SHARE_TYPE);
}
public function delVideoShare($video_id)
{
return $this->del($video_id,Params::VIDEO_SHARE_TYPE);
}
}