作者 何书鹏

给骑手佣金

<?php
return [
'First' => '首公里',
'First_fee' => '运费(元)',
'Additional' => '续公里',
'Max_distance' => '最大距离',
'Additional_fee' => '运费(元)',
'Goods_total_price' => '商品起送金额(元)'
'First' => '首公里',
'First_fee' => '收用户运费(元)',
'First_rider_fee' => '给骑手运费(元)',
'Additional' => '续公里',
'Additional_fee' => '收用户运费(元)',
'Additional_rider_fee' => '给骑手运费(元)',
'Max_distance' => '最大距离',
'Delivery_threshold' => '商品起送金额(元)'
];
... ...
... ... @@ -13,6 +13,12 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('First_rider_fee')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-first_rider_fee" data-rule="required" min="0" class="form-control" step="0.01" name="row[first_rider_fee]" type="number" value="{$row.first_rider_fee|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Additional')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-additional" data-rule="required" min="0" class="form-control" name="row[additional]" type="number" value="{$row.additional|htmlentities}">
... ... @@ -25,15 +31,21 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Additional_rider_fee')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-additional_rider_fee" data-rule="required" min="0" class="form-control" step="0.01" name="row[additional_rider_fee]" type="number" value="{$row.additional_rider_fee|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Max_distance')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-max_distance" data-rule="required" min="0" class="form-control" step="1" name="row[max_distance]" type="number" value="{$row.max_distance|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Goods_total_price')}:</label>
<label class="control-label col-xs-12 col-sm-2">{:__('Delivery_threshold')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-goods_total_price" data-rule="required" min="0" class="form-control" step="1" name="row[goods_total_price]" type="number" value="{$row.goods_total_price|htmlentities}">
<input id="c-delivery_threshold" data-rule="required" min="0" class="form-control" step="1" name="row[delivery_threshold]" type="number" value="{$row.delivery_threshold|htmlentities}">
</div>
</div>
<div class="form-group layer-footer">
... ...
... ... @@ -323,7 +323,8 @@ class Order extends Api
'code':'1',
'msg':'计算运费'
'data':
"price": "37574.00" 总价
"price": "37574.00", 总价
"delivery_threshold": "20.00", 起送价
})
*/
public function freightCalculation()
... ... @@ -342,7 +343,11 @@ class Order extends Api
$lng2 = $admin_address['lng'];
$sum_price = $this->distancePrice($lat1,$lng1,$lat2,$lng2,$goods_total_price);
if ($sum_price === false) $this->error('地址超出配送距离');
$this->success('计算运费',['price'=>$sum_price]);
$delivery_threshold = Db::name('litestore_rider_rule')->value('delivery_threshold');
$this->success('计算运费',[
'price' => $sum_price,
'delivery_threshold' => $delivery_threshold
]);
}
/**
... ... @@ -504,6 +509,20 @@ class Order extends Api
$sum_price += $distance_price; // 订单总价
$order_no = 'LQ-'.time().mt_rand(1000,9999); // 订单号
$couponprice = isset($coupon['price'])?$coupon['price']:0; // 优惠价格
// 给骑手佣金
$config = Db::name('litestore_rider_rule')->find();
$distance = ceil(getDistance($lat1,$lng1,$lat2,$lng2));
if ($distance > $config['first']){
$first_rider_fee = $config['first_rider_fee'];
$subdistance = $distance-$config['first'];
$count = ceil(bcdiv($subdistance,$config['additional'],1));
$second_rider_price = bcmul($count,$config['additional_rider_fee'],2);
$rider_price = bcadd($first_rider_fee,$second_rider_price,2);
}else{
$rider_price = $config['first_rider_fee'];
}
// 订单信息
$order = [
'order_no' => $order_no,
... ... @@ -512,7 +531,8 @@ class Order extends Api
'pay_price' => bcsub($sum_price,$couponprice,2), // 支付总价
'express_price' => $distance_price, // 骑手费用
'user_id' => $user_id,
'user_coupon_id' => $coupon_id > 0 ? $coupon_id : 0
'user_coupon_id' => $coupon_id > 0 ? $coupon_id : 0,
'rider_price' => $rider_price
];
// 添加订单
... ... @@ -633,7 +653,7 @@ class Order extends Api
$rider_order->sendtime = time(); //送达时间
$rider_order->save();
// 发放订单运费
\app\common\model\User::money($order->express_price,$order->rider_user_id,'订单运费');
\app\common\model\User::money($order->rider_price,$order->rider_user_id,'订单运费');
$this->success('收货成功');
}
... ...
... ... @@ -339,7 +339,7 @@ class Rider extends Api
$rider_order->sendtime = time(); //送达时间
$rider_order->save();
// 发放订单运费
User::money($order->express_price,$order->rider_user_id,'订单运费');
User::money($order->rider_price,$order->rider_user_id,'订单运费');
$this->success('送达成功',$order);
}
... ...
... ... @@ -31,10 +31,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'id', title: __('Id')},
{field: 'first', title: __('First'), operate:'BETWEEN'},
{field: 'first_fee', title: __('First_fee'), operate:'BETWEEN'},
{field: 'first_rider_fee', title: __('First_rider_fee'), operate:'BETWEEN'},
{field: 'additional', title: __('Additional'), operate:'BETWEEN'},
{field: 'additional_fee', title: __('Additional_fee'), operate:'BETWEEN'},
{field: 'additional_rider_fee', title: __('Additional_rider_fee'), operate:'BETWEEN'},
{field: 'max_distance', title: __('Max_distance'), operate:'BETWEEN'},
{field: 'goods_total_price', title: __('Goods_total_price'), operate:'BETWEEN'},
{field: 'delivery_threshold', title: __('Delivery_threshold'), operate:'BETWEEN'},
// {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
... ...