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.

100 lines
3.1 KiB

5 months ago
<?php
namespace App\Models;
class Company extends SoftDeletesModel
{
4 weeks ago
3 weeks ago
protected $casts = ['project_users' => 'json', 'partners' => 'json'];
4 weeks ago
5 months ago
public function users()
{
return $this->hasMany(User::class, 'company_id', 'id');
}
5 months ago
4 months ago
/**
* 地址转经纬度
*/
public static function addressTolocation($address)
{
$map = Config::getValueByKey('map_server');
$map = json_decode($map, true);
$url = "https://restapi.amap.com/v3/geocode/geo";
$params = [
'key' => $map['key'],
'address' => $address,
];
try {
$result = httpCurl($url, 'GET', $params);
$result = json_decode($result, true);
if ($result['status'] == 1) {
$location = $result['geocodes'][0]['location'];
$location = explode(',', $location);
return [
'lng' => $location[0],
'lat' => $location[1],
];
}
return [
'lng' => null,
'lat' => null,
];
} catch (\Exception $e) {
return [
'lng' => null,
'lat' => null,
];
}
}
3 weeks ago
/**
* 上市公司(统计或列表)
* @param bool $retList 是否返回列表false返回数量true返回列表
* @return int|\Illuminate\Database\Eloquent\Collection
*/
public static function companyMarket($start_date, $end_date, $retList = false)
{
$courseSignByType = CourseSign::whereDate('created_at', '>=', $start_date)
->whereDate('created_at', '<=', $end_date)
->whereNotIn('status', [4, 5])
->get();
$list = Company::whereHas('users', function ($query) use ($courseSignByType) {
$query->whereIn('id', $courseSignByType->pluck('user_id'));
})->where('company_market', 1)->get();
if ($retList) {
// 返回列表
return $list;
} else {
// 返回统计数据
return $list->count();
}
}
/**
* 今年上市公司(统计或列表)
* @param int|null $year 年份,不传则使用当前年份
* @param bool $retList 是否返回列表false返回数量true返回列表
* @return int|\Illuminate\Database\Eloquent\Collection
*/
public static function companyMarketYear($start_date, $end_date, $course_ids, $retList = false)
{
$year = date('Y');
$courseSignByType = CourseSign::whereDate('created_at', '>=', $start_date)
->whereDate('created_at', '<=', $end_date)
->whereNotIn('status', [4, 5])
->get();
$list = Company::whereHas('users', function ($query) use ($courseSignByType) {
$query->whereIn('id', $courseSignByType->pluck('user_id'));
})->where('company_market', 1)->whereYear('stock_date', $year)->get();
if ($retList) {
// 返回列表
return $list;
} else {
// 返回统计数据
return $list->count();
}
}
4 months ago
5 months ago
}