Share.php
3.04 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
98
99
<?php
namespace common\models;
use Yii;
use common\config\Params;
use backend\widgets\YHGImage\Common\Images as CommonImages;
/**
* 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 getLivingShare($room_id)
{
return $this->get($room_id, Params::LIVE_SHARE_TYPE);
}
public function getVideoShare($video_id)
{
return $this->get($video_id, Params::VIDEO_SHARE_TYPE);
}
private function get($obj_id, $type)
{
$ret = [
'share_pic' => 'http://img11.static.yhbimg.com/global/2016/08/17/18/01f17a9cd44149052482e4ee58e590cf1b.png?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
'share_url' => ($type == Params::LIVE_SHARE_TYPE) ? YOHOBUY_H5_DOMAIN.'/activity/live/' . $obj_id : YOHOBUY_H5_DOMAIN.'/activity/live/replay/' . $obj_id,
'share_title' => '有货潮流新品节直播开始啦,快来看!',
'share_content' => 'YO\'HOOD嘉年华现场火热直播中,明星潮牌等你来!',
];
if ($model = self::findOne(['obj_id' => $obj_id, 'type' => $type])) {
$ret['share_pic'] = CommonImages::getTemplateComplex($model->pic, 2);
$ret['share_title'] = $model->title;
$ret['share_content'] = $model->content;
}
return $ret;
}
/**
* 红包分享
* @return array
*/
public function redBag()
{
return [
'redbag_share_pic' => CommonImages::getTemplateComplex('/2016/11/01/17/01835bcc555349d7d7a5a83bb9e68f1fa7.png', 1),
'redbag_share_title' => '有货直播发红包啦,快来抢!',
'redbag_share_content' => '有货直播中狂发红包,领取立享优惠!',
];
}
}