|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
|
|
class Company extends SoftDeletesModel
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
protected $casts = ['project_users' => 'json', 'partners' => 'json'];
|
|
|
|
|
|
|
|
|
|
|
|
public function users()
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->hasMany(User::class, 'company_id', 'id');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 地址转经纬度
|
|
|
|
|
|
*/
|
|
|
|
|
|
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,
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 上市公司(统计或列表)
|
|
|
|
|
|
* @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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|