util.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. <?php
  2. namespace refill;
  3. require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
  4. require_once(BASE_HELPER_PATH . '/queue/rdispatcher.php');
  5. require_once(BASE_HELPER_PATH . '/refill/policy/rlock.php');
  6. use queue;
  7. use mtopcard;
  8. use Log;
  9. use Exception;
  10. use Cache;
  11. use QueueClient;
  12. use refill;
  13. use trans_wapper;
  14. class util
  15. {
  16. const ThirdRefillAmount = 100;
  17. static function make_mobile()
  18. {
  19. static $prefix = ["139", "138", "137", "136", "135", "134", "159", "158", "157", "150", "151", "152",
  20. "188", "187", "182", "183", "184", "178", "130", "131", "132", "156", "155", "186", "185",
  21. "176", "133", "153", "189", "180", "181", "177"];
  22. $pos = mt_rand(0, count($prefix) - 1);
  23. $no = "{$prefix[$pos]}" . mt_rand(10000000, 99999999);
  24. return $no;
  25. }
  26. public static function can_refill($card_no, $card_type)
  27. {
  28. if ($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard) {
  29. $result = rcache('card_expired', '', "{$card_no}");
  30. if (empty($result)) {
  31. wcache("card_expired", [$card_no => time()], '');
  32. return [true, 0];
  33. } else {
  34. $latest = current($result);
  35. $cur = time();
  36. $success = ($cur - $latest) > 2;
  37. if ($success) {
  38. wcache("card_expired", [$card_no => time()], '');
  39. }
  40. return [$success, $latest + 2 - $cur];
  41. }
  42. } else {
  43. return [true, 0];
  44. }
  45. }
  46. public static function can_commit($card_no, $card_type)
  47. {
  48. if ($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard)
  49. {
  50. $result = rcache('card_expired', '', "{$card_no}");
  51. if (empty($result)) {
  52. wcache("card_expired", [$card_no => time()], '');
  53. return [true, 0];
  54. }
  55. else
  56. {
  57. $latest = current($result);
  58. $cur = time();
  59. $lowest = 30;
  60. if ($cur > $latest && ($cur - $latest) >= $lowest) {
  61. wcache("card_expired", [$card_no => time()], '');
  62. return [true, 0];
  63. } else {
  64. wcache("card_expired", [$card_no => $latest + $lowest], '');
  65. return [false, $latest + $lowest - $cur];
  66. }
  67. }
  68. }
  69. else {
  70. return [true, 0];
  71. }
  72. }
  73. static function read_card($card_no, $card_type = 0)
  74. {
  75. if (empty($card_no)) return false;
  76. $data = rcache($card_no, 'cardrefill-');
  77. if (empty($data)) {
  78. $mod_topcard = Model('topcard');
  79. $ret = $mod_topcard->get_card($card_no);
  80. if (empty($ret)) {
  81. if ($card_type === 0) {
  82. $card_type = mtopcard\card_type($card_no,$regin_no);
  83. }
  84. $bind_phone = util::make_mobile();
  85. $mod_topcard->add($card_no, $card_type, time(), $bind_phone);
  86. $data['bind_phone'] = $bind_phone;
  87. $data['refill_time'] = time();
  88. $data['times'] = 0;
  89. $data['black_card'] = 0;
  90. wcache($card_no, $data, 'cardrefill-');
  91. } else {
  92. $val = $ret[0];
  93. $data['bind_phone'] = $val['bind_phone'];
  94. $data['black_card'] = $val['black_card'];
  95. $data['refill_time'] = time();
  96. $data['times'] = 0;
  97. }
  98. }
  99. //之前没加black_card处理,这个字段不存在.
  100. if (!array_key_exists('black_card', $data)) {
  101. $data['black_card'] = 0;
  102. }
  103. return $data;
  104. }
  105. static function inc_card($card_no, $card_info)
  106. {
  107. $card_info['times'] += 1;
  108. $card_info['refill_time'] = time();
  109. wcache($card_no, $card_info, 'cardrefill-');
  110. }
  111. public static function del_card($card_no)
  112. {
  113. dcache($card_no, 'cardrefill-');
  114. }
  115. public static function set_black($card_no)
  116. {
  117. if (empty($card_no)) return false;
  118. $card_info = util::read_card($card_no);
  119. if (!empty($card_info)) {
  120. $card_info['black_card'] = 1;
  121. $mod_topcard = Model('topcard');
  122. $mod_topcard->table('topcard')->where(['card_no' => $card_no])->update(['black_card' => 1]);
  123. wcache($card_no, $card_info, 'cardrefill-');
  124. return true;
  125. } else {
  126. return false;
  127. }
  128. }
  129. private static function black_order($order_sn, $msg)
  130. {
  131. static $errMsgs = ["只能给主卡且卡状态正常的加油卡充值", "加油卡卡号错误或不支持"];
  132. if (empty($msg)) return false;
  133. if (in_array($msg, $errMsgs)) {
  134. $refill = Model('refill_order');
  135. $order = $refill->getOrderInfo(['order_sn' => $order_sn]);
  136. if (empty($order)) return false;
  137. $card_no = $order['card_no'];
  138. return util::set_black($card_no);
  139. }
  140. }
  141. public static function black_from_log($file_name)
  142. {
  143. $fn = fopen($file_name, "r");
  144. if (empty($fn)) {
  145. Log::record("Open File {$file_name} error.", Log::ERR);
  146. return false;
  147. } else {
  148. Log::record("{$file_name} start woring", Log::DEBUG);
  149. }
  150. $errs = [];
  151. while (!feof($fn)) {
  152. $line = trim(fgets($fn));
  153. $ret = preg_match('/[\w\W]+"channelOrderNumber":"(?P<order_sn>[^"]+)"[\w\W]+"message":"(?P<message>[\x{4e00}-\x{9fa5}]+)"[\w\W]+"status":109/u', $line, $matches);
  154. if ($ret) {
  155. $order_sn = $matches['order_sn'];
  156. $message = $matches['message'];
  157. self::black_order($order_sn, $message);
  158. $errs[$message] = empty($errs[$message]) ? 1 : $errs[$message] + 1;
  159. }
  160. }
  161. foreach ($errs as $msg => $count) {
  162. Log::record("msg:{$msg} count:{$count}", Log::DEBUG);
  163. }
  164. fclose($fn);
  165. return true;
  166. }
  167. public static function async_add($params, $period = 10)
  168. {
  169. try {
  170. QueueClient::async_push("AysncAddDispatcher", ['method' => 'add', 'params' => $params], $period);
  171. return true;
  172. } catch (Exception $ex) {
  173. return false;
  174. }
  175. }
  176. public static function async_notify($chname,$data, $period)
  177. {
  178. try {
  179. QueueClient::async_push("AysncAddDispatcher", ['method' => 'notify', 'params' => ['channel' => $chname, 'params' => $data]], $period);
  180. return true;
  181. } catch (Exception $ex) {
  182. return false;
  183. }
  184. }
  185. public static function push_add($params)
  186. {
  187. try
  188. {
  189. $ret = self::push_queue('add', $params);
  190. return $ret !== false;
  191. }
  192. catch (Exception $ex) {
  193. return false;
  194. }
  195. }
  196. public static function push_add_zero($params)
  197. {
  198. try
  199. {
  200. $ret = self::push_queue('add_zero', $params);
  201. return $ret !== false;
  202. }
  203. catch (Exception $ex) {
  204. return false;
  205. }
  206. }
  207. public static function push_addthird($params)
  208. {
  209. try
  210. {
  211. $ret = self::push_queue('addthird', $params);
  212. return $ret !== false;
  213. }
  214. catch (Exception $ex) {
  215. return false;
  216. }
  217. }
  218. public static function push_notify($chname, $params)
  219. {
  220. try
  221. {
  222. $ret = self::push_queue('notify', ['channel' => $chname, 'params' => $params]);
  223. return $ret !== false;
  224. }
  225. catch (Exception $ex) {
  226. return false;
  227. }
  228. }
  229. public static function push_notify_merchant($order_id, $manual)
  230. {
  231. try
  232. {
  233. $ret = self::push_queue('notify_mechant', ['order_id' => $order_id, 'manual' => $manual]);
  234. return $ret !== false;
  235. }
  236. catch (Exception $ex) {
  237. return false;
  238. }
  239. }
  240. public static function push_query($order_id)
  241. {
  242. try
  243. {
  244. $ret = self::push_queue('query', ['order_id' => $order_id]);
  245. return $ret !== false;
  246. }
  247. catch (Exception $ex) {
  248. return false;
  249. }
  250. }
  251. public static function push_query_net($order_id)
  252. {
  253. try {
  254. $ret = self::push_queue('query_net', ['order_id' => $order_id]);
  255. return $ret !== false;
  256. }
  257. catch (Exception $ex) {
  258. return false;
  259. }
  260. }
  261. public static function manual_success($order_id)
  262. {
  263. try
  264. {
  265. $ret = self::push_queue('manual_success', ['order_id' => $order_id]);
  266. return $ret !== false;
  267. }
  268. catch (Exception $ex) {
  269. return false;
  270. }
  271. }
  272. public static function manual_cancel($order_id)
  273. {
  274. try
  275. {
  276. $ret = self::push_queue('manual_cancel', ['order_id' => $order_id]);
  277. return $ret !== false;
  278. }
  279. catch (Exception $ex) {
  280. return false;
  281. }
  282. }
  283. public static function push_queue($method, $value)
  284. {
  285. if (defined('USE_COROUTINE') && USE_COROUTINE && defined('COROUTINE_HOOK_TCP') && COROUTINE_HOOK_TCP) {
  286. $queue_name = 'QUEUE_DISPATCHER_CO';
  287. $ins = Cache::getInstance('cacheredis');
  288. return $ins->lpush($queue_name, serialize([$method => $value]));
  289. }
  290. else {
  291. return queue\DispatcherClient::instance()->push($method,$value);
  292. }
  293. }
  294. public static function dispatcher_queue_length()
  295. {
  296. $ins = Cache::getInstance('cacheredis');
  297. return $ins->lLen('QUEUE_DISPATCHER_CO');
  298. }
  299. //统计提交订单数据
  300. public static function incr_commit_pre($chname, $card_type, $spec, $quality)
  301. {
  302. $ins = Cache::getInstance('cacheredis');
  303. $name = 'commit_speed_monitor';
  304. $sec = time();
  305. $key_sec = "{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
  306. $ins->hIncrBy($name, $key_sec, 1);
  307. }
  308. public static function hget_commit_pre_sec($chname, $card_type, $spec, $quality, $time_stamp)
  309. {
  310. $ins = Cache::getInstance('cacheredis');
  311. $name = 'commit_speed_monitor';
  312. $key_sec = "{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
  313. $value = $ins->hget($name, '', $key_sec);
  314. return intval($value);
  315. }
  316. //统计用户提交数据
  317. public static function incr_user_commit($mchid,$card_type, $spec,$quality)
  318. {
  319. $ins = Cache::getInstance('cacheredis');
  320. $name = 'user_monitor_commit';
  321. $sec = time();
  322. $key_sec = "{$mchid}-{$quality}-{$card_type}-{$spec}-{$sec}";
  323. $ins->hIncrBy($name, $key_sec, 1);
  324. }
  325. public static function incr_user_success($mchid,$card_type, $spec,$quality)
  326. {
  327. $ins = Cache::getInstance('cacheredis');
  328. $name = 'user_monitor_success';
  329. $sec = time();
  330. $key_sec = "{$mchid}-{$quality}-{$card_type}-{$spec}-{$sec}";
  331. $ins->hIncrBy($name, $key_sec, 1);
  332. }
  333. public static function incr_user_fail($mchid,$card_type, $spec,$quality)
  334. {
  335. $ins = Cache::getInstance('cacheredis');
  336. $name = 'user_monitor_fail';
  337. $sec = time();
  338. $key_sec = "{$mchid}-{$quality}-{$card_type}-{$spec}-{$sec}";
  339. $ins->hIncrBy($name, $key_sec, 1);
  340. }
  341. public static function incr_commit($chname, $card_type, $spec, $quality, $fsuccess = true)
  342. {
  343. $ins = Cache::getInstance('cacheredis');
  344. $name = 'channel_monitor_commit';
  345. $sec = time();
  346. if ($fsuccess) {
  347. $key_sec = "succ-{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
  348. } else {
  349. $key_sec = "fail-{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
  350. }
  351. $ins->hIncrBy($name, $key_sec, 1);
  352. }
  353. public static function hget_commit_sec($chname, $card_type, $spec, $quality, $time_stamp, $fsuccess = true)
  354. {
  355. $ins = Cache::getInstance('cacheredis');
  356. $name = 'channel_monitor_commit';
  357. if ($fsuccess) {
  358. $key_sec = "succ-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
  359. } else {
  360. $key_sec = "fail-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
  361. }
  362. $value = $ins->hget($name, '', $key_sec);
  363. return intval($value);
  364. }
  365. //统计回调通知数据
  366. public static function incr_notify($chname, $card_type, $spec, $quality, $fsuccess = true)
  367. {
  368. $ins = Cache::getInstance('cacheredis');
  369. $name = 'channel_monitor_notify';
  370. $sec = time();
  371. if ($fsuccess) {
  372. $key_sec = "succ-{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
  373. } else {
  374. $key_sec = "fail-{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
  375. }
  376. $ins->hIncrBy($name, $key_sec, 1);
  377. }
  378. public static function hget_notify_sec($chname, $card_type, $spec, $quality, $time_stamp, $fsuccess = true)
  379. {
  380. $ins = Cache::getInstance('cacheredis');
  381. $name = 'channel_monitor_notify';
  382. if ($fsuccess) {
  383. $key_sec = "succ-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
  384. } else {
  385. $key_sec = "fail-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
  386. }
  387. $value = $ins->hget($name, '', $key_sec);
  388. return intval($value);
  389. }
  390. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  391. public static function incr_amount_lock($mchid, $card_type, $spec)
  392. {
  393. if ($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard) {
  394. refill\rlock::incr_sys_storage($card_type,$spec,1);
  395. refill\rlock::incr_mch_total_storage($mchid,$card_type,$spec);
  396. refill\rlock::incr_mch_storage($mchid,$card_type,$spec,1);
  397. }
  398. }
  399. public static function decr_amount_lock($mchid, $card_type, $spec)
  400. {
  401. if ($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard) {
  402. refill\rlock::decr_sys_storage($card_type,$spec,1);
  403. refill\rlock::decr_mch_total_storage($mchid,$card_type,$spec);
  404. refill\rlock::decr_mch_storage($mchid,$card_type,$spec,1);
  405. }
  406. }
  407. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  408. public static function set_order_channels($mchid,$mchorder,$datas)
  409. {
  410. $ins = Cache::getInstance('cacheredis');
  411. $name = 'order_channels';
  412. $key = "{$mchid}-{$mchorder}";
  413. $ins->hset($name, '', [$key => serialize($datas)]);
  414. }
  415. public static function get_order_channels($mchid, $mchorder)
  416. {
  417. //old-name oil_exclude_channels
  418. $ins = Cache::getInstance('cacheredis');
  419. $name = 'order_channels';
  420. $key = "{$mchid}-{$mchorder}";
  421. $chnames = $ins->hget($name, '', $key);
  422. $chnames = unserialize($chnames);
  423. if(is_array($chnames)) {
  424. return $chnames;
  425. } else {
  426. return [];
  427. }
  428. }
  429. public static function del_order_channels($mchid, $mchorder)
  430. {
  431. $ins = Cache::getInstance('cacheredis');
  432. $name = 'order_channels';
  433. $key = "{$mchid}-{$mchorder}";
  434. $ins->hdel($name, '', $key);
  435. }
  436. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  437. public static function set_cancel_order($mchid,$mch_order)
  438. {
  439. $ins = Cache::getInstance('cacheredis');
  440. $name = 'order_cancel_hash';
  441. $key = "{$mchid}-{$mch_order}";
  442. $ins->hset($name, '', [$key=> 1]);
  443. }
  444. public static function query_cancel_order($mchid,$mch_order)
  445. {
  446. $ins = Cache::getInstance('cacheredis');
  447. $name = 'order_cancel_hash';
  448. $key = "{$mchid}-{$mch_order}";
  449. $value = $ins->hget($name,'',$key);
  450. return $value;
  451. }
  452. public static function del_cancel_order($mchid,$mch_order)
  453. {
  454. $ins = Cache::getInstance('cacheredis');
  455. $name = 'order_cancel_hash';
  456. $key = "{$mchid}-{$mch_order}";
  457. $ins->hdel($name, $key);
  458. }
  459. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  460. public static function set_next_order($mchid,$mch_order)
  461. {
  462. $ins = Cache::getInstance('cacheredis');
  463. $name = 'order_next_hash';
  464. $key = "{$mchid}-{$mch_order}";
  465. $ins->hset($name, '', [$key=> 1]);
  466. }
  467. public static function query_next_order($mchid,$mch_order)
  468. {
  469. $ins = Cache::getInstance('cacheredis');
  470. $name = 'order_next_hash';
  471. $key = "{$mchid}-{$mch_order}";
  472. $value = $ins->hget($name,'',$key);
  473. return $value;
  474. }
  475. public static function del_next_order($mchid,$mch_order)
  476. {
  477. $ins = Cache::getInstance('cacheredis');
  478. $name = 'order_success_hash';
  479. $key = "{$mchid}-{$mch_order}";
  480. $ins->hdel($name, $key);
  481. }
  482. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  483. public static function push_queue_order($mchid,$mch_order,$order_state)
  484. {
  485. if(empty($mch_order)) return;
  486. $ins = Cache::getInstance('cacheredis');
  487. $name = 'merchant_order_query';
  488. $key = "{$mchid}-{$mch_order}";
  489. $ins->hset($name, '', [$key => $order_state]);
  490. }
  491. public static function del_queue_order($mchid,$mch_order)
  492. {
  493. if(empty($mch_order)) return;
  494. $ins = Cache::getInstance('cacheredis');
  495. $name = 'merchant_order_query';
  496. $key = "{$mchid}-{$mch_order}";
  497. $ret = $ins->hdel($name, '', $key);
  498. }
  499. public static function pop_queue_order($mchid,$mch_order)
  500. {
  501. util::del_order_channels($mchid,$mch_order);
  502. Model('refill_order')->edit_detail($mchid,$mch_order,['order_state' => ORDER_STATE_HANDLED]);
  503. $ins = Cache::getInstance('cacheredis');
  504. $name = 'merchant_order_query';
  505. $key = "{$mchid}-{$mch_order}";
  506. $ret = $ins->hdel($name, '', $key);
  507. }
  508. public static function query_queue_order($mchid,$mch_order)
  509. {
  510. $ins = Cache::getInstance('cacheredis');
  511. $name = 'merchant_order_query';
  512. $key = "{$mchid}-{$mch_order}";
  513. $value = $ins->hget($name,'',$key);
  514. return $value;
  515. }
  516. public static function need_check($net_errno)
  517. {
  518. if(empty($net_errno)) return false;
  519. [$type,$code] = explode('-',$net_errno);
  520. $code = intval($code);
  521. if($type == "CURL") {
  522. static $errors = [CURLE_GOT_NOTHING,CURLE_RECV_ERROR];
  523. return in_array($code,$errors);
  524. } elseif($type == "HTTP") {
  525. static $excludes = [404];
  526. return !in_array($code,$excludes);
  527. } else {
  528. return false;
  529. }
  530. }
  531. public static function order_errflag($net_errno) {
  532. return ($net_errno === 'ORDER_CREATE_FAIL');
  533. }
  534. public static function onOrderSuccess($refill_info,$order_info)
  535. {
  536. $data = store_member::instance()->get_member($order_info['store_id']);
  537. if(empty($data)) {
  538. Log::record("cannot find member when store_id={$order_info['store_id']}",Log::ERR);
  539. return false;
  540. }
  541. $data['order_sn'] = $refill_info['order_sn'];
  542. $data['amount'] = $refill_info['channel_amount'];
  543. $model_pd = Model('predeposit');
  544. $model_pd->changePd('order_pay',$data,true);
  545. return true;
  546. }
  547. public static function getProvider($name,$type = 'RefillPhone')
  548. {
  549. $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
  550. if(!file_exists($file)){
  551. Log::record("provider api file={$file} not exist.",Log::DEBUG);
  552. return false;
  553. } else {
  554. require_once($file);
  555. Log::record("file={$file} load success.",Log::DEBUG);
  556. }
  557. $class_name = "refill\\{$name}\\{$type}";
  558. if (class_exists($class_name, false)) {
  559. $caller = new $class_name([]);
  560. return $caller;
  561. } else {
  562. $error = "Base Error: class {$class_name} isn't exists!";
  563. Log::record($error, Log::ERR);
  564. return false;
  565. }
  566. }
  567. public static function xmlToArray($xml)
  568. {
  569. $object = simplexml_load_string($xml);
  570. $val = json_decode(json_encode($object), true);
  571. $msg = json_encode($val);
  572. Log::record("xmlToArray result={$msg}", Log::DEBUG);
  573. return $val;
  574. }
  575. //for tester
  576. public static function send_normal($order_sn)
  577. {
  578. $status = mt_rand(1,100);
  579. if($status > 97) {
  580. $status = 1;
  581. } else {
  582. $status = 0;
  583. }
  584. $url = BASE_SITE_URL . "/mobile/callback/refill_baidu.php";
  585. go(function () use ($url, $status,$order_sn)
  586. {
  587. sleep(3);
  588. while (true)
  589. {
  590. $resp = http_request($url,['status' => $status,'order_sn' => $order_sn],'GET', false, [], $net_errno);
  591. if($resp == 'SUCCESS') {
  592. break;
  593. }
  594. }
  595. Log::record("resp = {$resp}",Log::DEBUG);
  596. });
  597. }
  598. public static function send_quick($order_sn)
  599. {
  600. $status = mt_rand(1,10);
  601. if($status > 3) {
  602. $status = 1;
  603. } else {
  604. $status = 0;
  605. }
  606. $url = BASE_SITE_URL . "/mobile/callback/refill_baidu.php";
  607. go(function () use ($url, $status,$order_sn)
  608. {
  609. sleep(3);
  610. while (true)
  611. {
  612. $resp = http_request($url,['status' => $status,'order_sn' => $order_sn],'GET', false, [], $net_errno);
  613. if($resp == 'SUCCESS') {
  614. break;
  615. }
  616. }
  617. Log::record("resp = {$resp}",Log::DEBUG);
  618. });
  619. }
  620. public static function retry_canceled_order($order_id)
  621. {
  622. $mod_order = Model('vr_order');
  623. $mod_refill = Model('refill_order');
  624. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
  625. $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id,'inner_status' => 0]);
  626. if(empty($refill_info) || empty($order_info)) {
  627. return [false,'无此订单或者订单已经重试中了...'];
  628. }
  629. $tran = new trans_wapper($mod_order,'notify change order state trans');
  630. try
  631. {
  632. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id], '*', true, true);
  633. $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id, 'inner_status' => 0], '*', true, true);
  634. $order_state = intval($order_info['order_state']);
  635. if(empty($refill_info) || $refill_info['is_retrying'] == 1 || $order_state != ORDER_STATE_CANCEL) {
  636. $tran->commit();
  637. return [false,'订单已经在重试'];
  638. }
  639. $mod_refill->edit($order_id, ['is_retrying' => 1]);
  640. $tran->commit();
  641. $order = refill\order::from_db($refill_info,$order_info);
  642. $params = $order->queue_params();
  643. if(util::push_add($params)) {
  644. return [true,''];
  645. } else {
  646. return [false,'加入队列出错'];
  647. }
  648. }
  649. catch (Exception $ex) {
  650. $tran->rollback();
  651. Log::record($ex->getMessage(),Log::ERR);
  652. return [false,"{$ex->getMessage()}"];
  653. }
  654. }
  655. }