182 lines
3.9 KiB
PHP
182 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace app\admin\model\course;
|
|
|
|
use think\Model;
|
|
use app\admin\model\course\GroupBind;
|
|
|
|
class Live extends Model
|
|
{
|
|
// 表名
|
|
protected $name = 'course';
|
|
|
|
// 自动写入时间戳字段
|
|
protected $autoWriteTimestamp = 'integer';
|
|
|
|
// 定义时间戳字段名
|
|
protected $createTime = 'createtime';
|
|
protected $updateTime = 'updatetime';
|
|
protected $deleteTime = false;
|
|
|
|
|
|
// 追加属性
|
|
protected $append = [
|
|
'live_status',
|
|
'live_status_text',
|
|
'live_start_time_text'
|
|
// 'pay_type_text',
|
|
// 'validity_type_text',
|
|
// 'validity_diy_time_text',
|
|
// 'validity_fix_time_text',
|
|
// 'shelf_time_text',
|
|
// 'unshelf_time_text'
|
|
];
|
|
|
|
/**
|
|
* 通过优惠券 ids 集合获取可正常展示的优惠券
|
|
* @param $ids
|
|
* @return void
|
|
*/
|
|
public function idsGetLives($ids,$limit=0){
|
|
|
|
$lives = self::normal()
|
|
->where([
|
|
'id'=>['in',$ids]
|
|
]) // 符合指定商品,并且检测商品所属分类
|
|
->order('id', 'desc');
|
|
|
|
if($limit){
|
|
$lives = $lives->limit($limit);
|
|
}
|
|
|
|
$lives = $lives->select();
|
|
|
|
$lives = collection($lives)->each(function ($coupon) {
|
|
|
|
});
|
|
|
|
return $lives;
|
|
}
|
|
|
|
|
|
public function scopeNormal($query)
|
|
{
|
|
return $query->where([
|
|
'status'=>1,
|
|
'sales_type'=>['like',"%alone%"],
|
|
'hide'=>0,
|
|
'type'=>'live'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 直播中
|
|
* @param $query
|
|
* @return void
|
|
*/
|
|
public function scopeIng($query){
|
|
return $query->where([
|
|
'live_start_time'=>['<',time()],
|
|
'live_end_time'=>['>',time()]
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 未开始
|
|
* @param $query
|
|
* @return void
|
|
*/
|
|
public function scopeUnstart($query){
|
|
return $query->where([
|
|
'live_start_time'=>['>',time()]
|
|
]);
|
|
}
|
|
|
|
|
|
/**
|
|
* 已结束
|
|
* @param $query
|
|
* @return void
|
|
*/
|
|
public function scopeEnd($query){
|
|
return $query->where([
|
|
'live_end_time'=>['<',time()]
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 最近直播
|
|
* @param $query
|
|
* @return void
|
|
*/
|
|
public function scopeRecently($query){
|
|
return $query->order('live_start_time','desc');
|
|
}
|
|
|
|
/**
|
|
* 最近直播
|
|
* @param $query
|
|
* @return void
|
|
*/
|
|
public function scopeFieldLimit($query){
|
|
return $query->field(['id','name','price','price_marking','pay_type','cover','briefing','status','live_start_time','live_end_time']);
|
|
}
|
|
|
|
|
|
/**
|
|
* 直播状态
|
|
* @return void
|
|
*/
|
|
public function getLiveStatusList()
|
|
{
|
|
return [
|
|
'ing'=>'直播中',
|
|
'recently'=>'最近直播',
|
|
'unstart'=>'未开始',
|
|
'end'=>'已结束'
|
|
];
|
|
}
|
|
|
|
public function getLiveStatusAttr($value, $data)
|
|
{
|
|
|
|
if($data['live_end_time'] < time()){
|
|
return 'end';
|
|
}
|
|
|
|
if($data['live_start_time'] > time()){
|
|
return 'unstart';
|
|
}
|
|
|
|
if($data['live_end_time'] > time() && $data['live_start_time'] < time()){
|
|
return 'ing';
|
|
}
|
|
}
|
|
|
|
public function getLiveStatusTextAttr($value, $data)
|
|
{
|
|
$liveStatusList = $this->getLiveStatusList();
|
|
return $liveStatusList[$this->getLiveStatusAttr($value, $data)];
|
|
}
|
|
|
|
public function getLiveStartTimeTextAttr($value, $data)
|
|
{
|
|
return date('Y-m-d H:i',$data['live_start_time']);
|
|
}
|
|
|
|
|
|
public function getPayTypeList()
|
|
{
|
|
return ['free' => __('Free'), 'pay' => __('Pay'), 'password' => __('Password')];
|
|
}
|
|
|
|
|
|
public function getTypeTextAttr($value, $data)
|
|
{
|
|
$value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
|
|
$list = $this->getTypeList();
|
|
return isset($list[$value]) ? $list[$value] : '';
|
|
}
|
|
|
|
}
|