CalcMerchantPrice.php 1.5 KB

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