初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\live;
|
||||
|
||||
use think\Model;
|
||||
|
||||
|
||||
class Goods extends Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 表名
|
||||
protected $name = 'live_room_goods';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'integer';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = false;
|
||||
protected $deleteTime = false;
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'status_text',
|
||||
'explaining_text',
|
||||
'sellout_text'
|
||||
];
|
||||
|
||||
|
||||
|
||||
public function getStatusList()
|
||||
{
|
||||
return ['1' => __('Status 1'), '0' => __('Status 0')];
|
||||
}
|
||||
|
||||
|
||||
public function getStatusTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
|
||||
$list = $this->getStatusList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
public function getExplainingList()
|
||||
{
|
||||
return ['1' => __('Explaining 1'), '0' => __('Explaining 0')];
|
||||
}
|
||||
|
||||
|
||||
public function getExplainingTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['explaining']) ? $data['explaining'] : '');
|
||||
$list = $this->getExplainingList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
public function getSelloutList()
|
||||
{
|
||||
return ['1' => __('Sellout 1'), '0' => __('Sellout 0')];
|
||||
}
|
||||
|
||||
|
||||
public function getSelloutTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : (isset($data['sellout']) ? $data['sellout'] : '');
|
||||
$list = $this->getSelloutList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function course()
|
||||
{
|
||||
return $this->belongsTo('app\admin\model\Course', 'live_id', 'id', [], 'LEFT')->setEagerlyType(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定商品
|
||||
* @param [type] $query
|
||||
* @param [type] $goods
|
||||
* @return void
|
||||
*/
|
||||
public function scopeNormal($query)
|
||||
{
|
||||
return $query->where([
|
||||
'status'=>1,
|
||||
'sellout'=>0
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定商品
|
||||
* @param [type] $query
|
||||
* @param [type] $goods
|
||||
* @return void
|
||||
*/
|
||||
public function scopeSort($query)
|
||||
{
|
||||
return $query->order('explaining DESC, id ASC');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user