Share.php 3.04 KB
<?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' => '有货直播中狂发红包,领取立享优惠!',
        ];
    }
}