order.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. namespace refill;
  3. use mtopcard;
  4. class order
  5. {
  6. private $mMchid;
  7. private $mBuyerId;
  8. private $mAmount;
  9. private $mCardNo;
  10. private $mMchOrder;
  11. private $mNotifyUrl;
  12. private $mIdCard;
  13. private $mCardName;
  14. private $mOrderTime;
  15. private $mCommitTimes;
  16. private $mLastOrderID;
  17. private $mOriginQuality;
  18. private $mCurQuality;
  19. private $mCardType;
  20. private $mRegionNo;
  21. private $mIsTransfer;
  22. private $mCardState;
  23. private $mIsValidate;
  24. private $mFirstCommit;
  25. private $mProductCode;
  26. private $mQuantity;
  27. private $mThirdCardType; // 三方充值账号类型
  28. public function __construct()
  29. {
  30. $this->mProductCode = '';
  31. }
  32. public function mchid() {
  33. return $this->mMchid;
  34. }
  35. public function buyer_id() {
  36. return $this->mBuyerId;
  37. }
  38. public function mch_order() {
  39. return $this->mMchOrder;
  40. }
  41. public function set_mchorder($mch_order) {
  42. $this->mMchOrder = $mch_order;
  43. }
  44. public function set_last_orderid($order_id) {
  45. $this->mLastOrderID = $order_id;
  46. }
  47. public function first_commit() {
  48. return $this->mFirstCommit;
  49. }
  50. public function spec() {
  51. return $this->mAmount;
  52. }
  53. public function card_no() {
  54. return $this->mCardNo;
  55. }
  56. public function card_type() {
  57. return $this->mCardType;
  58. }
  59. public function org_quality() {
  60. return $this->mOriginQuality;
  61. }
  62. public function cur_quality() {
  63. return $this->mCurQuality;
  64. }
  65. public function set_quality($org_quality,$quality) {
  66. $this->mOriginQuality = $org_quality;
  67. $this->mCurQuality = $quality;
  68. }
  69. public function order_time() {
  70. return $this->mOrderTime;
  71. }
  72. public function commit_times() {
  73. return $this->mCommitTimes;
  74. }
  75. public function commit_times_inc() {
  76. $this->mCommitTimes += 1;
  77. }
  78. public function elapse_secs() {
  79. return time() - $this->mOrderTime;
  80. }
  81. public function region_no() {
  82. return $this->mRegionNo;
  83. }
  84. public function pcode() {
  85. return $this->mProductCode;
  86. }
  87. public function last_order_id() {
  88. return $this->mLastOrderID;
  89. }
  90. public function validate() {
  91. return $this->mIsValidate;
  92. }
  93. public function quantity() {
  94. return $this->mQuantity;
  95. }
  96. public function card_state() {
  97. return $this->mCardState;
  98. }
  99. public function thrid_params()
  100. {
  101. $third_params = ['product_code' => $this->mProductCode,
  102. 'quantity' => $this->mQuantity,
  103. 'third_card_type' => $this->mThirdCardType];
  104. return $third_params;
  105. }
  106. public function is_transfer() {
  107. return $this->mIsTransfer;
  108. }
  109. public static function from_parameters($params)
  110. {
  111. $order = new order();
  112. $order->setParams($params);
  113. return $order;
  114. }
  115. public static function from_db(array $refill_info, array $order_info)
  116. {
  117. $order = new order();
  118. $order->setDbParams($refill_info, $order_info);
  119. return $order;
  120. }
  121. private function setDbParams(array $refill_info, array $order_info)
  122. {
  123. $this->mMchid = intval($refill_info['mchid']);
  124. $this->mBuyerId = intval($order_info['buyer_id']);
  125. $this->mAmount = intval($refill_info['refill_amount']);
  126. $this->mCardNo = $refill_info['card_no'];
  127. $this->mCardType = intval($refill_info['card_type']);
  128. $this->mRegionNo = intval($refill_info['regin_no']);
  129. $this->mOriginQuality = intval($refill_info['org_quality']);
  130. $this->mCurQuality = intval($refill_info['quality']);
  131. $this->mMchOrder = $refill_info['mch_order'] ?? '';
  132. $this->mNotifyUrl = $refill_info['notify_url'] ?? '';
  133. $this->mIdCard = $refill_info['idcard'] ?? '';
  134. $this->mCardName = $refill_info['card_name'] ?? '';
  135. $this->mOrderTime = intval($refill_info['order_time']);
  136. $this->mCommitTimes = intval($refill_info['commit_times']);
  137. $this->mLastOrderID = intval($refill_info['order_id']);
  138. $this->mCardState = intval($refill_info['cardno_state']);
  139. $this->mIsTransfer = $refill_info['is_transfer'] == 1;
  140. $this->mIsValidate = mtopcard\is_validate($this->mCardState);
  141. }
  142. public function is_third() {
  143. return $this->mCardType == 7;
  144. }
  145. public function is_oil() {
  146. return in_array($this->mCardType,[mtopcard\SinopecCard,mtopcard\PetroChinaCard]);
  147. }
  148. public function is_phone() {
  149. return in_array($this->mCardType,[mtopcard\ChinaMobileCard,mtopcard\ChinaUnicomCard,mtopcard\ChinaTelecomCard]);
  150. }
  151. private function setParams($params)
  152. {
  153. $this->mMchid = intval($params['mchid']);
  154. $this->mBuyerId = intval($params['buyer_id']);
  155. $this->mAmount = intval($params['amount']);
  156. $this->mCardNo = $params['card_no'];
  157. $this->mMchOrder = $params['mch_order'] ?? '';
  158. $this->mNotifyUrl = $params['notify_url'] ?? '';
  159. $this->mIdCard = $params['idcard'] ?? '';
  160. $this->mCardName = $params['card_name'] ?? '';
  161. $this->mOrderTime = $params['order_time'] ?? time();
  162. $this->mCommitTimes = $params['commit_times'] ?? 0;
  163. $this->mLastOrderID = $params['order_id'] ?? 0;
  164. $this->mQuantity = $params['quantity'] ?? 1;
  165. $this->mOriginQuality = intval($params['org_quality']) ?? 0;
  166. $card_type = intval($params['card_type']) ?? 0;
  167. if($card_type == 7) {
  168. $this->mCurQuality = $this->mOriginQuality;
  169. $this->mProductCode = $params['product_code'];
  170. $this->mThirdCardType = $params['third_card_type'];
  171. $this->mRegionNo = 0;
  172. $this->mIsTransfer = false;
  173. $this->mCardState = 0;
  174. $this->mCardType = $card_type;
  175. $this->mIsValidate = true;
  176. $this->mFirstCommit = true;
  177. }
  178. else
  179. {
  180. $this->mProductCode = '';
  181. $this->mCurQuality = intval($params['quality']) ?? 0;
  182. $this->mThirdCardType = 1; //deafult value
  183. if($card_type == 0)
  184. {
  185. $this->mFirstCommit = true;
  186. [$validate,$card_type,$regin_no,$isTransfer,$card_state] = mtopcard\valid_phone($this->mCardNo);
  187. $this->mIsValidate = $validate;
  188. $this->mCardType = $card_type;
  189. $this->mRegionNo = $regin_no;
  190. $this->mIsTransfer = $isTransfer;
  191. $this->mCardState = $card_state;
  192. }
  193. else {
  194. $this->mFirstCommit = false;
  195. $this->mCardType = $params['card_type'];
  196. $this->mRegionNo = $params['regin_no'];
  197. $this->mIsTransfer = $params['is_transfer'] == 1;
  198. $this->mCardState = $params['cardno_state'];
  199. $this->mIsValidate = $params['is_validate'] == 1;
  200. }
  201. }
  202. }
  203. public function ZeroRefillParams($order_id,$order_sn,$spec,$mch_amount,$channel_name,$channel_amout,$err_msg)
  204. {
  205. $refill_amount = $spec * $this->mQuantity;
  206. $params = ['order_id' => $order_id, 'order_sn' => $order_sn,
  207. 'mchid' => $this->mMchid, 'refill_amount' => $refill_amount, 'mch_order' => $this->mMchOrder,
  208. 'idcard' => $this->mIdCard, 'card_name' => $this->mCardName,
  209. 'notify_url' => $this->mNotifyUrl,
  210. 'channel_name' => $channel_name, 'mch_amount' => $mch_amount, 'channel_amount' => $channel_amout,
  211. 'order_time' => $this->mOrderTime, 'commit_times' => $this->mCommitTimes,
  212. 'commit_time' => time(), 'notify_state' => 1, 'notify_time' => time(),
  213. 'is_transfer' => $this->mIsTransfer ? 1 : 0, 'cardno_state' => $this->mCardState,
  214. 'card_type' => $this->mCardType, 'regin_no' => $this->mRegionNo,
  215. 'card_no' => $this->mCardNo, 'quality' => $this->mCurQuality, 'org_quality' => $this->mOriginQuality,
  216. 'err_msg' => $err_msg];
  217. return $params;
  218. }
  219. public function refill_params($order_id,$order_sn,$spec,$channel_name,$channel_amout,$mch_amount)
  220. {
  221. $refill_amount = $spec * $this->mQuantity;
  222. $params = ['order_id' => $order_id, 'order_sn' => $order_sn, 'mchid' => $this->mMchid,
  223. 'refill_amount' => $refill_amount, 'mch_order' => $this->mMchOrder,
  224. 'idcard' => $this->mIdCard, 'card_name' => $this->mCardName,
  225. 'notify_url' => $this->mNotifyUrl,'channel_name' => $channel_name,
  226. 'mch_amount' => $mch_amount, 'channel_amount' => $channel_amout,
  227. 'order_time' => $this->mOrderTime, 'commit_times' => $this->mCommitTimes,
  228. 'card_type' => $this->mCardType, 'regin_no' => $this->mRegionNo,
  229. 'is_transfer' => $this->mIsTransfer ? 1 : 0, 'cardno_state' => $this->mCardState,
  230. 'card_no' => $this->mCardNo, 'quality' => $this->mCurQuality, 'org_quality' => $this->mOriginQuality];
  231. return $params;
  232. }
  233. public function third_extparams($order_id,$order_sn)
  234. {
  235. $ext = ['order_id' => $order_id, 'order_sn' => $order_sn, 'account_type' => $this->mThirdCardType,
  236. 'quantity' => $this->mQuantity, 'user_account' => $this->mCardNo , 'pcode' => $this->mProductCode
  237. ];
  238. return $ext;
  239. }
  240. public function channel_params($order_id,$order_sn,$goods_id)
  241. {
  242. $params = ['order_sn' => $order_sn, 'idcard' => $this->mIdCard, 'card_name' => $this->mCardName,
  243. 'buyer_id' => $this->mBuyerId,
  244. 'quality' => $this->mCurQuality, 'order_id' => $order_id, 'regin_no' => $this->mRegionNo];
  245. if($this->is_third()) {
  246. $params['quantity'] = $this->mQuantity;
  247. $params['product_code'] = $this->mProductCode;
  248. $params['third_card_type'] = $this->mThirdCardType;
  249. $params['goods_id'] = $goods_id;
  250. }
  251. return $params;
  252. }
  253. public function queue_params()
  254. {
  255. $params = ['mchid' => $this->mMchid,
  256. 'buyer_id' => $this->mBuyerId,
  257. 'amount' => $this->mAmount,
  258. 'card_no' => $this->mCardNo,
  259. 'card_type' => $this->mCardType,
  260. 'regin_no' => $this->mRegionNo,
  261. 'org_quality' => $this->mOriginQuality,
  262. 'quality' => $this->mCurQuality,
  263. 'mch_order' => $this->mMchOrder,
  264. 'notify_url' => $this->mNotifyUrl,
  265. 'idcard' => $this->mIdCard,
  266. 'card_name' => $this->mCardName,
  267. 'order_time' => $this->mOrderTime,
  268. 'commit_times' => $this->mCommitTimes,
  269. 'is_transfer' => $this->mIsTransfer ? 1 : 0,
  270. 'cardno_state' => $this->mCardState,
  271. 'order_id' => $this->mLastOrderID,
  272. 'is_validate' => $this->mIsValidate];
  273. return $params;
  274. }
  275. }