CalcMerchantPrice.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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,$spec,$card_type,$quality,$policy)
  11. {
  12. $price = $policy->price($mchid,$spec,$card_type,$quality);
  13. if($price === false) {
  14. throw new Exception("没有协商商品购买价格.");
  15. }
  16. else {
  17. $this->mPrice = $price;
  18. }
  19. }
  20. public function calc_vgoods_price($goods_info)
  21. {
  22. return round($this->mPrice,2);
  23. }
  24. public function calc_vorder_amount($order_info)
  25. {
  26. $num = $order_info['quantity'];
  27. return round($this->mPrice * $num,2);
  28. }
  29. public function calc_tips()
  30. {
  31. Log::record("没有实现该接口" . __FUNCTION__ ,Log::ERR);
  32. return [];
  33. }
  34. }
  35. class ZeroMerchantPrice implements ICalc
  36. {
  37. public function __construct($mchid,$amount,$card_type,$quality)
  38. {
  39. }
  40. public function calc_vgoods_price($goods_info)
  41. {
  42. return round(0,2);
  43. }
  44. public function calc_vorder_amount($order_info)
  45. {
  46. return round(0,2);
  47. }
  48. public function calc_tips()
  49. {
  50. Log::record("没有实现该接口" . __FUNCTION__ ,Log::ERR);
  51. return [];
  52. }
  53. }