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

3 months ago
<?php
namespace App\Models;
class StockCompany extends SoftDeletesModel
{
3 months ago
public $table = 'stock_companys';
3 months ago
protected $appends = ['is_after_enrollment_text'];
/**
* 获取是否入学后上市的文本
*/
public function getIsAfterEnrollmentTextAttribute()
{
$array = [
0 => '否',
1 => '是',
];
return $array[$this->is_after_enrollment] ?? '否';
}
3 months ago
/**
* 关联公司
*/
public function company()
{
return $this->belongsTo(Company::class, 'company_id', 'id');
}
3 months ago
/**
* 获取指定时间范围内的上市公司数量(统计或列表)
* @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();
}
}
3 months ago
}