Fare.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 运费管理
  7. */
  8. namespace app\fastshop\model;
  9. use think\Model;
  10. class Fare extends Model{
  11. protected $pk = 'id';
  12. protected $table = 'ai_fastshop_fare';
  13. protected $autoWriteTimestamp = true;
  14. protected $createTime = false;
  15. /**
  16. * 计算运费多少钱
  17. * @param array $item [计算参数]
  18. * @return array 商品价格信息
  19. */
  20. public static function realAmount($item,$member_miniapp_id){
  21. $fare = self::where(['member_miniapp_id' => $member_miniapp_id])->find();
  22. $real_amount = 0; //商品总价
  23. $real_weight = 0; //商品总重量
  24. $real_freight = 0; //运费总价
  25. //计算商品价格+商品总重量
  26. foreach($item as $value){
  27. $real_amount += $value['amount'];
  28. $real_weight += $value['weight'] * $value['num'];
  29. }
  30. //计算运费和商品价格
  31. if($real_weight <= $fare['first_weight'] || 0 == $fare['second_weight']){
  32. $real_freight = $fare['first_price'];
  33. }else{
  34. $weight = $real_weight - $fare['second_weight'];
  35. $real_freight = $fare['first_price'] + ceil($weight/$fare['second_weight']) * $fare['second_price'];
  36. }
  37. $data['real_amount'] = money($real_amount); //商品价格
  38. $data['real_freight'] = money($real_freight); //运费
  39. $data['order_amount'] = money($real_freight+$real_amount); //商品总价+运费
  40. return $data;
  41. }
  42. }