You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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();
}
}
}