order.php 11 KB

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