mProductCode = ''; $this->mThirdPorductType = 0; $this->mMatchRatio = false; $this->mMchCardTypes = []; $this->mFirstQuality = 0; $this->mOverPriceFlag = 0; $this->mMchAmount = 0; } public function finish() { if($this->mChannelFilter != null) { $this->mChannelFilter->finish(); } } public function mchid() { return $this->mMchid; } public function buyer_id() { return $this->mBuyerId; } public function mch_order() { return $this->mMchOrder; } public function set_mchorder($mch_order) { $this->mMchOrder = $mch_order; } public function set_last_orderid($order_id) { $this->mLastOrderID = $order_id; } public function first_commit() { return $this->mFirstCommit; } public function set_match($match) { $this->mMatchRatio = $match; } public function match_ratio() { return $this->mMatchRatio; } public function spec() { return $this->mAmount; } public function mch_amount() { return $this->mMchAmount; } public function card_no() { return $this->mCardNo; } public function card_type() { return $this->mCardType; } public function org_quality() { return $this->mOriginQuality; } public function cur_quality() { return $this->mCurQuality; } public function set_first_quality($quality) { $this->mFirstQuality = $quality; } public function set_can_overprice($match_ratio, $can_last) { if($match_ratio) //能匹配成功率 { if($can_last) { $value = 11;//能匹配成功率,能匹配利润率 -> 不要溢价补充 } else { $value = 12; //能匹配成功率,不能匹配利润率 -> 不要溢价补充 } } elseif($can_last) { $value = 1;//不能匹配成功率,但能匹配利润率 -> 需要溢价补充 } else { $value = 2;//不能匹配成功率,也不能匹配利润率 -> 不需要溢价补充 } $this->mOverPriceFlag = $value; } public function can_over_price() { //尚未设置初始值,不可溢价 if($this->mFirstQuality === 0) { return false; } if($this->mFirstQuality === $this->mCurQuality) { return false; } else { $value = $this->mOverPriceFlag; Log::record("can_over_price value is $value", Log::DEBUG); if ($value === 1 or $value === 0) { return true; } else { return false; } } } public function set_quality($org_quality, $quality) { $this->mOriginQuality = $org_quality; $this->mCurQuality = $quality; } public function order_time() { return $this->mOrderTime; } public function commit_times() { return $this->mCommitTimes; } public function commit_times_inc() { $this->mCommitTimes += 1; } public function elapse_secs() { return time() - $this->mOrderTime; } public function region_no() { return $this->mRegionNo; } public function pcode() { return $this->mProductCode; } public function last_order_id() { return $this->mLastOrderID; } public function validate() { return $this->mIsValidate; } public function quantity() { return $this->mQuantity; } public function card_state() { return $this->mCardState; } public function thrid_params() { $third_params = ['product_code' => $this->mProductCode, 'quantity' => $this->mQuantity, 'third_card_type' => $this->mThirdCardType]; return $third_params; } public function match_card_type() { if (empty($this->mMchCardTypes)) { return true; } else { return in_array($this->card_type(), $this->mMchCardTypes); } } public function is_transfer() { return $this->mIsTransfer; } public function is_black() { return $this->mBlack == 1; } public static function from_parameters($params) { $order = new order(); $order->setParams($params); return $order; } public static function from_db(array $refill_info, array $order_info, array $third_info = []) { $order = new order(); $order->setDbParams($refill_info, $order_info, $third_info); return $order; } private function setDbParams(array $refill_info, array $order_info, array $third_info = []) { $this->mMchid = intval($refill_info['mchid']); $this->mBuyerId = intval($order_info['buyer_id']); $this->mAmount = intval($refill_info['refill_amount']); $this->mCardNo = $refill_info['card_no']; $this->mCardType = intval($refill_info['card_type']); $this->mRegionNo = intval($refill_info['regin_no']); $this->mOriginQuality = intval($refill_info['org_quality']); $this->mCurQuality = intval($refill_info['quality']); $this->mMchOrder = $refill_info['mch_order'] ?? ''; $this->mNotifyUrl = $refill_info['notify_url'] ?? ''; $this->mIdCard = $refill_info['idcard'] ?? ''; $this->mCardName = $refill_info['card_name'] ?? ''; $this->mOrderTime = intval($refill_info['order_time']); $this->mCommitTimes = intval($refill_info['commit_times']); $this->mLastOrderID = intval($refill_info['order_id']); $this->mCardState = intval($refill_info['cardno_state']); $this->mIsTransfer = $refill_info['is_transfer'] == 1; $this->mIsValidate = mtopcard\is_validate($this->mCardState); $this->mQuantity = intval($order_info['goods_num'] ?? 1); $mch_amount = $refill_info['mch_amount']; if (bccomp("$mch_amount", '0', 5) === 0) { $this->mMchAmount = 0; } else { $this->mMchAmount = $mch_amount; } if (!empty($third_info) && $this->is_third()) { $this->mProductCode = $third_info['product_code']; $this->mThirdPorductType = $third_info['third_product_type']; $this->mThirdCardType = $third_info['third_card_type']; if ($this->mThirdPorductType == mtopcard\ThirdElectricProduct) { $this->mThirdExtes['company_type'] = $third_info['company_type']; $this->mThirdExtes['use_type'] = $third_info['use_type']; $this->mThirdExtes['province'] = $third_info['province']; $this->mThirdExtes['city'] = $third_info['city']; $this->mThirdExtes['card_id'] = $third_info['card_id']; } elseif ($this->mThirdPorductType == mtopcard\ThirdSinopecECouponPoroduct) { $this->mThirdExtes['province'] = $third_info['province']; } } $this->mChannelFilter = new channel_filter($this->mMchid,$this->mMchOrder,$this->mCardType); } public function is_third() { return $this->mCardType == 7; } public function third_product_type() { return $this->mThirdPorductType; } public function is_oil() { return in_array($this->mCardType, [mtopcard\SinopecCard, mtopcard\PetroChinaCard]); } public function is_phone() { return in_array($this->mCardType, [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard]); } public function unique_id() { return "{$this->mMchid}-{$this->mMchOrder}"; } public function filter() { return $this->mChannelFilter; } private function setParams($params) { $this->mMchid = intval($params['mchid']); $this->mBuyerId = intval($params['buyer_id']); $this->mAmount = intval($params['amount']); $this->mMchAmount = $params['mch_amount'] ?? 0; $this->mCardNo = $params['card_no']; $this->mMchOrder = $params['mch_order'] ?? ''; $this->mNotifyUrl = $params['notify_url'] ?? ''; $this->mIdCard = $params['idcard'] ?? ''; $this->mCardName = $params['card_name'] ?? ''; $this->mOrderTime = $params['order_time'] ?? time(); $this->mCommitTimes = $params['commit_times'] ?? 0; $this->mLastOrderID = $params['order_id'] ?? 0; $this->mQuantity = $params['quantity'] ?? 1; $this->mOriginQuality = intval($params['org_quality']) ?? 0; $this->mMatchRatio = $params['match_ratio'] ?? false; $this->mMchCardTypes = $params['mch_card_types'] ?? []; $card_type = intval($params['card_type']) ?? 0; if ($card_type == mtopcard\ThirdRefillCard) { $this->mCurQuality = $this->mOriginQuality; $this->mProductCode = $params['product_code']; $this->mThirdPorductType = $params['third_product_type']; $this->mThirdCardType = $params['third_card_type']; $this->mRegionNo = $params['province']; $this->mIsTransfer = false; $this->mCardState = 0; $this->mCardType = $card_type; $this->mIsValidate = true; $this->mFirstCommit = true; if ($this->mThirdPorductType == mtopcard\ThirdElectricProduct) { $this->mThirdExtes['company_type'] = $params['company_type']; $this->mThirdExtes['use_type'] = $params['use_type']; $this->mThirdExtes['province'] = $params['province']; $this->mThirdExtes['city'] = $params['city']; $this->mThirdExtes['card_id'] = $params['card_id']; } elseif ($this->mThirdPorductType == mtopcard\ThirdSinopecECouponPoroduct) { $this->mThirdExtes['province'] = $params['province']; } } else { $this->mProductCode = ''; $this->mCurQuality = intval($params['quality']) ?? 0; $this->mThirdCardType = 1; //deafult value if ($card_type == 0) { $this->mFirstCommit = true; [$validate, $card_type, $regin_no, $isTransfer, $card_state, $black] = mtopcard\valid_phone($this->mCardNo); $this->mCardType = $card_type; $this->mRegionNo = $regin_no; $this->mIsTransfer = $isTransfer; $mchid = $this->mMchid; global $config; $no_valid_mchids = $config['neednot_check_card_mchids'] ?? []; if(in_array($mchid,$no_valid_mchids)) { $this->mIsValidate = true; $this->mCardState = 1; $this->mBlack = false; } else { $this->mIsValidate = $validate; $this->mCardState = $card_state; $this->mBlack = $black; } } else { $this->mFirstCommit = false; $this->mCardType = $params['card_type']; $this->mRegionNo = $params['regin_no']; $this->mIsTransfer = $params['is_transfer'] == 1; $this->mCardState = $params['cardno_state']; $this->mIsValidate = $params['is_validate'] == 1; } } $this->mChannelFilter = new channel_filter($this->mMchid,$this->mMchOrder,$this->mCardType); } public function ZeroRefillParams($order_id, $order_sn, $spec, $mch_amount, $channel_name, $channel_amout, $err_msg) { $refill_amount = $spec * $this->mQuantity; $params = ['order_id' => $order_id, 'order_sn' => $order_sn, 'mchid' => $this->mMchid, 'refill_amount' => $refill_amount, 'mch_order' => $this->mMchOrder, 'idcard' => $this->mIdCard, 'card_name' => $this->mCardName, 'notify_url' => $this->mNotifyUrl, 'channel_name' => $channel_name, 'mch_amount' => $mch_amount, 'channel_amount' => $channel_amout, 'order_time' => $this->mOrderTime, 'commit_times' => $this->mCommitTimes, 'commit_time' => time(), 'notify_state' => 1, 'notify_time' => time(), 'is_transfer' => $this->mIsTransfer ? 1 : 0, 'cardno_state' => $this->mCardState, 'card_type' => $this->mCardType, 'regin_no' => $this->mRegionNo, 'card_no' => $this->mCardNo, 'quality' => $this->mCurQuality, 'org_quality' => $this->mOriginQuality, 'err_msg' => $err_msg]; return $params; } public function refill_params($order_id, $order_sn, $spec, $channel_name, $channel_amout, $mch_amount) { $refill_amount = $spec * $this->mQuantity; $params = ['order_id' => $order_id, 'order_sn' => $order_sn, 'mchid' => $this->mMchid, 'refill_amount' => $refill_amount, 'mch_order' => $this->mMchOrder, 'idcard' => $this->mIdCard, 'card_name' => $this->mCardName, 'notify_url' => $this->mNotifyUrl, 'channel_name' => $channel_name, 'mch_amount' => $mch_amount, 'channel_amount' => $channel_amout, 'order_time' => $this->mOrderTime, 'commit_times' => $this->mCommitTimes, 'card_type' => $this->mCardType, 'regin_no' => $this->mRegionNo, 'is_transfer' => $this->mIsTransfer ? 1 : 0, 'cardno_state' => $this->mCardState, 'card_no' => $this->mCardNo, 'quality' => $this->mCurQuality, 'org_quality' => $this->mOriginQuality]; return $params; } public function third_extparams($order_id, $order_sn) { $ext = ['order_id' => $order_id, 'order_sn' => $order_sn, 'product_type' => $this->mThirdPorductType, 'account_type' => $this->mThirdCardType, 'quantity' => $this->mQuantity, 'user_account' => $this->mCardNo, 'pcode' => $this->mProductCode, 'add_time' => time() ]; if ($this->is_third()) { if ($this->mThirdPorductType == mtopcard\ThirdElectricProduct) { $ext['company_type'] = $this->mThirdExtes['company_type']; $ext['use_type'] = $this->mThirdExtes['use_type']; $ext['province'] = $this->mThirdExtes['province']; $ext['city'] = $this->mThirdExtes['city']; $ext['card_id'] = $this->mThirdExtes['card_id']; } elseif ($this->mThirdPorductType == mtopcard\ThirdSinopecECouponPoroduct) { $ext['province'] = $this->mThirdExtes['province']; } } return $ext; } public function channel_params($order_id, $order_sn, $goods_id, $ch_price) { $params = ['order_sn' => $order_sn, 'idcard' => $this->mIdCard, 'card_name' => $this->mCardName, 'buyer_id' => $this->mBuyerId, 'quality' => $this->mCurQuality, 'order_id' => $order_id, 'regin_no' => $this->mRegionNo, 'mchid' => $this->mMchid,'ch_price' => $ch_price]; if ($this->is_third()) { $params['quantity'] = $this->mQuantity; $params['product_code'] = $this->mProductCode; $params['third_product_type'] = $this->mThirdPorductType; $params['third_card_type'] = $this->mThirdCardType; $params['goods_id'] = $goods_id; if ($this->mThirdPorductType == mtopcard\ThirdElectricProduct) { $params['company_type'] = $this->mThirdExtes['company_type']; $params['use_type'] = $this->mThirdExtes['use_type']; $params['province'] = $this->mThirdExtes['province']; $params['city'] = $this->mThirdExtes['city']; $params['card_id'] = $this->mThirdExtes['card_id']; } elseif ($this->mThirdPorductType == mtopcard\ThirdSinopecECouponPoroduct) { $params['province'] = $this->mThirdExtes['province']; } } return $params; } public function queue_params() { $params = ['mchid' => $this->mMchid, 'buyer_id' => $this->mBuyerId, 'amount' => $this->mAmount, //spec 'mch_amount' => $this->mMchAmount, 'quantity' => $this->mQuantity, 'card_no' => $this->mCardNo, 'card_type' => $this->mCardType, 'regin_no' => $this->mRegionNo, 'org_quality' => $this->mOriginQuality, 'quality' => $this->mCurQuality, 'mch_order' => $this->mMchOrder, 'notify_url' => $this->mNotifyUrl, 'idcard' => $this->mIdCard, 'card_name' => $this->mCardName, 'order_time' => $this->mOrderTime, 'commit_times' => $this->mCommitTimes, 'is_transfer' => $this->mIsTransfer ? 1 : 0, 'cardno_state' => $this->mCardState, 'order_id' => $this->mLastOrderID, 'is_validate' => $this->mIsValidate, 'match_ratio' => $this->mMatchRatio]; return $params; } public function third_requeue_params($pcode) { $params = ['mchid' => $this->mMchid, 'buyer_id' => $this->mBuyerId, 'mch_amount' => $this->mMchAmount, 'quantity' => $this->mQuantity, 'card_no' => $this->mCardNo, 'org_quality' => $this->mOriginQuality, 'quality' => $this->mCurQuality, 'mch_order' => $this->mMchOrder, 'notify_url' => $this->mNotifyUrl, 'idcard' => $this->mIdCard, 'card_name' => $this->mCardName, 'order_time' => $this->mOrderTime, 'commit_times' => $this->mCommitTimes, 'order_id' => $this->mLastOrderID, 'card_type' => $this->mCardType, 'third_product_type' => $this->mThirdPorductType, 'third_card_type' => $this->mThirdCardType ]; $params['product_code'] = $pcode; if($this->is_third()) { $params['amount'] = util::ThirdRefillAmount;; } else { $params['amount'] = $this->mAmount; } if ($this->mThirdPorductType == mtopcard\ThirdElectricProduct) { $params['company_type'] = $this->mThirdExtes['company_type']; $params['use_type'] = $this->mThirdExtes['use_type']; $params['province'] = $this->mThirdExtes['province']; $params['city'] = $this->mThirdExtes['city']; $params['card_id'] = $this->mThirdExtes['card_id']; } elseif ($this->mThirdPorductType == mtopcard\ThirdSinopecECouponPoroduct) { $params['province'] = $this->mThirdExtes['province']; } return $params; } }