Fare.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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\popupshop\model;
  9. use think\Model;
  10. class Fare extends Model{
  11. protected $pk = 'id';
  12. protected $table = 'ai_popupshop_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_freight = 0; //运费总价
  24. $total = 0; //单SKU运费
  25. foreach($item as $value){
  26. $real_amount += $value['amount'];
  27. $weight = $value['weight'] * $value['num'];
  28. if($weight <= $fare['first_weight'] || 0 == $fare['second_weight']){
  29. $total = $fare['first_price'];
  30. }else{
  31. $weight = $weight - $fare['second_weight'];
  32. $total = $fare['first_price'] + ceil($weight/$fare['second_weight']) * $fare['second_price'];
  33. }
  34. $real_freight += $total;
  35. }
  36. $data['real_amount'] = money($real_amount); //商品价格
  37. $data['real_freight'] = money($real_freight); //运费
  38. $data['order_amount'] = money($real_freight+$real_amount); //商品总价+运费
  39. return $data;
  40. }
  41. }