CalcMerchantPrice.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. }
  22. else {
  23. $this->mPrice = $price;
  24. }
  25. }
  26. public function calc_vgoods_price($goods_info)
  27. {
  28. return round($this->mPrice,2);
  29. }
  30. public function calc_vorder_amount($order_info)
  31. {
  32. $num = $order_info['quantity'];
  33. return round($this->mPrice * $num,2);
  34. }
  35. public function calc_tips()
  36. {
  37. Log::record("没有实现该接口" . __FUNCTION__ ,Log::ERR);
  38. return [];
  39. }
  40. }
  41. class ZeroMerchantPrice implements ICalc
  42. {
  43. public function __construct($mchid,$amount,$card_type,$quality)
  44. {
  45. }
  46. public function calc_vgoods_price($goods_info)
  47. {
  48. return round(0,2);
  49. }
  50. public function calc_vorder_amount($order_info)
  51. {
  52. return round(0,2);
  53. }
  54. public function calc_tips()
  55. {
  56. Log::record("没有实现该接口" . __FUNCTION__ ,Log::ERR);
  57. return [];
  58. }
  59. }