12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace refill;
- require_once (BASE_HELPER_PATH . '/icalc.php');
- use ICalc;
- use Exception;
- use Log;
- class CalcMerchantPrice implements ICalc
- {
- private $mPrice;
- public function __construct($mchid,$amount,$card_type)
- {
- $model = Model('merchant');
- $items = $model->getPrices($mchid,$amount);
- $match = false;
- foreach ($items as $item) {
- $types = $item['card_types'];
- $types = explode(',',$types);
- if(in_array($card_type,$types)) {
- $this->mPrice = round($item['price'],2);
- $match = true;
- break;
- }
- }
- if($match === false) {
- throw new Exception("没有协商商品购买价格.");
- }
- }
- public function calc_vgoods_price($goods_info)
- {
- return round($this->mPrice,2);
- }
- public function calc_vorder_amount($order_info)
- {
- $num = $order_info['quantity'];
- return round($this->mPrice * $num,2);
- }
- public function calc_tips()
- {
- Log::record("没有实现该接口" . __FUNCTION__ ,Log::ERR);
- return [];
- }
- }
- class ZeroMerchantPrice implements ICalc
- {
- public function __construct($mchid,$amount,$card_type)
- {
- }
- public function calc_vgoods_price($goods_info)
- {
- return round(0,2);
- }
- public function calc_vorder_amount($order_info)
- {
- return round(0,2);
- }
- public function calc_tips()
- {
- Log::record("没有实现该接口" . __FUNCTION__ ,Log::ERR);
- return [];
- }
- }
|