|
|
@@ -100,8 +100,8 @@ class AutomaticDispatch extends Command
|
|
|
*/
|
|
|
protected function platformWorker($item) {
|
|
|
|
|
|
- // 定义地球半径(单位:千米)
|
|
|
- $earthRadius = 6371;
|
|
|
+ // 定义地球半径(单位:米)
|
|
|
+ $earthRadius = 6371000;
|
|
|
|
|
|
// 定义 Haversine 公式计算距离的 SQL 片段
|
|
|
$distanceCalculation = "{$earthRadius} * 2 * ASIN(SQRT(
|
|
|
@@ -123,6 +123,7 @@ class AutomaticDispatch extends Command
|
|
|
['service_area_id', '=', $item['service_area_id']],
|
|
|
['tenant_id', '=', 0]
|
|
|
])
|
|
|
+ ->distinct('a.id')
|
|
|
->whereRaw('FIND_IN_SET(' . $item['goods_category_id'] . ', a.category_ids)')
|
|
|
->whereRaw("{$distanceCalculation} <= a.distance")
|
|
|
->field([
|
|
|
@@ -141,6 +142,7 @@ class AutomaticDispatch extends Command
|
|
|
->limit(100)
|
|
|
->select()
|
|
|
->toArray();
|
|
|
+ //echo MasterWorker::getLastSql();die;
|
|
|
$queue = [];
|
|
|
foreach($worker as $key => $value) {
|
|
|
//过滤已接过此单的师傅
|
|
|
@@ -150,7 +152,7 @@ class AutomaticDispatch extends Command
|
|
|
}
|
|
|
|
|
|
//计算地理效率得分
|
|
|
- $realDistance = ceil($value['real_distance'] / 1000);
|
|
|
+ $realDistance = bcdiv($value['real_distance'],1000,2);
|
|
|
$travelTime = $realDistance * 2;//预计每公里行驶2分钟
|
|
|
|
|
|
$distanceScore = 100 - ($travelTime * 1.5) - ($realDistance * 5);
|
|
|
@@ -206,8 +208,8 @@ class AutomaticDispatch extends Command
|
|
|
*/
|
|
|
protected function teamWorker($item) {
|
|
|
|
|
|
- // 地球半径,单位:千米
|
|
|
- $earthRadius = 6371;
|
|
|
+ // 地球半径,单位:米
|
|
|
+ $earthRadius = 6371000;
|
|
|
|
|
|
// 定义 Haversine 公式计算距离的 SQL 片段
|
|
|
$distanceCalculation = "{$earthRadius} * 2 * ASIN(SQRT(
|
|
|
@@ -255,6 +257,7 @@ class AutomaticDispatch extends Command
|
|
|
->select()
|
|
|
->toArray();
|
|
|
|
|
|
+ //echo MasterWorkerTeam::getLastSql();die;
|
|
|
$minQueue = [];
|
|
|
$queue = [];
|
|
|
foreach($worker as $key => $value) {
|
|
|
@@ -264,13 +267,6 @@ class AutomaticDispatch extends Command
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if ( $value['distance'] > 0) {
|
|
|
- //校验客户的地址是否在工程师的接单区域内
|
|
|
- $realDistance = haversineDistance($item['lat'],$item['lon'], $value['lat'],$value['lon'],$value['distance']);
|
|
|
- if ($realDistance > $value['distance']) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
if ($value['am_order'] + $value['pm_order'] < $value['min_order']) {
|
|
|
$minQueue[] = $value;
|
|
|
} else {
|