123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- <?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 $mCardType;
- private $mRegionNo;
- private $mIsTransfer;
- private $mCardState;
- private $mIsValidate;
- private $mFirstCommit;
- private $mProductCode;
- private $mQuantity;
- private $mThirdCardType; // 三方充值账号类型
- public function __construct()
- {
- $this->mProductCode = '';
- }
- 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 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 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->mThirdCardType = $params['third_card_type'];
- $this->mRegionNo = 0;
- $this->mIsTransfer = false;
- $this->mCardState = 0;
- $this->mCardType = $card_type;
- $this->mIsValidate = true;
- $this->mFirstCommit = true;
- }
- 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] = mtopcard\valid_phone($this->mCardNo);
- $this->mIsValidate = $validate;
- $this->mCardType = $card_type;
- $this->mRegionNo = $regin_no;
- $this->mIsTransfer = $isTransfer;
- $this->mCardState = $card_state;
- }
- 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, 'account_type' => $this->mThirdCardType,
- 'quantity' => $this->mQuantity, 'user_account' => $this->mCardNo , 'pcode' => $this->mProductCode
- ];
- 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];
- if($this->is_third()) {
- $params['quantity'] = $this->mQuantity;
- $params['product_code'] = $this->mProductCode;
- $params['third_card_type'] = $this->mThirdCardType;
- $params['goods_id'] = $goods_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;
- }
- }
|