作者 何书鹏

商品起送金额

... ... @@ -5,5 +5,6 @@ return [
'First_fee' => '运费(元)',
'Additional' => '续公里',
'Max_distance' => '最大距离',
'Additional_fee' => '运费(元)'
'Additional_fee' => '运费(元)',
'Goods_total_price' => '商品起送金额(元)'
];
... ...
... ... @@ -30,6 +30,12 @@
<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>
<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}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
... ...
... ... @@ -226,7 +226,7 @@ class Order extends Api
$admin_address = Db::name('admin_address')->find();
$lat2 = $admin_address['lat'];
$lng2 = $admin_address['lng'];
$express_price = $this->distancePrice($lat1,$lng1,$lat2,$lng2);
$express_price = $this->distancePrice($lat1,$lng1,$lat2,$lng2,$sum_price);
if ($express_price === false) $express_price = 0;
}else{
$address = [];
... ... @@ -315,6 +315,7 @@ class Order extends Api
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="address_id", type="integer", required=true, description="地址id")
* @ApiParams (name="goods_total_price", type="string", required=true, description="商品总价")
* @ApiReturn ({
'code':'1',
'msg':'计算运费'
... ... @@ -325,7 +326,9 @@ class Order extends Api
public function freightCalculation()
{
$address_id = $this->request->post('address_id');
$goods_total_price = $this->request->post('goods_total_price');
if (!$address_id) $this->error('请选择地址');
if (!$goods_total_price) $this->error('请计算商品总价');
$model = new UserAddress();
$address = $model::get($address_id);
if (!$address) $this->error('地址不存在');
... ... @@ -334,7 +337,7 @@ class Order extends Api
$admin_address = Db::name('admin_address')->find();
$lat2 = $admin_address['lat'];
$lng2 = $admin_address['lng'];
$sum_price = $this->distancePrice($lat1,$lng1,$lat2,$lng2);
$sum_price = $this->distancePrice($lat1,$lng1,$lat2,$lng2,$goods_total_price);
if ($sum_price === false) $this->error('地址超出配送距离');
$this->success('计算运费',['price'=>$sum_price]);
}
... ... @@ -478,7 +481,7 @@ class Order extends Api
$admin_address = Db::name('admin_address')->find();
$lat2 = $admin_address['lat'];
$lng2 = $admin_address['lng'];
$distance_price = $this->distancePrice($lat1,$lng1,$lat2,$lng2);
$distance_price = $this->distancePrice($lat1,$lng1,$lat2,$lng2,$sum_price);
if ($distance_price === false) $this->error('地址超出配送距离');
if ($coupon !== [] && $coupon['full_price'] > $sum_price) $this->error('优惠券不可使用');
... ...
... ... @@ -819,6 +819,7 @@ class User extends Api
/**
* 测试
* @ApiInternal
*/
public function notice(){
$client = new Client();
... ...
... ... @@ -388,14 +388,17 @@ class Api
* @param $lat1
* @param $lng2
* @param $lat2
* @param $goods_total_price
* @return bool|float
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
protected function distancePrice($lat1,$lng1,$lat2,$lng2)
protected function distancePrice($lat1,$lng1,$lat2,$lng2,$goods_total_price=0)
{
$config = Db::name('litestore_rider_rule')->find();
// 商品起送金额
if($goods_total_price >= $config['goods_total_price']) return 0;
$distance = ceil(getDistance($lat1,$lng1,$lat2,$lng2));
if ($distance > $config['max_distance']) return false;
if ($distance > $config['first']){
... ...
... ... @@ -34,6 +34,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'additional', title: __('Additional'), operate:'BETWEEN'},
{field: 'additional_fee', title: __('Additional_fee'), operate:'BETWEEN'},
{field: 'max_distance', title: __('Max_distance'), operate:'BETWEEN'},
{field: 'goods_total_price', title: __('Goods_total_price'), 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}
]
... ...