|
|
<?php
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
class StockCompany extends SoftDeletesModel
|
|
|
{
|
|
|
public $table = 'stock_companys';
|
|
|
|
|
|
protected $appends = ['is_after_enrollment_text'];
|
|
|
|
|
|
/**
|
|
|
* 获取是否入学后上市的文本
|
|
|
*/
|
|
|
public function getIsAfterEnrollmentTextAttribute()
|
|
|
{
|
|
|
$array = [
|
|
|
0 => '否',
|
|
|
1 => '是',
|
|
|
];
|
|
|
return $array[$this->is_after_enrollment] ?? '否';
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 关联公司
|
|
|
*/
|
|
|
public function company()
|
|
|
{
|
|
|
return $this->belongsTo(Company::class, 'company_id', 'id');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取指定时间范围内的上市公司数量(统计或列表)
|
|
|
* @param string|null $start_date 开始日期
|
|
|
* @param string|null $end_date 结束日期
|
|
|
* @param bool $retList 是否返回列表,false返回数量,true返回列表
|
|
|
* @return int|\Illuminate\Database\Eloquent\Collection
|
|
|
*/
|
|
|
public static function getByDateRange($start_date = null, $end_date = null, $retList = false)
|
|
|
{
|
|
|
$query = self::when($start_date && $end_date, function ($query) use ($start_date, $end_date) {
|
|
|
$query->whereBetween('stock_date', [$start_date, $end_date]);
|
|
|
});
|
|
|
|
|
|
if ($retList) {
|
|
|
return $query->get();
|
|
|
} else {
|
|
|
return $query->count();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取入学后上市的公司数量(统计或列表)
|
|
|
* @param string|null $start_date 开始日期
|
|
|
* @param string|null $end_date 结束日期
|
|
|
* @param bool $retList 是否返回列表,false返回数量,true返回列表
|
|
|
* @return int|\Illuminate\Database\Eloquent\Collection
|
|
|
*/
|
|
|
public static function getAfterEnrollment($start_date = null, $end_date = null, $retList = false)
|
|
|
{
|
|
|
$query = self::where('is_after_enrollment', 1)
|
|
|
->when($start_date && $end_date, function ($query) use ($start_date, $end_date) {
|
|
|
$query->whereBetween('stock_date', [$start_date, $end_date]);
|
|
|
});
|
|
|
|
|
|
if ($retList) {
|
|
|
return $query->get();
|
|
|
} else {
|
|
|
return $query->count();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|