TaskSystem/app/api/controller/RemoteController.php

227 lines
8.0 KiB
PHP
Raw Normal View History

2023-08-15 09:44:59 +08:00
<?php
namespace app\api\controller;
2023-08-15 13:46:31 +08:00
use Symfony\Component\HttpClient\HttpClient;
use think\facade\Log;
2023-08-16 15:44:36 +08:00
use app\common\model\informationg\UserInformationg;
2023-09-05 15:52:01 +08:00
use app\common\model\task_template\TaskTemplate;
2023-08-15 13:46:31 +08:00
class RemoteController extends BaseApiController
{
public array $notNeedLogin = ['index'];
2023-08-16 15:44:36 +08:00
2023-09-13 14:29:48 +08:00
public function shang_date_total_price($company, $arr = [], $template_id = 0)
2023-08-15 13:46:31 +08:00
{
2023-09-08 10:25:10 +08:00
$start_time = date('Y-m-d');
2023-09-13 14:29:48 +08:00
$time = strtotime($start_time) + 86399;
$end_time = date('Y-m-d H:i:s', $time);
2023-09-08 10:25:10 +08:00
2023-09-13 14:29:48 +08:00
if (isset($arr['start_time']) && $arr['end_time']) {
2023-08-22 16:12:34 +08:00
$start_time = $arr['start_time'];
$end_time = $arr['end_time'];
2023-08-17 17:12:49 +08:00
}
2023-08-15 13:46:31 +08:00
$parmas = [
2023-08-22 16:12:34 +08:00
"start_date" => $start_time,
"end_date" => $end_time
2023-08-15 13:46:31 +08:00
];
2023-08-16 15:44:36 +08:00
switch ($company['company_type']) {
case 18:
2023-08-30 17:34:51 +08:00
$parmas['brigade_id'] = $company['responsible_area'];
2023-08-16 15:44:36 +08:00
$parmas['village_code'] = $company['village'];
$parmas['street_code'] = $company['street'];
$parmas['district_code'] = $company['area'];
$parmas['city_code'] = $company['city'];
break;
case 17:
2023-08-30 17:34:51 +08:00
$parmas['village_code'] = $company['responsible_area'];
2023-08-16 15:44:36 +08:00
$parmas['street_code'] = $company['street'];
$parmas['district_code'] = $company['area'];
$parmas['city_code'] = $company['city'];
break;
case 16:
2023-08-30 17:34:51 +08:00
$parmas['street_code'] = $company['responsible_area'];
2023-08-16 15:44:36 +08:00
$parmas['district_code'] = $company['area'];
$parmas['city_code'] = $company['city'];
break;
case 15:
$parmas['district_code'] = $company['area'];
$parmas['city_code'] = $company['city'];
break;
case 14:
$parmas['city_code'] = $company['city'];
break;
default:
Log::error('任务结算失败,公司类型错误:' . $company['company_type']);
2023-09-13 14:29:48 +08:00
Log::error('片区交易错误:' . $company);
2023-08-16 15:44:36 +08:00
return false;
}
2023-08-15 13:46:31 +08:00
try {
2023-09-13 14:29:48 +08:00
$res = HttpClient::create()->request('GET', env('url.shop_prefix') . '/api/order/statistics', [
2023-08-15 13:46:31 +08:00
'query' => $parmas,
]);
2023-08-16 15:44:36 +08:00
$json = json_decode($res->getContent(), true);
$arr['total_price'] = 0;
$arr['status'] = 0;
2023-08-16 16:00:04 +08:00
$arr['day_money'] = 0;
2023-08-16 15:44:36 +08:00
$name = '片区交易';
if ($json['status'] == 200) {
$arr['total_price'] = $json['data']['total_price'];
//基础金额*(每日基户数*天数)//且户数小于公司总户数
$user_count = UserInformationg::where('company_id', $company['id'])->count();
2023-09-13 14:29:48 +08:00
$day_count = TaskTemplate::where('id', $template_id)->value('day_count');
2023-08-16 16:00:04 +08:00
//
2023-09-13 14:29:48 +08:00
if ($day_count == 0) {
2023-08-21 15:14:39 +08:00
$user_count_two = 5 * 1;
2023-09-13 14:29:48 +08:00
} else {
2023-09-05 15:52:01 +08:00
$user_count_two = 5 * $day_count;
2023-08-21 15:14:39 +08:00
}
2023-08-16 15:44:36 +08:00
if ($user_count_two > $user_count) {
$user_count_money = 58 * $user_count;
} else {
$user_count_money = 58 * $user_count_two;
}
if ($json['data']['total_price'] > $user_count_money) {
$arr['status'] = 1;
$name = '片区交易';
}
2023-08-16 16:00:04 +08:00
$arr['day_money'] = $user_count_money;
2023-08-15 13:46:31 +08:00
} else {
2023-08-16 15:44:36 +08:00
Log::error('获取订单金额失败:' . $json . '参数:' . json_encode($parmas));
2023-08-15 13:46:31 +08:00
}
2023-08-16 15:44:36 +08:00
return ['name' => $name, 'arr' => $arr];
2023-08-15 13:46:31 +08:00
} catch (\Exception $e) {
2023-08-16 15:44:36 +08:00
Log::error('获取订单金额失败:' . $e->getMessage() . '参数:' . json_encode($parmas));
return false;
2023-08-15 13:46:31 +08:00
}
}
2023-08-21 16:32:56 +08:00
2023-09-13 14:29:48 +08:00
public function shang_date_list($company, $querys)
{
$start_time = date('Y-m-d');
$time = strtotime($start_time) + 86399;
$end_time = date('Y-m-d H:i:s', $time);
if (isset($querys['start_time']) && isset($querys['end_time'])) {
2023-08-24 12:07:04 +08:00
$start_time = $querys['start_time'];
$end_time = $querys['end_time'];
2023-08-22 14:54:34 +08:00
}
$parmas = [
2023-08-24 11:52:56 +08:00
"start_date" => $start_time,
"end_date" => $end_time
2023-08-22 14:54:34 +08:00
];
switch ($company['company_type']) {
case 18:
2023-08-30 21:08:12 +08:00
$parmas['brigade_id'] = $company['responsible_area'];
2023-08-22 14:54:34 +08:00
$parmas['village_code'] = $company['village'];
$parmas['street_code'] = $company['street'];
$parmas['district_code'] = $company['area'];
$parmas['city_code'] = $company['city'];
break;
case 17:
2023-08-30 21:08:12 +08:00
$parmas['village_code'] = $company['responsible_area'];
2023-08-22 14:54:34 +08:00
$parmas['street_code'] = $company['street'];
$parmas['district_code'] = $company['area'];
$parmas['city_code'] = $company['city'];
break;
case 16:
2023-08-30 21:08:12 +08:00
$parmas['street_code'] = $company['responsible_area'];
2023-08-22 14:54:34 +08:00
$parmas['district_code'] = $company['area'];
$parmas['city_code'] = $company['city'];
break;
case 15:
$parmas['district_code'] = $company['area'];
$parmas['city_code'] = $company['city'];
break;
case 14:
$parmas['city_code'] = $company['city'];
break;
default:
return false;
}
2023-09-13 14:29:48 +08:00
if (isset($querys['page'])) {
$parmas['page'] = $querys['page'];
2023-08-22 15:05:16 +08:00
}
2023-08-30 21:08:12 +08:00
2023-09-13 14:29:48 +08:00
try {
$list = HttpClient::create()->request('GET', env('url.shop_prefix') . '/api/region/order', [
2023-08-22 14:54:34 +08:00
'query' => $parmas,
]);
$json_list = json_decode($list->getContent(), true);
2023-08-30 21:08:12 +08:00
2023-09-13 14:29:48 +08:00
$data = [];
if ($json_list['status'] == 200) {
$data = $json_list['data']['list'];
2023-08-22 14:54:34 +08:00
}
return $data;
2023-09-13 14:29:48 +08:00
} catch (\Exception $e) {
2023-08-22 14:54:34 +08:00
return false;
}
}
2023-08-21 16:32:56 +08:00
/**
*
* 获取坐标的距离
*/
2023-09-13 14:29:48 +08:00
public function coordinate($parmas, $longitude1, $latitude1)
{
$res = HttpClient::create()->request('GET', env('project.logistic_domain') . '/api/getCarHistory', [
2023-08-21 16:32:56 +08:00
'query' => $parmas,
]);
2023-09-13 14:29:48 +08:00
$json = json_decode($res->getContent(), true);
$points = $json['data'];
if (empty($points)) {
2023-08-30 17:34:51 +08:00
return false;
}
2023-09-13 14:29:48 +08:00
$target = [
"lat" => $latitude1,
"lon" => $longitude1
2023-08-21 16:32:56 +08:00
];
$closestPoint = $this->getClosestPoint($points, $target);
2023-09-13 14:29:48 +08:00
return $this->calculateDistance($target['lon'], $target['lat'], $closestPoint[0]['lon'], $closestPoint[0]['lat']);
2023-08-21 16:32:56 +08:00
}
/**
*
* 计算两点之间的距离
*/
2023-09-13 14:29:48 +08:00
function getClosestPoint($points, $target)
{
2023-08-21 16:32:56 +08:00
$minDistance = PHP_INT_MAX;
$closestPoint = null;
foreach ($points as $point) {
// halt($point,$target);
2023-08-21 16:32:56 +08:00
$distance = sqrt(pow(($point['lat'] - $target['lat']), 2) + pow(($point['lon'] - $target['lon']), 2));
if ($distance < $minDistance) {
$minDistance = $distance;
$closestPoint = $point;
2023-09-13 14:29:48 +08:00
} else {
$distance = 0;
2023-08-21 16:32:56 +08:00
}
}
2023-09-13 14:29:48 +08:00
return [$closestPoint, $distance];
2023-08-21 16:32:56 +08:00
}
/**
*
* 计算两点之间的距离
*/
2023-09-13 14:29:48 +08:00
function calculateDistance($longitude1, $latitude1, $longitude2, $latitude2)
{
2023-08-21 16:32:56 +08:00
$earthRadius = 6371; // 地球半径,单位为公里
2023-09-13 14:29:48 +08:00
2023-08-21 16:32:56 +08:00
$dLat = deg2rad($latitude2 - $latitude1);
$dLon = deg2rad($longitude2 - $longitude1);
2023-09-13 14:29:48 +08:00
$a = sin($dLat / 2) * sin($dLat / 2) +
2023-08-21 16:32:56 +08:00
cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) *
2023-09-13 14:29:48 +08:00
sin($dLon / 2) * sin($dLon / 2);
2023-08-21 16:32:56 +08:00
$c = 2 * asin(sqrt($a));
2023-09-13 14:29:48 +08:00
return $earthRadius * $c * 100;
2023-08-21 16:32:56 +08:00
}
2023-08-15 09:44:59 +08:00
}