123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492 |
- <?php
- namespace refill;
- use mtopcard;
- class order
- {
- private $mMchid;
- private $mBuyerId;
- private $mAmount;
- private $mCardNo;
- private $mMchOrder;
- private $mNotifyUrl;
- private $mIdCard;
- private $mCardName;
- private $mOrderTime;
- private $mCommitTimes;
- private $mLastOrderID;
- private $mOriginQuality;
- private $mCurQuality;
- private $mMchCardTypes; //用于产品和卡类型绑定的充值机构.
- private $mCardType;
- private $mRegionNo;
- private $mIsTransfer;
- private $mCardState;
- private $mBlack = 0;
- private $mIsValidate;
- private $mFirstCommit;
- private $mMatchRatio;
- //mCardType等于7的时候,需要这些参数
- private $mProductCode;
- private $mQuantity; //数量
- private $mThirdPorductType;
- private $mThirdCardType; // 三方充值账号类型
- private $mThirdExtes = []; //三方扩展参数
- public function __construct()
- {
- $this->mProductCode = '';
- $this->mThirdPorductType = 0;
- $this->mMatchRatio = false;
- $this->mMchCardTypes = [];
- }
- 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 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 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);
- 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'];
- }
- }
- }
- 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;
- $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 = 0;
- $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->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()) {
- 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)
- {
- $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->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,
- '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,
- '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;
- }
- }
|