order.php 14 KB

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