foreach ($store_arr as $store_value){
$res_arr = [];
$money = 0;
if ($store_value['store_info']['send_mode'] == 2){
$res_data[$store_value['store_id']] = [
'money' => $store_value['delivery_money'],
'list' => [[
'title' => '基础配送费',
'name' => 'money',
'money' => $store_value['delivery_money']
]],
'special_time_id' => 0
];
continue;
}
if ($store_value['partner_info']['type'] == 1){
$money = bcadd($money, $store_value['partner_info']['fixed_cost'], 2); //固定配送费
$res_arr[] = [
'title' => '基础配送费',
'name' => 'money',
'money' => $money
];
}else{
$money = $store_value['partner_info']['base_price'];
$res_arr[] = [
'title' => '基础配送费',
'name' => 'money',
'money' => $money
];
//计算公里数
if ($store_value['partner_info']['range'] > 0) {
if ($store_value['distance']) {
$d = $store_value['distance'];
} else {
$d = get_cycling($store_value['store_info']['lng'] . ',' . $store_value['store_info']['lat'],
$address['lng'] . ',' . $address['lat']);
}
$each_km = $store_value['partner_info']['each_km'];
if ($d > $store_value['partner_info']['range']) {
$dff = bcsub($d, $store_value['partner_info']['range'], 2);
$dff = ceil($dff);
$range_money = bcmul($dff, $each_km, 2);
$res_arr[] = [
'title' => '距离:' . $d . 'km收费',
'name' => 'range_money',
'money' => $range_money
];
$money = bcadd($money, $range_money, 2);
} else {
$res_arr[] = [
'title' => '距离:' . $d . 'km收费',
'name' => 'range_money',
'money' => 0
];
}
}
}
if (floatval($store_value['partner_info']['special_sky_price']) > 0) {
$money = bcadd($money, $store_value['partner_info']['special_sky_price'], 2); //特殊天气加价
$res_arr[] = [
'title' => '特殊天气加价',
'name' => 'special_sky_price',
'money' => $store_value['partner_info']['special_sky_price']
];
}
//特殊时间段
$special_time_price = 0;
$special_time_id = 0;
if (array_key_exists('special_time_info',$store_value) && $store_value['special_time_info']){
if ($is_once == 1) { //立即开始
$order_start_time = time();
} else {
$order_start_time = strtotime($pickup_time);
}
foreach ($store_value['special_time_info'] as $s) {
$start = strtotime(date("Y-m-d ") . $s['start_time']);
$end = strtotime(date("Y-m-d ") . $s['end_time']);
if ($start < $order_start_time && $order_start_time < $end) {
$special_time_price = bcadd($special_time_price, $s['cost'], 2);
$special_time_id = $s['id'];
}
}
}
if (floatval($special_time_price) > 0) {
$res_arr[] = [
'title' => '特殊时间段加价',
'name' => 'special_time_price',
'money' => $special_time_price
];
}
$money = bcadd($money, $special_time_price, 2);
if (array_key_exists('plan_info',$store_value) && $store_value['plan_info']){
$special_map_price = 0;
foreach ($store_value['plan_info'] as $p) {
$position = json_decode($p['position'], true);
$pts = [];
foreach ($position as $a) {
$pts[] = [
'lng' => $a['lng'],
'lat' => $a['lat']
];
}
$res = is_point_in_polygon(['lng' => $address['lng'], 'lat' => $address['lat']], $pts);
if ($res) {
$special_map_price = $p['money'];
break;
}
}
if (floatval($special_map_price) > 0) {
$res_arr[] = [
'title' => '地图围栏加价',
'name' => 'special_map_price',
'money' => $special_map_price
];
}
$money = bcadd($money, $special_map_price, 2);
}
$reduction_money = 0;
if (array_key_exists('reduction_info',$store_value) && $store_value['reduction_info']) {
foreach ($store_value['reduction_info'] as $p) {
$position = json_decode($p['position'], true);
$pts = [];
foreach ($position as $a) {
$pts[] = [
'lng' => $a['lng'],
'lat' => $a['lat']
];
}
$res = is_point_in_polygon(['lng' => $address['lng'], 'lat' => $address['lat']], $pts);
if ($res) {
$reduction_money = $p['money'];
break;
}
}
}
if ($reduction_money > 0) {
$res_arr[] = [
'title' => '商家承担配送费',
'name' => 'reduction_money',
'money' => $reduction_money
];
$money = bcsub($money, $reduction_money, 2);
}
if ($money < 0) {
$money = 0;
}
$res_data[$store_value['store_id']] = [
'money' => floatval($money),
'list' => $res_arr,
'special_time_id' => $special_time_id ?? 0
];
}
解释代码
最新发布