order.php 13 KB

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