CalcMerchantPrice.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace refill;
  3. require_once (BASE_HELPER_PATH . '/icalc.php');
  4. use ICalc;
  5. use Exception;
  6. use Log;
  7. class CalcMerchantPrice implements ICalc
  8. {
  9. private $mPrice;
  10. public function __construct($mchid,$amount,$card_type)
  11. {
  12. $model = Model('merchant');
  13. $items = $model->getPrices($mchid,$amount);
  14. $match = false;
  15. foreach ($items as $item) {
  16. $types = $item['card_types'];
  17. $types = explode(',',$types);
  18. if(in_array($card_type,$types)) {
  19. $this->mPrice = round($item['price'],2);
  20. $match = true;
  21. break;
  22. }
  23. }
  24. if($match === false) {
  25. throw new Exception("没有协商商品购买价格.");
  26. }
  27. }
  28. public function calc_vgoods_price($goods_info)
  29. {
  30. return round($this->mPrice,2);
  31. }
  32. public function calc_vorder_amount($order_info)
  33. {
  34. $num = $order_info['quantity'];
  35. return round($this->mPrice * $num,2);
  36. }
  37. public function calc_tips()
  38. {
  39. Log::record("没有实现该接口" . __FUNCTION__ ,Log::ERR);
  40. return [];
  41. }
  42. }