200,'freight'=> $goods_info['postage'],'msg'=>'','id'=>0]; } else if($goods_info['freight_id']){ return self::getExpressPrice($address_info,$goods_info['freight_id'],$num) ; // 快递费用 }else{ return ['code'=>200,'freight'=> 0,'msg'=>'','id'=>0]; } } /** * @param array $address_info 收货地址 * @param $freight_id 运费模板id * @param int $num 商品数量 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public static function getExpressPrice($address_info,$freight_id,$num = 1) { $data = ['code'=>200,'freight'=>0 ,'msg'=>'','id'=>0]; $template_info = Db::name('freight_template')->find($freight_id); if(empty($address_info)){ $data['code'] = 201; $data['msg'] = '运费模板不存在'; return $data; } $city_id = $address_info['city_id']; $no_express = explode(',',$template_info['no_express']); if(in_array($city_id,$no_express)) return ['code'=>202,'freight'=>0 ,'msg'=>'该收货地址不配送物流']; // 模板自定义分组 $custom = json_decode($template_info['custom'],true); $base_num = $template_info['base_num'];// 基件数量 $base_price = $template_info['base_price']; // 基件费用 $base_keep_price = $template_info['base_keep_price']; // 续件费用 foreach($custom as $cus_info) { $express =explode(',',$cus_info['express']); if(in_array($city_id,$express)) { $base_num = $cus_info['first_num']; $base_price = $cus_info['first_price']; $base_keep_price = $cus_info['keep_price']; break; } } if($base_num >= $num ) return $data = ['code'=>200,'freight'=>$base_price ,'msg'=>'ok']; $sub_keep = bcmul(bcsub($num,$base_num),$base_keep_price,2); return $data = ['code'=>200,'freight'=>bcadd($base_price,$sub_keep,2) ,'msg'=>'ok']; } }