CalcMerchantPrice.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. }
  43. class ZeroMerchantPrice implements ICalc
  44. {
  45. public function __construct($mchid,$amount,$card_type)
  46. {
  47. }
  48. public function calc_vgoods_price($goods_info)
  49. {
  50. return round(0,2);
  51. }
  52. public function calc_vorder_amount($order_info)
  53. {
  54. return round(0,2);
  55. }
  56. public function calc_tips()
  57. {
  58. Log::record("没有实现该接口" . __FUNCTION__ ,Log::ERR);
  59. return [];
  60. }
  61. }