mProductCode = ''; $this->mThirdPorductType = 0; } 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 spec() { return $this->mAmount; } 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_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 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) { $order = new order(); $order->setDbParams($refill_info, $order_info); return $order; } private function setDbParams(array $refill_info, array $order_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); } 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]); } private function setParams($params) { $this->mMchid = intval($params['mchid']); $this->mBuyerId = intval($params['buyer_id']); $this->mAmount = intval($params['amount']); $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; $card_type = intval($params['card_type']) ?? 0; if($card_type == 7) { $this->mCurQuality = $this->mOriginQuality; $this->mProductCode = $params['product_code']; $this->mThirdPorductType = $params['third_product_type']; $this->mThirdCardType = $params['third_card_type']; $this->mRegionNo = 0; $this->mIsTransfer = false; $this->mCardState = 0; $this->mCardType = $card_type; $this->mIsValidate = true; $this->mFirstCommit = true; if($this->mThirdPorductType == mtopcard\ThirdElectricProduct) { $this->mElecticExtes['company_type'] = $params['company_type']; $this->mElecticExtes['use_type'] = $params['use_type']; $this->mElecticExtes['province'] = $params['province']; $this->mElecticExtes['city'] = $params['city']; $this->mElecticExtes['card_id'] = $params['card_id']; } } 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->mIsValidate = $validate; $this->mCardType = $card_type; $this->mRegionNo = $regin_no; $this->mIsTransfer = $isTransfer; $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; } } } 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() && $this->mThirdPorductType == mtopcard\ThirdElectricProduct) { $ext['company_type'] = $this->mElecticExtes['company_type']; $ext['use_type'] = $this->mElecticExtes['use_type']; $ext['province'] = $this->mElecticExtes['province']; $ext['city'] = $this->mElecticExtes['city']; $ext['card_id'] = $this->mElecticExtes['card_id']; } return $ext; } public function channel_params($order_id,$order_sn,$goods_id) { $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]; 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->mElecticExtes['company_type']; $params['use_type'] = $this->mElecticExtes['use_type']; $params['province'] = $this->mElecticExtes['province']; $params['city'] = $this->mElecticExtes['city']; $params['card_id'] = $this->mElecticExtes['card_id']; } } return $params; } public function queue_params() { $params = ['mchid' => $this->mMchid, 'buyer_id' => $this->mBuyerId, 'amount' => $this->mAmount, '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]; return $params; } }