123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkAdmin
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://demo.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
- // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
- // +----------------------------------------------------------------------
- namespace app\common\service;
- use think\Db;
- /**
- * 商城邮费服务
- * Class ExpressService
- * @package app\store\service
- */
- class ExpressService
- {
- public static function getGoodsExpressPrice($goods_info,$address_info,$num)
- {
- if($goods_info['freight_type'] == 0){
- return ['code'=>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'];
- }
- }
|